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);
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations