use of com.epam.ta.reportportal.entity.pattern.PatternTemplate in project service-api by reportportal.
the class DeleteProjectSettingsHandlerImpl method deletePatternTemplate.
@Override
public OperationCompletionRS deletePatternTemplate(String projectName, ReportPortalUser user, Long id) {
Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
PatternTemplate patternTemplate = patternTemplateRepository.findByIdAndProjectId(id, project.getId()).orElseThrow(() -> new ReportPortalException(ErrorType.PATTERN_TEMPLATE_NOT_FOUND_IN_PROJECT, id, project.getName()));
PatternTemplateActivityResource before = PatternTemplateConverter.TO_ACTIVITY_RESOURCE.apply(patternTemplate);
patternTemplateRepository.deleteById(patternTemplate.getId());
messageBus.publishActivity(new PatternDeletedEvent(user.getUserId(), user.getUsername(), before));
return new OperationCompletionRS(Suppliers.formattedSupplier("Pattern template with id = '{}' has been successfully removed.", id).get());
}
use of com.epam.ta.reportportal.entity.pattern.PatternTemplate in project service-api by reportportal.
the class UpdateProjectSettingsHandlerImpl method updatePatternTemplate.
@Override
public OperationCompletionRS updatePatternTemplate(Long id, String projectName, UpdatePatternTemplateRQ updatePatternTemplateRQ, ReportPortalUser user) {
Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
PatternTemplate patternTemplate = patternTemplateRepository.findById(id).orElseThrow(() -> new ReportPortalException(ErrorType.PATTERN_TEMPLATE_NOT_FOUND_IN_PROJECT, id, project.getId()));
final String name = StringUtils.trim(updatePatternTemplateRQ.getName());
if (!patternTemplate.getName().equalsIgnoreCase(name)) {
BusinessRule.expect(patternTemplateRepository.existsByProjectIdAndNameIgnoreCase(project.getId(), name), equalTo(false)).verify(ErrorType.RESOURCE_ALREADY_EXISTS, name);
}
PatternTemplateActivityResource before = PatternTemplateConverter.TO_ACTIVITY_RESOURCE.apply(patternTemplate);
patternTemplate.setName(name);
patternTemplate.setEnabled(updatePatternTemplateRQ.getEnabled());
PatternTemplateActivityResource after = PatternTemplateConverter.TO_ACTIVITY_RESOURCE.apply(patternTemplate);
messageBus.publishActivity(new PatternUpdatedEvent(user.getUserId(), user.getUsername(), before, after));
return new OperationCompletionRS(Suppliers.formattedSupplier("Pattern template with ID = '{}' has been successfully updated", id).get());
}
use of com.epam.ta.reportportal.entity.pattern.PatternTemplate in project service-api by reportportal.
the class PatternTemplateConverterTest method toResourceTest.
@Test
public void toResourceTest() {
PatternTemplate patternTemplate = get();
PatternTemplateResource resource = PatternTemplateConverter.TO_RESOURCE.apply(patternTemplate);
assertEquals(patternTemplate.getId(), resource.getId());
assertEquals(patternTemplate.getTemplateType().name(), resource.getType());
assertEquals(patternTemplate.getName(), resource.getName());
assertEquals(patternTemplate.getValue(), resource.getValue());
assertEquals(patternTemplate.isEnabled(), resource.getEnabled());
}
use of com.epam.ta.reportportal.entity.pattern.PatternTemplate in project service-api by reportportal.
the class PatternTemplateConverterTest method toActivityResourceTest.
@Test
public void toActivityResourceTest() {
PatternTemplate patternTemplate = get();
PatternTemplateActivityResource resource = PatternTemplateConverter.TO_ACTIVITY_RESOURCE.apply(patternTemplate);
assertEquals(patternTemplate.getId(), resource.getId());
assertEquals(patternTemplate.getProjectId(), resource.getProjectId());
assertEquals(patternTemplate.getName(), resource.getName());
}
use of com.epam.ta.reportportal.entity.pattern.PatternTemplate in project service-api by reportportal.
the class PatternTemplateConverterTest method get.
private PatternTemplate get() {
PatternTemplate patternTemplate = new PatternTemplate();
patternTemplate.setId(1L);
patternTemplate.setProjectId(1L);
patternTemplate.setTemplateType(PatternTemplateType.STRING);
patternTemplate.setEnabled(true);
patternTemplate.setValue("qwe");
patternTemplate.setName("name");
return patternTemplate;
}
Aggregations