use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.
the class DefaultProcessingJobAccessor method convertToFilteredDistributionJobResponseModel.
private FilteredDistributionJobResponseModel convertToFilteredDistributionJobResponseModel(DistributionJobEntity jobEntity) {
UUID jobId = jobEntity.getJobId();
ProcessingType processingType = Enum.valueOf(ProcessingType.class, jobEntity.getProcessingType());
String channelName = jobEntity.getChannelDescriptorName();
String jobName = jobEntity.getName();
BlackDuckJobDetailsEntity blackDuckJobDetails = jobEntity.getBlackDuckJobDetails();
List<String> notificationTypes = blackDuckJobDetailsAccessor.retrieveNotificationTypesForJob(jobId);
List<BlackDuckProjectDetailsModel> projectDetails = blackDuckJobDetailsAccessor.retrieveProjectDetailsForJob(jobId);
List<String> policyNames = blackDuckJobDetailsAccessor.retrievePolicyNamesForJob(jobId);
List<String> vulnerabilitySeverityNames = blackDuckJobDetailsAccessor.retrieveVulnerabilitySeverityNamesForJob(jobId);
boolean filterByProject = blackDuckJobDetails.getFilterByProject();
String projectNamePattern = blackDuckJobDetails.getProjectNamePattern();
String projectVersionNamePattern = blackDuckJobDetails.getProjectVersionNamePattern();
return new FilteredDistributionJobResponseModel(jobId, processingType, channelName, jobName, notificationTypes, projectDetails, policyNames, vulnerabilitySeverityNames, filterByProject, projectNamePattern, projectVersionNamePattern);
}
use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.
the class NotificationProcessorTest method createNonMatchingJobs.
private List<FilteredDistributionJobResponseModel> createNonMatchingJobs(int numberToCreate, String notificationType, boolean filterByProject, String projectNamePattern) {
List<FilteredDistributionJobResponseModel> nonMatchingJobs = new ArrayList<>(numberToCreate);
for (int i = 0; i < numberToCreate; i++) {
FilteredDistributionJobResponseModel job = createJob(notificationType, filterByProject, projectNamePattern);
nonMatchingJobs.add(job);
}
return nonMatchingJobs;
}
use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.
the class NotificationProcessorTest method processNotificationsWithMoreThanAPageOfJobsTest.
@Test
public // Passing case: A distribution event is sent
void processNotificationsWithMoreThanAPageOfJobsTest() {
String projectName = "2468 - Test Project";
String matchingProjectNamePattern = "2468.*";
String nonMatchingProjectNamePattern = "13579asdf - DO NOT MATCH";
String targetNotificationType = NotificationType.RULE_VIOLATION.name();
String nonTargetNotificationType = NotificationType.LICENSE_LIMIT.name();
RuleViolationNotificationView ruleViolationNotificationView = createRuleViolationNotificationView(projectName);
String notificationContentString = GSON.toJson(ruleViolationNotificationView);
AlertNotificationModel notification = createNotification(targetNotificationType, notificationContentString);
FilteredDistributionJobResponseModel matchingJob = createJob(targetNotificationType, true, matchingProjectNamePattern);
List<FilteredDistributionJobResponseModel> nonMatchingJobs = createNonMatchingJobs(250, nonTargetNotificationType, true, nonMatchingProjectNamePattern);
// Only needs to handle the target notification type
NotificationDetailExtractionDelegator extractionDelegator = new NotificationDetailExtractionDelegator(BLACK_DUCK_RESPONSE_RESOLVER, List.of(RULE_VIOLATION_NDE));
ProcessingJobAccessor processingJobAccessor = new MockProcessingJobAccessor(nonMatchingJobs, matchingJob, 199);
// This is needed to verify the notification is "sent"
ProviderMessageDistributor distributor = Mockito.mock(ProviderMessageDistributor.class);
Mockito.doNothing().when(distributor).distribute(Mockito.any(), Mockito.any());
NotificationProcessor notificationProcessor = createNotificationProcessor(extractionDelegator, processingJobAccessor, distributor);
notificationProcessor.processNotifications(List.of(notification), List.of(FrequencyType.REAL_TIME, FrequencyType.DAILY));
// Exactly one distribution event should be sent
Mockito.verify(distributor, Mockito.times(1)).distribute(Mockito.any(), Mockito.any());
}
use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.
the class JobNotificationFilterUtilsTest method doesProjectVersionNameMatchWithNoProjectTest.
@Test
public void doesProjectVersionNameMatchWithNoProjectTest() {
FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(List.of(), List.of(), List.of(), List.of(), true, "", "1.0.*");
boolean doesProjectApplyToJob = JobNotificationFilterUtils.doesProjectApplyToJob(jobResponseModel, "projectName", "1.0.0");
assertTrue(doesProjectApplyToJob);
}
use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.
the class JobNotificationFilterUtilsTest method doesProjectApplyToJobPatternMatchingTest.
@Test
public void doesProjectApplyToJobPatternMatchingTest() {
FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(List.of(NotificationType.VULNERABILITY.name()), List.of(PROJECT_NAME), List.of(), List.of(), true, ".*", "");
assertTrue(JobNotificationFilterUtils.doesProjectApplyToJob(jobResponseModel, PROJECT_NAME, PROJECT_VERSION_NAME));
FilteredDistributionJobResponseModel jobResponseModelFilterByNamePattern = createFilteredDistributionJobResponseModel(List.of(NotificationType.VULNERABILITY.name()), List.of(PROJECT_NAME), List.of(), List.of(), true, "project*", "");
assertTrue(JobNotificationFilterUtils.doesProjectApplyToJob(jobResponseModelFilterByNamePattern, PROJECT_NAME, PROJECT_VERSION_NAME));
assertFalse(JobNotificationFilterUtils.doesProjectApplyToJob(jobResponseModelFilterByNamePattern, "nonMatchingName", PROJECT_VERSION_NAME));
}
Aggregations