use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class DigestNotificationProcessorIT method processNotificationDataBasicTestIT.
@Test
public void processNotificationDataBasicTestIT() {
final Long distributionConfigId = 10L;
final String distributionType = SupportedChannels.HIPCHAT;
final String name = "Config Name";
final DigestTypeEnum frequency = DigestTypeEnum.REAL_TIME;
final Boolean filterByProject = true;
final String projectName = "Test Hub Project Name";
final CommonDistributionConfigEntity commonDistributionConfigEntity = commonDistributionRepository.save(new CommonDistributionConfigEntity(distributionConfigId, distributionType, name, frequency, filterByProject));
final ConfiguredProjectEntity configuredProjectEntity = configuredProjectsRepository.save(new ConfiguredProjectEntity(projectName));
distributionProjectRepository.save(new DistributionProjectRelation(commonDistributionConfigEntity.getId(), configuredProjectEntity.getId()));
final CommonDistributionConfigRestModel restModel = new CommonDistributionConfigRestModel(null, null, null, null, null, null, null, Arrays.asList("POLICY_VIOLATION"));
notificationActions.saveNotificationTypes(commonDistributionConfigEntity, restModel);
final List<NotificationModel> notificationList = new ArrayList<>();
final NotificationEntity applicableNotification = new NotificationEntity("event_key_1", new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, projectName, "", "", "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
final NotificationEntity nonApplicableNotification = new NotificationEntity("event_key_2", new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, "Project that we don't care about", "", "", "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
notificationList.add(new NotificationModel(applicableNotification, Collections.emptyList()));
notificationList.add(new NotificationModel(nonApplicableNotification, Collections.emptyList()));
final List<AbstractChannelEvent> eventsCreated = processor.processNotifications(DigestTypeEnum.REAL_TIME, notificationList);
assertEquals(1, eventsCreated.size());
final AbstractChannelEvent event = eventsCreated.get(0);
assertTrue(event instanceof HipChatEvent);
assertEquals(commonDistributionConfigEntity.getId(), event.getCommonDistributionConfigId());
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class NotificationManager method saveNotification.
public NotificationModel saveNotification(final NotificationModel notification) {
final NotificationEntity notificationEntity = notificationRepository.save(notification.getNotificationEntity());
List<VulnerabilityEntity> vulnerabilities = Collections.emptyList();
if (notification.getVulnerabilityList() != null) {
final Collection<VulnerabilityEntity> vulnerabilityList = notification.getVulnerabilityList();
final List<VulnerabilityEntity> vulnerabilitiesToSave = vulnerabilityList.stream().map(vulnerability -> new VulnerabilityEntity(vulnerability.getVulnerabilityId(), vulnerability.getOperation(), notificationEntity.getId())).collect(Collectors.toList());
vulnerabilities = vulnerabilityRepository.save(vulnerabilitiesToSave);
}
return new NotificationModel(notificationEntity, vulnerabilities);
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class ProjectDataFactory method createProjectDataCollection.
public Collection<ProjectData> createProjectDataCollection(final Collection<NotificationModel> notifications, final DigestTypeEnum digestType) {
final Map<String, ProjectDataBuilder> projectDataMap = new LinkedHashMap<>();
for (final NotificationModel entity : notifications) {
final String projectKey = entity.getProjectName() + entity.getProjectVersion();
ProjectDataBuilder projectDataBuilder;
if (projectDataMap.containsKey(projectKey)) {
projectDataBuilder = projectDataMap.get(projectKey);
} else {
projectDataBuilder = getProjectDataBuilder(entity, digestType);
projectDataMap.put(projectKey, projectDataBuilder);
}
projectDataBuilder.addNotificationId(entity.getNotificationEntity().getId());
final CategoryDataBuilder categoryDataBuilder = getCategoryDataBuilder(entity, projectDataBuilder.getCategoryBuilderMap());
addCategoryData(entity, categoryDataBuilder);
}
return collectProjectDataFromMap(projectDataMap);
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class PurgeReader method read.
@Override
public List<NotificationModel> read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
try {
logger.debug("Purge Reader Starting ");
ZonedDateTime zonedDate = ZonedDateTime.now();
zonedDate = zonedDate.withZoneSameInstant(ZoneOffset.UTC);
zonedDate = zonedDate.withSecond(0).withNano(0);
final Date date = Date.from(zonedDate.toInstant());
logger.info("Searching for notifications to purge earlier than {}", date);
final List<NotificationModel> notificationList = notificationManager.findByCreatedAtBefore(date);
if (notificationList == null || notificationList.isEmpty()) {
logger.debug("No notifications found to purge");
return null;
}
logger.debug("Found {} notifications to purge", notificationList.size());
return notificationList;
} catch (final Exception ex) {
logger.error("Error in Purge Reader", ex);
}
return null;
}
Aggregations