use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class EmailMessagingService method sendMessages.
public void sendMessages(boolean auth, String host, int port, String username, String password, Session session, List<Message> messages) throws AlertException {
Set<String> errorMessages = new HashSet<>();
try (Transport transport = getAndConnectTransport(auth, host, port, username, password, session)) {
for (Message message : messages) {
Optional<String> errors = sendMessage(transport, message);
errors.ifPresent(errorMessages::add);
}
} catch (MessagingException e) {
String errorMessage = "Could not setup the email transport: " + e.getMessage();
logger.error(errorMessage);
throw new AlertException(errorMessage, e);
}
logger.trace("Transport session closed.");
if (!errorMessages.isEmpty()) {
String joinedErrorMessages = StringUtils.join(errorMessages, System.lineSeparator());
logger.error(joinedErrorMessages);
throw new AlertException(joinedErrorMessages);
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class AlertStartupInitializer method initializeConfiguration.
private void initializeConfiguration(Collection<DescriptorKey> descriptorKeys) {
for (DescriptorKey descriptorKey : descriptorKeys) {
logger.info(LINE_DIVIDER);
logger.info("Descriptor: {}", descriptorKey.getUniversalKey());
logger.info(LINE_DIVIDER);
logger.info(" Starting Descriptor Initialization...");
try {
List<DefinedFieldModel> fieldsForDescriptor = descriptorAccessor.getFieldsForDescriptor(descriptorKey, ConfigContextEnum.GLOBAL).stream().sorted(Comparator.comparing(DefinedFieldModel::getKey)).collect(Collectors.toList());
List<ConfigurationModel> foundConfigurationModels = fieldConfigurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey, ConfigContextEnum.GLOBAL);
Map<String, ConfigurationFieldModel> existingConfiguredFields = new HashMap<>();
foundConfigurationModels.forEach(config -> existingConfiguredFields.putAll(config.getCopyOfKeyToFieldMap()));
Set<ConfigurationFieldModel> configurationModels = createFieldModelsFromDefinedFields(descriptorKey, fieldsForDescriptor, existingConfiguredFields);
logConfiguration(configurationModels);
updateConfigurationFields(descriptorKey, foundConfigurationModels, configurationModels);
} catch (IllegalArgumentException | SecurityException | AlertException ex) {
logger.error("error initializing descriptor", ex);
} finally {
logger.info(" Finished Descriptor Initialization...");
logger.info(LINE_DIVIDER);
}
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class ConfigurationOverridesStartupComponent method initialize.
@Override
protected void initialize() {
try {
FieldModel fieldModel = getFieldModel();
checkAndDisableLdapAuthentication(fieldModel);
checkAndDisableSamlAuthentication(fieldModel);
checkAndResetDefaultAdminPassword();
if (StringUtils.isBlank(fieldModel.getId())) {
configUtility.save(fieldModel);
} else {
configUtility.update(Long.valueOf(fieldModel.getId()), fieldModel);
}
} catch (AlertException | NumberFormatException ex) {
logger.error("Error performing configuration overrides.", ex);
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class EmailMessagingService method createMessages.
private List<Message> createMessages(Collection<String> emailAddresses, String subjectLine, Session session, MimeMultipart mimeMultipart, String fromString) throws AlertException, MessagingException {
List<InternetAddress> addresses = new ArrayList<>();
Set<String> invalidAddresses = new HashSet<>();
for (String emailAddress : emailAddresses) {
try {
InternetAddress toAddress = new InternetAddress(emailAddress);
toAddress.validate();
addresses.add(toAddress);
} catch (AddressException e) {
invalidAddresses.add(emailAddress);
logger.warn("Could not create the address from {}: {}", emailAddress, e.getMessage());
}
}
if (addresses.isEmpty()) {
String noValidAddressesErrorMessage = "There were no valid email addresses supplied.";
if (!invalidAddresses.isEmpty()) {
String invalidAddressesString = StringUtils.join(invalidAddresses, ", ");
noValidAddressesErrorMessage = String.format("%s Invalid addresses: %s", noValidAddressesErrorMessage, invalidAddressesString);
}
throw new AlertException(noValidAddressesErrorMessage);
}
InternetAddress fromAddress;
if (StringUtils.isBlank(fromString)) {
logger.warn("No 'from' address specified");
throw new AlertException(String.format("Required field '%s' was blank", EmailPropertyKeys.JAVAMAIL_FROM_KEY.getPropertyKey()));
} else {
fromAddress = new InternetAddress(fromString);
try {
fromAddress.validate();
} catch (AddressException e) {
logger.warn("Invalid 'from' address specified: {}", fromString);
throw new AlertException(String.format("'%s' is not a valid email address: %s", fromString, e.getMessage()));
}
}
List<Message> messages = new ArrayList<>(addresses.size());
for (InternetAddress address : addresses) {
Message message = new MimeMessage(session);
message.setContent(mimeMultipart);
message.setFrom(fromAddress);
message.setRecipients(Message.RecipientType.TO, new Address[] { address });
message.setSubject(subjectLine);
messages.add(message);
}
return messages;
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class AzureCustomFieldManager method findOrCreateAlertCustomProjectField.
private ProjectWorkItemFieldModel findOrCreateAlertCustomProjectField(String projectName, String fieldName, String fieldReferenceName, String fieldDescription) throws AlertException {
ProjectWorkItemFieldModel fieldRequestModel = ProjectWorkItemFieldModel.workItemStringField(fieldName, fieldReferenceName, fieldDescription);
Optional<ProjectWorkItemFieldModel> customField = getAlertCustomProjectField(projectName, fieldRequestModel.getReferenceName());
if (customField.isPresent()) {
return customField.get();
}
// custom field not found so create it
try {
return projectService.createProjectField(organizationName, projectName, fieldRequestModel);
} catch (IOException e) {
throw new AlertException(String.format("There was a problem creating the request to create the Alert Custom Field (%s) in the Azure project: %s", fieldReferenceName, projectName), e);
} catch (HttpServiceException e) {
throw new AlertException(String.format("There was a problem creating the Alert Custom Field (%s) in the Azure project: %s", fieldReferenceName, projectName), e);
}
}
Aggregations