Search in sources :

Example 1 with ReportPortalExtensionPoint

use of com.epam.reportportal.extension.ReportPortalExtensionPoint in project service-api by reportportal.

the class ExecuteIntegrationHandlerImpl method executeCommand.

@Override
public Object executeCommand(ReportPortalUser.ProjectDetails projectDetails, Long integrationId, String command, Map<String, Object> executionParams) {
    Integration integration = integrationRepository.findByIdAndProjectId(integrationId, projectDetails.getProjectId()).orElseGet(() -> integrationRepository.findGlobalById(integrationId).orElseThrow(() -> new ReportPortalException(INTEGRATION_NOT_FOUND, integrationId)));
    ReportPortalExtensionPoint pluginInstance = pluginBox.getInstance(integration.getType().getName(), ReportPortalExtensionPoint.class).orElseThrow(() -> new ReportPortalException(BAD_REQUEST_ERROR, formattedSupplier("Plugin for '{}' isn't installed", integration.getType().getName()).get()));
    Boolean asyncMode = ofNullable((Boolean) executionParams.get(ASYNC_MODE)).orElse(false);
    executionParams.put(PROJECT_ID, projectDetails.getProjectId());
    return ofNullable(pluginInstance.getCommandToExecute(command)).map(it -> {
        if (asyncMode) {
            supplyAsync(() -> it.executeCommand(integration, executionParams));
            return new OperationCompletionRS(formattedSupplier("Command '{}' accepted for processing in plugin", command, integration.getType().getName()).get());
        }
        return it.executeCommand(integration, executionParams);
    }).orElseThrow(() -> new ReportPortalException(BAD_REQUEST_ERROR, formattedSupplier("Command '{}' is not found in plugin {}.", command, integration.getType().getName()).get()));
}
Also used : Async(org.springframework.scheduling.annotation.Async) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) Optional.ofNullable(java.util.Optional.ofNullable) Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) INTEGRATION_NOT_FOUND(com.epam.ta.reportportal.ws.model.ErrorType.INTEGRATION_NOT_FOUND) Supplier(java.util.function.Supplier) PluginBox(com.epam.ta.reportportal.core.plugin.PluginBox) ReportPortalExtensionPoint(com.epam.reportportal.extension.ReportPortalExtensionPoint) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Service(org.springframework.stereotype.Service) ExecuteIntegrationHandler(com.epam.ta.reportportal.core.integration.ExecuteIntegrationHandler) Map(java.util.Map) BAD_REQUEST_ERROR(com.epam.ta.reportportal.ws.model.ErrorType.BAD_REQUEST_ERROR) IntegrationRepository(com.epam.ta.reportportal.dao.IntegrationRepository) Suppliers.formattedSupplier(com.epam.ta.reportportal.commons.validation.Suppliers.formattedSupplier) Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ReportPortalExtensionPoint(com.epam.reportportal.extension.ReportPortalExtensionPoint) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

ReportPortalExtensionPoint (com.epam.reportportal.extension.ReportPortalExtensionPoint)1 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)1 Suppliers.formattedSupplier (com.epam.ta.reportportal.commons.validation.Suppliers.formattedSupplier)1 ExecuteIntegrationHandler (com.epam.ta.reportportal.core.integration.ExecuteIntegrationHandler)1 PluginBox (com.epam.ta.reportportal.core.plugin.PluginBox)1 IntegrationRepository (com.epam.ta.reportportal.dao.IntegrationRepository)1 Integration (com.epam.ta.reportportal.entity.integration.Integration)1 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)1 BAD_REQUEST_ERROR (com.epam.ta.reportportal.ws.model.ErrorType.BAD_REQUEST_ERROR)1 INTEGRATION_NOT_FOUND (com.epam.ta.reportportal.ws.model.ErrorType.INTEGRATION_NOT_FOUND)1 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)1 Map (java.util.Map)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Supplier (java.util.function.Supplier)1 Async (org.springframework.scheduling.annotation.Async)1 Service (org.springframework.stereotype.Service)1