Search in sources :

Example 16 with NotificationCategoryEnum

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();
}
Also used : CategoryData(com.blackducksoftware.integration.hub.alert.digest.model.CategoryData) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) JsonObject(com.google.gson.JsonObject) ItemData(com.blackducksoftware.integration.hub.alert.digest.model.ItemData)

Example 17 with NotificationCategoryEnum

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);
}
Also used : NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)

Example 18 with NotificationCategoryEnum

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;
}
Also used : NotificationContentItem(com.blackducksoftware.integration.hub.notification.NotificationContentItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)

Example 19 with NotificationCategoryEnum

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

NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)19 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)8 Date (java.util.Date)6 HashMap (java.util.HashMap)6 VulnerabilityEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)5 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)5 CategoryData (com.blackducksoftware.integration.hub.alert.digest.model.CategoryData)4 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)3 VulnerabilityOperationEnum (com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum)3 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 NotificationTypeEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity)2 DistributionNotificationTypeRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionNotificationTypeRelation)2 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)2 ZonedDateTime (java.time.ZonedDateTime)2 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)1