use of com.synopsys.integration.alert.api.common.model.exception.AlertException 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.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class JiraIssueStatusCreator method createIssueStatus.
public IssueStatus createIssueStatus(JiraSearcherResponseModel issue, ThrowingFunction<String, TransitionsResponseModel, IntegrationException> transitionsRetriever) {
try {
String issueKey = issue.getIssueKey();
List<TransitionComponent> issueTransitions = retrieveTransitions(issueKey, transitionsRetriever);
for (TransitionComponent transition : issueTransitions) {
String transitionName = transition.getName();
if (transitionName.equals(resolveTransition)) {
return IssueStatus.RESOLVABLE;
} else if (transitionName.equals(reopenTransition)) {
return IssueStatus.REOPENABLE;
}
}
} catch (AlertException e) {
return IssueStatus.UNKNOWN;
}
return IssueStatus.UNKNOWN;
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class SlackChannelMessageSender method sendMessages.
@Override
public MessageResult sendMessages(SlackJobDetailsModel slackJobDetails, List<SlackChannelMessageModel> channelMessages) throws AlertException {
String webhook = slackJobDetails.getWebhook();
String channelName = slackJobDetails.getChannelName();
String channelUsername = Optional.ofNullable(slackJobDetails.getChannelUsername()).orElse(SLACK_DEFAULT_USERNAME);
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("Content-Type", "application/json");
IntHttpClient intHttpClient = connectionFactory.createIntHttpClient(webhook);
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
List<Request> requests = channelMessages.stream().map(channelMessage -> createJsonString(channelMessage.getMarkdownContent(), channelName, channelUsername)).map(jsonString -> restChannelUtility.createPostMessageRequest(webhook, requestHeaders, jsonString)).collect(Collectors.toList());
restChannelUtility.sendMessage(requests, slackChannelKey.getUniversalKey());
return new MessageResult(String.format("Successfully sent %d Slack message(s)", requests.size()));
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class ChannelITTestAssertions method assertSendSimpleMessageSuccess.
public static <D extends DistributionJobDetailsModel> void assertSendSimpleMessageSuccess(DistributionChannel<D> channel, D distributionDetails) {
MessageResult messageResult = null;
try {
messageResult = channel.distributeMessages(distributionDetails, TEST_MESSAGE_HOLDER, "jobName");
} catch (AlertException e) {
Assertions.fail("Failed to distribute simple channel message due to an exception", e);
}
assertFalse(messageResult.hasErrors(), "The message result had errors");
assertFalse(messageResult.hasWarnings(), "The message result had warnings");
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class AlertTrustStoreManager method removeCertificate.
public synchronized void removeCertificate(String certificateAlias) throws AlertException {
logger.debug("Removing certificate by alias from trust store.");
if (StringUtils.isBlank(certificateAlias)) {
throw new AlertException("The alias cannot be blank");
}
try {
File trustStore = getAndValidateTrustStoreFile();
KeyStore keyStore = getAsKeyStore(trustStore, getTrustStorePassword(), getTrustStoreType());
if (keyStore.containsAlias(certificateAlias)) {
keyStore.deleteEntry(certificateAlias);
try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(trustStore))) {
keyStore.store(stream, getTrustStorePassword());
}
}
} catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException e) {
throw new AlertException("There was a problem removing the certificate.", e);
}
}
Aggregations