Search in sources :

Example 21 with IntegrationRestException

use of com.synopsys.integration.rest.exception.IntegrationRestException in project hub-alert by blackducksoftware.

the class JiraIssueCreator method createIssueAndExtractDetails.

@Override
protected final ExistingIssueDetails<String> createIssueAndExtractDetails(IssueCreationModel alertIssueCreationModel) throws AlertException {
    MessageReplacementValues replacementValues = alertIssueCreationModel.getSource().map(this::createCustomFieldReplacementValues).orElse(new MessageReplacementValues.Builder(alertIssueCreationModel.getProvider().getLabel(), MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE).build());
    T creationRequest = createIssueCreationRequest(alertIssueCreationModel, replacementValues);
    try {
        IssueCreationResponseModel issueCreationResponseModel = createIssue(creationRequest);
        IssueResponseModel createdIssue = fetchIssue(issueCreationResponseModel.getKey());
        IssueFieldsComponent createdIssueFields = createdIssue.getFields();
        String issueUILink = JiraCallbackUtils.createUILink(createdIssue);
        IssueCategory issueCategory = alertIssueCreationModel.getSource().map(issueCategoryRetriever::retrieveIssueCategoryFromProjectIssueModel).orElse(IssueCategory.BOM);
        return new ExistingIssueDetails<>(createdIssue.getId(), createdIssue.getKey(), createdIssueFields.getSummary(), issueUILink, IssueStatus.RESOLVABLE, issueCategory);
    } catch (IntegrationRestException restException) {
        throw jiraErrorMessageUtility.improveRestException(restException, issueCreatorDescriptorKey, extractReporter(creationRequest));
    } catch (JiraPreconditionNotMetException jiraException) {
        String message = StringUtils.join(FAILED_TO_CREATE_ISSUE_MESSAGE, jiraException.getMessage(), " ");
        throw new AlertException(message, jiraException);
    } catch (IntegrationException intException) {
        throw new AlertException(FAILED_TO_CREATE_ISSUE_MESSAGE, intException);
    }
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) IssueCreationResponseModel(com.synopsys.integration.jira.common.model.response.IssueCreationResponseModel) IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) IntegrationException(com.synopsys.integration.exception.IntegrationException) IssueResponseModel(com.synopsys.integration.jira.common.model.response.IssueResponseModel) MessageReplacementValues(com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues) JiraPreconditionNotMetException(com.synopsys.integration.jira.common.exception.JiraPreconditionNotMetException) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) IssueFieldsComponent(com.synopsys.integration.jira.common.model.components.IssueFieldsComponent) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 22 with IntegrationRestException

use of com.synopsys.integration.rest.exception.IntegrationRestException in project hub-alert by blackducksoftware.

the class IntegrationAlertRequestUtility method executeRequest.

private String executeRequest(HttpMethod httpMethod, MockHttpServletRequestBuilder requestBuilder, String error) throws IntegrationException {
    MockHttpServletRequestBuilder request = requestBuilder.with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    try {
        MvcResult mvcResult = mockMvc.perform(request).andReturn();
        String responseContent = mvcResult.getResponse().getContentAsString();
        int status = mvcResult.getResponse().getStatus();
        if (status >= RestConstants.BAD_REQUEST_400) {
            intLogger.error(String.format("Error code: %s", status));
            intLogger.error(String.format("Response: %s", responseContent));
            intLogger.error(error);
            throw new IntegrationRestException(httpMethod, new HttpUrl("https://google.com"), status, "Bad Request", responseContent, error);
        }
        return responseContent;
    } catch (IntegrationRestException e) {
        throw e;
    } catch (Exception e) {
        throw new IntegrationException(e.getMessage(), e);
    }
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) IntegrationException(com.synopsys.integration.exception.IntegrationException) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) MvcResult(org.springframework.test.web.servlet.MvcResult) HttpUrl(com.synopsys.integration.rest.HttpUrl) IntegrationException(com.synopsys.integration.exception.IntegrationException) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException)

Aggregations

IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)22 HttpUrl (com.synopsys.integration.rest.HttpUrl)15 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)13 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)12 Test (org.junit.jupiter.api.Test)10 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)8 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)8 IntegrationException (com.synopsys.integration.exception.IntegrationException)7 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)6 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)5 BlackDuckMessageBomComponentDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator)5 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)4 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)4 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)3 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)3 VulnerabilityUniqueProjectNotificationContent (com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent)3 ComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView)3 Gson (com.google.gson.Gson)2 JiraCustomFieldResolver (com.synopsys.integration.alert.api.channel.jira.distribution.custom.JiraCustomFieldResolver)2 JiraServerProperties (com.synopsys.integration.alert.channel.jira.server.JiraServerProperties)2