Search in sources :

Example 1 with ProcessedProviderMessageHolder

use of com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder in project hub-alert by blackducksoftware.

the class ProviderMessageDistributorTest method distributeMissingDestinationKeyTest.

@Test
public void distributeMissingDestinationKeyTest() {
    MockProcessingAuditAccessor processingAuditAccessor = new MockProcessingAuditAccessor();
    EventManager eventManager = Mockito.mock(EventManager.class);
    ProcessedNotificationDetails processedNotificationDetails = new ProcessedNotificationDetails(uuid, "bad channel key", "JobName");
    ProcessedProviderMessageHolder processedMessageHolder = createProcessedProviderMessageHolder(1, 0);
    ProviderMessageDistributor providerMessageDistributor = new ProviderMessageDistributor(processingAuditAccessor, eventManager);
    providerMessageDistributor.distribute(processedNotificationDetails, processedMessageHolder);
    Mockito.verify(eventManager, Mockito.times(0)).sendEvent(Mockito.any());
}
Also used : MockProcessingAuditAccessor(com.synopsys.integration.alert.processor.api.MockProcessingAuditAccessor) EventManager(com.synopsys.integration.alert.api.event.EventManager) ProcessedProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder) Test(org.junit.jupiter.api.Test)

Example 2 with ProcessedProviderMessageHolder

use of com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder 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());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProcessedProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder) ProcessedProviderMessage(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage) RuleViolationUniquePolicyNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.RuleViolationUniquePolicyNotificationContent) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage) NotificationContentWrapper(com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper) Test(org.junit.jupiter.api.Test)

Example 3 with ProcessedProviderMessageHolder

use of com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder in project hub-alert by blackducksoftware.

the class JobNotificationProcessor method processAndDistribute.

private void processAndDistribute(ProcessedNotificationDetails processedNotificationDetails, ProcessingType processingType, List<AlertNotificationModel> notifications) {
    List<NotificationContentWrapper> notificationContentWrappers = notifications.stream().map(notificationDetailExtractionDelegator::wrapNotification).flatMap(List::stream).map(DetailedNotificationContent::getNotificationContentWrapper).collect(Collectors.toList());
    ProcessedProviderMessageHolder processedMessageHolder = notificationContentProcessor.processNotificationContent(processingType, notificationContentWrappers);
    providerMessageDistributor.distribute(processedNotificationDetails, processedMessageHolder);
}
Also used : ProcessedProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder) List(java.util.List) NotificationContentWrapper(com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper)

Example 4 with ProcessedProviderMessageHolder

use of com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder in project hub-alert by blackducksoftware.

the class ProviderMessageDistributor method distribute.

public void distribute(ProcessedNotificationDetails processedNotificationDetails, ProcessedProviderMessageHolder processedMessageHolder) {
    String channelName = processedNotificationDetails.getChannelName();
    ChannelKey destinationKey = ChannelKeys.getChannelKey(channelName);
    if (null == destinationKey) {
        logger.warn("Unable to send {}. No {} with the name {} exists", EVENT_CLASS_NAME, DESTINATION_WRAPPER_CLASS_NAME, channelName);
        return;
    }
    for (ProcessedProviderMessageHolder singleMessageHolder : processedMessageHolder.expand()) {
        distributeIndividually(processedNotificationDetails.getJobId(), processedNotificationDetails.getJobName(), destinationKey, singleMessageHolder);
    }
}
Also used : ProcessedProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey)

Example 5 with ProcessedProviderMessageHolder

use of com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder in project hub-alert by blackducksoftware.

the class ProviderMessageExtractor method extract.

public final ProcessedProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper) {
    if (!notificationContentClass.isAssignableFrom(notificationContentWrapper.getNotificationContentClass())) {
        logger.error("The notification type provided is incompatible with this extractor: {}", notificationContentWrapper.extractNotificationType());
        return ProcessedProviderMessageHolder.empty();
    }
    T stronglyTypedContent = notificationContentClass.cast(notificationContentWrapper.getNotificationContent());
    ProviderMessageHolder extractedMessages = extract(notificationContentWrapper, stronglyTypedContent);
    return toProcessedProviderMessageHolder(notificationContentWrapper.getNotificationId(), extractedMessages);
}
Also used : ProcessedProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)

Aggregations

ProcessedProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder)10 NotificationContentWrapper (com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper)5 Test (org.junit.jupiter.api.Test)5 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)3 RuleViolationUniquePolicyNotificationContent (com.synopsys.integration.alert.provider.blackduck.processor.model.RuleViolationUniquePolicyNotificationContent)3 EventManager (com.synopsys.integration.alert.api.event.EventManager)2 MockProcessingAuditAccessor (com.synopsys.integration.alert.processor.api.MockProcessingAuditAccessor)2 ProcessedProviderMessage (com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage)2 SimpleMessage (com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)2 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)2 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)1 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)1 ProcessedNotificationDetails (com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails)1 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)1 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)1 ProjectOperation (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1