Search in sources :

Example 1 with FilteredDistributionJobRequestModel

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);
}
Also used : FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) FilteredDistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel) AlertPagedDetails(com.synopsys.integration.alert.common.rest.model.AlertPagedDetails) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with FilteredDistributionJobRequestModel

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());
}
Also used : FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) ArrayList(java.util.ArrayList) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) UUID(java.util.UUID) HashSet(java.util.HashSet) FilteredDistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with FilteredDistributionJobRequestModel

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;
}
Also used : DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) FilteredDistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel)

Aggregations

FilteredDistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel)3 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)3 FilteredDistributionJobResponseModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel)2 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)1 AlertPagedDetails (com.synopsys.integration.alert.common.rest.model.AlertPagedDetails)1 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Test (org.junit.jupiter.api.Test)1