Search in sources :

Example 26 with ProjectMessage

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

the class ProjectMessageToIssueModelTransformer method convertToIssueModels.

private List<ProjectIssueModel> convertToIssueModels(ProjectMessage projectMessage, IssueBomComponentDetails issueBomComponent, List<ComponentConcern> componentConcerns) {
    List<ComponentConcern> policyConcerns = new LinkedList<>();
    List<ComponentConcern> vulnerabilityConcerns = new LinkedList<>();
    List<ComponentConcern> estimatedRiskConcerns = new LinkedList<>();
    for (ComponentConcern componentConcern : componentConcerns) {
        if (ComponentConcernType.POLICY.equals(componentConcern.getType())) {
            policyConcerns.add(componentConcern);
        } else if (ComponentConcernType.UNKNOWN_VERSION.equals(componentConcern.getType())) {
            estimatedRiskConcerns.add(componentConcern);
        } else {
            vulnerabilityConcerns.add(componentConcern);
        }
    }
    List<ProjectIssueModel> projectIssueModels = new LinkedList<>();
    policyConcerns.stream().map(concern -> createPolicyProjectIssueModel(projectMessage, issueBomComponent, concern)).forEach(projectIssueModels::add);
    if (!vulnerabilityConcerns.isEmpty()) {
        ProjectIssueModel vulnerabilityProjectIssueModel = createVulnerabilityProjectIssueModel(projectMessage, issueBomComponent, vulnerabilityConcerns);
        projectIssueModels.add(vulnerabilityProjectIssueModel);
    }
    if (!estimatedRiskConcerns.isEmpty()) {
        ProjectIssueModel estimatedRiskProjectIssueModel = createEstimatedRiskProjectIssueModel(projectMessage, issueBomComponent, estimatedRiskConcerns);
        projectIssueModels.add(estimatedRiskProjectIssueModel);
    }
    return projectIssueModels;
}
Also used : ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) ComponentVulnerabilities(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) List(java.util.List) Component(org.springframework.stereotype.Component) IssueEstimatedRiskModel(com.synopsys.integration.alert.api.channel.issue.model.IssueEstimatedRiskModel) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) LinkedList(java.util.LinkedList) IssueVulnerabilityModel(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityModel) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) LinkedList(java.util.LinkedList)

Example 27 with ProjectMessage

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

the class AbstractChannelMessageConverterTest method convertToChannelMessagesTest.

@Test
public void convertToChannelMessagesTest() {
    MockChannelMessageFormatter mockChannelMessageFormatter = new MockChannelMessageFormatter(Integer.MAX_VALUE);
    MockChannelMessageConverter mockChannelMessageConverter = new MockChannelMessageConverter(mockChannelMessageFormatter);
    MockDistributionJobDetailsModel jobDetails = new MockDistributionJobDetailsModel(UUID.randomUUID());
    ProviderDetails providerDetails = new ProviderDetails(0L, new LinkableItem("Provider", "Black Duck"));
    ProjectMessage projectCreateMessage = ProjectMessage.projectStatusInfo(providerDetails, new LinkableItem("Project", "A project"), ProjectOperation.CREATE);
    SimpleMessage simpleMessage = SimpleMessage.original(providerDetails, "Summary", "Description", List.of());
    ProviderMessageHolder providerMessageHolder = new ProviderMessageHolder(List.of(projectCreateMessage), List.of(simpleMessage));
    List<MockOutputModel> mockOutputModels = mockChannelMessageConverter.convertToChannelMessages(jobDetails, providerMessageHolder, "jobName");
    assertEquals(2, mockOutputModels.size());
    for (MockOutputModel mockOutputModel : mockOutputModels) {
        assertEquals(1, mockOutputModel.getMessagePieces().size());
    }
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage) MockChannelMessageFormatter(com.synopsys.integration.alert.api.channel.convert.mock.MockChannelMessageFormatter) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) Test(org.junit.jupiter.api.Test)

Example 28 with ProjectMessage

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

the class EmailChannelMessageConverter method convertSimpleMessageToChannelMessages.

@Override
protected List<EmailChannelMessageModel> convertSimpleMessageToChannelMessages(EmailJobDetailsModel distributionDetails, SimpleMessage simpleMessage, List<String> messageChunks) {
    String subjectLinePrefix = createSubjectLinePrefix(distributionDetails);
    String subjectLine = String.format("%s%s", subjectLinePrefix, simpleMessage.getSummary());
    subjectLine = StringUtils.abbreviate(subjectLine, SUBJECT_LINE_MAX_LENGTH);
    String messageContent = StringUtils.join(messageChunks, "");
    LinkableItem provider = simpleMessage.getProvider();
    String providerName = provider.getValue();
    String providerUrl = provider.getUrl().orElse("#");
    Optional<ProjectMessage> optionalSource = simpleMessage.getSource();
    EmailChannelMessageModel model;
    if (optionalSource.isPresent()) {
        model = EmailChannelMessageModel.simpleProject(subjectLine, messageContent, providerName, providerUrl, optionalSource.get());
    } else {
        model = EmailChannelMessageModel.simple(subjectLine, messageContent, providerName, providerUrl);
    }
    return List.of(model);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)

Example 29 with ProjectMessage

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

the class EmailChannelMessageSender method sendMessages.

