Search in sources :

Example 6 with DetailedNotificationContent

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

the class JobNotificationFilterUtilsTest method testPolicyNotifications.

private void testPolicyNotifications(NotificationType notificationType) {
    NotificationContentComponent notificationContent = Mockito.mock(NotificationContentComponent.class);
    AlertNotificationModel notificationModel = createAlertNotificationModel(notificationType);
    DetailedNotificationContent detailedNotificationContent = DetailedNotificationContent.policy(notificationModel, notificationContent, PROJECT_NAME, POLICY_NAME, PROJECT_VERSION_NAME);
    FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(List.of(notificationType.name()), List.of(), List.of(), List.of(), false, "", "");
    assertTrue(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)

Example 7 with DetailedNotificationContent

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

the class BomEditNotificationDetailExtractorTest method extractDetailedContentTest.

@Test
public void extractDetailedContentTest() throws IOException, IntegrationException {
    String projectName = "project-name";
    String projectVersionName = "project-version-name";
    Long blackDuckConfigId = 0L;
    String notificationString = TestResourceUtils.readFileToString(BOM_EDIT_JSON_PATH);
    BomEditNotificationView notificationView = gson.fromJson(notificationString, BomEditNotificationView.class);
    NotificationExtractorBlackDuckServicesFactoryCache cache = createCache(blackDuckConfigId, projectName, projectVersionName);
    BomEditNotificationDetailExtractor extractor = new BomEditNotificationDetailExtractor(cache);
    AlertNotificationModel notification = new AlertNotificationModel(0L, blackDuckConfigId, "BlackDuck", "Config 1", null, null, null, null, false);
    List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
    assertEquals(1, detailedNotificationContents.size());
    DetailedNotificationContent detailedNotificationContent = detailedNotificationContents.get(0);
    Optional<String> detailedProjectName = detailedNotificationContent.getProjectName();
    assertTrue(detailedProjectName.isPresent(), "Expected project name to be present");
    assertEquals(projectName, detailedProjectName.get());
    assertTrue(detailedNotificationContent.getPolicyName().isEmpty(), "Expected no policy name to be present");
    assertEquals(0, detailedNotificationContent.getVulnerabilitySeverities().size());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) BomEditNotificationView(com.synopsys.integration.blackduck.api.manual.view.BomEditNotificationView) Test(org.junit.jupiter.api.Test)

Example 8 with DetailedNotificationContent

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

the class BomEditNotificationDetailExtractor method extractDetailedContent.

@Override
public List<DetailedNotificationContent> extractDetailedContent(AlertNotificationModel alertNotificationModel, BomEditNotificationView notificationView) {
    BomEditNotificationContent notificationContent = notificationView.getContent();
    Optional<ProjectVersionWrapper> optionalProjectAndVersion = retrieveProjectAndVersion(alertNotificationModel.getProviderConfigId(), notificationContent.getProjectVersion());
    if (optionalProjectAndVersion.isPresent()) {
        ProjectVersionWrapper projectAndVersion = optionalProjectAndVersion.get();
        ProjectView project = projectAndVersion.getProjectView();
        ProjectVersionView projectVersion = projectAndVersion.getProjectVersionView();
        String projectName = project.getName();
        BomEditWithProjectNameNotificationContent updatedNotificationContent = new BomEditWithProjectNameNotificationContent(notificationContent, projectName, projectVersion.getVersionName());
        DetailedNotificationContent detailedContent = DetailedNotificationContent.project(alertNotificationModel, updatedNotificationContent, projectName, projectVersion.getVersionName());
        return List.of(detailedContent);
    }
    return List.of();
}
Also used : BomEditNotificationContent(com.synopsys.integration.blackduck.api.manual.component.BomEditNotificationContent) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) BomEditWithProjectNameNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.BomEditWithProjectNameNotificationContent) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)

Example 9 with DetailedNotificationContent

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

the class VulnerabilityNotificationDetailExtractor method extractDetailedContent.

@Override
public List<DetailedNotificationContent> extractDetailedContent(AlertNotificationModel alertNotificationModel, VulnerabilityNotificationView notificationView) {
    VulnerabilityNotificationContent notificationContent = notificationView.getContent();
    List<String> applicableSeverityTypes = new LinkedList<>(getApplicableSeverityTypes(notificationContent));
    // Separating this notification to be per project should fix a bug with alerts being sent about unrelated projects
    return notificationContent.getAffectedProjectVersions().stream().map(affectedProjectVersion -> new VulnerabilityUniqueProjectNotificationContent(notificationContent, affectedProjectVersion)).map(vulnerabilityUniqueProjectNotificationContent -> DetailedNotificationContent.vulnerability(// This leaves the AlertNotificationModel as the original but modifies the NotificationContent field
    alertNotificationModel, vulnerabilityUniqueProjectNotificationContent, vulnerabilityUniqueProjectNotificationContent.getAffectedProjectVersion().getProjectName(), vulnerabilityUniqueProjectNotificationContent.getAffectedProjectVersion().getProjectVersionName(), applicableSeverityTypes)).collect(Collectors.toList());
}
Also used : DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) VulnerabilityNotificationContent(com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent) VulnerabilitySeverityType(com.synopsys.integration.blackduck.api.generated.enumeration.VulnerabilitySeverityType) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) List(java.util.List) Component(org.springframework.stereotype.Component) VulnerabilitySourceQualifiedId(com.synopsys.integration.blackduck.api.manual.component.VulnerabilitySourceQualifiedId) VulnerabilityUniqueProjectNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent) VulnerabilityNotificationView(com.synopsys.integration.blackduck.api.manual.view.VulnerabilityNotificationView) LinkedList(java.util.LinkedList) NotificationDetailExtractor(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractor) VulnerabilityNotificationContent(com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent) VulnerabilityUniqueProjectNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent) LinkedList(java.util.LinkedList)

Example 10 with DetailedNotificationContent

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

the class LicenseLimitNotificationDetailExtractorTest method extractDetailedContentTest.

@Test
public void extractDetailedContentTest() {
    LicenseLimitNotificationDetailExtractor extractor = new LicenseLimitNotificationDetailExtractor();
    LicenseLimitNotificationView notificationView = new LicenseLimitNotificationView();
    LicenseLimitNotificationContent notificationContent = new LicenseLimitNotificationContent();
    notificationView.setContent(notificationContent);
    AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
    List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
    assertEquals(1, detailedNotificationContents.size());
    DetailedNotificationContent detailedNotificationContent = detailedNotificationContents.get(0);
    assertTrue(detailedNotificationContent.getProjectName().isEmpty(), "Expected no project name to be present");
    assertTrue(detailedNotificationContent.getPolicyName().isEmpty(), "Expected no policy name to be present");
    assertEquals(0, detailedNotificationContent.getVulnerabilitySeverities().size());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LicenseLimitNotificationContent(com.synopsys.integration.blackduck.api.manual.component.LicenseLimitNotificationContent) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) LicenseLimitNotificationView(com.synopsys.integration.blackduck.api.manual.view.LicenseLimitNotificationView) Test(org.junit.jupiter.api.Test)

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