Search in sources :

Example 1 with CategoryData

use of com.blackducksoftware.integration.hub.alert.digest.model.CategoryData in project hub-alert by blackducksoftware.

the class NotificationPostProcessorTestIT method getApplicableConfigurationsTest.

@Test
public void getApplicableConfigurationsTest() {
    final NotificationPostProcessor postProcessor = new NotificationPostProcessor(distributionProjectRepository, configuredProjectsRepository, distributionNotificationTypeRepository, notificationTypeRepository);
    final DigestTypeEnum digestType = DigestTypeEnum.REAL_TIME;
    final String projectName = "Project Name";
    final String projectVersion = "Project Version";
    final List<Long> notificationIds = Collections.emptyList();
    final Map<NotificationCategoryEnum, CategoryData> categoryMap = new HashMap<>();
    for (final NotificationCategoryEnum categoryEnum : NotificationCategoryEnum.values()) {
        categoryMap.put(categoryEnum, new CategoryData(null, null, 0));
        notificationTypeRepository.save(new NotificationTypeEntity(categoryEnum));
    }
    final ProjectData projectData = new ProjectData(digestType, projectName, projectVersion, notificationIds, categoryMap);
    final Long config1Id = 13L;
    final CommonDistributionConfigEntity config1 = new CommonDistributionConfigEntity(config1Id, SupportedChannels.EMAIL_GROUP, "Config 1", digestType, true);
    config1.setId(config1Id);
    final Long config2Id = 17L;
    final CommonDistributionConfigEntity config2 = new CommonDistributionConfigEntity(config2Id, SupportedChannels.EMAIL_GROUP, "Config 2", digestType, false);
    config2.setId(config2Id);
    final Long notificationTypeId = notificationTypeRepository.findAll().get(0).getId();
    distributionNotificationTypeRepository.save(new DistributionNotificationTypeRelation(config1.getId(), notificationTypeId));
    distributionNotificationTypeRepository.save(new DistributionNotificationTypeRelation(config2.getId(), notificationTypeId));
    final ConfiguredProjectEntity configuredProjectEntity = configuredProjectsRepository.save(new ConfiguredProjectEntity(projectName));
    distributionProjectRepository.save(new DistributionProjectRelation(config1.getId(), configuredProjectEntity.getId()));
    final Set<CommonDistributionConfigEntity> applicableConfigs = postProcessor.getApplicableConfigurations(Arrays.asList(config1, config2), projectData);
    assertTrue(applicableConfigs.contains(config1));
    assertTrue(applicableConfigs.contains(config2));
    assertEquals(2, applicableConfigs.size());
}
Also used : DigestTypeEnum(com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum) CategoryData(com.blackducksoftware.integration.hub.alert.digest.model.CategoryData) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) HashMap(java.util.HashMap) ConfiguredProjectEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity) DistributionNotificationTypeRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionNotificationTypeRelation) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) DistributionProjectRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation) NotificationTypeEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 2 with CategoryData

use of com.blackducksoftware.integration.hub.alert.digest.model.CategoryData in project hub-alert by blackducksoftware.

the class SlackChannelTestIT method createCategoryData.

private CategoryData createCategoryData() {
    final Map<String, Object> itemDataDataSet = new HashMap<>();
    itemDataDataSet.put(ProjectDataFactory.VULNERABILITY_COUNT_KEY_ADDED, 1);
    itemDataDataSet.put(ProjectDataFactory.VULNERABILITY_COUNT_KEY_UPDATED, 1);
    itemDataDataSet.put(ProjectDataFactory.VULNERABILITY_COUNT_KEY_DELETED, 1);
    final CategoryData categoryData = new CategoryData("key", Arrays.asList(new ItemData(itemDataDataSet)), 0);
    return categoryData;
}
Also used : CategoryData(com.blackducksoftware.integration.hub.alert.digest.model.CategoryData) HashMap(java.util.HashMap) ItemData(com.blackducksoftware.integration.hub.alert.digest.model.ItemData)

Example 3 with CategoryData

use of com.blackducksoftware.integration.hub.alert.digest.model.CategoryData in project hub-alert by blackducksoftware.

the class SlackChannelTestIT method createSlackProjectData.

private ProjectData createSlackProjectData() {
    final Map<NotificationCategoryEnum, CategoryData> categoryMap = new HashMap<>();
    categoryMap.put(NotificationCategoryEnum.HIGH_VULNERABILITY, createCategoryData());
    final ProjectData projectData = new ProjectData(DigestTypeEnum.DAILY, "Slack", "1", null, categoryMap);
    return projectData;
}
Also used : CategoryData(com.blackducksoftware.integration.hub.alert.digest.model.CategoryData) HashMap(java.util.HashMap) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)

Example 4 with CategoryData

use of com.blackducksoftware.integration.hub.alert.digest.model.CategoryData in project hub-alert by blackducksoftware.

the class ChannelTest method createProjectData.

public ProjectData createProjectData(final String testName) {
    final HashMap<NotificationCategoryEnum, CategoryData> categoryMap = new HashMap<>();
    categoryMap.put(NotificationCategoryEnum.POLICY_VIOLATION, createMockPolicyViolation());
    categoryMap.put(NotificationCategoryEnum.MEDIUM_VULNERABILITY, createMockVulnerability());
    final ProjectData projectData = new ProjectData(DigestTypeEnum.REAL_TIME, testName, testName + " Version", Collections.emptyList(), categoryMap);
    return projectData;
}
Also used : CategoryData(com.blackducksoftware.integration.hub.alert.digest.model.CategoryData) HashMap(java.util.HashMap) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)

Example 5 with CategoryData

use of com.blackducksoftware.integration.hub.alert.digest.model.CategoryData 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)

Aggregations

CategoryData (com.blackducksoftware.integration.hub.alert.digest.model.CategoryData)5 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)4 HashMap (java.util.HashMap)4 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)3 ItemData (com.blackducksoftware.integration.hub.alert.digest.model.ItemData)2 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)1 ConfiguredProjectEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)1 NotificationTypeEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity)1 DistributionNotificationTypeRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionNotificationTypeRelation)1 DistributionProjectRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)1 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)1 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)1 JsonObject (com.google.gson.JsonObject)1 Test (org.junit.Test)1