Search in sources :

Example 86 with AlertException

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);
    }
}
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 87 with AlertException

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;
}
Also used : TransitionComponent(com.synopsys.integration.jira.common.model.components.TransitionComponent) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 88 with AlertException

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()));
}
Also used : JsonObject(com.google.gson.JsonObject) Request(com.synopsys.integration.rest.request.Request) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) RestChannelUtility(com.synopsys.integration.alert.api.channel.rest.RestChannelUtility) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ChannelRestConnectionFactory(com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) ChannelMessageSender(com.synopsys.integration.alert.api.channel.ChannelMessageSender) List(java.util.List) Component(org.springframework.stereotype.Component) SlackChannelKey(com.synopsys.integration.alert.descriptor.api.SlackChannelKey) Map(java.util.Map) Optional(java.util.Optional) HashMap(java.util.HashMap) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) RestChannelUtility(com.synopsys.integration.alert.api.channel.rest.RestChannelUtility) Request(com.synopsys.integration.rest.request.Request) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult)

Example 89 with AlertException

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");
}
Also used : MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 90 with AlertException

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);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) File(java.io.File) KeyStore(java.security.KeyStore) BufferedOutputStream(java.io.BufferedOutputStream) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)101 Test (org.junit.jupiter.api.Test)35 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)22 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)18 List (java.util.List)18 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)17 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)16 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)16 Optional (java.util.Optional)13 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)12 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)12 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)11 HashMap (java.util.HashMap)11 IntegrationException (com.synopsys.integration.exception.IntegrationException)10 ArrayList (java.util.ArrayList)9 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)8 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)8 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)8 UUID (java.util.UUID)8 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)7