Search in sources :

Example 6 with NotificationContentItem

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"));
    }
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) HashMap(java.util.HashMap) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) Date(java.util.Date) NotificationContentItem(com.blackducksoftware.integration.hub.notification.NotificationContentItem) OutputLogger(com.blackducksoftware.integration.hub.alert.OutputLogger) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) Test(org.junit.Test)

Example 7 with NotificationContentItem

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;
}
Also used : NotificationContentItem(com.blackducksoftware.integration.hub.notification.NotificationContentItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)

Example 8 with NotificationContentItem

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;
}
Also used : NotificationContentItem(com.blackducksoftware.integration.hub.notification.NotificationContentItem)

Aggregations

NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)8 Date (java.util.Date)6 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)5 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)5 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)4 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)3 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)2 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)2 ArrayList (java.util.ArrayList)2 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 OutputLogger (com.blackducksoftware.integration.hub.alert.OutputLogger)1 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)1 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)1 VulnerabilityEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)1 RealTimeEvent (com.blackducksoftware.integration.hub.alert.event.RealTimeEvent)1 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)1 AssignedUserView (com.blackducksoftware.integration.hub.api.generated.view.AssignedUserView)1 NotificationResults (com.blackducksoftware.integration.hub.notification.NotificationResults)1