Search in sources :

Example 21 with VulnerabilityEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity in project hub-alert by blackducksoftware.

the class AccumulatorWriter method getVulnerabilities.

// The dataset contains string keys and object values. Therefore we need to type cast because the contents are various types.
@SuppressWarnings("unchecked")
private Collection<VulnerabilityEntity> getVulnerabilities(final NotificationEvent notification, final NotificationEntity entity) {
    final List<VulnerabilityEntity> vulnerabilityList = new ArrayList<>();
    final String key = VulnerabilityCache.VULNERABILITY_OPERATION;
    if (notification.getDataSet().containsKey(key)) {
        final String operationName = (String) notification.getDataSet().get(key);
        final Set<String> vulnerabilitySet = (Set<String>) notification.getDataSet().get(VulnerabilityCache.VULNERABILITY_ID_SET);
        if (!vulnerabilitySet.isEmpty()) {
            vulnerabilitySet.forEach(vulnerability -> {
                final VulnerabilityEntity vulnerabilityEntity = new VulnerabilityEntity(vulnerability, VulnerabilityOperationEnum.valueOf(operationName), entity.getId());
                vulnerabilityList.add(vulnerabilityEntity);
            });
        }
    }
    return vulnerabilityList;
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)

Example 22 with VulnerabilityEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity 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)22 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)13 Test (org.junit.Test)13 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)12 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)10 Date (java.util.Date)6 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)5 ArrayList (java.util.ArrayList)5 VulnerabilityOperationEnum (com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum)3 List (java.util.List)2 Set (java.util.Set)2 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)1 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)1 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)1 NotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.NotificationRepositoryWrapper)1 VulnerabilityRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.VulnerabilityRepositoryWrapper)1 RealTimeEvent (com.blackducksoftware.integration.hub.alert.event.RealTimeEvent)1 MockVulnerabilityEntity (com.blackducksoftware.integration.hub.alert.mock.entity.MockVulnerabilityEntity)1 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)1 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)1