use of com.blackducksoftware.integration.hub.notification.NotificationEvent 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.NotificationEvent in project hub-alert by blackducksoftware.
the class PolicyOverrideProcessor method process.
@Override
public void process(final NotificationContentItem notification) throws HubIntegrationException {
final PolicyOverrideContentItem policyOverrideContentItem = (PolicyOverrideContentItem) notification;
final Map<String, Object> dataMap = new HashMap<>();
for (final PolicyRuleView rule : policyOverrideContentItem.getPolicyRuleList()) {
dataMap.put(POLICY_CONTENT_ITEM, policyOverrideContentItem);
dataMap.put(POLICY_RULE, rule);
final String eventKey = generateEventKey(dataMap);
final Map<String, Object> dataSet = generateDataSet(dataMap);
final NotificationEvent event = new NotificationEvent(eventKey, NotificationCategoryEnum.POLICY_VIOLATION, dataSet);
if (getCache().hasEvent(event.getEventKey())) {
getCache().removeEvent(event);
} else {
event.setCategoryType(NotificationCategoryEnum.POLICY_VIOLATION_OVERRIDE);
getCache().addEvent(event);
}
}
}
use of com.blackducksoftware.integration.hub.notification.NotificationEvent in project hub-alert by blackducksoftware.
the class VulnerabilityCache method addEvent.
// The dataset contains string keys and object values. Therefore we need to type cast because the contents are various types.
@SuppressWarnings("unchecked")
@Override
public void addEvent(final NotificationEvent event) {
final String key = event.getEventKey();
if (!hasEvent(key)) {
getEventMap().put(key, event);
} else {
final NotificationEvent storedEvent = getEventMap().get(key);
final Map<String, Object> storedEventDataMap = storedEvent.getDataSet();
final Map<String, Object> eventDataMap = event.getDataSet();
final Set<String> eventVulnIdSet = (Set<String>) eventDataMap.get(VULNERABILITY_ID_SET);
final Set<String> storedVulnIdSet = (Set<String>) storedEventDataMap.get(VULNERABILITY_ID_SET);
if (!eventVulnIdSet.isEmpty()) {
storedVulnIdSet.addAll(eventVulnIdSet);
}
}
}
use of com.blackducksoftware.integration.hub.notification.NotificationEvent in project hub-alert by blackducksoftware.
the class VulnerabilityCache method getEvents.
@Override
public Collection<NotificationEvent> getEvents() throws HubIntegrationException {
final Collection<NotificationEvent> vulnerabilities = super.getEvents();
// need to group the vulnerabilities by severity which can be gathered by the vulnerability API.
final Collection<NotificationEvent> result = new LinkedList<>();
for (final NotificationEvent event : vulnerabilities) {
List<NotificationEvent> vulnerabilityEvents;
try {
vulnerabilityEvents = createVulnerabilityEvents(event);
} catch (final IntegrationException e) {
throw new HubIntegrationException(e);
}
for (final NotificationEvent vulnerability : vulnerabilityEvents) {
result.add(vulnerability);
}
}
return this.addUserInformation(result);
}
use of com.blackducksoftware.integration.hub.notification.NotificationEvent in project hub-alert by blackducksoftware.
the class VulnerabilityCache method addCountsToDataSet.
@SuppressWarnings("unchecked")
private void addCountsToDataSet(final List<NotificationEvent> eventList) {
for (final NotificationEvent event : eventList) {
final Set<String> eventVulnIdSet = (Set<String>) event.getDataSet().get(VULNERABILITY_ID_SET);
final int size = eventVulnIdSet.size();
if (size > 1) {
event.getDataSet().put(ItemTypeEnum.COUNT.name(), new Integer(size));
}
}
}
Aggregations