Search in sources :

Example 1 with IssueEstimatedRiskModel

use of com.synopsys.integration.alert.api.channel.issue.model.IssueEstimatedRiskModel in project hub-alert by blackducksoftware.

the class ProjectMessageToIssueModelTransformerTest method convertToIssueModelsForComponentUnknownVersionTest.

@Test
public void convertToIssueModelsForComponentUnknownVersionTest() {
    ComponentConcern unknownComponentConcern = ComponentConcern.unknownComponentVersion(ItemOperation.ADD, "Component01", ComponentConcernSeverity.MAJOR_HIGH, 2, "https://synopsys.com");
    BomComponentDetails bomComponentDetails = createBomComponentDetails(unknownComponentConcern);
    ProjectMessage projectMessage = ProjectMessage.componentConcern(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, List.of(bomComponentDetails));
    ProjectMessageToIssueModelTransformer modelTransformer = new ProjectMessageToIssueModelTransformer();
    List<ProjectIssueModel> policyIssueModels = modelTransformer.convertToIssueModels(projectMessage);
    assertEquals(1, policyIssueModels.size());
    ProjectIssueModel unknownVersionIssueModel = policyIssueModels.get(0);
    assertRequiredDetails(unknownVersionIssueModel);
    Optional<IssueComponentUnknownVersionDetails> optionalDetails = unknownVersionIssueModel.getComponentUnknownVersionDetails();
    assertTrue(optionalDetails.isPresent(), "Expected unknown component details to be present");
    IssueComponentUnknownVersionDetails details = optionalDetails.get();
    assertEquals(ItemOperation.ADD, details.getItemOperation());
    assertEquals(1, details.getEstimatedRiskModelList().size());
    IssueEstimatedRiskModel estimatedRiskModel = details.getEstimatedRiskModelList().get(0);
    assertEquals(ComponentConcernSeverity.MAJOR_HIGH, estimatedRiskModel.getSeverity());
    assertEquals("Component01", estimatedRiskModel.getName());
    assertEquals(2, estimatedRiskModel.getCount());
    assertTrue(estimatedRiskModel.getComponentVersionUrl().isPresent());
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) IssueEstimatedRiskModel(com.synopsys.integration.alert.api.channel.issue.model.IssueEstimatedRiskModel) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) Test(org.junit.jupiter.api.Test)

Example 2 with IssueEstimatedRiskModel

use of com.synopsys.integration.alert.api.channel.issue.model.IssueEstimatedRiskModel in project hub-alert by blackducksoftware.

the class IssueComponentUnknownVersionDetailsConverter method createEstimatedRiskDetailsSectionPieces.

public List<String> createEstimatedRiskDetailsSectionPieces(IssueComponentUnknownVersionDetails unknownVersionDetails) {
    List<String> estimatedRiskSectionPieces = new LinkedList<>();
    if (ItemOperation.DELETE.equals(unknownVersionDetails.getItemOperation())) {
        estimatedRiskSectionPieces.add(formatter.encode(TEXT_COMPONENT_DELETE));
        estimatedRiskSectionPieces.add(formatter.getLineSeparator());
    } else {
        estimatedRiskSectionPieces.add(formatter.encode(SECTION_LABEL_VULNERABILITY_COUNTS));
        estimatedRiskSectionPieces.add(formatter.getLineSeparator());
        estimatedRiskSectionPieces.add(formatter.getLineSeparator());
        for (IssueEstimatedRiskModel estimatedRiskModel : unknownVersionDetails.getEstimatedRiskModelList()) {
            estimatedRiskSectionPieces.add(createEstimatedRiskString(estimatedRiskModel));
            estimatedRiskSectionPieces.add(formatter.getLineSeparator());
        }
    }
    return estimatedRiskSectionPieces;
}
Also used : IssueEstimatedRiskModel(com.synopsys.integration.alert.api.channel.issue.model.IssueEstimatedRiskModel) LinkedList(java.util.LinkedList)

Example 3 with IssueEstimatedRiskModel

use of com.synopsys.integration.alert.api.channel.issue.model.IssueEstimatedRiskModel in project hub-alert by blackducksoftware.

the class ProjectMessageToIssueModelTransformer method createEstimatedRiskProjectIssueModel.

private ProjectIssueModel createEstimatedRiskProjectIssueModel(ProjectMessage projectMessage, IssueBomComponentDetails issueBomComponent, List<ComponentConcern> estimatedRiskConcerns) {
    List<IssueEstimatedRiskModel> estimatedRiskModels = new LinkedList<>();
    ItemOperation itemOperation = estimatedRiskConcerns.stream().map(ComponentConcern::getOperation).findFirst().orElse(ItemOperation.ADD);
    // all component concerns for this type have the same operation.
    for (ComponentConcern componentConcern : estimatedRiskConcerns) {
        estimatedRiskModels.add(IssueEstimatedRiskModel.fromComponentConcern(componentConcern));
    }
    IssueComponentUnknownVersionDetails unknownVersionDetails = new IssueComponentUnknownVersionDetails(itemOperation, estimatedRiskModels);
    return ProjectIssueModel.componentUnknownVersion(projectMessage.getProviderDetails(), projectMessage.getProject(), projectMessage.getProjectVersion().orElse(null), issueBomComponent, unknownVersionDetails);
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) IssueEstimatedRiskModel(com.synopsys.integration.alert.api.channel.issue.model.IssueEstimatedRiskModel) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) LinkedList(java.util.LinkedList)

Aggregations

IssueEstimatedRiskModel (com.synopsys.integration.alert.api.channel.issue.model.IssueEstimatedRiskModel)3 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)2 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)2 LinkedList (java.util.LinkedList)2 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)1 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)1 ItemOperation (com.synopsys.integration.alert.common.enumeration.ItemOperation)1 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)1 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)1 Test (org.junit.jupiter.api.Test)1