Search in sources :

Example 1 with IssueComponentUnknownVersionDetails

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

the class AzureBoardsComponentIssueFinderTest method findExistingIssuesByProjectIssueModelForUnknownVersionTest.

@Test
public void findExistingIssuesByProjectIssueModelForUnknownVersionTest() throws AlertException {
    Gson gson = new Gson();
    String organizationName = "orgName";
    AzureBoardsIssueTrackerQueryManager queryManager = Mockito.mock(AzureBoardsIssueTrackerQueryManager.class);
    IssueCategoryRetriever issueCategoryRetriever = new IssueCategoryRetriever();
    AzureBoardsExistingIssueDetailsCreator issueDetailsCreator = new AzureBoardsExistingIssueDetailsCreator(organizationName, issueCategoryRetriever, azureBoardsIssueStatusResolver);
    AzureBoardsWorkItemFinder workItemFinder = new AzureBoardsWorkItemFinder(queryManager, "test proj");
    AzureBoardsComponentIssueFinder componentIssueFinder = new AzureBoardsComponentIssueFinder(gson, workItemFinder, issueDetailsCreator);
    IssueComponentUnknownVersionDetails componentUnknownVersionDetails = new IssueComponentUnknownVersionDetails(ItemOperation.ADD, createRiskModels());
    IssuePolicyDetails testPolicy = new IssuePolicyDetails("Test Policy", ItemOperation.ADD, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
    ProjectIssueModel projectIssueModel = ProjectIssueModel.componentUnknownVersion(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ISSUE_BOM_COMPONENT_DETAILS, componentUnknownVersionDetails);
    WorkItemResponseModel workItemResponseModel = createWorkItemResponseModel(workItemReopenState);
    Mockito.when(queryManager.executeQueryAndRetrieveWorkItems(Mockito.any())).thenReturn(List.of(workItemResponseModel));
    List<ExistingIssueDetails<Integer>> existingIssueDetailsList = componentIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel);
    assertEquals(1, existingIssueDetailsList.size());
    ExistingIssueDetails<Integer> existingIssueDetails = existingIssueDetailsList.get(0);
    assertEquals(IssueStatus.RESOLVABLE, existingIssueDetails.getIssueStatus());
    assertEquals(IssueCategory.BOM, existingIssueDetails.getIssueCategory());
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) AzureBoardsIssueTrackerQueryManager(com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager) Gson(com.google.gson.Gson) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) WorkItemResponseModel(com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel) IssueCategoryRetriever(com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever) Test(org.junit.jupiter.api.Test)

Example 2 with IssueComponentUnknownVersionDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails 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 3 with IssueComponentUnknownVersionDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails 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)

Example 4 with IssueComponentUnknownVersionDetails

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

the class IssueTrackerSearcher method isOnlyDeleteOperation.

private boolean isOnlyDeleteOperation(ProjectIssueModel projectIssueModel) {
    boolean isPolicyDelete = projectIssueModel.getPolicyDetails().map(IssuePolicyDetails::getOperation).filter(ItemOperation.DELETE::equals).isPresent();
    boolean isEstimatedRiskDelete = projectIssueModel.getComponentUnknownVersionDetails().map(IssueComponentUnknownVersionDetails::getItemOperation).filter(ItemOperation.DELETE::equals).isPresent();
    boolean isVulnerabilityDelete = false;
    Optional<IssueVulnerabilityDetails> optionalVulnDetails = projectIssueModel.getVulnerabilityDetails();
    if (optionalVulnDetails.isPresent()) {
        IssueVulnerabilityDetails vulnDetails = optionalVulnDetails.get();
        boolean allVulnsRemediated = vulnDetails.areAllComponentVulnerabilitiesRemediated();
        boolean hasDeletions = !vulnDetails.getVulnerabilitiesDeleted().isEmpty();
        boolean doesNotHaveAdditions = vulnDetails.getVulnerabilitiesAdded().isEmpty();
        boolean doesNotHaveUpdates = vulnDetails.getVulnerabilitiesUpdated().isEmpty();
        isVulnerabilityDelete = allVulnsRemediated || (hasDeletions && doesNotHaveAdditions && doesNotHaveUpdates);
    }
    return isPolicyDelete || isVulnerabilityDelete || isEstimatedRiskDelete;
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation)

