Search in sources :

Example 16 with ComponentConcern

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

the class ComponentUnknownVersionExtractor method createBomComponentDetails.

@Override
protected List<BomComponentDetails> createBomComponentDetails(ComponentUnknownVersionWithStatusNotificationContent notificationContent, BlackDuckServicesFactory blackDuckServicesFactory) throws IntegrationException {
    BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    BlackDuckMessageBomComponentDetailsCreator bomComponentDetailsCreator = detailsCreatorFactory.createBomComponentDetailsCreator(blackDuckServicesFactory);
    List<ComponentConcern> componentConcerns = createComponentConcerns(notificationContent);
    BomComponentDetails bomComponentDetails;
    try {
        ProjectVersionComponentVersionView bomComponent = blackDuckApiClient.getResponse(new HttpUrl(notificationContent.getBomComponent()), ProjectVersionComponentVersionView.class);
        bomComponentDetails = bomComponentDetailsCreator.createBomComponentUnknownVersionDetails(bomComponent, componentConcerns, ComponentUpgradeGuidance.none(), List.of());
    } catch (IntegrationRestException e) {
        bomComponent404Handler.logIf404OrThrow(e, notificationContent.getComponentName(), null);
        bomComponentDetails = bomComponentDetailsCreator.createMissingBomComponentDetailsForUnknownVersion(notificationContent.getComponentName(), notificationContent.getBomComponent(), BlackDuckMessageBomComponentDetailsCreator.COMPONENT_VERSION_UNKNOWN, componentConcerns, ComponentUpgradeGuidance.none(), List.of());
    }
    return List.of(bomComponentDetails);
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckMessageBomComponentDetailsCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) HttpUrl(com.synopsys.integration.rest.HttpUrl) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Example 17 with ComponentConcern

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

the class ComponentConcernConverterTest method callGatherComponentConcernSectionPieces.

private List<String> callGatherComponentConcernSectionPieces() {
    ChannelMessageFormatter channelMessageFormatter = new MockChannelMessageFormatter(Integer.MAX_VALUE);
    ComponentConcernConverter componentConcernConverter = new ComponentConcernConverter(channelMessageFormatter);
    List<ComponentConcern> componentConcerns = createALotOfComponentConcerns();
    return componentConcernConverter.gatherComponentConcernSectionPieces(componentConcerns);
}
Also used : MockChannelMessageFormatter(com.synopsys.integration.alert.api.channel.convert.mock.MockChannelMessageFormatter) MockChannelMessageFormatter(com.synopsys.integration.alert.api.channel.convert.mock.MockChannelMessageFormatter) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)

Example 18 with ComponentConcern

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

the class ComponentConcernConverter method gatherComponentConcernSectionPieces.

public List<String> gatherComponentConcernSectionPieces(List<ComponentConcern> componentConcerns) {
    List<String> componentConcernSectionPieces = new LinkedList<>();
    List<ComponentConcern> vulnerabilityConcerns = new LinkedList<>();
    List<ComponentConcern> estimatedRiskConcerns = new LinkedList<>();
    Set<ComponentConcern> sortedConcerns = new TreeSet<>(componentConcerns);
    for (ComponentConcern componentConcern : sortedConcerns) {
        if (ComponentConcernType.POLICY.equals(componentConcern.getType())) {
            String policySectionPiece = createPolicySectionPiece(componentConcern);
            componentConcernSectionPieces.add(policySectionPiece);
            componentConcernSectionPieces.add(formatter.getLineSeparator());
        } else if (ComponentConcernType.UNKNOWN_VERSION.equals(componentConcern.getType())) {
            estimatedRiskConcerns.add(componentConcern);
        } else {
            vulnerabilityConcerns.add(componentConcern);
        }
    }
    List<String> vulnerabilitySectionPieces = createVulnerabilitySectionPieces(vulnerabilityConcerns);
    List<String> estimatedRiskSectionPieces = createEstimatedRiskSectionPieces(estimatedRiskConcerns);
    componentConcernSectionPieces.addAll(vulnerabilitySectionPieces);
    componentConcernSectionPieces.addAll(estimatedRiskSectionPieces);
    return componentConcernSectionPieces;
}
Also used : TreeSet(java.util.TreeSet) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) LinkedList(java.util.LinkedList)

Example 19 with ComponentConcern

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

the class ComponentConcernConverter method createEstimatedRiskSectionPieces.

