use of com.epam.ta.reportportal.core.events.activity.PatternUpdatedEvent 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());
}
Aggregations