Search in sources :

Example 81 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class JiraIssueSearchResultCreator method createResultFromProjectIssue.

public ProjectIssueSearchResult<String> createResultFromProjectIssue(JiraSearcherResponseModel issue, ProviderDetails providerDetails, LinkableItem project) throws AlertException {
    JiraIssueSearchProperties issueProperties = issuePropertiesManager.retrieveIssueProperties(issue.getIssueKey());
    String nullableSubComponentName = issueProperties.getSubComponentName();
    String nullableSubComponentValue = issueProperties.getSubComponentValue();
    LinkableItem componentVersion = null;
    if (StringUtils.isNotBlank(nullableSubComponentName) && StringUtils.isNotBlank(nullableSubComponentValue)) {
        componentVersion = new LinkableItem(nullableSubComponentName, nullableSubComponentValue);
    }
    LinkableItem projectVersion = new LinkableItem(issueProperties.getSubTopicName(), issueProperties.getSubTopicValue());
    IssueBomComponentDetails bomComponentDetails = IssueBomComponentDetails.fromSearchResults(new LinkableItem(issueProperties.getComponentName(), issueProperties.getComponentValue()), componentVersion);
    ProjectIssueModel projectIssueModel = ProjectIssueModel.bom(providerDetails, project, projectVersion, bomComponentDetails);
    return createIssueResult(issue, projectIssueModel);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) JiraIssueSearchProperties(com.synopsys.integration.alert.api.channel.jira.JiraIssueSearchProperties) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)

Example 82 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class ProjectMessageSummarizer method constructMessageDetails.

private List<LinkableItem> constructMessageDetails(ProjectMessage projectMessage) {
    List<LinkableItem> details = new LinkedList<>();
    details.add(projectMessage.getProject());
    projectMessage.getProjectVersion().ifPresent(details::add);
    Map<ComponentConcernSummaryGrouping, Integer> groupedConcernCounts = new LinkedHashMap<>();
    for (BomComponentDetails bomComponent : projectMessage.getBomComponents()) {
        for (ComponentConcern concern : bomComponent.getComponentConcerns()) {
            ComponentConcernSummaryGrouping concernKey = new ComponentConcernSummaryGrouping(concern.getType(), concern.getOperation(), concern.getSeverity());
            int currentCount = groupedConcernCounts.getOrDefault(concernKey, 0);
            Number concernNumericValue = concern.getNumericValue();
            int concernCount = (concernNumericValue != null) ? concernNumericValue.intValue() : 1;
            groupedConcernCounts.put(concernKey, currentCount + concernCount);
        }
    }
    Map<ComponentConcernSummaryGrouping, Integer> sortedGroupedConcernCountsBySeverity = groupedConcernCounts.entrySet().stream().sorted(Map.Entry.comparingByKey(ComponentConcernSummaryGrouping.getComparator())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, // Merge operation is equivalent to Map::putIfAbsent
    (old, newIgnored) -> old, LinkedHashMap::new));
    for (Map.Entry<ComponentConcernSummaryGrouping, Integer> groupedConcernCount : sortedGroupedConcernCountsBySeverity.entrySet()) {
        ComponentConcernSummaryGrouping concernGrouping = groupedConcernCount.getKey();
        String severityLabel = ComponentConcernType.POLICY.equals(concernGrouping.type) ? concernGrouping.severity.getPolicyLabel() : concernGrouping.severity.getVulnerabilityLabel();
        String stateTypeString = convertToUppercasePlural(concernGrouping.type);
        String stateAdjective = convertToAdjective(concernGrouping.type, concernGrouping.operation);
        String label = String.format("(%s) %s %s count", severityLabel, stateTypeString, stateAdjective);
        LinkableItem concernDetail = new LinkableItem(label, groupedConcernCount.getValue().toString());
        concernDetail.setNumericValueFlag(true);
        details.add(concernDetail);
    }
    return details;
}
Also used : ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) MessageReason(com.synopsys.integration.alert.processor.api.extract.model.project.MessageReason) ComponentConcernSeverity(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernSeverity) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) Collectors(java.util.stream.Collectors) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) LinkedHashMap(java.util.LinkedHashMap) ProcessedProviderMessage(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage) List(java.util.List) Component(org.springframework.stereotype.Component) Pair(org.apache.commons.lang3.tuple.Pair) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) ProjectOperation(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation) Map(java.util.Map) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) Optional(java.util.Optional) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage) Comparator(java.util.Comparator) LinkedList(java.util.LinkedList) AlertSerializableModel(com.synopsys.integration.alert.api.common.model.AlertSerializableModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)

