Search in sources :

Example 21 with ProjectMessage

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

the class ProjectNotificationMessageExtractor method extract.

@Override
protected ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, ProjectNotificationContent notificationContent) {
    AlertNotificationModel alertNotificationModel = notificationContentWrapper.getAlertNotificationModel();
    Long providerConfigId = alertNotificationModel.getProviderConfigId();
    String providerUrl;
    try {
        BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
        providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
    } catch (AlertConfigurationException e) {
        logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, alertNotificationModel.getProviderConfigName(), e);
        return ProviderMessageHolder.empty();
    }
    LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), alertNotificationModel.getProviderConfigName(), providerUrl);
    ProviderDetails providerDetails = new ProviderDetails(alertNotificationModel.getProviderConfigId(), providerItem);
    LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), notificationContent.getProject());
    ProjectOperation operation = ProjectOperation.fromOperationType(notificationContent.getOperationType());
    ProjectMessage projectMessage = ProjectMessage.projectStatusInfo(providerDetails, project, operation);
    return new ProviderMessageHolder(List.of(projectMessage), List.of());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) ProjectOperation(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)

Example 22 with ProjectMessage

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

the class AbstractBlackDuckComponentConcernMessageExtractor method extract.

@Override
protected final ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, T notificationContent) {
    AlertNotificationModel notificationModel = notificationContentWrapper.getAlertNotificationModel();
    Long providerConfigId = notificationModel.getProviderConfigId();
    String providerUrl;
    List<BomComponentDetails> bomComponentDetails;
    try {
        BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
        providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
        bomComponentDetails = createBomComponentDetails(notificationContent, blackDuckServicesFactory);
    } catch (AlertConfigurationException e) {
        logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, notificationModel.getProviderConfigName(), e);
        return ProviderMessageHolder.empty();
    } catch (IntegrationException e) {
        logger.warn("Failed to retrieve BOM Component(s) from BlackDuck", e);
        return ProviderMessageHolder.empty();
    }
    LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), notificationModel.getProviderConfigName(), providerUrl);
    ProviderDetails providerDetails = new ProviderDetails(notificationModel.getProviderConfigId(), providerItem);
    Optional<String> projectUrl = extractProjectUrl(notificationContent.getProjectVersionUrl());
    LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), projectUrl.orElse(null));
    LinkableItem projectVersion = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT_VERSION, notificationContent.getProjectVersionName(), notificationContent.getProjectVersionUrl());
    // FIXME this is where I should put the additional info
    ProjectMessage projectMessage = createProjectMessage(providerDetails, project, projectVersion, bomComponentDetails);
    return new ProviderMessageHolder(List.of(projectMessage), List.of());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IntegrationException(com.synopsys.integration.exception.IntegrationException) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 23 with ProjectMessage

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

the class ProjectMessageConverter method convertToFormattedMessageChunks.

