How to use findByNameAndVersionId method of com.testsigma.service.ElementService class

Best Testsigma code snippet using com.testsigma.service.ElementService.findByNameAndVersionId

Source:ElementService.java Github

copy

Full Screen

...49 private final ApplicationEventPublisher applicationEventPublisher;50 public List<Element> findByNameInAndWorkspaceVersionId(List<String> elementNames, Long workspaceVersionId) {51 return elementRepository.findByNameInAndWorkspaceVersionId(elementNames, workspaceVersionId);52 }53 public Element findByNameAndVersionId(String name, Long versionId) {54 return elementRepository.findFirstElementByNameAndWorkspaceVersionId(name,55 versionId);56 }57 public Element find(Long id) throws ResourceNotFoundException {58 return elementRepository.findById(id)59 .orElseThrow(() -> new ResourceNotFoundException("Element is not found with id: " + id));60 }61 public Page<Element> findAll(Specification<Element> specification, Pageable pageable) {62 return elementRepository.findAll(specification, pageable);63 }64 public Element save(Element element) {65 return elementRepository.save(element);66 }67 public Element create(Element element) {68 element = this.save(element);69 this.markAsDuplicated(element);70 publishEvent(element, EventType.CREATE);71 return element;72 }73 public Element update(Element element, String oldName, String previousLocatorValue, LocatorType previousLocatorType, Long previousScreenNameId)74 throws ResourceNotFoundException {75 element = this.save(element);76 if (!Objects.equals(element.getLocatorValue(), previousLocatorValue) || element.getLocatorType() != previousLocatorType77 || !Objects.equals(element.getScreenNameId(), previousScreenNameId)) {78 this.markAsDuplicated(element);79 this.resetDuplicate(element.getWorkspaceVersionId(), previousLocatorValue, previousLocatorType, previousScreenNameId);80 }81 this.eventCallForUpdate(oldName, element);82 return element;83 }84 public Element update(Element element, String oldName) {85 element = this.save(element);86 this.eventCallForUpdate(oldName, element);87 return element;88 }89 public void delete(Element element) {90 elementRepository.delete(element);91 this.resetDuplicate(element.getWorkspaceVersionId(), element.getLocatorValue(), element.getLocatorType(), element.getScreenNameId());92 publishEvent(element, EventType.DELETE);93 }94 public void bulkDelete(Long[] ids, Long workspaceVersionId) throws Exception {95 Boolean allIdsDeleted = true;96 TestCaseSpecificationsBuilder builder = new TestCaseSpecificationsBuilder();97 for (Long id : ids) {98 List<SearchCriteria> params = new ArrayList<>();99 Element element = this.find(id);100 params.add(new SearchCriteria("element", SearchOperation.EQUALITY, element.getName()));101 params.add(new SearchCriteria("workspaceVersionId", SearchOperation.EQUALITY, workspaceVersionId));102 builder.setParams(params);103 Specification<TestCase> spec = builder.build();104 Page<TestCase> linkedTestCases = testCaseService.findAll(spec, PageRequest.of(0, 1));105 if (linkedTestCases.getTotalElements() == 0) {106 this.delete(element);107 } else {108 allIdsDeleted = false;109 }110 }111 if (!allIdsDeleted) {112 throw new DataIntegrityViolationException("dataIntegrityViolationException: Failed to delete some of the Elements " +113 "since they are already associated to some Test Cases.");114 }115 }116 public void bulkUpdateScreenNameAndTags(Long[] ids, String screenName, String[] tags) throws ResourceNotFoundException {117 for (Long id : ids) {118 Element element = find(id);119 if (screenName.length() > 0) {120 ElementScreenNameRequest elementScreenNameRequest = new ElementScreenNameRequest();121 elementScreenNameRequest.setName(screenName);122 elementScreenNameRequest.setWorkspaceVersionId(element.getWorkspaceVersionId());123 ElementScreenName elementScreenName = screenNameService.save(elementScreenNameRequest);124 element.setScreenNameId(elementScreenName.getId());125 }126 update(element, element.getName(), element.getLocatorValue(), element.getLocatorType(), element.getScreenNameId());127 tagService.updateTags(Arrays.asList(tags), TagType.ELEMENT, id);128 }129 }130 public void updateByName(String name, ElementRequest elementRequest) {131 Element element = findByNameAndVersionId(name, elementRequest.getWorkspaceVersionId());132 String oldName = element.getName();133 elementMapper.merge(elementRequest, element);134 update(element, oldName);135 }136 public void publishEvent(Element element, EventType eventType) {137 ElementEvent<Element> event = createEvent(element, eventType);138 log.info("Publishing event - " + event.toString());139 applicationEventPublisher.publishEvent(event);140 }141 public ElementEvent<Element> createEvent(Element element, EventType eventType) {142 ElementEvent<Element> event = new ElementEvent<>();143 event.setEventData(element);144 event.setEventType(eventType);145 return event;...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful