Search in sources :

Example 1 with IntegrationUpdatedEvent

use of com.epam.ta.reportportal.core.events.activity.IntegrationUpdatedEvent in project service-api by reportportal.

the class CreateIntegrationHandlerImpl method updateProjectIntegration.

@Override
public OperationCompletionRS updateProjectIntegration(Long id, String projectName, IntegrationRQ updateRequest, ReportPortalUser user) {
    Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
    final Integration integration = integrationRepository.findByIdAndProjectId(id, project.getId()).orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, id));
    IntegrationActivityResource beforeUpdate = TO_ACTIVITY_RESOURCE.apply(integration);
    ofNullable(updateRequest.getName()).map(String::toLowerCase).ifPresent(name -> {
        if (!name.equals(integration.getName())) {
            validateProjectIntegrationName(name, integration.getType(), project);
            updateRequest.setName(name);
        }
    });
    IntegrationService integrationService = integrationServiceMapping.getOrDefault(integration.getType().getName(), this.basicIntegrationService);
    Integration updatedIntegration = integrationService.updateIntegration(integration, updateRequest);
    updatedIntegration.setProject(project);
    integrationService.checkConnection(integration);
    integrationRepository.save(updatedIntegration);
    messageBus.publishActivity(new IntegrationUpdatedEvent(user.getUserId(), user.getUsername(), beforeUpdate, TO_ACTIVITY_RESOURCE.apply(updatedIntegration)));
    return new OperationCompletionRS("Integration with id = " + updatedIntegration.getId() + " has been successfully updated.");
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) Integration(com.epam.ta.reportportal.entity.integration.Integration) IntegrationUpdatedEvent(com.epam.ta.reportportal.core.events.activity.IntegrationUpdatedEvent) IntegrationActivityResource(com.epam.ta.reportportal.ws.model.activity.IntegrationActivityResource) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IntegrationService(com.epam.ta.reportportal.core.integration.util.IntegrationService) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

IntegrationUpdatedEvent (com.epam.ta.reportportal.core.events.activity.IntegrationUpdatedEvent)1 IntegrationService (com.epam.ta.reportportal.core.integration.util.IntegrationService)1 Integration (com.epam.ta.reportportal.entity.integration.Integration)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 IntegrationActivityResource (com.epam.ta.reportportal.ws.model.activity.IntegrationActivityResource)1