Search in sources :

Example 11 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class UpdateEmailService method sendUpdateEmail.

public void sendUpdateEmail(UpdateModel updateModel) {
    String updateVersion = updateModel.getDockerTagVersion();
    if (wasEmailAlreadySentForVersion(updateVersion)) {
        return;
    }
    String username = "sysadmin";
    Optional<String> optionalEmailAddress = userAccessor.getUser(username).map(UserModel::getEmailAddress).filter(StringUtils::isNotBlank);
    if (optionalEmailAddress.isPresent()) {
        try {
            EmailGlobalConfigModel emailServerConfiguration = emailGlobalConfigAccessor.getConfiguration().orElseThrow(() -> new AlertException("No global email configuration found"));
            String alertServerUrl = alertProperties.getServerURL();
            Map<String, Object> templateFields = new HashMap<>();
            templateFields.put(EmailPropertyKeys.TEMPLATE_KEY_SUBJECT_LINE.getPropertyKey(), SUBJECT_LINE);
            templateFields.put("newVersionName", updateVersion);
            templateFields.put("repositoryUrl", updateModel.getRepositoryUrl());
            templateFields.put(FreemarkerTemplatingService.KEY_ALERT_SERVER_URL, alertServerUrl);
            handleSend(javamailPropertiesFactory.createJavaMailProperties(emailServerConfiguration), emailServerConfiguration.getSmtpFrom().orElse(StringUtils.EMPTY), emailServerConfiguration.getSmtpHost().orElse(StringUtils.EMPTY), emailServerConfiguration.getSmtpPort().orElse(0), emailServerConfiguration.getSmtpAuth().orElse(false), emailServerConfiguration.getSmtpUsername().orElse(StringUtils.EMPTY), emailServerConfiguration.getSmtpPassword().orElse(StringUtils.EMPTY), templateFields, optionalEmailAddress.get());
            settingsKeyAccessor.saveSettingsKey(SETTINGS_KEY_VERSION_FOR_UPDATE_EMAIL, updateVersion);
        } catch (AlertException e) {
            logger.debug("Problem sending version update email.", e);
        }
    } else {
        logger.debug("No email address configured for user: {}", username);
    }
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 12 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class JiraServerSummaryFieldLengthTestIT method summaryLength254SucceedsTest.

@Test
public void summaryLength254SucceedsTest() {
    IssueCreationModel issueCreationModel = createIssueCreationModel(254);
    IssueTrackerModelHolder<String> messages = new IssueTrackerModelHolder<>(List.of(issueCreationModel), List.of(), List.of());
    try {
        jiraServerMessageSender.sendMessages(messages);
    } catch (AlertException e) {
        fail("Failed to send a message with a 254 character summary", e);
    }
}
Also used : IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 13 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class JiraServerIssueCreator method retrieveProjectComponent.

private ProjectComponent retrieveProjectComponent() throws AlertException {
    String jiraProjectName = distributionDetails.getProjectNameOrKey();
    List<ProjectComponent> foundProjectComponents;
    try {
        foundProjectComponents = projectService.getProjectsByName(jiraProjectName);
    } catch (IntegrationException e) {
        throw new AlertException("Failed to retrieve projects from Jira", e);
    }
    return foundProjectComponents.stream().findAny().orElseThrow(() -> new AlertException(String.format("Unable to find project matching '%s'", jiraProjectName)));
}
Also used : ProjectComponent(com.synopsys.integration.jira.common.model.components.ProjectComponent) IntegrationException(com.synopsys.integration.exception.IntegrationException) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 14 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class MSTeamsChannelMessageSender method sendMessages.

@Override
public MessageResult sendMessages(MSTeamsJobDetailsModel msTeamsJobDetailsModel, List<MSTeamsChannelMessageModel> channelMessages) throws AlertException {
    String webhook = msTeamsJobDetailsModel.getWebhook();
    Map<String, String> requestHeaders = new HashMap<>();
    requestHeaders.put("Content-Type", "application/json");
    IntHttpClient intHttpClient = connectionFactory.createIntHttpClient(webhook);
    RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
    List<Request> messageRequests = channelMessages.stream().map(this::createJsonString).map(jsonString -> restChannelUtility.createPostMessageRequest(webhook, requestHeaders, jsonString)).collect(Collectors.toList());
    restChannelUtility.sendMessage(messageRequests, msTeamsKey.getUniversalKey());
    return new MessageResult(String.format("Successfully sent %d MSTeams message(s)", channelMessages.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) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) ChannelMessageSender(com.synopsys.integration.alert.api.channel.ChannelMessageSender) List(java.util.List) Component(org.springframework.stereotype.Component) JsonArray(com.google.gson.JsonArray) Map(java.util.Map) MsTeamsKey(com.synopsys.integration.alert.descriptor.api.MsTeamsKey) 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 15 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class BlackDuckSSOConfigRetrieverTest method retrieveTestIT.

@Test
@Tags({ @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_BLACKDUCK_CONNECTION) })
public void retrieveTestIT() throws AlertException {
    BlackDuckProperties blackDuckProperties = createBlackDuckProperties();
    BlackDuckSSOConfigRetriever ssoConfigRetriever = BlackDuckSSOConfigRetriever.fromProperties(blackDuckProperties);
    try {
        BlackDuckSSOConfigView ssoConfig = ssoConfigRetriever.retrieve();
        System.out.println("SSO Config:");
        System.out.println(ssoConfig);
    } catch (AlertException e) {
        fail("SSO Config Retrieval Failed", e);
    }
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test) TestTags(com.synopsys.integration.alert.test.common.TestTags) Tags(org.junit.jupiter.api.Tags)

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