use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel 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.hub.model.NotificationModel 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);
}
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class AuditEntryActions method createRestModel.
private AuditEntryRestModel createRestModel(final AuditEntryEntity auditEntryEntity) {
final Long commonConfigId = auditEntryEntity.getCommonConfigId();
final List<AuditNotificationRelation> relations = auditNotificationRepository.findByAuditEntryId(auditEntryEntity.getId());
final List<Long> notificationIds = relations.stream().map(relation -> relation.getNotificationId()).collect(Collectors.toList());
final List<NotificationModel> notifications = notificationManager.findByIds(notificationIds);
final CommonDistributionConfigEntity commonConfigEntity = commonDistributionRepository.findOne(commonConfigId);
final String id = objectTransformer.objectToString(auditEntryEntity.getId());
final String timeCreated = objectTransformer.objectToString(auditEntryEntity.getTimeCreated());
final String timeLastSent = objectTransformer.objectToString(auditEntryEntity.getTimeLastSent());
String status = null;
if (auditEntryEntity.getStatus() != null) {
status = auditEntryEntity.getStatus().getDisplayName();
}
final String errorMessage = auditEntryEntity.getErrorMessage();
final String errorStackTrace = auditEntryEntity.getErrorStackTrace();
NotificationRestModel notificationRestModel = null;
if (!notifications.isEmpty() && notifications.get(0) != null) {
try {
notificationRestModel = objectTransformer.databaseEntityToConfigRestModel(notifications.get(0).getNotificationEntity(), NotificationRestModel.class);
final Set<String> notificationTypes = notifications.stream().map(notification -> notification.getNotificationType().name()).collect(Collectors.toSet());
notificationRestModel.setNotificationTypes(notificationTypes);
final Set<ComponentRestModel> components = notifications.stream().map(notification -> new ComponentRestModel(notification.getComponentName(), notification.getComponentVersion(), notification.getPolicyRuleName(), notification.getPolicyRuleUser())).collect(Collectors.toSet());
notificationRestModel.setComponents(components);
} catch (final AlertException e) {
logger.error("Problem converting audit entry with id {}: {}", auditEntryEntity.getId(), e.getMessage());
}
}
String distributionConfigName = null;
String eventType = null;
if (commonConfigEntity != null) {
distributionConfigName = commonConfigEntity.getName();
eventType = commonConfigEntity.getDistributionType();
}
return new AuditEntryRestModel(id, distributionConfigName, eventType, timeCreated, timeLastSent, status, errorMessage, errorStackTrace, notificationRestModel);
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class AuditEntryActions method resendNotification.
public List<AuditEntryRestModel> resendNotification(final Long id) throws IntegrationException, IllegalArgumentException {
AuditEntryEntity auditEntryEntity = null;
auditEntryEntity = auditEntryRepository.findOne(id);
if (auditEntryEntity == null) {
throw new AlertException("No audit entry with the provided id exists.");
}
final List<AuditNotificationRelation> relations = auditNotificationRepository.findByAuditEntryId(auditEntryEntity.getId());
final List<Long> notificationIds = relations.stream().map(relation -> relation.getNotificationId()).collect(Collectors.toList());
final List<NotificationModel> notifications = notificationManager.findByIds(notificationIds);
final Long commonConfigId = auditEntryEntity.getCommonConfigId();
final CommonDistributionConfigEntity commonConfigEntity = commonDistributionRepository.findOne(commonConfigId);
if (notifications == null || notifications.isEmpty()) {
throw new IllegalArgumentException("The notification for this entry was purged. To edit the purge schedule, please see the Scheduling Configuration.");
}
if (commonConfigEntity == null) {
throw new IllegalArgumentException("The job for this entry was deleted, can not re-send this entry.");
}
final Collection<ProjectData> projectDataList = projectDataFactory.createProjectDataCollection(notifications);
for (final ProjectData projectData : projectDataList) {
final AbstractChannelEvent event = channelEventFactory.createEvent(commonConfigId, commonConfigEntity.getDistributionType(), projectData);
event.setAuditEntryId(auditEntryEntity.getId());
channelTemplateManager.sendEvent(event);
}
return get();
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class NotificationManagerTestIT method findByCreatedAtBefore.
@Test
public void findByCreatedAtBefore() {
final LocalDateTime time = LocalDateTime.now();
Date searchDate = createDate(time.plusHours(1));
final Date createdAt = createDate(time.minusHours(5));
NotificationEntity entity = createNotificationEntity(createdAt);
notificationManager.saveNotification(new NotificationModel(entity, Collections.emptyList()));
final Date createdAtLaterThanSearch = createDate(time.plusHours(3));
entity = createNotificationEntity(createdAtLaterThanSearch);
notificationManager.saveNotification(new NotificationModel(entity, Collections.emptyList()));
List<NotificationModel> foundList = notificationManager.findByCreatedAtBefore(searchDate);
assertEquals(1, foundList.size());
searchDate = createDate(time.minusHours(6));
foundList = notificationManager.findByCreatedAtBefore(searchDate);
assertTrue(foundList.isEmpty());
}
Aggregations