Search in sources :

Example 6 with IntegrationService

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.");
}
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

IntegrationService (com.epam.ta.reportportal.core.integration.util.IntegrationService)6 Integration (com.epam.ta.reportportal.entity.integration.Integration)6 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)6 Project (com.epam.ta.reportportal.entity.project.Project)4 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)4 IntegrationUpdatedEvent (com.epam.ta.reportportal.core.events.activity.IntegrationUpdatedEvent)3 IntegrationActivityResource (com.epam.ta.reportportal.ws.model.activity.IntegrationActivityResource)3 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)2 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)2 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)2 IntegrationCreatedEvent (com.epam.ta.reportportal.core.events.activity.IntegrationCreatedEvent)2 CreateIntegrationHandler (com.epam.ta.reportportal.core.integration.CreateIntegrationHandler)2 IntegrationRepository (com.epam.ta.reportportal.dao.IntegrationRepository)2 IntegrationTypeRepository (com.epam.ta.reportportal.dao.IntegrationTypeRepository)2 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)2 IntegrationType (com.epam.ta.reportportal.entity.integration.IntegrationType)2 TO_ACTIVITY_RESOURCE (com.epam.ta.reportportal.ws.converter.converters.IntegrationConverter.TO_ACTIVITY_RESOURCE)2 EntryCreatedRS (com.epam.ta.reportportal.ws.model.EntryCreatedRS)2 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)2