Search in sources :

Example 1 with AlertPagedDetails

use of com.synopsys.integration.alert.common.rest.model.AlertPagedDetails in project hub-alert by blackducksoftware.

the class JobNotificationMapper method mapPageOfJobsToNotification.

private AlertPagedDetails<FilteredJobNotificationWrapper> mapPageOfJobsToNotification(List<DetailedNotificationContent> detailedContents, List<FrequencyType> frequencies, int pageNumber, int pageSize) {
    if (detailedContents.isEmpty()) {
        return new AlertPagedDetails<>(1, pageNumber, pageSize, List.of());
    }
    Map<FilteredDistributionJobResponseModel, List<NotificationContentWrapper>> groupedFilterableNotifications = new HashMap<>();
    FilteredDistributionJobRequestModel filteredDistributionJobRequestModel = createRequestModelFromNotifications(detailedContents, frequencies);
    AlertPagedDetails<FilteredDistributionJobResponseModel> jobs = processingJobAccessor.getMatchingEnabledJobsByFilteredNotifications(filteredDistributionJobRequestModel, pageNumber, pageSize);
    for (DetailedNotificationContent detailedNotificationContent : detailedContents) {
        for (FilteredDistributionJobResponseModel filteredDistributionJobResponseModel : jobs.getModels()) {
            if (JobNotificationFilterUtils.doesNotificationApplyToJob(filteredDistributionJobResponseModel, detailedNotificationContent)) {
                List<NotificationContentWrapper> applicableNotifications = groupedFilterableNotifications.computeIfAbsent(filteredDistributionJobResponseModel, ignoredKey -> new LinkedList<>());
                applicableNotifications.add(detailedNotificationContent.getNotificationContentWrapper());
            }
        }
    }
    List<FilteredJobNotificationWrapper> filterableJobNotifications = new LinkedList<>();
    for (Map.Entry<FilteredDistributionJobResponseModel, List<NotificationContentWrapper>> groupedEntry : groupedFilterableNotifications.entrySet()) {
        FilteredDistributionJobResponseModel filteredJob = groupedEntry.getKey();
        FilteredJobNotificationWrapper wrappedJobNotifications = new FilteredJobNotificationWrapper(filteredJob.getId(), filteredJob.getProcessingType(), filteredJob.getChannelName(), filteredJob.getJobName(), groupedEntry.getValue());
        filterableJobNotifications.add(wrappedJobNotifications);
    }
    return new AlertPagedDetails<>(jobs.getTotalPages(), pageNumber, pageSize, filterableJobNotifications);
}
Also used : FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) FilteredDistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel) AlertPagedDetails(com.synopsys.integration.alert.common.rest.model.AlertPagedDetails) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AlertPagedDetails

use of com.synopsys.integration.alert.common.rest.model.AlertPagedDetails in project hub-alert by blackducksoftware.

the class NotificationReceivedEventHandlerTest method mockNotificationProcessor.

private NotificationProcessor mockNotificationProcessor(NotificationAccessor notificationAccessor) {
    NotificationDetailExtractionDelegator detailExtractionDelegator = new NotificationDetailExtractionDelegator(blackDuckResponseResolver, List.of());
    JobNotificationMapper jobNotificationMapper = Mockito.mock(JobNotificationMapper.class);
    Predicate<AlertPagedDetails> hasNextPage = page -> page.getCurrentPage() < (page.getTotalPages() - 1);
    StatefulAlertPage<FilteredJobNotificationWrapper, RuntimeException> statefulAlertPage = new StatefulAlertPage(AlertPagedDetails.emptyPage(), Mockito.mock(PageRetriever.class), hasNextPage);
    Mockito.when(jobNotificationMapper.mapJobsToNotifications(Mockito.anyList(), Mockito.anyList())).thenReturn(statefulAlertPage);
    return new NotificationProcessor(detailExtractionDelegator, jobNotificationMapper, null, null, List.of(), notificationAccessor);
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) JobNotificationMapper(com.synopsys.integration.alert.processor.api.filter.JobNotificationMapper) PageRetriever(com.synopsys.integration.alert.processor.api.filter.PageRetriever) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) AlertPagedDetails(com.synopsys.integration.alert.common.rest.model.AlertPagedDetails) FilteredJobNotificationWrapper(com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper) Predicate(java.util.function.Predicate) BlackDuckResponseResolver(com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver) IOException(java.io.IOException) StatefulAlertPage(com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage) TestResourceUtils(com.synopsys.integration.alert.test.common.TestResourceUtils) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) Gson(com.google.gson.Gson) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator) JmsTemplate(org.springframework.jms.core.JmsTemplate) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) DateUtils(com.synopsys.integration.alert.common.util.DateUtils) EventManager(com.synopsys.integration.alert.api.event.EventManager) StatefulAlertPage(com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage) PageRetriever(com.synopsys.integration.alert.processor.api.filter.PageRetriever) JobNotificationMapper(com.synopsys.integration.alert.processor.api.filter.JobNotificationMapper) AlertPagedDetails(com.synopsys.integration.alert.common.rest.model.AlertPagedDetails) FilteredJobNotificationWrapper(com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)

Example 3 with AlertPagedDetails

use of com.synopsys.integration.alert.common.rest.model.AlertPagedDetails in project hub-alert by blackducksoftware.

the class BlackDuckAccumulatorTest method createMockNotificationPage.

private StatefulAlertPage<NotificationUserView, IntegrationException> createMockNotificationPage(PageRetriever pageRetriever) throws IntegrationException {
    NotificationUserView notificationView = createMockNotificationView();
    AlertPagedDetails<NotificationUserView> alertPagedDetails = new AlertPagedDetails<>(1, 0, 1, List.of(notificationView));
    return new StatefulAlertPage<>(alertPagedDetails, pageRetriever, BlackDuckNotificationRetriever.HAS_NEXT_PAGE);
}
Also used : StatefulAlertPage(com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage) AlertPagedDetails(com.synopsys.integration.alert.common.rest.model.AlertPagedDetails) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)

Aggregations

AlertPagedDetails (com.synopsys.integration.alert.common.rest.model.AlertPagedDetails)3 StatefulAlertPage (com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage)2 List (java.util.List)2 Gson (com.google.gson.Gson)1 EventManager (com.synopsys.integration.alert.api.event.EventManager)1 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)1 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)1 FilteredDistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel)1 FilteredDistributionJobResponseModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel)1 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)1 DateUtils (com.synopsys.integration.alert.common.util.DateUtils)1 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)1 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)1 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)1 FilteredJobNotificationWrapper (com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper)1 JobNotificationMapper (com.synopsys.integration.alert.processor.api.filter.JobNotificationMapper)1 PageRetriever (com.synopsys.integration.alert.processor.api.filter.PageRetriever)1 TestResourceUtils (com.synopsys.integration.alert.test.common.TestResourceUtils)1 NotificationUserView (com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)1 BlackDuckResponseResolver (com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver)1