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