Example 5 with IssueComponentUnknownVersionDetails

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

the class ProjectIssueModelConverter method createProjectIssueModelConcernSectionPieces.

private List<String> createProjectIssueModelConcernSectionPieces(ProjectIssueModel projectIssueModel, boolean commentFormat) {
    List<String> concernSectionPieces = new LinkedList<>();
    IssueBomComponentDetails bomComponentDetails = projectIssueModel.getBomComponentDetails();
    Optional<IssuePolicyDetails> optionalPolicyDetails = projectIssueModel.getPolicyDetails();
    if (optionalPolicyDetails.isPresent()) {
        List<String> policyDetailsSectionPieces = issuePolicyDetailsConverter.createPolicyDetailsSectionPieces(bomComponentDetails, optionalPolicyDetails.get());
        concernSectionPieces.addAll(policyDetailsSectionPieces);
        concernSectionPieces.add(formatter.getLineSeparator());
        concernSectionPieces.add(formatter.getSectionSeparator());
        concernSectionPieces.add(formatter.getLineSeparator());
    }
    Optional<IssueVulnerabilityDetails> optionalVulnDetails = projectIssueModel.getVulnerabilityDetails();
    if (optionalVulnDetails.isPresent()) {
        List<String> vulnDetailsSectionPieces;
        if (commentFormat) {
            vulnDetailsSectionPieces = issueVulnerabilityDetailsConverter.createVulnerabilityDetailsSectionPieces(optionalVulnDetails.get());
        } else {
            vulnDetailsSectionPieces = componentVulnerabilitiesConverter.createComponentVulnerabilitiesSectionPieces(projectIssueModel.getBomComponentDetails().getComponentVulnerabilities());
        }
        concernSectionPieces.addAll(vulnDetailsSectionPieces);
        concernSectionPieces.add(formatter.getLineSeparator());
        concernSectionPieces.add(formatter.getSectionSeparator());
        concernSectionPieces.add(formatter.getLineSeparator());
    }
    Optional<IssueComponentUnknownVersionDetails> optionalUnknownVersionDetails = projectIssueModel.getComponentUnknownVersionDetails();
    if (optionalUnknownVersionDetails.isPresent()) {
        List<String> componentUnknownVersionDetailsSectionPieces;
        componentUnknownVersionDetailsSectionPieces = issueComponentUnknownVersionDetailsConverter.createEstimatedRiskDetailsSectionPieces(optionalUnknownVersionDetails.get());
        concernSectionPieces.addAll(componentUnknownVersionDetailsSectionPieces);
        concernSectionPieces.add(formatter.getLineSeparator());
        concernSectionPieces.add(formatter.getSectionSeparator());
        concernSectionPieces.add(formatter.getLineSeparator());
    }
    return concernSectionPieces;
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) LinkedList(java.util.LinkedList)

Aggregations

IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)7 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)4 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)3 ItemOperation (com.synopsys.integration.alert.common.enumeration.ItemOperation)3 Test (org.junit.jupiter.api.Test)3 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)2 IssueEstimatedRiskModel (com.synopsys.integration.alert.api.channel.issue.model.IssueEstimatedRiskModel)2 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)2 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)2 LinkedList (java.util.LinkedList)2 Gson (com.google.gson.Gson)1 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)1 IssueCategoryRetriever (com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever)1 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 AzureBoardsIssueTrackerQueryManager (com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager)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 WorkItemResponseModel (com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel)1 Set (java.util.Set)1