Search in sources :

Example 1 with BAD_REQUEST_ERROR

use of com.epam.ta.reportportal.ws.model.ErrorType.BAD_REQUEST_ERROR in project service-api by reportportal.

the class CreateTicketHandlerImpl method createIssue.

@Override
public Ticket createIssue(PostTicketRQ postTicketRQ, Long integrationId, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    validatePostTicketRQ(postTicketRQ);
    List<TestItem> testItems = ofNullable(postTicketRQ.getBackLinks()).map(links -> testItemRepository.findAllById(links.keySet())).orElseGet(Collections::emptyList);
    List<TestItemActivityResource> before = testItems.stream().map(it -> TO_ACTIVITY_RESOURCE.apply(it, projectDetails.getProjectId())).collect(Collectors.toList());
    Integration integration = getIntegrationHandler.getEnabledBtsIntegration(projectDetails, integrationId);
    expect(BtsConstants.DEFECT_FORM_FIELDS.getParam(integration.getParams()), notNull()).verify(BAD_REQUEST_ERROR, "There aren't any submitted BTS fields!");
    BtsExtension btsExtension = pluginBox.getInstance(integration.getType().getName(), BtsExtension.class).orElseThrow(() -> new ReportPortalException(BAD_REQUEST_ERROR, Suppliers.formattedSupplier("BugTracking plugin for {} isn't installed", BtsConstants.PROJECT.getParam(integration.getParams())).get()));
    Ticket ticket = btsExtension.submitTicket(postTicketRQ, integration);
    before.forEach(it -> messageBus.publishActivity(new TicketPostedEvent(ticket, user.getUserId(), user.getUsername(), it)));
    return ticket;
}
Also used : TicketPostedEvent(com.epam.ta.reportportal.core.events.activity.TicketPostedEvent) GetIntegrationHandler(com.epam.ta.reportportal.core.integration.GetIntegrationHandler) TestItem(com.epam.ta.reportportal.entity.item.TestItem) Autowired(org.springframework.beans.factory.annotation.Autowired) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) Ticket(com.epam.ta.reportportal.ws.model.externalsystem.Ticket) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Service(org.springframework.stereotype.Service) BAD_REQUEST_ERROR(com.epam.ta.reportportal.ws.model.ErrorType.BAD_REQUEST_ERROR) UNABLE_POST_TICKET(com.epam.ta.reportportal.ws.model.ErrorType.UNABLE_POST_TICKET) BtsConstants(com.epam.reportportal.extension.bugtracking.BtsConstants) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) PostTicketRQ(com.epam.ta.reportportal.ws.model.externalsystem.PostTicketRQ) Predicates.notNull(com.epam.ta.reportportal.commons.Predicates.notNull) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) Optional.ofNullable(java.util.Optional.ofNullable) Integration(com.epam.ta.reportportal.entity.integration.Integration) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.TestItemConverter.TO_ACTIVITY_RESOURCE) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Collectors(java.util.stream.Collectors) CreateTicketHandler(com.epam.ta.reportportal.core.bts.handler.CreateTicketHandler) PluginBox(com.epam.ta.reportportal.core.plugin.PluginBox) List(java.util.List) BtsExtension(com.epam.reportportal.extension.bugtracking.BtsExtension) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) Collections(java.util.Collections) Ticket(com.epam.ta.reportportal.ws.model.externalsystem.Ticket) Integration(com.epam.ta.reportportal.entity.integration.Integration) BtsExtension(com.epam.reportportal.extension.bugtracking.BtsExtension) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) Collections(java.util.Collections) TicketPostedEvent(com.epam.ta.reportportal.core.events.activity.TicketPostedEvent) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Example 2 with BAD_REQUEST_ERROR

use of com.epam.ta.reportportal.ws.model.ErrorType.BAD_REQUEST_ERROR 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)

Example 3 with BAD_REQUEST_ERROR

use of com.epam.ta.reportportal.ws.model.ErrorType.BAD_REQUEST_ERROR in project service-api by reportportal.

the class SauceLabsIntegrationService method retrieveCreateParams.

@Override
public Map<String, Object> retrieveCreateParams(String integrationType, Map<String, Object> integrationParams) {
    expect(integrationParams, MapUtils::isNotEmpty).verify(BAD_REQUEST_ERROR, "No integration params provided");
    final String encryptedToken = encryptor.encrypt(ACCESS_TOKEN.getParameter(integrationParams).orElseThrow(() -> new ReportPortalException(BAD_REQUEST_ERROR, "Access token value is not specified")));
    final String username = USERNAME.getParameter(integrationParams).orElseThrow(() -> new ReportPortalException(BAD_REQUEST_ERROR, "Username value is not specified"));
    HashMap<String, Object> result = Maps.newHashMapWithExpectedSize(integrationParams.size());
    result.put(ACCESS_TOKEN.getName(), encryptedToken);
    result.put(USERNAME.getName(), username);
    integrationParams.entrySet().stream().filter(it -> !it.getKey().equals(ACCESS_TOKEN.getName()) && !it.getKey().equals(USERNAME.getName())).forEach(it -> result.put(it.getKey(), it.getValue()));
    return result;
}
Also used : MapUtils(org.apache.commons.collections4.MapUtils) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) BasicTextEncryptor(org.jasypt.util.text.BasicTextEncryptor) Maps(com.google.common.collect.Maps) PluginBox(com.epam.ta.reportportal.core.plugin.PluginBox) USERNAME(com.epam.ta.reportportal.core.integration.util.property.SauceLabsProperties.USERNAME) Service(org.springframework.stereotype.Service) Map(java.util.Map) ACCESS_TOKEN(com.epam.ta.reportportal.core.integration.util.property.SauceLabsProperties.ACCESS_TOKEN) BAD_REQUEST_ERROR(com.epam.ta.reportportal.ws.model.ErrorType.BAD_REQUEST_ERROR) IntegrationRepository(com.epam.ta.reportportal.dao.IntegrationRepository) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException)

Aggregations

PluginBox (com.epam.ta.reportportal.core.plugin.PluginBox)3 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)3 BAD_REQUEST_ERROR (com.epam.ta.reportportal.ws.model.ErrorType.BAD_REQUEST_ERROR)3 Service (org.springframework.stereotype.Service)3 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)2 IntegrationRepository (com.epam.ta.reportportal.dao.IntegrationRepository)2 Integration (com.epam.ta.reportportal.entity.integration.Integration)2 Map (java.util.Map)2 Optional.ofNullable (java.util.Optional.ofNullable)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ReportPortalExtensionPoint (com.epam.reportportal.extension.ReportPortalExtensionPoint)1 BtsConstants (com.epam.reportportal.extension.bugtracking.BtsConstants)1 BtsExtension (com.epam.reportportal.extension.bugtracking.BtsExtension)1 Predicates.notNull (com.epam.ta.reportportal.commons.Predicates.notNull)1 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)1 Suppliers.formattedSupplier (com.epam.ta.reportportal.commons.validation.Suppliers.formattedSupplier)1 CreateTicketHandler (com.epam.ta.reportportal.core.bts.handler.CreateTicketHandler)1 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)1 TicketPostedEvent (com.epam.ta.reportportal.core.events.activity.TicketPostedEvent)1