Search in sources :

Example 1 with IntegrationService

use of com.epam.ta.reportportal.core.integration.util.IntegrationService in project service-api by reportportal.

the class CreateIntegrationHandlerImpl method createGlobalIntegration.

@Override
public EntryCreatedRS createGlobalIntegration(IntegrationRQ createRequest, String pluginName, ReportPortalUser user) {
    IntegrationType integrationType = integrationTypeRepository.findByName(pluginName).orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, pluginName));
    IntegrationService integrationService = integrationServiceMapping.getOrDefault(integrationType.getName(), this.basicIntegrationService);
    String integrationName = ofNullable(createRequest.getName()).map(String::toLowerCase).map(name -> {
        validateGlobalIntegrationName(name, integrationType);
        return name;
    }).orElseThrow(() -> new ReportPortalException(ErrorType.INCORRECT_INTEGRATION_NAME, "Integration name should be not null"));
    createRequest.setName(integrationName);
    Integration integration = integrationService.createIntegration(createRequest, integrationType);
    integration.setCreator(user.getUsername());
    integrationService.checkConnection(integration);
    integrationRepository.save(integration);
    return new EntryCreatedRS(integration.getId());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) IntegrationCreatedEvent(com.epam.ta.reportportal.core.events.activity.IntegrationCreatedEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) StringUtils(org.apache.commons.lang3.StringUtils) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Service(org.springframework.stereotype.Service) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.IntegrationConverter.TO_ACTIVITY_RESOURCE) IntegrationRepository(com.epam.ta.reportportal.dao.IntegrationRepository) CreateIntegrationHandler(com.epam.ta.reportportal.core.integration.CreateIntegrationHandler) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) Optional.ofNullable(java.util.Optional.ofNullable) Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IntegrationTypeRepository(com.epam.ta.reportportal.dao.IntegrationTypeRepository) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) IntegrationRQ(com.epam.ta.reportportal.ws.model.integration.IntegrationRQ) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) IntegrationUpdatedEvent(com.epam.ta.reportportal.core.events.activity.IntegrationUpdatedEvent) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) IntegrationActivityResource(com.epam.ta.reportportal.ws.model.activity.IntegrationActivityResource) IntegrationService(com.epam.ta.reportportal.core.integration.util.IntegrationService) Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType) IntegrationService(com.epam.ta.reportportal.core.integration.util.IntegrationService)

Example 2 with IntegrationService

use of com.epam.ta.reportportal.core.integration.util.IntegrationService in project service-api by reportportal.

the class CreateIntegrationHandlerImpl method updateGlobalIntegration.

@Override
public OperationCompletionRS updateGlobalIntegration(Long id, IntegrationRQ updateRequest) {
    final Integration integration = integrationRepository.findGlobalById(id).orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, id));
    ofNullable(updateRequest.getName()).map(String::toLowerCase).ifPresent(name -> {
        if (!name.equals(integration.getName())) {
            validateGlobalIntegrationName(name, integration.getType());
            updateRequest.setName(name);
        }
    });
    IntegrationService integrationService = integrationServiceMapping.getOrDefault(integration.getType().getName(), this.basicIntegrationService);
    Integration updatedIntegration = integrationService.updateIntegration(integration, updateRequest);
    integrationService.checkConnection(integration);
    integrationRepository.save(updatedIntegration);
    return new OperationCompletionRS("Integration with id = " + updatedIntegration.getId() + " has been successfully updated.");
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IntegrationService(com.epam.ta.reportportal.core.integration.util.IntegrationService) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 3 with IntegrationService

use of com.epam.ta.reportportal.core.integration.util.IntegrationService in project service-api by reportportal.

the class CreateIntegrationHandlerImpl method createProjectIntegration.

@Override
public EntryCreatedRS createProjectIntegration(String projectName, IntegrationRQ createRequest, String pluginName, ReportPortalUser user) {
    Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
    IntegrationType integrationType = integrationTypeRepository.findByName(pluginName).orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, pluginName));
    IntegrationService integrationService = integrationServiceMapping.getOrDefault(integrationType.getName(), this.basicIntegrationService);
    String integrationName = ofNullable(createRequest.getName()).map(String::toLowerCase).map(name -> {
        validateProjectIntegrationName(name, integrationType, project);
        return name;
    }).orElseThrow(() -> new ReportPortalException(ErrorType.INCORRECT_INTEGRATION_NAME, "Integration name should be not null"));
    createRequest.setName(integrationName);
    Integration integration = integrationService.createIntegration(createRequest, integrationType);
    integration.setProject(project);
    integration.setCreator(user.getUsername());
    integrationService.checkConnection(integration);
    integrationRepository.save(integration);
    messageBus.publishActivity(new IntegrationCreatedEvent(TO_ACTIVITY_RESOURCE.apply(integration), user.getUserId(), user.getUsername()));
    return new EntryCreatedRS(integration.getId());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) IntegrationCreatedEvent(com.epam.ta.reportportal.core.events.activity.IntegrationCreatedEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) StringUtils(org.apache.commons.lang3.StringUtils) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Service(org.springframework.stereotype.Service) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.IntegrationConverter.TO_ACTIVITY_RESOURCE) IntegrationRepository(com.epam.ta.reportportal.dao.IntegrationRepository) CreateIntegrationHandler(com.epam.ta.reportportal.core.integration.CreateIntegrationHandler) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) Optional.ofNullable(java.util.Optional.ofNullable) Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IntegrationTypeRepository(com.epam.ta.reportportal.dao.IntegrationTypeRepository) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) IntegrationRQ(com.epam.ta.reportportal.ws.model.integration.IntegrationRQ) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) IntegrationUpdatedEvent(com.epam.ta.reportportal.core.events.activity.IntegrationUpdatedEvent) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) IntegrationActivityResource(com.epam.ta.reportportal.ws.model.activity.IntegrationActivityResource) IntegrationService(com.epam.ta.reportportal.core.integration.util.IntegrationService) IntegrationCreatedEvent(com.epam.ta.reportportal.core.events.activity.IntegrationCreatedEvent) Project(com.epam.ta.reportportal.entity.project.Project) Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType) IntegrationService(com.epam.ta.reportportal.core.integration.util.IntegrationService)

Example 4 with IntegrationService

use of com.epam.ta.reportportal.core.integration.util.IntegrationService in project service-api by reportportal.

the class GetIntegrationHandlerImpl method testConnection.

@Override
public boolean testConnection(Long integrationId, String projectName) {
    Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
    Integration integration = integrationRepository.findByIdAndProjectId(integrationId, project.getId()).orElseGet(() -> integrationRepository.findGlobalById(integrationId).orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, integrationId)));
    IntegrationService integrationService = integrationServiceMapping.getOrDefault(integration.getType().getName(), this.basicIntegrationService);
    return integrationService.checkConnection(integration);
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IntegrationService(com.epam.ta.reportportal.core.integration.util.IntegrationService)

Example 5 with IntegrationService

use of com.epam.ta.reportportal.core.integration.util.IntegrationService in project service-api by reportportal.

the class GetIntegrationHandlerImpl method testConnection.

@Override
public boolean testConnection(Long integrationId) {
    Integration integration = integrationRepository.findGlobalById(integrationId).orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, integrationId));
    IntegrationService integrationService = integrationServiceMapping.getOrDefault(integration.getType().getName(), this.basicIntegrationService);
    return integrationService.checkConnection(integration);
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IntegrationService(com.epam.ta.reportportal.core.integration.util.IntegrationService)

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