use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum in project hub-alert by blackducksoftware.
the class SlackChannel method createHtmlMessage.
private String createHtmlMessage(final ProjectData projectData) {
final StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append(projectData.getProjectName());
messageBuilder.append(" > ");
messageBuilder.append(projectData.getProjectVersion());
messageBuilder.append(System.lineSeparator());
final Map<NotificationCategoryEnum, CategoryData> categoryMap = projectData.getCategoryMap();
if (categoryMap != null) {
for (final NotificationCategoryEnum category : NotificationCategoryEnum.values()) {
final CategoryData data = categoryMap.get(category);
if (data != null) {
messageBuilder.append("- - - - - - - - - - - - - - - - - - - -");
messageBuilder.append(System.lineSeparator());
messageBuilder.append("Type: ");
messageBuilder.append(data.getCategoryKey());
messageBuilder.append(System.lineSeparator());
messageBuilder.append("Number of Changes: ");
messageBuilder.append(data.getItemCount());
for (final ItemData item : data.getItemList()) {
messageBuilder.append(System.lineSeparator());
final Map<String, Object> dataSet = item.getDataSet();
final String ruleKey = ItemTypeEnum.RULE.toString();
if (dataSet.containsKey(ruleKey) && StringUtils.isNotBlank(dataSet.get(ruleKey).toString())) {
messageBuilder.append("Rule: " + dataSet.get(ItemTypeEnum.RULE.toString()));
messageBuilder.append(System.lineSeparator());
}
if (dataSet.containsKey(ProjectDataFactory.VULNERABILITY_COUNT_KEY_ADDED)) {
final Number numericValue = (Number) dataSet.get(ProjectDataFactory.VULNERABILITY_COUNT_KEY_ADDED);
messageBuilder.append("Vulnerability Count Added: " + numericValue.intValue());
messageBuilder.append(System.lineSeparator());
}
if (dataSet.containsKey(ProjectDataFactory.VULNERABILITY_COUNT_KEY_UPDATED)) {
final Number numericValue = (Number) dataSet.get(ProjectDataFactory.VULNERABILITY_COUNT_KEY_UPDATED);
messageBuilder.append("Vulnerability Count Updated: " + numericValue.intValue());
messageBuilder.append(System.lineSeparator());
}
if (dataSet.containsKey(ProjectDataFactory.VULNERABILITY_COUNT_KEY_DELETED)) {
final Number numericValue = (Number) dataSet.get(ProjectDataFactory.VULNERABILITY_COUNT_KEY_DELETED);
messageBuilder.append("Vulnerability Count Deleted: " + numericValue.intValue());
messageBuilder.append(System.lineSeparator());
}
messageBuilder.append("Component: " + dataSet.get(ItemTypeEnum.COMPONENT.toString()));
messageBuilder.append(" [" + dataSet.get(ItemTypeEnum.VERSION.toString()) + "]");
}
messageBuilder.append(System.lineSeparator());
}
}
} else {
messageBuilder.append(" A notification was received, but it was empty.");
}
return messageBuilder.toString();
}
use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum in project hub-alert by blackducksoftware.
the class ProjectDataFactory method getCategoryDataBuilder.
private CategoryDataBuilder getCategoryDataBuilder(final NotificationModel notification, final Map<NotificationCategoryEnum, CategoryDataBuilder> categoryBuilderMap) {
CategoryDataBuilder categoryData;
final NotificationCategoryEnum categoryKey = notification.getNotificationType();
if (!categoryBuilderMap.containsKey(categoryKey)) {
categoryData = new CategoryDataBuilder();
categoryData.setCategoryKey(categoryKey.name());
categoryBuilderMap.put(categoryKey, categoryData);
}
return categoryBuilderMap.get(categoryKey);
}
use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum in project hub-alert by blackducksoftware.
the class UserNotificationCache method addUserInformation.
public Collection<NotificationEvent> addUserInformation(final Collection<NotificationEvent> notificationEvents) {
final List<NotificationEvent> userEventList = new ArrayList<>();
final String key = AlertConstants.DATASET_KEY_HUB_USER;
notificationEvents.forEach(currentNotification -> {
final NotificationContentItem notificationContentItem = (NotificationContentItem) currentNotification.getDataSet().get(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT);
final String projectName = notificationContentItem.getProjectVersion().getProjectName();
final List<String> userNameList = getUserNames(projectName);
userNameList.forEach(userName -> {
final String eventKey = currentNotification.getEventKey();
final NotificationCategoryEnum categoryType = currentNotification.getCategoryType();
final Map<String, Object> dataSet = new HashMap<>(currentNotification.getDataSet());
dataSet.put(key, userName);
final NotificationEvent userEvent = new NotificationEvent(eventKey, categoryType, dataSet);
userEventList.add(userEvent);
});
});
return userEventList;
}
use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum 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