@Override
public List<String> convertToFormattedMessageChunks(ProjectMessage projectMessage, String jobName) {
    ChunkedStringBuilder chunkedStringBuilder = new ChunkedStringBuilder(messageFormatter.getMaxMessageLength());
    String projectString;
    Optional<String> optionalProjectVersionString;
    Optional<LinkableItem> optionalProjectVersion = projectMessage.getProjectVersion();
    if (optionalProjectVersion.isPresent()) {
        projectString = linkableItemConverter.convertToStringWithoutLink(projectMessage.getProject(), true);
        optionalProjectVersionString = optionalProjectVersion.map(projectVersion -> linkableItemConverter.convertToString(projectVersion, true));
    } else {
        projectString = linkableItemConverter.convertToString(projectMessage.getProject(), true);
        optionalProjectVersionString = Optional.empty();
    }
    String nonBreakingSpace = messageFormatter.getNonBreakingSpace();
    String jobLine = String.format("Job%sname:%s%s", nonBreakingSpace, nonBreakingSpace, jobName);
    String boldJobName = messageFormatter.emphasize(jobLine);
    chunkedStringBuilder.append(boldJobName);
    chunkedStringBuilder.append(messageFormatter.getLineSeparator());
    chunkedStringBuilder.append(projectString);
    chunkedStringBuilder.append(messageFormatter.getLineSeparator());
    optionalProjectVersionString.ifPresent(projectVersionString -> {
        chunkedStringBuilder.append(projectVersionString);
        chunkedStringBuilder.append(messageFormatter.getLineSeparator());
    });
    MessageReason messageReason = projectMessage.getMessageReason();
    if (MessageReason.PROJECT_STATUS.equals(messageReason) || MessageReason.PROJECT_VERSION_STATUS.equals(messageReason)) {
        projectMessage.getOperation().map(operation -> String.format("Project%sAction:%s%s", nonBreakingSpace, nonBreakingSpace, operation.name())).map(messageFormatter::encode).ifPresent(chunkedStringBuilder::append);
        return chunkedStringBuilder.collectCurrentChunks();
    }
    List<BomComponentDetails> bomComponents = projectMessage.getBomComponents();
    if (!bomComponents.isEmpty()) {
        chunkedStringBuilder.append(messageFormatter.getSectionSeparator());
        chunkedStringBuilder.append(messageFormatter.getLineSeparator());
    }
    for (BomComponentDetails bomComponentDetails : bomComponents) {
        List<String> bomComponentMessagePieces = gatherBomComponentAndConcernSectionPieces(bomComponentDetails);
        bomComponentMessagePieces.forEach(chunkedStringBuilder::append);
        chunkedStringBuilder.append(messageFormatter.getSectionSeparator());
        chunkedStringBuilder.append(messageFormatter.getLineSeparator());
    }
    return chunkedStringBuilder.collectCurrentChunks();
}
Also used : List(java.util.List) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder) MessageReason(com.synopsys.integration.alert.processor.api.extract.model.project.MessageReason) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) Optional(java.util.Optional) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) LinkedList(java.util.LinkedList) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder) MessageReason(com.synopsys.integration.alert.processor.api.extract.model.project.MessageReason) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)

Example 24 with ProjectMessage

use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage 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 25 with ProjectMessage

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

the class NotificationContentProcessorTest method runProjectMessageAssertions.

private void runProjectMessageAssertions(ProcessedProviderMessageHolder processedProviderMessageHolder, String projectName, String projectVersionName) {
    List<ProcessedProviderMessage<ProjectMessage>> processedProjectMessages = processedProviderMessageHolder.getProcessedProjectMessages();
    List<ProcessedProviderMessage<SimpleMessage>> processedSimpleMessages = processedProviderMessageHolder.getProcessedSimpleMessages();
    assertTrue(processedSimpleMessages.isEmpty());
    assertEquals(1, processedProjectMessages.size());
    ProcessedProviderMessage<ProjectMessage> processedProjectMessage = processedProjectMessages.get(0);
    assertEquals(1, processedProjectMessage.getNotificationIds().size());
    assertTrue(processedProjectMessage.getNotificationIds().contains(notificationId));
    ProjectMessage projectMessage = processedProjectMessage.getProviderMessage();
    assertEquals(projectName, projectMessage.getProject().getValue());
    assertTrue(projectMessage.getProjectVersion().isPresent());
    assertEquals(projectVersionName, projectMessage.getProjectVersion().get().getValue());
    assertEquals(PROVIDER_DETAILS, projectMessage.getProviderDetails());
}
Also used : ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProcessedProviderMessage(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage)

Aggregations

ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)45 Test (org.junit.jupiter.api.Test)32 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)22 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)14 ProcessedProviderMessage (com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage)13 ProjectOperation (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)13 SimpleMessage (com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)12 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)11 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)9 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)7 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)6 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)5 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)4 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)4 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)4 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)4 LinkedList (java.util.LinkedList)4 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)3 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)3 ActionableIssueSearchResult (com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult)3