use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class RuleViolationClearedNotificationContentDetailExtractorTest method extractDetailedContentTest.
@Test
public void extractDetailedContentTest() throws IOException {
String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
RuleViolationClearedNotificationView notificationView = gson.fromJson(jsonContent, RuleViolationClearedNotificationView.class);
RuleViolationClearedNotificationContent notificationContent = notificationView.getContent();
AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
RuleViolationClearedNotificationDetailExtractor extractor = new RuleViolationClearedNotificationDetailExtractor();
List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
assertEquals(2, detailedNotificationContents.size());
for (DetailedNotificationContent detailedContent : detailedNotificationContents) {
Optional<String> optionalProjectName = detailedContent.getProjectName();
assertTrue(optionalProjectName.isPresent(), "Expect project name to be present");
assertEquals(notificationContent.getProjectName(), optionalProjectName.get());
Optional<String> optionalPolicyName = detailedContent.getPolicyName();
assertTrue(optionalPolicyName.isPresent(), "Expected policy name to be present");
boolean containsPolicy = notificationContent.getPolicyInfos().stream().map(PolicyInfo::getPolicyName).anyMatch(policyName -> policyName.equals(optionalPolicyName.get()));
assertTrue(containsPolicy, "Expected policy name to be present in original notification");
assertEquals(0, detailedContent.getVulnerabilitySeverities().size());
}
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class BlackDuckAccumulator method computeLatestNotificationCreatedAtDate.
// Expects that the notifications are sorted oldest to newest
private Optional<OffsetDateTime> computeLatestNotificationCreatedAtDate(List<AlertNotificationModel> sortedNotifications) {
if (!sortedNotifications.isEmpty()) {
int lastIndex = sortedNotifications.size() - 1;
AlertNotificationModel lastNotification = sortedNotifications.get(lastIndex);
return Optional.of(lastNotification.getProviderCreationTime());
}
return Optional.empty();
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class BlackDuckAccumulator method write.
private void write(List<AlertNotificationModel> contentList) {
logger.info("Writing {} notifications...", contentList.size());
List<AlertNotificationModel> savedNotifications = notificationAccessor.saveAllNotifications(contentList);
if (logger.isDebugEnabled()) {
List<Long> notificationIds = savedNotifications.stream().map(AlertNotificationModel::getId).collect(Collectors.toList());
String joinedIds = StringUtils.join(notificationIds, ", ");
notificationLogger.debug("Saved notifications: {}", joinedIds);
}
eventManager.sendEvent(new NotificationReceivedEvent());
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class AuditEntryActions method resendNotification.
public ActionResponse<AuditEntryPageModel> resendNotification(Long notificationId, @Nullable UUID requestedJobId) {
if (!authorizationManager.hasExecutePermission(ConfigContextEnum.GLOBAL, descriptorKey)) {
return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
}
Optional<AlertNotificationModel> notification = notificationAccessor.findById(notificationId);
if (notification.isEmpty()) {
return new ActionResponse<>(HttpStatus.GONE, "No notification with this id exists.");
}
AlertNotificationModel notificationContent = notification.get();
if (null != requestedJobId) {
Optional<DistributionJobModel> optionalDistributionJob = jobAccessor.getJobById(requestedJobId);
if (optionalDistributionJob.isEmpty()) {
String message = String.format("The Distribution Job with this id could not be found. %s", requestedJobId.toString());
return new ActionResponse<>(HttpStatus.GONE, message);
}
DistributionJobModel distributionJob = optionalDistributionJob.get();
if (distributionJob.isEnabled()) {
ProcessedNotificationDetails processedNotificationDetails = ProcessedNotificationDetails.fromDistributionJob(distributionJob);
jobNotificationProcessor.processNotificationForJob(processedNotificationDetails, distributionJob.getProcessingType(), List.of(notificationContent));
} else {
UUID jobConfigId = distributionJob.getJobId();
logger.warn("The Distribution Job with Id {} was disabled. This notification could not be sent", jobConfigId);
String message = String.format("The Distribution Job is currently disabled. %s", jobConfigId);
return new ActionResponse<>(HttpStatus.BAD_REQUEST, message);
}
} else {
notificationProcessor.processNotifications(List.of(notificationContent), List.of(FrequencyType.DAILY, FrequencyType.REAL_TIME));
}
return get();
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class NotificationAccessorTestIT method testFindAllWithSearchByFieldValue.
@Test
public void testFindAllWithSearchByFieldValue() {
NotificationEntity notificationContent = createNotificationContent();
notificationContent = notificationContentRepository.save(notificationContent);
OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
DistributionJobEntity distributionJobEntity = new DistributionJobEntity(null, "job_name", true, FrequencyType.REAL_TIME.name(), ProcessingType.DEFAULT.name(), ChannelKeys.EMAIL.getUniversalKey(), UUID.randomUUID(), currentTime, null);
DistributionJobEntity savedJob = distributionJobRepository.save(distributionJobEntity);
final String auditStatus = "audit status thing";
AuditEntryEntity auditEntryEntity = new AuditEntryEntity(savedJob.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), auditStatus, "", "");
auditEntryEntity = auditEntryRepository.save(auditEntryEntity);
AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(auditEntryEntity.getId(), notificationContent.getId());
auditNotificationRepository.save(auditNotificationRelation);
PageRequest pageRequest = PageRequest.of(0, 10);
Page<AlertNotificationModel> all = notificationManager.findAllWithSearch(ChannelKeys.EMAIL.getUniversalKey(), pageRequest, false);
// Search term should match the channel name
assertFalse(all.isEmpty());
}
Aggregations