use of com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel in project hub-alert by blackducksoftware.
the class EmailTestActionHelper method createUpdatedEmailAddresses.
public Set<String> createUpdatedEmailAddresses(DistributionJobModel distributionJobModel) throws AlertException {
Set<String> emailAddresses = new HashSet<>();
DistributionJobDetailsModel distributionJobDetails = distributionJobModel.getDistributionJobDetails();
EmailJobDetailsModel emailJobDetails = distributionJobDetails.getAs(DistributionJobDetailsModel.EMAIL);
Long providerConfigId = distributionJobModel.getBlackDuckGlobalConfigId();
boolean onlyAdditionalEmails = emailJobDetails.isAdditionalEmailAddressesOnly();
if (null != providerConfigId && !onlyAdditionalEmails) {
Set<ProviderProject> providerProjects = retrieveProviderProjects(distributionJobModel, providerConfigId);
if (CollectionUtils.isNotEmpty(providerProjects)) {
Set<String> providerEmailAddresses = addEmailAddresses(providerConfigId, providerProjects, distributionJobModel, emailJobDetails);
emailAddresses.addAll(providerEmailAddresses);
}
}
return emailAddresses;
}
use of com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel in project hub-alert by blackducksoftware.
the class DistributionJobModelExtractor method convertToJobModel.
public final DistributionJobModel convertToJobModel(UUID jobId, Map<String, ConfigurationFieldModel> configuredFieldsMap, OffsetDateTime createdAt, @Nullable OffsetDateTime lastUpdated, List<BlackDuckProjectDetailsModel> projectFilterDetails) {
String channelDescriptorName = distributionJobFieldExtractor.extractFieldValueOrEmptyString(ChannelDescriptor.KEY_CHANNEL_NAME, configuredFieldsMap);
DistributionJobModelBuilder builder = DistributionJobModel.builder().jobId(jobId).enabled(distributionJobFieldExtractor.extractFieldValue(ChannelDescriptor.KEY_ENABLED, configuredFieldsMap).map(Boolean::valueOf).orElse(true)).name(distributionJobFieldExtractor.extractFieldValueOrEmptyString(ChannelDescriptor.KEY_NAME, configuredFieldsMap)).distributionFrequency(distributionJobFieldExtractor.extractFieldValueOrEmptyString(ChannelDescriptor.KEY_FREQUENCY, configuredFieldsMap)).processingType(distributionJobFieldExtractor.extractFieldValueOrEmptyString(ProviderDescriptor.KEY_PROCESSING_TYPE, configuredFieldsMap)).channelDescriptorName(channelDescriptorName).channelGlobalConfigId(distributionJobFieldExtractor.extractFieldValue(ChannelDescriptor.KEY_CHANNEL_GLOBAL_CONFIG_ID, configuredFieldsMap).map(UUID::fromString).orElse(null)).createdAt(createdAt).lastUpdated(lastUpdated).blackDuckGlobalConfigId(distributionJobFieldExtractor.extractFieldValue(ProviderDescriptor.KEY_COMMON_CONFIG_ID, configuredFieldsMap).map(Long::valueOf).orElse(-1L)).filterByProject(distributionJobFieldExtractor.extractFieldValue(ProviderDescriptor.KEY_FILTER_BY_PROJECT, configuredFieldsMap).map(Boolean::valueOf).orElse(false)).projectNamePattern(distributionJobFieldExtractor.extractFieldValue(ProviderDescriptor.KEY_PROJECT_NAME_PATTERN, configuredFieldsMap).orElse(null)).projectVersionNamePattern(distributionJobFieldExtractor.extractFieldValue(ProviderDescriptor.KEY_PROJECT_VERSION_NAME_PATTERN, configuredFieldsMap).orElse(null)).notificationTypes(distributionJobFieldExtractor.extractFieldValues(ProviderDescriptor.KEY_NOTIFICATION_TYPES, configuredFieldsMap)).policyFilterPolicyNames(distributionJobFieldExtractor.extractFieldValues("blackduck.policy.notification.filter", configuredFieldsMap)).vulnerabilityFilterSeverityNames(distributionJobFieldExtractor.extractFieldValues("blackduck.vulnerability.notification.filter", configuredFieldsMap)).projectFilterDetails(projectFilterDetails);
DistributionJobDetailsExtractor extractor = jobDetailsExtractorMap.findRequiredAction(channelDescriptorName);
DistributionJobDetailsModel distributionJobDetailsModel = extractor.extractDetails(jobId, configuredFieldsMap);
builder.distributionJobDetails(distributionJobDetailsModel);
return builder.build();
}
use of com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel in project hub-alert by blackducksoftware.
the class DistributionEventHandlerTest method handleEventJobDetailsMissingTest.
@Test
public void handleEventJobDetailsMissingTest() {
ProcessingAuditAccessor auditAccessor = Mockito.mock(ProcessingAuditAccessor.class);
Mockito.doNothing().when(auditAccessor).setAuditEntryFailure(Mockito.any(), Mockito.anySet(), Mockito.anyString(), Mockito.any());
JobDetailsAccessor<DistributionJobDetailsModel> jobDetailsAccessor = x -> Optional.empty();
DistributionEventHandler<DistributionJobDetailsModel> eventHandler = new DistributionEventHandler<>(null, jobDetailsAccessor, auditAccessor);
UUID testJobId = UUID.randomUUID();
Set<Long> testNotificationIds = Set.of(1L, 3L, 5L);
DistributionEvent testEvent = new DistributionEvent(channelKey, testJobId, "jobName", testNotificationIds, null);
eventHandler.handle(testEvent);
Mockito.verify(auditAccessor, Mockito.times(1)).setAuditEntryFailure(Mockito.eq(testJobId), Mockito.eq(testNotificationIds), Mockito.anyString(), Mockito.any());
}
use of com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel in project hub-alert by blackducksoftware.
the class DistributionEventHandlerTest method handleEventExceptionTest.
@Test
public void handleEventExceptionTest() {
ProcessingAuditAccessor auditAccessor = Mockito.mock(ProcessingAuditAccessor.class);
Mockito.doNothing().when(auditAccessor).setAuditEntryFailure(Mockito.any(), Mockito.anySet(), Mockito.anyString(), Mockito.any());
DistributionJobDetailsModel details = new DistributionJobDetailsModel(null, null) {
};
JobDetailsAccessor<DistributionJobDetailsModel> jobDetailsAccessor = x -> Optional.of(details);
AlertException testException = new AlertException("Test exception");
DistributionChannel<DistributionJobDetailsModel> channel = (x, y, z) -> {
throw testException;
};
DistributionEventHandler<DistributionJobDetailsModel> eventHandler = new DistributionEventHandler<>(channel, jobDetailsAccessor, auditAccessor);
UUID testJobId = UUID.randomUUID();
Set<Long> testNotificationIds = Set.of(1L, 3L, 5L);
DistributionEvent testEvent = new DistributionEvent(channelKey, testJobId, "jobName", testNotificationIds, null);
eventHandler.handle(testEvent);
Mockito.verify(auditAccessor, Mockito.times(1)).setAuditEntryFailure(Mockito.eq(testJobId), Mockito.eq(testNotificationIds), Mockito.anyString(), Mockito.any());
}
use of com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel in project hub-alert by blackducksoftware.
the class MessageBoardChannelTest method distributeMessagesTest.
@Test
public void distributeMessagesTest() throws AlertException {
MessageResult expectedResult = new MessageResult("Test result");
DistributionJobDetailsModel testDetails = new DistributionJobDetailsModel(null, null) {
};
AbstractChannelMessageConverter<DistributionJobDetailsModel, Object> converter = createConverter();
ChannelMessageSender<DistributionJobDetailsModel, Object, MessageResult> sender = (x, y) -> expectedResult;
MessageBoardChannel<DistributionJobDetailsModel, Object> messageBoardChannel = new MessageBoardChannel<>(converter, sender) {
};
MessageResult testResult = messageBoardChannel.distributeMessages(testDetails, ProviderMessageHolder.empty(), "jobName");
assertEquals(expectedResult, testResult);
}
Aggregations