Search in sources :

Example 1 with FilteredDistributionJobResponseModel

use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.

the class DefaultProcessingJobAccessor method getMatchingEnabledJobsByFilteredNotifications.

@Override
public AlertPagedModel<FilteredDistributionJobResponseModel> getMatchingEnabledJobsByFilteredNotifications(FilteredDistributionJobRequestModel filteredDistributionJobRequestModel, int pageNumber, int pageLimit) {
    List<String> frequencyTypes = filteredDistributionJobRequestModel.getFrequencyTypes().stream().map(Enum::name).collect(Collectors.toList());
    Set<String> projectNames = filteredDistributionJobRequestModel.getProjectName();
    Set<String> notificationTypes = filteredDistributionJobRequestModel.getNotificationTypes();
    // If no policies and/or vulnerabilitySeverities exist the repository query expects a null to be passed
    Set<String> policyNames = filteredDistributionJobRequestModel.getPolicyNames().isEmpty() ? null : filteredDistributionJobRequestModel.getPolicyNames();
    Set<String> vulnerabilitySeverities = filteredDistributionJobRequestModel.getVulnerabilitySeverities().isEmpty() ? null : filteredDistributionJobRequestModel.getVulnerabilitySeverities();
    PageRequest pageRequest = PageRequest.of(pageNumber, pageLimit);
    Page<DistributionJobEntity> pageOfDistributionJobEntities = distributionJobRepository.findAndSortMatchingEnabledJobsByFilteredNotifications(filteredDistributionJobRequestModel.getProviderConfigId(), frequencyTypes, notificationTypes, projectNames, policyNames, vulnerabilitySeverities, pageRequest);
    List<FilteredDistributionJobResponseModel> distributionJobResponseModels = pageOfDistributionJobEntities.getContent().stream().map(this::convertToFilteredDistributionJobResponseModel).collect(Collectors.toList());
    return new AlertPagedModel<>(pageOfDistributionJobEntities.getTotalPages(), pageNumber, pageLimit, distributionJobResponseModels);
}
Also used : FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) PageRequest(org.springframework.data.domain.PageRequest) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel)

Example 2 with FilteredDistributionJobResponseModel

use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel 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 FilteredDistributionJobResponseModel

use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.

the class JobNotificationFilterUtilsTest method doesNotificationTypeMatchTest.

@Test
public void doesNotificationTypeMatchTest() {
    List<String> notificationTypes = List.of(NotificationType.VULNERABILITY.name(), NotificationType.POLICY_OVERRIDE.name());
    FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(notificationTypes, List.of(), List.of(), List.of(), false, "", "");
    assertTrue(JobNotificationFilterUtils.doesNotificationTypeMatch(jobResponseModel, NotificationType.VULNERABILITY.name()));
    assertTrue(JobNotificationFilterUtils.doesNotificationTypeMatch(jobResponseModel, NotificationType.POLICY_OVERRIDE.name()));
    assertFalse(JobNotificationFilterUtils.doesNotificationTypeMatch(jobResponseModel, NotificationType.RULE_VIOLATION.name()));
}
Also used : FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) Test(org.junit.jupiter.api.Test)

Example 4 with FilteredDistributionJobResponseModel

use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.

the class JobNotificationFilterUtilsTest method doesNotificationApplyToJobProjectFailureTest.

@Test
public void doesNotificationApplyToJobProjectFailureTest() {
    NotificationContentComponent notificationContent = Mockito.mock(NotificationContentComponent.class);
    AlertNotificationModel notificationModel = createAlertNotificationModel(NotificationType.VULNERABILITY);
    DetailedNotificationContent detailedNotificationContent = DetailedNotificationContent.project(notificationModel, notificationContent, PROJECT_NAME, PROJECT_VERSION_NAME);
    FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(List.of(NotificationType.VULNERABILITY.name()), List.of("projectDoesNotExist"), List.of(), List.of(), true, "", "");
    assertFalse(JobNotificationFilterUtils.doesNotificationApplyToJob(jobResponseModel, detailedNotificationContent));
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) NotificationContentComponent(com.synopsys.integration.blackduck.api.manual.component.NotificationContentComponent) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) Test(org.junit.jupiter.api.Test)

Example 5 with FilteredDistributionJobResponseModel

use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.

the class JobNotificationFilterUtilsTest method doesNotificationApplyToJobVulnerabilityTest.

@Test
public void doesNotificationApplyToJobVulnerabilityTest() {
    NotificationContentComponent notificationContent = Mockito.mock(NotificationContentComponent.class);
    AlertNotificationModel notificationModel = createAlertNotificationModel(NotificationType.VULNERABILITY);
    DetailedNotificationContent detailedNotificationContent = DetailedNotificationContent.vulnerability(notificationModel, notificationContent, PROJECT_NAME, PROJECT_VERSION_NAME, List.of("vuln"));
    FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(List.of(NotificationType.VULNERABILITY.name()), List.of(), List.of(), List.of(), false, "", "");
    assertTrue(JobNotificationFilterUtils.doesNotificationApplyToJob(jobResponseModel, detailedNotificationContent));
    FilteredDistributionJobResponseModel jobResponseModelWithFailure = createFilteredDistributionJobResponseModel(List.of(NotificationType.VULNERABILITY.name()), List.of(), List.of(), List.of("vulnDoesNotExist"), false, "", "");
    assertFalse(JobNotificationFilterUtils.doesNotificationApplyToJob(jobResponseModelWithFailure, detailedNotificationContent));
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) NotificationContentComponent(com.synopsys.integration.blackduck.api.manual.component.NotificationContentComponent) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) Test(org.junit.jupiter.api.Test)

Aggregations

FilteredDistributionJobResponseModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel)24 Test (org.junit.jupiter.api.Test)19 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)8 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)7 NotificationContentComponent (com.synopsys.integration.blackduck.api.manual.component.NotificationContentComponent)6 FilteredDistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 ProcessingType (com.synopsys.integration.alert.common.enumeration.ProcessingType)1 ProcessingJobAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProcessingJobAccessor)1 BlackDuckProjectDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.BlackDuckProjectDetailsModel)1 AlertPagedDetails (com.synopsys.integration.alert.common.rest.model.AlertPagedDetails)1 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)1 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)1 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)1 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)1 ProviderMessageDistributor (com.synopsys.integration.alert.processor.api.distribute.ProviderMessageDistributor)1 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)1 RuleViolationNotificationView (com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView)1 HashMap (java.util.HashMap)1