Search in sources :

Example 11 with NotificationEvent

use of com.blackducksoftware.integration.hub.notification.NotificationEvent in project hub-alert by blackducksoftware.

the class VulnerabilityCache method addEventsToList.

@SuppressWarnings("unchecked")
private void addEventsToList(final NotificationEvent originalEvent, final List<VulnerabilityV2View> vulnerabilityList, final List<NotificationEvent> eventList) {
    final Map<NotificationCategoryEnum, NotificationEvent> eventMap = new HashMap<>();
    final Set<String> eventVulnIdSet = (Set<String>) originalEvent.getDataSet().get(VULNERABILITY_ID_SET);
    for (final String vulnId : eventVulnIdSet) {
        for (final VulnerabilityV2View vulnerability : vulnerabilityList) {
            final NotificationCategoryEnum eventCategory = getEventCategory(vulnerability.severity);
            final String vulnName = vulnerability.name;
            if (vulnId.equals(vulnName)) {
                if (eventMap.containsKey(eventCategory)) {
                    final NotificationEvent event = eventMap.get(eventCategory);
                    final Set<String> vulnSet = (Set<String>) event.getDataSet().get(VULNERABILITY_ID_SET);
                    vulnSet.add(vulnName);
                } else {
                    final Set<String> vulnset = new HashSet<>();
                    vulnset.add(vulnName);
                    final Map<String, Object> dataSet = new HashMap<>(originalEvent.getDataSet());
                    dataSet.put(VULNERABILITY_ID_SET, vulnset);
                    final NotificationEvent event = new NotificationEvent(originalEvent.getEventKey(), eventCategory, dataSet);
                    eventMap.put(eventCategory, event);
                    eventList.add(event);
                }
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) VulnerabilityV2View(com.blackducksoftware.integration.hub.api.generated.view.VulnerabilityV2View) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) HashSet(java.util.HashSet)

Example 12 with NotificationEvent

use of com.blackducksoftware.integration.hub.notification.NotificationEvent in project hub-alert by blackducksoftware.

the class VulnerabilityCache method createVulnerabilityEvents.

private List<NotificationEvent> createVulnerabilityEvents(final NotificationEvent originalEvent) throws IntegrationException {
    final List<NotificationEvent> eventList = new LinkedList<>();
    final VulnerabilityContentItem vulnerabilityContent = (VulnerabilityContentItem) originalEvent.getDataSet().get(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT);
    final List<VulnerabilityV2View> vulnerabilityList = hubServicesFactory.createHubService().getAllResponses(vulnerabilityContent.getComponentVersion(), ComponentVersionView.VULNERABILITIES_LINK_RESPONSE);
    addEventsToList(originalEvent, vulnerabilityList, eventList);
    addCountsToDataSet(eventList);
    return eventList;
}
Also used : VulnerabilityContentItem(com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem) VulnerabilityV2View(com.blackducksoftware.integration.hub.api.generated.view.VulnerabilityV2View) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) LinkedList(java.util.LinkedList)

Example 13 with NotificationEvent

use of com.blackducksoftware.integration.hub.notification.NotificationEvent in project hub-alert by blackducksoftware.

the class AccumulatorWriterTest method testWrite.

@Test
public void testWrite() throws Exception {
    final NotificationManager notificationManager = Mockito.mock(NotificationManager.class);
    final ChannelTemplateManager channelTemplateManager = Mockito.mock(ChannelTemplateManager.class);
    final AccumulatorWriter accumulatorWriter = new AccumulatorWriter(notificationManager, channelTemplateManager);
    final String eventKey = "_event_key_";
    final NotificationCategoryEnum categoryType = NotificationCategoryEnum.HIGH_VULNERABILITY;
    final NotificationEvent notificationEvent = new NotificationEvent(eventKey, categoryType, generateDataSet());
    final DBStoreEvent storeEvent = new DBStoreEvent(Arrays.asList(notificationEvent));
    accumulatorWriter.write(Arrays.asList(storeEvent));
    Mockito.verify(channelTemplateManager).sendEvent(Mockito.any());
}
Also used : NotificationManager(com.blackducksoftware.integration.hub.alert.NotificationManager) ChannelTemplateManager(com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent) Test(org.junit.Test)

Example 14 with NotificationEvent

use of com.blackducksoftware.integration.hub.notification.NotificationEvent in project hub-alert by blackducksoftware.

the class NotificationItemProcessorTest method testProcessEvents.

@Test
public void testProcessEvents() throws HubIntegrationException {
    final GlobalProperties globalProperties = new TestGlobalProperties();
    final NotificationEvent event1 = new NotificationEvent("event 1", NotificationCategoryEnum.HIGH_VULNERABILITY, null);
    final NotificationEvent event2 = new NotificationEvent("event 2", NotificationCategoryEnum.LOW_VULNERABILITY, null);
    final List<NotificationEvent> eventList = Arrays.asList(event1, event2);
    final NotificationItemProcessor notificationItemProcessor = new NotificationItemProcessor(globalProperties, new TestLogger());
    final DBStoreEvent storeEvent = notificationItemProcessor.processEvents(eventList);
    assertEquals("DB_STORE_EVENT", storeEvent.getTopic());
    assertTrue(storeEvent.getNotificationList().size() == 2);
}
Also used : TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent) TestLogger(com.blackducksoftware.integration.test.TestLogger) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test)

Example 15 with NotificationEvent

use of com.blackducksoftware.integration.hub.notification.NotificationEvent in project hub-alert by blackducksoftware.

the class UserNotificationCacheTest method testAddUserInformation.

@Test
public void testAddUserInformation() throws IntegrationException {
    final ProjectService mockedProjectService = Mockito.mock(ProjectService.class);
    final UserNotificationCache userNotificationCache = new UserNotificationCache(mockedProjectService);
    final AssignedUserView assignedUser = new AssignedUserView();
    assignedUser.name = "test name";
    final List<AssignedUserView> assignedUsersList = Arrays.asList(assignedUser);
    Mockito.when(mockedProjectService.getAssignedUsersToProject(Mockito.anyString())).thenReturn(assignedUsersList);
    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> notEmptyEventList = Arrays.asList();
    assertTrue(notEmptyEventList.size() == 0);
    notEmptyEventList = userNotificationCache.addUserInformation(notificationEvents);
    assertTrue(notEmptyEventList.size() == 1);
}
Also used : 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) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) AssignedUserView(com.blackducksoftware.integration.hub.api.generated.view.AssignedUserView) Test(org.junit.Test)

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