@Override
public MessageResult sendMessages(EmailJobDetailsModel emailJobDetails, List<EmailChannelMessageModel> emailMessages) throws AlertException {
    // Validation
    ValidatedEmailAddresses validatedAdditionalEmailAddresses;
    UUID jobId = emailJobDetails.getJobId();
    if (null != jobId) {
        validatedAdditionalEmailAddresses = emailAddressValidator.validate(jobId, emailJobDetails.getAdditionalEmailAddresses());
    } else {
        validatedAdditionalEmailAddresses = new ValidatedEmailAddresses(new HashSet<>(emailJobDetails.getAdditionalEmailAddresses()), Set.of());
    }
    Set<String> invalidEmailAddresses = validatedAdditionalEmailAddresses.getInvalidEmailAddresses();
    if (!invalidEmailAddresses.isEmpty()) {
        emailJobDetails = new EmailJobDetailsModel(emailJobDetails.getJobId(), emailJobDetails.getSubjectLine().orElse(null), emailJobDetails.isProjectOwnerOnly(), emailJobDetails.isAdditionalEmailAddressesOnly(), emailJobDetails.getAttachmentFileType(), new ArrayList<>(validatedAdditionalEmailAddresses.getValidEmailAddresses()));
    }
    // Distribution
    EmailGlobalConfigModel emailServerConfiguration = emailGlobalConfigAccessor.getConfiguration().orElseThrow(() -> new AlertConfigurationException("ERROR: Missing Email global config."));
    SmtpConfig smtpConfig = SmtpConfig.builder().setJavamailProperties(javamailPropertiesFactory.createJavaMailProperties(emailServerConfiguration)).setSmtpFrom(emailServerConfiguration.getSmtpFrom().orElse(null)).setSmtpHost(emailServerConfiguration.getSmtpHost().orElse(null)).setSmtpPort(emailServerConfiguration.getSmtpPort().orElse(-1)).setSmtpAuth(emailServerConfiguration.getSmtpAuth().orElse(false)).setSmtpUsername(emailServerConfiguration.getSmtpUsername().orElse(null)).setSmtpPassword(emailServerConfiguration.getSmtpPassword().orElse(null)).build();
    int totalEmailsSent = 0;
    for (EmailChannelMessageModel message : emailMessages) {
        Set<String> projectHrefs = message.getSource().map(ProjectMessage::getProject).flatMap(LinkableItem::getUrl).map(Set::of).orElse(Set.of());
        Set<String> gatheredEmailAddresses = emailAddressGatherer.gatherEmailAddresses(emailJobDetails, projectHrefs);
        if (gatheredEmailAddresses.isEmpty()) {
            if (invalidEmailAddresses.isEmpty()) {
                throw new AlertException("Could not determine what email addresses to send this content to");
            } else {
                String invalidEmailAddressesString = StringUtils.join(invalidEmailAddresses, ", ");
                throw new AlertException(String.format("No valid email addresses to send this content to. The following email addresses were invalid: %s", invalidEmailAddressesString));
            }
        }
        EmailTarget emailTarget = emailChannelMessagingService.createTarget(message, gatheredEmailAddresses);
        Optional<ProjectMessage> optionalProjectMessage = message.getSource();
        if (optionalProjectMessage.isPresent()) {
            EmailAttachmentFormat attachmentFormat = EmailAttachmentFormat.getValueSafely(emailJobDetails.getAttachmentFileType());
            emailChannelMessagingService.sendMessageWithAttachedProjectMessage(smtpConfig, emailTarget, optionalProjectMessage.get(), attachmentFormat);
        } else {
            emailChannelMessagingService.sendMessage(smtpConfig, emailTarget);
        }
        totalEmailsSent += emailTarget.getEmailAddresses().size();
    }
    // Reporting
    if (!invalidEmailAddresses.isEmpty()) {
        String invalidEmailAddressesString = StringUtils.join(invalidEmailAddresses, ", ");
        String errorMessage = String.format("No emails were sent to the following recipients because they were invalid: %s", invalidEmailAddressesString);
        AlertFieldStatus errorStatus = new AlertFieldStatus(EmailDescriptor.KEY_EMAIL_ADDITIONAL_ADDRESSES, FieldStatusSeverity.ERROR, errorMessage);
        return new MessageResult(errorMessage, List.of(errorStatus));
    }
    return new MessageResult(String.format("Successfully sent %d email(s)", totalEmailsSent));
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) SmtpConfig(com.synopsys.integration.alert.service.email.SmtpConfig) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ArrayList(java.util.ArrayList) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) EmailAttachmentFormat(com.synopsys.integration.alert.channel.email.attachment.EmailAttachmentFormat) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) EmailTarget(com.synopsys.integration.alert.service.email.EmailTarget) UUID(java.util.UUID) ValidatedEmailAddresses(com.synopsys.integration.alert.channel.email.distribution.address.ValidatedEmailAddresses) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) HashSet(java.util.HashSet) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 30 with ProjectMessage

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

the class BomEditNotificationMessageExtractorTest method createProjectMessageTest.

@Test
public void createProjectMessageTest() {
    BomComponentDetails bomComponentDetails = new BomComponentDetails(COMPONENT, COMPONENT_VERSION, COMPONENT_VULNERABILITIES, List.of(), List.of(), LICENSE, USAGE, ComponentUpgradeGuidance.none(), List.of(), ISSUES_URL);
    ProjectMessage projectMessage = extractor.createProjectMessage(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, List.of(bomComponentDetails));
    assertEquals(MessageReason.COMPONENT_UPDATE, projectMessage.getMessageReason());
    assertTrue(projectMessage.getBomComponents().contains(bomComponentDetails));
}
Also used : ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) Test(org.junit.jupiter.api.Test)

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