Search in sources :

Example 11 with DetailedNotificationContent

use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.

the class ProjectNotificationDetailExtractorTest method extractDetailedContentTest.

@Test
public void extractDetailedContentTest() throws IOException {
    String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
    ProjectNotificationView projectNotificationView = gson.fromJson(jsonContent, ProjectNotificationView.class);
    ProjectNotificationContent projectNotificationContent = projectNotificationView.getContent();
    AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
    ProjectNotificationDetailExtractor extractor = new ProjectNotificationDetailExtractor();
    List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, projectNotificationView);
    assertEquals(1, detailedNotificationContents.size());
    DetailedNotificationContent detailedNotificationContent = detailedNotificationContents.get(0);
    Optional<String> optionalProjectName = detailedNotificationContent.getProjectName();
    assertTrue(optionalProjectName.isPresent(), "Expect project name to be present");
    assertEquals(projectNotificationContent.getProjectName(), optionalProjectName.get());
    assertTrue(detailedNotificationContent.getPolicyName().isEmpty(), "Expected no policy name to be present");
    assertEquals(0, detailedNotificationContent.getVulnerabilitySeverities().size());
}
Also used : ProjectNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProjectNotificationView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationView) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) Test(org.junit.jupiter.api.Test)

Example 12 with DetailedNotificationContent

use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.

the class VulnerabilityNotificationDetailExtractorTest method verifyExtraction.

@Test
public void verifyExtraction() throws IOException {
    VulnerabilityNotificationView vulnerabilityNotificationView = getVulnerabilityNotificationView(VULNERABILITY_COMPLEX_JSON_PATH);
    VulnerabilityNotificationContent content = vulnerabilityNotificationView.getContent();
    VulnerabilityNotificationDetailExtractor vulnerabilityNotificationDetailExtractor = new VulnerabilityNotificationDetailExtractor();
    AlertNotificationModel alertNotificationModel = createAlertNotificationModel();
    List<DetailedNotificationContent> filterableNotificationWrappers = vulnerabilityNotificationDetailExtractor.extractDetailedContent(alertNotificationModel, vulnerabilityNotificationView);
    assertEquals(3, filterableNotificationWrappers.size());
    for (DetailedNotificationContent filterableNotificationWrapper : filterableNotificationWrappers) {
        NotificationContentWrapper notificationContentWrapper = filterableNotificationWrapper.getNotificationContentWrapper();
        assertEquals(NotificationType.VULNERABILITY.name(), notificationContentWrapper.extractNotificationType());
        // The Vuln extractor should return a different object structure
        assertNotEquals(content, notificationContentWrapper.getNotificationContent());
        assertEquals(3, filterableNotificationWrapper.getVulnerabilitySeverities().size());
        assertFalse(filterableNotificationWrapper.getVulnerabilitySeverities().contains(VulnerabilitySeverityType.CRITICAL.name()));
        assertTrue(filterableNotificationWrapper.getPolicyName().isEmpty(), "Expected no policy name to be present");
    }
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) VulnerabilityNotificationView(com.synopsys.integration.blackduck.api.manual.view.VulnerabilityNotificationView) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) VulnerabilityNotificationContent(com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent) NotificationContentWrapper(com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper) Test(org.junit.jupiter.api.Test)

Example 13 with DetailedNotificationContent

use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.

the class VulnerabilityNotificationDetailExtractorTest method allSeverityTypesApplyTest.

@Test
public void allSeverityTypesApplyTest() throws IOException {
    VulnerabilityNotificationView vulnerabilityNotificationView = getVulnerabilityNotificationView(VULNERABILITY_SIMPLE_ALL_SEVERITY_JSON_PATH);
    VulnerabilityNotificationDetailExtractor vulnerabilityNotificationDetailExtractor = new VulnerabilityNotificationDetailExtractor();
    AlertNotificationModel alertNotificationModel = createAlertNotificationModel();
    List<DetailedNotificationContent> filterableNotificationWrappers = vulnerabilityNotificationDetailExtractor.extractDetailedContent(alertNotificationModel, vulnerabilityNotificationView);
    assertEquals(1, filterableNotificationWrappers.size());
    DetailedNotificationContent detailedNotificationContent = filterableNotificationWrappers.get(0);
    assertEquals(4, detailedNotificationContent.getVulnerabilitySeverities().size());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) VulnerabilityNotificationView(com.synopsys.integration.blackduck.api.manual.view.VulnerabilityNotificationView) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) Test(org.junit.jupiter.api.Test)

Example 14 with DetailedNotificationContent

use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent 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 15 with DetailedNotificationContent

use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.

the class NotificationProcessor method processAndDistribute.

private void processAndDistribute(List<AlertNotificationModel> notifications, List<FrequencyType> frequencies) {
    List<DetailedNotificationContent> filterableNotifications = notifications.stream().map(notificationDetailExtractionDelegator::wrapNotification).flatMap(List::stream).collect(Collectors.toList());
    StatefulAlertPage<FilteredJobNotificationWrapper, RuntimeException> statefulAlertPage = jobNotificationMapper.mapJobsToNotifications(filterableNotifications, frequencies);
    // If there are elements to process in the current page or if there are more pages, keep looping.
    while (!statefulAlertPage.isCurrentPageEmpty() || statefulAlertPage.hasNextPage()) {
        for (FilteredJobNotificationWrapper jobNotificationWrapper : statefulAlertPage.getCurrentModels()) {
            processAndDistribute(jobNotificationWrapper);
        }
        statefulAlertPage = statefulAlertPage.retrieveNextPage();
    }
}
Also used : DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) FilteredJobNotificationWrapper(com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper)

Aggregations

DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)27 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)21 Test (org.junit.jupiter.api.Test)17 FilteredDistributionJobResponseModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel)8 NotificationContentComponent (com.synopsys.integration.blackduck.api.manual.component.NotificationContentComponent)6 FilteredDistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel)3 VulnerabilityNotificationView (com.synopsys.integration.blackduck.api.manual.view.VulnerabilityNotificationView)3 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)2 VulnerabilityUniqueProjectNotificationContent (com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent)2 VulnerabilityNotificationContent (com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent)2 BomEditNotificationView (com.synopsys.integration.blackduck.api.manual.view.BomEditNotificationView)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)1 AlertPagedDetails (com.synopsys.integration.alert.common.rest.model.AlertPagedDetails)1 NotificationDetailExtractor (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractor)1 FilteredJobNotificationWrapper (com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper)1 NotificationContentWrapper (com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper)1