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