Search in sources :

Example 6 with NotificationCategoryEnum

use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum 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 NotificationCategoryEnum

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

the class NotificationTypesActions method addNewDistributionNotificationTypes.

private void addNewDistributionNotificationTypes(final Long commonDistributionConfigId, final List<String> notificationTypesFromRestModel) {
    for (final String notificationType : notificationTypesFromRestModel) {
        final NotificationCategoryEnum notificationTypeEnum = NotificationCategoryEnum.valueOf(notificationType);
        Long notificationTypeId;
        final NotificationTypeEntity foundEntity = notificationTypeRepository.findByType(notificationTypeEnum);
        if (foundEntity != null) {
            notificationTypeId = foundEntity.getId();
        } else {
            final NotificationTypeEntity createdEntity = notificationTypeRepository.save(new NotificationTypeEntity(notificationTypeEnum));
            notificationTypeId = createdEntity.getId();
        }
        distributionNotificationTypeRepository.save(new DistributionNotificationTypeRelation(commonDistributionConfigId, notificationTypeId));
    }
}
Also used : DistributionNotificationTypeRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionNotificationTypeRelation) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationTypeEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity)

Example 8 with NotificationCategoryEnum

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

the class NotificationManagerTestIT method createNotificationEntity.

private NotificationEntity createNotificationEntity(final Date createdAt) {
    final String eventKey = "event_key_for_notification";
    final NotificationCategoryEnum notificationType = NotificationCategoryEnum.VULNERABILITY;
    final String projectName = "projectName";
    final String projectVersion = "projectVersion";
    final String componentName = "componentName";
    final String componentVersion = "componentVersion";
    final String policyRuleName = "policyRuleName";
    final String person = "person";
    final String projectUrl = "projectURL";
    final String projectVersionUrl = "projectVersionUrl";
    final NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
    return entity;
}
Also used : NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)

Example 9 with NotificationCategoryEnum

use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum 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 10 with NotificationCategoryEnum

use of com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum 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)

Aggregations

NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)19 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)8 Date (java.util.Date)6 HashMap (java.util.HashMap)6 VulnerabilityEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)5 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)5 CategoryData (com.blackducksoftware.integration.hub.alert.digest.model.CategoryData)4 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)3 VulnerabilityOperationEnum (com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum)3 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 NotificationTypeEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity)2 DistributionNotificationTypeRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionNotificationTypeRelation)2 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)2 ZonedDateTime (java.time.ZonedDateTime)2 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)1