Search in sources :

Example 6 with VulnerabilityEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity in project hub-alert by blackducksoftware.

the class NotificationModelTest method testNotificationNull.

@Test
public void testNotificationNull() {
    final NotificationEntity entity = null;
    final VulnerabilityEntity vuln1 = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, 1L);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vuln1);
    final NotificationModel model = new NotificationModel(entity, vulnerabilityList);
    assertNull(model.getComponentName());
    assertNull(model.getComponentVersion());
    assertNull(model.getCreatedAt());
    assertNull(model.getEventKey());
    assertNull(model.getNotificationEntity());
    assertNull(model.getNotificationType());
    assertNull(model.getPolicyRuleName());
    assertNull(model.getPolicyRuleUser());
    assertNull(model.getProjectName());
    assertNull(model.getProjectUrl());
    assertNull(model.getProjectVersion());
    assertNull(model.getProjectVersionUrl());
    assertEquals(vulnerabilityList.size(), model.getVulnerabilityList().size());
    final boolean allEqual = model.getVulnerabilityList().stream().allMatch(vuln1::equals);
    assertTrue(allEqual);
}
Also used : 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) Test(org.junit.Test)

Example 7 with VulnerabilityEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity in project hub-alert by blackducksoftware.

the class NotificationModelTest method testModel.

@Test
public void testModel() {
    final NotificationEntity entity = createNotificationEntity();
    final VulnerabilityEntity vuln1 = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, 1L);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vuln1);
    final NotificationModel model = new NotificationModel(entity, vulnerabilityList);
    assertEquals(entity.getComponentName(), model.getComponentName());
    assertEquals(entity.getComponentVersion(), model.getComponentVersion());
    assertEquals(entity.getCreatedAt(), model.getCreatedAt());
    assertEquals(entity.getEventKey(), model.getEventKey());
    assertEquals(entity, model.getNotificationEntity());
    assertEquals(entity.getNotificationType(), model.getNotificationType());
    assertEquals(entity.getPolicyRuleName(), model.getPolicyRuleName());
    assertEquals(entity.getPolicyRuleUser(), model.getPolicyRuleUser());
    assertEquals(entity.getProjectName(), model.getProjectName());
    assertEquals(entity.getProjectUrl(), model.getProjectUrl());
    assertEquals(entity.getProjectVersion(), model.getProjectVersion());
    assertEquals(entity.getProjectVersionUrl(), model.getProjectVersionUrl());
    assertEquals(vulnerabilityList.size(), model.getVulnerabilityList().size());
    final boolean allEqual = model.getVulnerabilityList().stream().allMatch(vuln1::equals);
    assertTrue(allEqual);
}
Also used : 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) Test(org.junit.Test)

Example 8 with VulnerabilityEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity in project hub-alert by blackducksoftware.

the class VulnerabiltyRespositoryWrapperTest method testFindById.

@Test
public void testFindById() throws IOException, EncryptionException {
    final VulnerabilityRepositoryWrapper wrapper = getExceptionThrowingRepositoryWrapper();
    final VulnerabilityEntity entity = wrapper.findById(1L);
    assertExceptionThrown(entity);
}
Also used : VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) MockVulnerabilityEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockVulnerabilityEntity) Test(org.junit.Test)

Example 9 with VulnerabilityEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity in project hub-alert by blackducksoftware.

the class NotificationManager method createModelList.

private List<NotificationModel> createModelList(final List<NotificationEntity> entityList) {
    final List<NotificationModel> resultList = new ArrayList<>();
    entityList.forEach(notification -> {
        final List<VulnerabilityEntity> vulnerabilities = vulnerabilityRepository.findByNotificationId(notification.getId());
        resultList.add(new NotificationModel(notification, vulnerabilities));
    });
    return resultList;
}
Also used : ArrayList(java.util.ArrayList) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)

Example 10 with VulnerabilityEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity 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)

Aggregations

VulnerabilityEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)22 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)13 Test (org.junit.Test)13 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)12 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)10 Date (java.util.Date)6 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)5 ArrayList (java.util.ArrayList)5 VulnerabilityOperationEnum (com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum)3 List (java.util.List)2 Set (java.util.Set)2 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)1 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)1 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)1 NotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.NotificationRepositoryWrapper)1 VulnerabilityRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.VulnerabilityRepositoryWrapper)1 RealTimeEvent (com.blackducksoftware.integration.hub.alert.event.RealTimeEvent)1 MockVulnerabilityEntity (com.blackducksoftware.integration.hub.alert.mock.entity.MockVulnerabilityEntity)1 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)1 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)1