Example 83 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class ProjectMessageSummarizer method summarize.

public ProcessedProviderMessage<SimpleMessage> summarize(ProcessedProviderMessage<ProjectMessage> digestedProjectMessage) {
    ProjectMessage projectMessage = digestedProjectMessage.getProviderMessage();
    Pair<String, String> summaryAndDescription = constructSummaryAndDescription(projectMessage);
    List<LinkableItem> details = constructMessageDetails(projectMessage);
    SimpleMessage derivedSimpleMessage = SimpleMessage.derived(summaryAndDescription.getLeft(), summaryAndDescription.getRight(), details, projectMessage);
    return new ProcessedProviderMessage<>(digestedProjectMessage.getNotificationIds(), derivedSimpleMessage);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProcessedProviderMessage(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)

Example 84 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class ProjectMessageDigesterTest method createProcessedProviderMessage.

private ProcessedProviderMessage<ProjectMessage> createProcessedProviderMessage(String projectName, ProjectOperation operation) {
    LinkableItem project1 = new LinkableItem("proj", projectName, "https://" + projectName);
    ProjectMessage projectMessage1 = ProjectMessage.projectStatusInfo(PROVIDER_DETAILS, project1, operation);
    return new ProcessedProviderMessage<>(Set.of(), projectMessage1);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProcessedProviderMessage(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage)

Example 85 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class ProviderMessageDistributorTest method createProcessedProviderMessageHolder.

private ProcessedProviderMessageHolder createProcessedProviderMessageHolder(int numberOfProjectMessages, int numberOfSimpleMessages) {
    List<ProcessedProviderMessage<ProjectMessage>> processedProjectMessages = new ArrayList<>();
    List<ProcessedProviderMessage<SimpleMessage>> processedSimpleMessages = new ArrayList<>();
    LinkableItem commonProject = new LinkableItem("Project", "Common Project");
    ProjectOperation commonOperation = ProjectOperation.CREATE;
    for (long i = 1; i < numberOfProjectMessages + 1; i++) {
        LinkableItem provider = new LinkableItem("Provider", "Provider " + i);
        ProviderDetails providerDetails = new ProviderDetails(i, provider);
        ProjectMessage projectMessage = ProjectMessage.projectStatusInfo(providerDetails, commonProject, commonOperation);
        ProcessedProviderMessage<ProjectMessage> processedProviderMessage = ProcessedProviderMessage.singleSource(i, projectMessage);
        processedProjectMessages.add(processedProviderMessage);
    }
    for (long i = 1; i < numberOfSimpleMessages + 1; i++) {
        LinkableItem provider = new LinkableItem("Details", "Detail " + i);
        ProviderDetails providerDetails = new ProviderDetails(i, provider);
        SimpleMessage simpleMessage = SimpleMessage.original(providerDetails, "Summary " + i, "Description " + i, List.of(commonProject));
        ProcessedProviderMessage<SimpleMessage> processedSimpleMessage = ProcessedProviderMessage.singleSource(i, simpleMessage);
        processedSimpleMessages.add(processedSimpleMessage);
    }
    return new ProcessedProviderMessageHolder(processedProjectMessages, processedSimpleMessages);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProcessedProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder) ProcessedProviderMessage(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage) ArrayList(java.util.ArrayList) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProjectOperation(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)

Aggregations

LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)94 Test (org.junit.jupiter.api.Test)39 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)26 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)22 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)18 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)15 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)13 SimpleMessage (com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)11 ProjectOperation (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)11 ArrayList (java.util.ArrayList)11 LinkedList (java.util.LinkedList)11 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)9 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)9 List (java.util.List)9 ComponentVulnerabilities (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)8 Optional (java.util.Optional)7 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)6 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)6 ComponentConcernType (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType)6