Search in sources :

Example 1 with PatternUpdatedEvent

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());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) PatternTemplateActivityResource(com.epam.ta.reportportal.ws.model.activity.PatternTemplateActivityResource) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) PatternUpdatedEvent(com.epam.ta.reportportal.core.events.activity.PatternUpdatedEvent) PatternTemplate(com.epam.ta.reportportal.entity.pattern.PatternTemplate) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

PatternUpdatedEvent (com.epam.ta.reportportal.core.events.activity.PatternUpdatedEvent)1 PatternTemplate (com.epam.ta.reportportal.entity.pattern.PatternTemplate)1 Project (com.epam.ta.reportportal.entity.project.Project)1 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)1 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)1 PatternTemplateActivityResource (com.epam.ta.reportportal.ws.model.activity.PatternTemplateActivityResource)1