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;
}
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;
}
Aggregations