use of com.blackducksoftware.integration.hub.notification.NotificationContentItem 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.NotificationContentItem 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;
}
use of com.blackducksoftware.integration.hub.notification.NotificationContentItem in project hub-alert by blackducksoftware.
the class VulnerabilityProcessor method generateEventKey.
@Override
public String generateEventKey(final Map<String, Object> dataMap) {
final NotificationContentItem content = (NotificationContentItem) dataMap.get(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT);
final StringBuilder keyBuilder = new StringBuilder();
keyBuilder.append(NotificationEventConstants.EVENT_KEY_ISSUE_TYPE_NAME);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_SEPARATOR);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_ISSUE_TYPE_VALUE_VULNERABILITY);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_PAIR_SEPARATOR);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_HUB_PROJECT_VERSION_REL_URL_HASHED_NAME);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_SEPARATOR);
keyBuilder.append(hashString(content.getProjectVersion().getUrl()));
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_PAIR_SEPARATOR);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_HUB_COMPONENT_REL_URL_HASHED_NAME);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_SEPARATOR);
// There is never a component URL
keyBuilder.append("");
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_PAIR_SEPARATOR);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_HUB_COMPONENT_VERSION_REL_URL_HASHED_NAME);
keyBuilder.append(NotificationEventConstants.EVENT_KEY_NAME_VALUE_SEPARATOR);
keyBuilder.append(hashString(content.getComponentVersionUrl()));
final String key = keyBuilder.toString();
return key;
}
Aggregations