Search in sources :

Example 1 with NotificationCategoryEnum

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

the class ProjectDataFactoryTest method createVulnerabilityNotification.

private NotificationModel createVulnerabilityNotification(final String projectName, final String projectVersion) {
    final String eventKey = "key";
    final Date createdAt = new Date();
    final NotificationCategoryEnum notificationType = NotificationCategoryEnum.MEDIUM_VULNERABILITY;
    final String projectUrl = "http://localhost:8080";
    final String projectVersionUrl = "http://localhost:8080";
    final String componentName = "Component";
    final String componentVersion = "Component Version";
    final String policyRuleName = null;
    final String policyRuleUser = null;
    final String vulnerabilityId = NotificationCategoryEnum.VULNERABILITY.name();
    final VulnerabilityOperationEnum vulnerabilityOperation = VulnerabilityOperationEnum.ADD;
    final NotificationEntity notification = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, policyRuleUser);
    notification.setId(1L);
    final Collection<VulnerabilityEntity> vulnerabilityList = Arrays.asList(new VulnerabilityEntity(vulnerabilityId, vulnerabilityOperation, notification.getId()));
    return new NotificationModel(notification, vulnerabilityList);
}
Also used : NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) VulnerabilityOperationEnum(com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.util.Date)

Example 2 with NotificationCategoryEnum

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

the class PurgeJobIT method testReaderWithData.

@Test
public void testReaderWithData() throws Exception {
    final List<NotificationEntity> entityList = new ArrayList<>();
    final String eventKey = "eventKey";
    final NotificationCategoryEnum notificationType = NotificationCategoryEnum.VULNERABILITY;
    final String projectName = "ProjectName";
    final String projectUrl = "ProjectUrl";
    final String projectVersion = "ProjectVersion";
    final String projectVersionUrl = "ProjectVersionUrl";
    final String componentName = "ComponentName";
    final String componentVersion = "ComponentVersion";
    final String policyRuleName = "PolicyRuleName";
    final String person = "PolicyPerson";
    ZonedDateTime zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
    zonedDateTime = zonedDateTime.minusDays(1);
    Date createdAt = Date.from(zonedDateTime.toInstant());
    entityList.add(new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person));
    zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
    zonedDateTime = zonedDateTime.minusDays(3);
    createdAt = Date.from(zonedDateTime.toInstant());
    entityList.add(new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person));
    zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
    zonedDateTime = zonedDateTime.plusDays(1);
    createdAt = Date.from(zonedDateTime.toInstant());
    entityList.add(new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person));
    notificationRepository.save(entityList);
    final PurgeReader reader = purgeConfig.reader();
    final List<NotificationModel> resultList = reader.read();
    assertEquals(2, resultList.size());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ArrayList(java.util.ArrayList) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.util.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 3 with NotificationCategoryEnum

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

the class NotificationPostProcessorTestIT method getApplicableConfigurationsTest.

