use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class ProcessingTaskTest method initTest.
@BeforeEach
public void initTest() throws IOException {
String notificationJson = TestResourceUtils.readFileToString("json/projectVersionNotification.json");
AlertNotificationModel model = new AlertNotificationModel(1L, 1L, "BlackDuck", "BlackDuck_1", "PROJECT_VERSION", notificationJson, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), false);
modelList = List.of(model);
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class ProcessingTask method process.
private void process() {
DateRange dateRange = getDateRange();
AlertPagedModel<AlertNotificationModel> page = read(dateRange, AlertPagedModel.DEFAULT_PAGE_NUMBER, PAGE_SIZE);
int currentPage = page.getCurrentPage();
int totalPages = page.getTotalPages();
while (!page.getModels().isEmpty() || currentPage < totalPages) {
List<AlertNotificationModel> notificationList = page.getModels();
logger.info("Processing page {} of {}. {} notifications to process.", currentPage, totalPages, notificationList.size());
notificationProcessor.processNotifications(notificationList, List.of(frequencyType));
page = read(dateRange, currentPage + 1, PAGE_SIZE);
currentPage = page.getCurrentPage();
totalPages = page.getTotalPages();
}
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class JobNotificationProcessorTest method createNotification.
private AlertNotificationModel createNotification(String notificationType) {
RuleViolationNotificationView ruleViolationNotificationView = blackDuckResponseTestUtility.createRuleViolationNotificationView("project-name", "project-version-name");
String notificationContent = GSON.toJson(ruleViolationNotificationView);
return new AlertNotificationModel(123L, PROVIDER_DETAILS.getProviderConfigId(), PROVIDER_DETAILS.getProvider().getLabel(), PROVIDER_DETAILS.getProvider().getValue(), notificationType, notificationContent, OffsetDateTime.now(), OffsetDateTime.now(), false);
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class NotificationContentProcessorTest method processNotificationContentSummaryTest.
@Test
public void processNotificationContentSummaryTest() {
AlertNotificationModel notificationModel = createNotification(NotificationType.RULE_VIOLATION.name());
RuleViolationUniquePolicyNotificationContent notificationContent = blackDuckResponseTestUtility.createRuleViolationUniquePolicyNotificationContent(projectName, projectVersionName);
NotificationContentWrapper notificationContentWrapper1 = new NotificationContentWrapper(notificationModel, notificationContent, RuleViolationUniquePolicyNotificationContent.class);
// When set to summary, project messages will be summarized into a SimpleMessage rather than ProjectMessage
ProcessedProviderMessageHolder processedProviderMessageHolder = notificationContentProcessor.processNotificationContent(ProcessingType.SUMMARY, List.of(notificationContentWrapper1));
List<ProcessedProviderMessage<ProjectMessage>> processedProviderMessages = processedProviderMessageHolder.getProcessedProjectMessages();
List<ProcessedProviderMessage<SimpleMessage>> processedSimpleMessages = processedProviderMessageHolder.getProcessedSimpleMessages();
assertTrue(processedProviderMessages.isEmpty());
assertEquals(1, processedSimpleMessages.size());
ProcessedProviderMessage<SimpleMessage> processedSimpleMessage = processedSimpleMessages.get(0);
assertEquals(1, processedSimpleMessage.getNotificationIds().size());
assertTrue(processedSimpleMessage.getNotificationIds().contains(notificationId));
SimpleMessage simpleMessage = processedSimpleMessage.getProviderMessage();
assertEquals(PROVIDER_DETAILS, simpleMessage.getProviderDetails());
assertTrue(simpleMessage.getSource().isPresent());
ProjectMessage sourceProjectMessage = simpleMessage.getSource().get();
assertEquals(projectName, sourceProjectMessage.getProject().getValue());
assertTrue(sourceProjectMessage.getProjectVersion().isPresent());
assertEquals(projectVersionName, sourceProjectMessage.getProjectVersion().get().getValue());
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class MockNotificationAccessor method getFirstPageOfNotificationsNotProcessed.
@Override
public AlertPagedModel<AlertNotificationModel> getFirstPageOfNotificationsNotProcessed(int pageSize) {
ArrayList<AlertNotificationModel> notificationsNotProcessed = new ArrayList<>();
for (AlertNotificationModel notification : alertNotificationModels) {
if (!notification.getProcessed()) {
notificationsNotProcessed.add(notification);
}
}
Page<AlertNotificationModel> pageOfNotifications;
if (notificationsNotProcessed.size() > 0) {
pageOfNotifications = new PageImpl<>(notificationsNotProcessed);
} else {
pageOfNotifications = Page.empty();
}
return new AlertPagedModel<>(pageOfNotifications.getTotalPages(), pageOfNotifications.getNumber(), pageOfNotifications.getSize(), pageOfNotifications.getContent());
}
Aggregations