Search in sources :

Example 16 with NotificationEvent

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"));
    }
}
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 17 with NotificationEvent

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);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) PolicyRuleView(com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) PolicyViolationClearedContentItem(com.blackducksoftware.integration.hub.notification.PolicyViolationClearedContentItem)

Example 18 with NotificationEvent

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;
}
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)

Aggregations

NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)18 HashMap (java.util.HashMap)9 Test (org.junit.Test)7 Date (java.util.Date)6 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)5 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)4 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)4 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)4 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 DBStoreEvent (com.blackducksoftware.integration.hub.alert.event.DBStoreEvent)3 PolicyRuleView (com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView)3 VulnerabilityV2View (com.blackducksoftware.integration.hub.api.generated.view.VulnerabilityV2View)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 AssignedUserView (com.blackducksoftware.integration.hub.api.generated.view.AssignedUserView)2 VulnerabilityContentItem (com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem)2 ComponentService (com.blackducksoftware.integration.hub.service.ComponentService)2 HubService (com.blackducksoftware.integration.hub.service.HubService)2 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)2