@Test
public void getApplicableConfigurationsTest() {
    final NotificationPostProcessor postProcessor = new NotificationPostProcessor(distributionProjectRepository, configuredProjectsRepository, distributionNotificationTypeRepository, notificationTypeRepository);
    final DigestTypeEnum digestType = DigestTypeEnum.REAL_TIME;
    final String projectName = "Project Name";
    final String projectVersion = "Project Version";
    final List<Long> notificationIds = Collections.emptyList();
    final Map<NotificationCategoryEnum, CategoryData> categoryMap = new HashMap<>();
    for (final NotificationCategoryEnum categoryEnum : NotificationCategoryEnum.values()) {
        categoryMap.put(categoryEnum, new CategoryData(null, null, 0));
        notificationTypeRepository.save(new NotificationTypeEntity(categoryEnum));
    }
    final ProjectData projectData = new ProjectData(digestType, projectName, projectVersion, notificationIds, categoryMap);
    final Long config1Id = 13L;
    final CommonDistributionConfigEntity config1 = new CommonDistributionConfigEntity(config1Id, SupportedChannels.EMAIL_GROUP, "Config 1", digestType, true);
    config1.setId(config1Id);
    final Long config2Id = 17L;
    final CommonDistributionConfigEntity config2 = new CommonDistributionConfigEntity(config2Id, SupportedChannels.EMAIL_GROUP, "Config 2", digestType, false);
    config2.setId(config2Id);
    final Long notificationTypeId = notificationTypeRepository.findAll().get(0).getId();
    distributionNotificationTypeRepository.save(new DistributionNotificationTypeRelation(config1.getId(), notificationTypeId));
    distributionNotificationTypeRepository.save(new DistributionNotificationTypeRelation(config2.getId(), notificationTypeId));
    final ConfiguredProjectEntity configuredProjectEntity = configuredProjectsRepository.save(new ConfiguredProjectEntity(projectName));
    distributionProjectRepository.save(new DistributionProjectRelation(config1.getId(), configuredProjectEntity.getId()));
    final Set<CommonDistributionConfigEntity> applicableConfigs = postProcessor.getApplicableConfigurations(Arrays.asList(config1, config2), projectData);
    assertTrue(applicableConfigs.contains(config1));
    assertTrue(applicableConfigs.contains(config2));
    assertEquals(2, applicableConfigs.size());
}
Also used : DigestTypeEnum(com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum) CategoryData(com.blackducksoftware.integration.hub.alert.digest.model.CategoryData) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) HashMap(java.util.HashMap) ConfiguredProjectEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity) DistributionNotificationTypeRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionNotificationTypeRelation) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) DistributionProjectRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation) NotificationTypeEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 4 with NotificationCategoryEnum

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

the class ProjectDataFactory method addCategoryData.

// get the category data object to be able to add items.
private void addCategoryData(final NotificationModel notification, final CategoryDataBuilder categoryData) {
    final Map<String, Object> dataSet = new HashMap<>();
    final NotificationCategoryEnum categoryKey = notification.getNotificationType();
    int countAdded = 0;
    int countUpdated = 0;
    int countDeleted = 0;
    if (categoryKey == NotificationCategoryEnum.HIGH_VULNERABILITY || categoryKey == NotificationCategoryEnum.MEDIUM_VULNERABILITY || categoryKey == NotificationCategoryEnum.LOW_VULNERABILITY) {
        addVulnerabilitySets(dataSet, notification);
        countAdded = dataSet.containsKey(VULNERABILITY_ADDED_ID_SET) ? ((Set<?>) dataSet.get(VULNERABILITY_ADDED_ID_SET)).size() : 0;
        countUpdated = dataSet.containsKey(VULNERABILITY_UPDATED_ID_SET) ? ((Set<?>) dataSet.get(VULNERABILITY_UPDATED_ID_SET)).size() : 0;
        countDeleted = dataSet.containsKey(VULNERABILITY_DELETED_ID_SET) ? ((Set<?>) dataSet.get(VULNERABILITY_DELETED_ID_SET)).size() : 0;
    }
    if (StringUtils.isNotBlank(notification.getPolicyRuleName())) {
        dataSet.put(ItemTypeEnum.RULE.name(), notification.getPolicyRuleName());
    }
    dataSet.put(ItemTypeEnum.COMPONENT.name(), notification.getComponentName());
    dataSet.put(ItemTypeEnum.VERSION.name(), notification.getComponentVersion());
    if (countAdded > 0) {
        dataSet.put(VULNERABILITY_COUNT_KEY_ADDED, countAdded);
    }
    if (countUpdated > 0) {
        dataSet.put(VULNERABILITY_COUNT_KEY_UPDATED, countUpdated);
    }
    if (countDeleted > 0) {
        dataSet.put(VULNERABILITY_COUNT_KEY_DELETED, countDeleted);
    }
    categoryData.addItem(new ItemData(dataSet));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)

Example 5 with NotificationCategoryEnum

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

the class NotificationRepositoryTestIT 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 NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, null, projectVersion, null, componentName, componentVersion, policyRuleName, person);
    return entity;
}
Also used : NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)

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