use of com.epam.ta.reportportal.core.integration.util.IntegrationService 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.");
}
Aggregations