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