use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum 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.notification.NotificationCategoryEnum in project hub-alert by blackducksoftware.
the class PurgeJobIT method testReaderWithData.
@Test
public void testReaderWithData() throws Exception {
final List<NotificationEntity> entityList = new ArrayList<>();
final String eventKey = "eventKey";
final NotificationCategoryEnum notificationType = NotificationCategoryEnum.VULNERABILITY;
final String projectName = "ProjectName";
final String projectUrl = "ProjectUrl";
final String projectVersion = "ProjectVersion";
final String projectVersionUrl = "ProjectVersionUrl";
final String componentName = "ComponentName";
final String componentVersion = "ComponentVersion";
final String policyRuleName = "PolicyRuleName";
final String person = "PolicyPerson";
ZonedDateTime zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
zonedDateTime = zonedDateTime.minusDays(1);
Date createdAt = Date.from(zonedDateTime.toInstant());
entityList.add(new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person));
zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
zonedDateTime = zonedDateTime.minusDays(3);
createdAt = Date.from(zonedDateTime.toInstant());
entityList.add(new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person));
zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
zonedDateTime = zonedDateTime.plusDays(1);
createdAt = Date.from(zonedDateTime.toInstant());
entityList.add(new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person));
notificationRepository.save(entityList);
final PurgeReader reader = purgeConfig.reader();
final List<NotificationModel> resultList = reader.read();
assertEquals(2, resultList.size());
}
use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum 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.notification.NotificationCategoryEnum in project hub-alert by blackducksoftware.
the class ProjectDataFactory method addCategoryData.
// get the category data object to be able to add items.
private void addCategoryData(final NotificationModel notification, final CategoryDataBuilder categoryData) {
final Map<String, Object> dataSet = new HashMap<>();
final NotificationCategoryEnum categoryKey = notification.getNotificationType();
int countAdded = 0;
int countUpdated = 0;
int countDeleted = 0;
if (categoryKey == NotificationCategoryEnum.HIGH_VULNERABILITY || categoryKey == NotificationCategoryEnum.MEDIUM_VULNERABILITY || categoryKey == NotificationCategoryEnum.LOW_VULNERABILITY) {
addVulnerabilitySets(dataSet, notification);
countAdded = dataSet.containsKey(VULNERABILITY_ADDED_ID_SET) ? ((Set<?>) dataSet.get(VULNERABILITY_ADDED_ID_SET)).size() : 0;
countUpdated = dataSet.containsKey(VULNERABILITY_UPDATED_ID_SET) ? ((Set<?>) dataSet.get(VULNERABILITY_UPDATED_ID_SET)).size() : 0;
countDeleted = dataSet.containsKey(VULNERABILITY_DELETED_ID_SET) ? ((Set<?>) dataSet.get(VULNERABILITY_DELETED_ID_SET)).size() : 0;
}
if (StringUtils.isNotBlank(notification.getPolicyRuleName())) {
dataSet.put(ItemTypeEnum.RULE.name(), notification.getPolicyRuleName());
}
dataSet.put(ItemTypeEnum.COMPONENT.name(), notification.getComponentName());
dataSet.put(ItemTypeEnum.VERSION.name(), notification.getComponentVersion());
if (countAdded > 0) {
dataSet.put(VULNERABILITY_COUNT_KEY_ADDED, countAdded);
}
if (countUpdated > 0) {
dataSet.put(VULNERABILITY_COUNT_KEY_UPDATED, countUpdated);
}
if (countDeleted > 0) {
dataSet.put(VULNERABILITY_COUNT_KEY_DELETED, countDeleted);
}
categoryData.addItem(new ItemData(dataSet));
}
use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum in project hub-alert by blackducksoftware.
the class NotificationRepositoryTestIT method createNotificationEntity.
private NotificationEntity createNotificationEntity(final Date createdAt) {
final String eventKey = "event_key_for_notification";
final NotificationCategoryEnum notificationType = NotificationCategoryEnum.VULNERABILITY;
final String projectName = "projectName";
final String projectVersion = "projectVersion";
final String componentName = "componentName";
final String componentVersion = "componentVersion";
final String policyRuleName = "policyRuleName";
final String person = "person";
final NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, null, projectVersion, null, componentName, componentVersion, policyRuleName, person);
return entity;
}
Aggregations