use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum in project hub-alert by blackducksoftware.
the class AccumulatorWriter method write.
@Override
public void write(final List<? extends DBStoreEvent> itemList) throws Exception {
try {
if (itemList != null && !itemList.isEmpty()) {
logger.info("Writing {} notifications", itemList.size());
itemList.forEach(item -> {
final List<NotificationEvent> notificationList = item.getNotificationList();
final List<NotificationModel> entityList = new ArrayList<>();
notificationList.forEach(notification -> {
final String eventKey = notification.getEventKey();
final NotificationContentItem content = (NotificationContentItem) notification.getDataSet().get(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT);
final Date createdAt = content.getCreatedAt();
final NotificationCategoryEnum notificationType = notification.getCategoryType();
final String projectName = content.getProjectVersion().getProjectName();
final String projectUrl = content.getProjectVersion().getProjectLink();
final String projectVersion = content.getProjectVersion().getProjectVersionName();
final String projectVersionUrl = content.getProjectVersion().getUrl();
final String componentName = content.getComponentName();
final String componentVersion = content.getComponentVersion().versionName;
final String policyRuleName = getPolicyRule(notification);
final String person = getPerson(notification);
final NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
final Collection<VulnerabilityEntity> vulnerabilityList = getVulnerabilities(notification, entity);
NotificationModel model = new NotificationModel(entity, vulnerabilityList);
model = notificationManager.saveNotification(model);
entityList.add(model);
});
final RealTimeEvent realTimeEvent = new RealTimeEvent(entityList);
channelTemplateManager.sendEvent(realTimeEvent);
});
} else {
logger.info("No notifications to write");
}
} catch (final Exception ex) {
logger.error("Error occurred writing notification data", ex);
}
}
use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum in project hub-alert by blackducksoftware.
the class NotificationTypesActions method addNewDistributionNotificationTypes.
private void addNewDistributionNotificationTypes(final Long commonDistributionConfigId, final List<String> notificationTypesFromRestModel) {
for (final String notificationType : notificationTypesFromRestModel) {
final NotificationCategoryEnum notificationTypeEnum = NotificationCategoryEnum.valueOf(notificationType);
Long notificationTypeId;
final NotificationTypeEntity foundEntity = notificationTypeRepository.findByType(notificationTypeEnum);
if (foundEntity != null) {
notificationTypeId = foundEntity.getId();
} else {
final NotificationTypeEntity createdEntity = notificationTypeRepository.save(new NotificationTypeEntity(notificationTypeEnum));
notificationTypeId = createdEntity.getId();
}
distributionNotificationTypeRepository.save(new DistributionNotificationTypeRelation(commonDistributionConfigId, notificationTypeId));
}
}
use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum in project hub-alert by blackducksoftware.
the class NotificationManagerTestIT 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 String projectUrl = "projectURL";
final String projectVersionUrl = "projectVersionUrl";
final NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
return entity;
}
use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum in project hub-alert by blackducksoftware.
the class VulnerabilityCache method addEventsToList.
@SuppressWarnings("unchecked")
private void addEventsToList(final NotificationEvent originalEvent, final List<VulnerabilityV2View> vulnerabilityList, final List<NotificationEvent> eventList) {
final Map<NotificationCategoryEnum, NotificationEvent> eventMap = new HashMap<>();
final Set<String> eventVulnIdSet = (Set<String>) originalEvent.getDataSet().get(VULNERABILITY_ID_SET);
for (final String vulnId : eventVulnIdSet) {
for (final VulnerabilityV2View vulnerability : vulnerabilityList) {
final NotificationCategoryEnum eventCategory = getEventCategory(vulnerability.severity);
final String vulnName = vulnerability.name;
if (vulnId.equals(vulnName)) {
if (eventMap.containsKey(eventCategory)) {
final NotificationEvent event = eventMap.get(eventCategory);
final Set<String> vulnSet = (Set<String>) event.getDataSet().get(VULNERABILITY_ID_SET);
vulnSet.add(vulnName);
} else {
final Set<String> vulnset = new HashSet<>();
vulnset.add(vulnName);
final Map<String, Object> dataSet = new HashMap<>(originalEvent.getDataSet());
dataSet.put(VULNERABILITY_ID_SET, vulnset);
final NotificationEvent event = new NotificationEvent(originalEvent.getEventKey(), eventCategory, dataSet);
eventMap.put(eventCategory, event);
eventList.add(event);
}
}
}
}
}
use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum in project hub-alert by blackducksoftware.
the class AccumulatorWriterTest method testWrite.
@Test
public void testWrite() throws Exception {
final NotificationManager notificationManager = Mockito.mock(NotificationManager.class);
final ChannelTemplateManager channelTemplateManager = Mockito.mock(ChannelTemplateManager.class);
final AccumulatorWriter accumulatorWriter = new AccumulatorWriter(notificationManager, channelTemplateManager);
final String eventKey = "_event_key_";
final NotificationCategoryEnum categoryType = NotificationCategoryEnum.HIGH_VULNERABILITY;
final NotificationEvent notificationEvent = new NotificationEvent(eventKey, categoryType, generateDataSet());
final DBStoreEvent storeEvent = new DBStoreEvent(Arrays.asList(notificationEvent));
accumulatorWriter.write(Arrays.asList(storeEvent));
Mockito.verify(channelTemplateManager).sendEvent(Mockito.any());
}
Aggregations