Search in sources :

Example 1 with VulnerabilityOperationEnum

use of com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum in project hub-alert by blackducksoftware.

the class ProjectDataFactoryTest method createVulnerabilityNotification.

private NotificationModel createVulnerabilityNotification(final String projectName, final String projectVersion) {
    final String eventKey = "key";
    final Date createdAt = new Date();
    final NotificationCategoryEnum notificationType = NotificationCategoryEnum.MEDIUM_VULNERABILITY;
    final String projectUrl = "http://localhost:8080";
    final String projectVersionUrl = "http://localhost:8080";
    final String componentName = "Component";
    final String componentVersion = "Component Version";
    final String policyRuleName = null;
    final String policyRuleUser = null;
    final String vulnerabilityId = NotificationCategoryEnum.VULNERABILITY.name();
    final VulnerabilityOperationEnum vulnerabilityOperation = VulnerabilityOperationEnum.ADD;
    final NotificationEntity notification = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, policyRuleUser);
    notification.setId(1L);
    final Collection<VulnerabilityEntity> vulnerabilityList = Arrays.asList(new VulnerabilityEntity(vulnerabilityId, vulnerabilityOperation, notification.getId()));
    return new NotificationModel(notification, vulnerabilityList);
}
Also used : NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) VulnerabilityOperationEnum(com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.util.Date)

Example 2 with VulnerabilityOperationEnum

use of com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum in project hub-alert by blackducksoftware.

the class ProjectDataFactoryTest method createPolicyNotification.

private NotificationModel createPolicyNotification(final String projectName, final String projectVersion) {
    final String eventKey = "key";
    final Date createdAt = new Date();
    final NotificationCategoryEnum notificationType = NotificationCategoryEnum.POLICY_VIOLATION;
    final String projectUrl = "http://localhost:8080";
    final String projectVersionUrl = "http://localhost:8080";
    final String componentName = "Other Component";
    final String componentVersion = "Other Component Version";
    final String policyRuleName = "Policy Rule Name";
    final String person = "Person";
    final String vulnerabilityId = NotificationCategoryEnum.VULNERABILITY.name();
    final VulnerabilityOperationEnum vulnerabilityOperation = VulnerabilityOperationEnum.ADD;
    final NotificationEntity notification = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
    notification.setId(1L);
    final Collection<VulnerabilityEntity> vulnerabilityList = Arrays.asList(new VulnerabilityEntity(vulnerabilityId, vulnerabilityOperation, notification.getId()));
    return new NotificationModel(notification, vulnerabilityList);
}
Also used : NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) VulnerabilityOperationEnum(com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.util.Date)

Example 3 with VulnerabilityOperationEnum

use of com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum in project hub-alert by blackducksoftware.

the class DigestRemovalProcessor method processVulnerabilityNotifications.

private boolean processVulnerabilityNotifications(final String cacheKey, final Map<NotificationCategoryEnum, NotificationModel> categoryMap, final NotificationModel entity) {
    final NotificationCategoryEnum notificationType = entity.getNotificationType();
    final Collection<VulnerabilityEntity> vulnerabilities = entity.getVulnerabilityList();
    final Map<NotificationCategoryEnum, Set<String>> vulnerabilityCategoryMap = vulnerabilityCache.containsKey(cacheKey) ? vulnerabilityCache.get(cacheKey) : new HashMap<>();
    Set<String> vulnerabilityIds;
    if (vulnerabilityCategoryMap.containsKey(notificationType)) {
        vulnerabilityIds = vulnerabilityCategoryMap.get(notificationType);
    } else {
        vulnerabilityIds = new HashSet<>();
        vulnerabilityCategoryMap.put(notificationType, vulnerabilityIds);
    }
    if (!vulnerabilities.isEmpty()) {
        vulnerabilities.forEach(vulnerabilityEntity -> {
            final VulnerabilityOperationEnum operation = vulnerabilityEntity.getOperation();
            final String id = vulnerabilityEntity.getVulnerabilityId();
            if (VulnerabilityOperationEnum.DELETE.equals(operation)) {
                vulnerabilityIds.remove(id);
            } else {
                vulnerabilityIds.add(id);
            }
        });
    }
    if (vulnerabilityIds.isEmpty()) {
        vulnerabilityCategoryMap.remove(notificationType);
        categoryMap.remove(notificationType);
        if (vulnerabilityCategoryMap.isEmpty()) {
            vulnerabilityCache.remove(cacheKey);
            entityCache.remove(cacheKey);
        }
    } else {
        vulnerabilityCache.put(cacheKey, vulnerabilityCategoryMap);
        categoryMap.put(notificationType, entity);
    }
    return false;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) VulnerabilityOperationEnum(com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum)

Aggregations

VulnerabilityEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)3 VulnerabilityOperationEnum (com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum)3 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)3 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)2 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)2 Date (java.util.Date)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1