private List<String> createEstimatedRiskSectionPieces(List<ComponentConcern> estimatedRiskConcerns) {
    if (estimatedRiskConcerns.isEmpty()) {
        return List.of();
    }
    boolean isDelete = estimatedRiskConcerns.stream().allMatch(componentConcern -> ItemOperation.DELETE.equals(componentConcern.getOperation()));
    List<String> estimatedRiskForOperationSectionPieces = new LinkedList<>();
    estimatedRiskForOperationSectionPieces.add(formatter.getSectionSeparator());
    estimatedRiskForOperationSectionPieces.add(formatter.getLineSeparator());
    if (isDelete) {
        estimatedRiskForOperationSectionPieces.add(formatter.encode(TEXT_COMPONENT_DELETE));
        estimatedRiskForOperationSectionPieces.add(formatter.getLineSeparator());
    } else {
        estimatedRiskForOperationSectionPieces.add(String.format("%s%s", formattedVulnerabilityCountsString, formattedColonSpace));
        estimatedRiskForOperationSectionPieces.add(formatter.getLineSeparator());
        estimatedRiskForOperationSectionPieces.add(formatter.getLineSeparator());
        for (ComponentConcern componentConcern : estimatedRiskConcerns) {
            estimatedRiskForOperationSectionPieces.add(createEstimatedRiskConcernString(componentConcern));
            estimatedRiskForOperationSectionPieces.add(formatter.getLineSeparator());
        }
    }
    return estimatedRiskForOperationSectionPieces;
}
Also used : ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) LinkedList(java.util.LinkedList)

Example 20 with ComponentConcern

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

the class ComponentConcernConverter method createVulnerabilitySectionPieces.

private List<String> createVulnerabilitySectionPieces(List<ComponentConcern> vulnerabilityConcerns) {
    if (vulnerabilityConcerns.isEmpty()) {
        return List.of();
    }
    List<ComponentConcern> addedVulnerabilityConcerns = new LinkedList<>();
    List<ComponentConcern> updatedVulnerabilityConcerns = new LinkedList<>();
    List<ComponentConcern> deletedVulnerabilityConcerns = new LinkedList<>();
    for (ComponentConcern vulnerabilityConcern : vulnerabilityConcerns) {
        ItemOperation operation = vulnerabilityConcern.getOperation();
        if (ItemOperation.ADD.equals(operation)) {
            addedVulnerabilityConcerns.add(vulnerabilityConcern);
        } else if (ItemOperation.DELETE.equals(operation)) {
            deletedVulnerabilityConcerns.add(vulnerabilityConcern);
        } else {
            updatedVulnerabilityConcerns.add(vulnerabilityConcern);
        }
    }
    List<String> vulnerabilitySectionPieces = new LinkedList<>();
    vulnerabilitySectionPieces.add(formatter.getSectionSeparator());
    vulnerabilitySectionPieces.add(formatter.getLineSeparator());
    // Add Sections
    List<String> vulnerabilitiesAddedPieces = createVulnerabilityConcernsForOperation(formattedVerbAdded, addedVulnerabilityConcerns);
    vulnerabilitySectionPieces.addAll(vulnerabilitiesAddedPieces);
    List<String> vulnerabilitiesUpdatedPieces = createVulnerabilityConcernsForOperation(formattedVerbUpdated, updatedVulnerabilityConcerns);
    vulnerabilitySectionPieces.addAll(vulnerabilitiesUpdatedPieces);
    List<String> vulnerabilitiesDeletedPieces = createVulnerabilityConcernsForOperation(formattedVerbRemoved, deletedVulnerabilityConcerns);
    vulnerabilitySectionPieces.addAll(vulnerabilitiesDeletedPieces);
    return vulnerabilitySectionPieces;
}
Also used : ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) LinkedList(java.util.LinkedList)

Aggregations

ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)24 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)13 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)9 LinkedList (java.util.LinkedList)9 Test (org.junit.jupiter.api.Test)7 ItemOperation (com.synopsys.integration.alert.common.enumeration.ItemOperation)6 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)6 ProcessedProviderMessage (com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage)5 SimpleMessage (com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)5 HttpUrl (com.synopsys.integration.rest.HttpUrl)5 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)4 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)4 BlackDuckMessageBomComponentDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator)4 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)4 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)4 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)4 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)3 IssueEstimatedRiskModel (com.synopsys.integration.alert.api.channel.issue.model.IssueEstimatedRiskModel)3 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)3 ComponentConcernType (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType)3