Search in sources :

Example 1 with ProcessedNotificationDetails

use of com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails 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();
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProcessedNotificationDetails(com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails) UUID(java.util.UUID) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 2 with ProcessedNotificationDetails

use of com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails in project hub-alert by blackducksoftware.

the class JobNotificationProcessorTest method processNotificationForJobTest.

@Test
public void processNotificationForJobTest() throws IntegrationException {
    // Set up dependencies for JobNotificationProcessor
    RuleViolationNotificationDetailExtractor ruleViolationNotificationDetailExtractor = new RuleViolationNotificationDetailExtractor();
    NotificationDetailExtractionDelegator notificationDetailExtractionDelegator = new NotificationDetailExtractionDelegator(RESPONSE_RESOLVER, List.of(ruleViolationNotificationDetailExtractor));
    RuleViolationNotificationMessageExtractor ruleViolationNotificationMessageExtractor = createRuleViolationNotificationMessageExtractor();
    ProviderMessageExtractionDelegator providerMessageExtractionDelegator = new ProviderMessageExtractionDelegator(List.of(ruleViolationNotificationMessageExtractor));
    ProjectMessageDigester projectMessageDigester = new ProjectMessageDigester();
    ProjectMessageSummarizer projectMessageSummarizer = new ProjectMessageSummarizer();
    NotificationContentProcessor notificationContentProcessor = new NotificationContentProcessor(providerMessageExtractionDelegator, projectMessageDigester, projectMessageSummarizer);
    MockProcessingAuditAccessor processingAuditAccessor = new MockProcessingAuditAccessor();
    EventManager eventManager = Mockito.mock(EventManager.class);
    ProviderMessageDistributor providerMessageDistributor = new ProviderMessageDistributor(processingAuditAccessor, eventManager);
    NotificationExtractorBlackDuckServicesFactoryCache lifecycleCaches = createNotificationExtractorBlackDuckServicesFactoryCache();
    // Create Requirements for processNotificationForJob
    ProcessedNotificationDetails processedNotificationDetails = new ProcessedNotificationDetails(uuid, CHANNEL_KEY, "JobName");
    AlertNotificationModel notificationModel = createNotification(NotificationType.RULE_VIOLATION.name());
    // Run test and verify notification saved by ProcessingAuditAccessor
    JobNotificationProcessor jobNotificationProcessor = new JobNotificationProcessor(notificationDetailExtractionDelegator, notificationContentProcessor, providerMessageDistributor, List.of(lifecycleCaches));
    jobNotificationProcessor.processNotificationForJob(processedNotificationDetails, ProcessingType.DEFAULT, List.of(notificationModel));
    Set<Long> auditNotificationIds = processingAuditAccessor.getNotificationIds(uuid);
    Mockito.verify(eventManager, Mockito.times(1)).sendEvent(Mockito.any());
    assertEquals(1, auditNotificationIds.size());
    assertTrue(auditNotificationIds.contains(notificationId));
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProviderMessageDistributor(com.synopsys.integration.alert.processor.api.distribute.ProviderMessageDistributor) ProjectMessageDigester(com.synopsys.integration.alert.processor.api.digest.ProjectMessageDigester) EventManager(com.synopsys.integration.alert.api.event.EventManager) RuleViolationNotificationDetailExtractor(com.synopsys.integration.alert.provider.blackduck.processor.detail.RuleViolationNotificationDetailExtractor) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) ProviderMessageExtractionDelegator(com.synopsys.integration.alert.processor.api.extract.ProviderMessageExtractionDelegator) ProjectMessageSummarizer(com.synopsys.integration.alert.processor.api.summarize.ProjectMessageSummarizer) RuleViolationNotificationMessageExtractor(com.synopsys.integration.alert.provider.blackduck.processor.message.RuleViolationNotificationMessageExtractor) ProcessedNotificationDetails(com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator) Test(org.junit.jupiter.api.Test)

Example 3 with ProcessedNotificationDetails

use of com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails in project hub-alert by blackducksoftware.

the class NotificationProcessor method processAndDistribute.

private void processAndDistribute(FilteredJobNotificationWrapper jobNotificationWrapper) {
    List<NotificationContentWrapper> filteredNotifications = jobNotificationWrapper.getJobNotifications();
    ProcessedNotificationDetails processedNotificationDetails = new ProcessedNotificationDetails(jobNotificationWrapper.getJobId(), jobNotificationWrapper.getChannelName(), jobNotificationWrapper.getJobName());
    ProcessedProviderMessageHolder processedMessageHolder = notificationContentProcessor.processNotificationContent(jobNotificationWrapper.getProcessingType(), filteredNotifications);
    providerMessageDistributor.distribute(processedNotificationDetails, processedMessageHolder);
}
Also used : ProcessedProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder) ProcessedNotificationDetails(com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails) NotificationContentWrapper(com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper)

Aggregations

ProcessedNotificationDetails (com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails)3 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)2 EventManager (com.synopsys.integration.alert.api.event.EventManager)1 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)1 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)1 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)1 ProjectMessageDigester (com.synopsys.integration.alert.processor.api.digest.ProjectMessageDigester)1 ProviderMessageDistributor (com.synopsys.integration.alert.processor.api.distribute.ProviderMessageDistributor)1 ProviderMessageExtractionDelegator (com.synopsys.integration.alert.processor.api.extract.ProviderMessageExtractionDelegator)1 ProcessedProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder)1 NotificationContentWrapper (com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper)1 ProjectMessageSummarizer (com.synopsys.integration.alert.processor.api.summarize.ProjectMessageSummarizer)1 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)1 RuleViolationNotificationDetailExtractor (com.synopsys.integration.alert.provider.blackduck.processor.detail.RuleViolationNotificationDetailExtractor)1 RuleViolationNotificationMessageExtractor (com.synopsys.integration.alert.provider.blackduck.processor.message.RuleViolationNotificationMessageExtractor)1 UUID (java.util.UUID)1 Test (org.junit.jupiter.api.Test)1