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);
}
}
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);
}
}
Aggregations