Search in sources :

Example 6 with NotificationEvent

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

the class AccumulatorWriter method write.

@Override
public void write(final List<? extends DBStoreEvent> itemList) throws Exception {
    try {
        if (itemList != null && !itemList.isEmpty()) {
            logger.info("Writing {} notifications", itemList.size());
            itemList.forEach(item -> {
                final List<NotificationEvent> notificationList = item.getNotificationList();
                final List<NotificationModel> entityList = new ArrayList<>();
                notificationList.forEach(notification -> {
                    final String eventKey = notification.getEventKey();
                    final NotificationContentItem content = (NotificationContentItem) notification.getDataSet().get(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT);
                    final Date createdAt = content.getCreatedAt();
                    final NotificationCategoryEnum notificationType = notification.getCategoryType();
                    final String projectName = content.getProjectVersion().getProjectName();
                    final String projectUrl = content.getProjectVersion().getProjectLink();
                    final String projectVersion = content.getProjectVersion().getProjectVersionName();
                    final String projectVersionUrl = content.getProjectVersion().getUrl();
                    final String componentName = content.getComponentName();
                    final String componentVersion = content.getComponentVersion().versionName;
                    final String policyRuleName = getPolicyRule(notification);
                    final String person = getPerson(notification);
                    final NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
                    final Collection<VulnerabilityEntity> vulnerabilityList = getVulnerabilities(notification, entity);
                    NotificationModel model = new NotificationModel(entity, vulnerabilityList);
                    model = notificationManager.saveNotification(model);
                    entityList.add(model);
                });
                final RealTimeEvent realTimeEvent = new RealTimeEvent(entityList);
                channelTemplateManager.sendEvent(realTimeEvent);
            });
        } else {
            logger.info("No notifications to write");
        }
    } catch (final Exception ex) {
        logger.error("Error occurred writing notification data", ex);
    }
}
Also used : ArrayList(java.util.ArrayList) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) RealTimeEvent(com.blackducksoftware.integration.hub.alert.event.RealTimeEvent) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) Date(java.util.Date) NotificationContentItem(com.blackducksoftware.integration.hub.notification.NotificationContentItem) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)

Example 7 with NotificationEvent

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

the class PolicyOverrideProcessor method process.

@Override
public void process(final NotificationContentItem notification) throws HubIntegrationException {
    final PolicyOverrideContentItem policyOverrideContentItem = (PolicyOverrideContentItem) notification;
    final Map<String, Object> dataMap = new HashMap<>();
    for (final PolicyRuleView rule : policyOverrideContentItem.getPolicyRuleList()) {
        dataMap.put(POLICY_CONTENT_ITEM, policyOverrideContentItem);
        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_OVERRIDE);
            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) PolicyOverrideContentItem(com.blackducksoftware.integration.hub.notification.PolicyOverrideContentItem)

Example 8 with NotificationEvent

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

the class VulnerabilityCache method addEvent.

// The dataset contains string keys and object values. Therefore we need to type cast because the contents are various types.
@SuppressWarnings("unchecked")
@Override
public void addEvent(final NotificationEvent event) {
    final String key = event.getEventKey();
    if (!hasEvent(key)) {
        getEventMap().put(key, event);
    } else {
        final NotificationEvent storedEvent = getEventMap().get(key);
        final Map<String, Object> storedEventDataMap = storedEvent.getDataSet();
        final Map<String, Object> eventDataMap = event.getDataSet();
        final Set<String> eventVulnIdSet = (Set<String>) eventDataMap.get(VULNERABILITY_ID_SET);
        final Set<String> storedVulnIdSet = (Set<String>) storedEventDataMap.get(VULNERABILITY_ID_SET);
        if (!eventVulnIdSet.isEmpty()) {
            storedVulnIdSet.addAll(eventVulnIdSet);
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent)

Example 9 with NotificationEvent

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

the class VulnerabilityCache method getEvents.

@Override
public Collection<NotificationEvent> getEvents() throws HubIntegrationException {
    final Collection<NotificationEvent> vulnerabilities = super.getEvents();
    // need to group the vulnerabilities by severity which can be gathered by the vulnerability API.
    final Collection<NotificationEvent> result = new LinkedList<>();
    for (final NotificationEvent event : vulnerabilities) {
        List<NotificationEvent> vulnerabilityEvents;
        try {
            vulnerabilityEvents = createVulnerabilityEvents(event);
        } catch (final IntegrationException e) {
            throw new HubIntegrationException(e);
        }
        for (final NotificationEvent vulnerability : vulnerabilityEvents) {
            result.add(vulnerability);
        }
    }
    return this.addUserInformation(result);
}
Also used : HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) LinkedList(java.util.LinkedList) HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException)

Example 10 with NotificationEvent

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

the class VulnerabilityCache method addCountsToDataSet.

@SuppressWarnings("unchecked")
private void addCountsToDataSet(final List<NotificationEvent> eventList) {
    for (final NotificationEvent event : eventList) {
        final Set<String> eventVulnIdSet = (Set<String>) event.getDataSet().get(VULNERABILITY_ID_SET);
        final int size = eventVulnIdSet.size();
        if (size > 1) {
            event.getDataSet().put(ItemTypeEnum.COUNT.name(), new Integer(size));
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent)

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