use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel in project hub-alert by blackducksoftware.
the class JobNotificationMapper method mapPageOfJobsToNotification.
private AlertPagedDetails<FilteredJobNotificationWrapper> mapPageOfJobsToNotification(List<DetailedNotificationContent> detailedContents, List<FrequencyType> frequencies, int pageNumber, int pageSize) {
if (detailedContents.isEmpty()) {
return new AlertPagedDetails<>(1, pageNumber, pageSize, List.of());
}
Map<FilteredDistributionJobResponseModel, List<NotificationContentWrapper>> groupedFilterableNotifications = new HashMap<>();
FilteredDistributionJobRequestModel filteredDistributionJobRequestModel = createRequestModelFromNotifications(detailedContents, frequencies);
AlertPagedDetails<FilteredDistributionJobResponseModel> jobs = processingJobAccessor.getMatchingEnabledJobsByFilteredNotifications(filteredDistributionJobRequestModel, pageNumber, pageSize);
for (DetailedNotificationContent detailedNotificationContent : detailedContents) {
for (FilteredDistributionJobResponseModel filteredDistributionJobResponseModel : jobs.getModels()) {
if (JobNotificationFilterUtils.doesNotificationApplyToJob(filteredDistributionJobResponseModel, detailedNotificationContent)) {
List<NotificationContentWrapper> applicableNotifications = groupedFilterableNotifications.computeIfAbsent(filteredDistributionJobResponseModel, ignoredKey -> new LinkedList<>());
applicableNotifications.add(detailedNotificationContent.getNotificationContentWrapper());
}
}
}
List<FilteredJobNotificationWrapper> filterableJobNotifications = new LinkedList<>();
for (Map.Entry<FilteredDistributionJobResponseModel, List<NotificationContentWrapper>> groupedEntry : groupedFilterableNotifications.entrySet()) {
FilteredDistributionJobResponseModel filteredJob = groupedEntry.getKey();
FilteredJobNotificationWrapper wrappedJobNotifications = new FilteredJobNotificationWrapper(filteredJob.getId(), filteredJob.getProcessingType(), filteredJob.getChannelName(), filteredJob.getJobName(), groupedEntry.getValue());
filterableJobNotifications.add(wrappedJobNotifications);
}
return new AlertPagedDetails<>(jobs.getTotalPages(), pageNumber, pageSize, filterableJobNotifications);
}
use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel in project hub-alert by blackducksoftware.
the class ProcessingJobAccessorTestIT method testMatchingEnabledJobsUniqueJobsPerPage.
@Test
public void testMatchingEnabledJobsUniqueJobsPerPage() throws InterruptedException {
int expectedNumOfJobs = 1000;
Set<UUID> previousJobIdSet = new HashSet<>();
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name(), VulnerabilitySeverityType.HIGH.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
List<DetailedNotificationContent> notifications = new ArrayList<>();
notifications.addAll(createVulnerabilityNotificationWrappers(List.of(VulnerabilitySeverityType.LOW.name()), PROJECT_NAME_1, PROJECT_VERSION_NAME_1));
notifications.addAll(createVulnerabilityNotificationWrappers(List.of(VulnerabilitySeverityType.HIGH.name()), PROJECT_NAME_2, PROJECT_VERSION_NAME_2));
int currentPage = 0;
FilteredDistributionJobRequestModel filteredDistributionJobRequestModel = new FilteredDistributionJobRequestModel(providerConfigId, List.of(FrequencyType.REAL_TIME));
filteredDistributionJobRequestModel.addProjectName(PROJECT_NAME_1);
filteredDistributionJobRequestModel.addProjectName(PROJECT_NAME_2);
filteredDistributionJobRequestModel.addNotificationType(NotificationType.VULNERABILITY.name());
filteredDistributionJobRequestModel.addVulnerabilitySeverities(List.of(VulnerabilitySeverityType.LOW.name(), VulnerabilitySeverityType.HIGH.name()));
AlertPagedDetails<FilteredDistributionJobResponseModel> jobs = processingJobAccessor.getMatchingEnabledJobsByFilteredNotifications(filteredDistributionJobRequestModel, currentPage, 100);
while (currentPage < jobs.getTotalPages()) {
currentPage++;
for (FilteredDistributionJobResponseModel jobResponseModel : jobs.getModels()) {
// this will update the job id such that last updated time will change.
// need to make sure the subsequent page requests don't return duplicate jobs.
UUID jobId = jobResponseModel.getId();
// cannot find the same job id in subsequent page requests for jobs.
assertFalse(previousJobIdSet.contains(jobId), String.format("Job id: %s found in set of previously mapped job ids.", jobId));
previousJobIdSet.add(jobId);
}
jobs = processingJobAccessor.getMatchingEnabledJobsByFilteredNotifications(filteredDistributionJobRequestModel, currentPage, 100);
}
assertEquals(expectedNumOfJobs, previousJobIdSet.size());
}
use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel in project hub-alert by blackducksoftware.
the class JobNotificationMapper method createRequestModelFromNotifications.
private FilteredDistributionJobRequestModel createRequestModelFromNotifications(List<DetailedNotificationContent> detailedContents, List<FrequencyType> frequencies) {
Long commonProviderConfigId = detailedContents.stream().map(DetailedNotificationContent::getProviderConfigId).findAny().orElseThrow(() -> new AlertRuntimeException("Notification(s) missing provider configuration id"));
FilteredDistributionJobRequestModel filteredDistributionJobRequestModel = new FilteredDistributionJobRequestModel(commonProviderConfigId, frequencies);
for (DetailedNotificationContent detailedNotificationContent : detailedContents) {
detailedNotificationContent.getProjectName().ifPresent(filteredDistributionJobRequestModel::addProjectName);
filteredDistributionJobRequestModel.addNotificationType(detailedNotificationContent.getNotificationContentWrapper().extractNotificationType());
filteredDistributionJobRequestModel.addVulnerabilitySeverities(detailedNotificationContent.getVulnerabilitySeverities());
detailedNotificationContent.getPolicyName().ifPresent(filteredDistributionJobRequestModel::addPolicyName);
}
return filteredDistributionJobRequestModel;
}
Aggregations