use of com.blackducksoftware.integration.hub.notification.NotificationEvent in project hub-alert by blackducksoftware.
the class UserNotificationCacheTest method testAddUserInformationException.
@Test
public void testAddUserInformationException() throws Exception {
try (OutputLogger outputLogger = new OutputLogger()) {
final ProjectService mockedProjectService = Mockito.mock(ProjectService.class);
final UserNotificationCache userNotificationCache = new UserNotificationCache(mockedProjectService);
Mockito.doThrow(new IntegrationException()).when(mockedProjectService).getAssignedUsersToProject(Mockito.anyString());
final Date createdAt = new Date();
final ProjectVersionModel projectVersionModel = new ProjectVersionModel();
projectVersionModel.setProjectLink("New project link");
final String componentName = "notification test";
final ComponentVersionView componentVersionView = new ComponentVersionView();
final String componentVersionUrl = "sss";
final String componentIssueUrl = "ddd";
final Map<String, Object> dataSet = new HashMap<>();
dataSet.put(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT, new NotificationContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, componentIssueUrl));
final NotificationEvent notificationEvent = new NotificationEvent("key", NotificationCategoryEnum.HIGH_VULNERABILITY, dataSet);
final List<NotificationEvent> notificationEvents = Arrays.asList(notificationEvent);
Collection<NotificationEvent> emptyEventList = Arrays.asList();
assertEquals(0, emptyEventList.size());
emptyEventList = userNotificationCache.addUserInformation(notificationEvents);
assertEquals(0, emptyEventList.size());
assertTrue(outputLogger.isLineContainingText("Error getting the users for project"));
}
}
use of com.blackducksoftware.integration.hub.notification.NotificationEvent in project hub-alert by blackducksoftware.
the class PolicyViolationClearedProcessor method process.
@Override
public void process(final NotificationContentItem notification) throws HubIntegrationException {
if (notification instanceof PolicyViolationClearedContentItem) {
final PolicyViolationClearedContentItem policyViolationCleared = (PolicyViolationClearedContentItem) notification;
final Map<String, Object> dataMap = new HashMap<>();
for (final PolicyRuleView rule : policyViolationCleared.getPolicyRuleList()) {
dataMap.put(POLICY_CONTENT_ITEM, policyViolationCleared);
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_CLEARED);
getCache().addEvent(event);
}
}
}
}
use of com.blackducksoftware.integration.hub.notification.NotificationEvent in project hub-alert by blackducksoftware.
the class UserNotificationCache method addUserInformation.
public Collection<NotificationEvent> addUserInformation(final Collection<NotificationEvent> notificationEvents) {
final List<NotificationEvent> userEventList = new ArrayList<>();
final String key = AlertConstants.DATASET_KEY_HUB_USER;
notificationEvents.forEach(currentNotification -> {
final NotificationContentItem notificationContentItem = (NotificationContentItem) currentNotification.getDataSet().get(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT);
final String projectName = notificationContentItem.getProjectVersion().getProjectName();
final List<String> userNameList = getUserNames(projectName);
userNameList.forEach(userName -> {
final String eventKey = currentNotification.getEventKey();
final NotificationCategoryEnum categoryType = currentNotification.getCategoryType();
final Map<String, Object> dataSet = new HashMap<>(currentNotification.getDataSet());
dataSet.put(key, userName);
final NotificationEvent userEvent = new NotificationEvent(eventKey, categoryType, dataSet);
userEventList.add(userEvent);
});
});
return userEventList;
}
Aggregations