Search in sources :

Example 11 with IssuePolicyDetails

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

the class AzureBoardsComponentIssueFinderTest method findExistingIssuesByProjectIssueModelTest.

@Test
public void findExistingIssuesByProjectIssueModelTest() 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);
    IssuePolicyDetails testPolicy = new IssuePolicyDetails("Test Policy", ItemOperation.ADD, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
    ProjectIssueModel projectIssueModel = ProjectIssueModel.policy(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ISSUE_BOM_COMPONENT_DETAILS, testPolicy);
    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.POLICY, existingIssueDetails.getIssueCategory());
}
Also used : 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 12 with IssuePolicyDetails

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

the class AzureBoardsComponentIssueFinder method findExistingIssuesByProjectIssueModel.

@Override
public List<ExistingIssueDetails<Integer>> findExistingIssuesByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
    LinkableItem projectVersion = projectIssueModel.getProjectVersion().orElseThrow(() -> new AlertRuntimeException("Missing project-version"));
    String categoryKey = AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_VULNERABILITY_COMPATIBILITY_LABEL;
    AzureSearchFieldMappingBuilder fieldRefNameToValue = createBomFieldReferenceToValueMap(projectVersion, projectIssueModel.getBomComponentDetails());
    Optional<IssuePolicyDetails> policyDetails = projectIssueModel.getPolicyDetails();
    Optional<String> optionalPolicyName = policyDetails.map(IssuePolicyDetails::getName);
    if (optionalPolicyName.isPresent()) {
        categoryKey = AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_POLICY_COMPATIBILITY_LABEL;
        String additionalInfoKey = AzureBoardsAlertIssuePropertiesManager.POLICY_ADDITIONAL_KEY_COMPATIBILITY_LABEL + optionalPolicyName.get();
        fieldRefNameToValue.addAdditionalInfoKey(additionalInfoKey);
    }
    if (projectIssueModel.getComponentUnknownVersionDetails().isPresent()) {
        categoryKey = AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_COMPONENT_UNKNOWN_VERSION_COMPATIBILITY_LABEL;
    }
    fieldRefNameToValue.addCategoryKey(categoryKey);
    return workItemFinder.findWorkItems(projectIssueModel.getProvider(), projectIssueModel.getProject(), fieldRefNameToValue).stream().map(workItemResponseModel -> createIssueDetails(workItemResponseModel, projectIssueModel)).collect(Collectors.toList());
}
Also used : ExactIssueFinder(com.synopsys.integration.alert.api.channel.issue.search.ExactIssueFinder) WorkItemResponseModel(com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) Collectors(java.util.stream.Collectors) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ArrayList(java.util.ArrayList) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ProjectVersionComponentIssueFinder(com.synopsys.integration.alert.api.channel.issue.search.ProjectVersionComponentIssueFinder) AzureBoardsSearchPropertiesUtils(com.synopsys.integration.alert.channel.azure.boards.distribution.util.AzureBoardsSearchPropertiesUtils) List(java.util.List) AbstractBomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.AbstractBomComponentDetails) Gson(com.google.gson.Gson) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) Optional(java.util.Optional) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) ProjectIssueSearchResult(com.synopsys.integration.alert.api.channel.issue.search.ProjectIssueSearchResult) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)

Example 13 with IssuePolicyDetails

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

the class AzureBoardsAlertIssuePropertiesManagerTest method verifyValidPolicyIssuesAreCreated.

@Test
public void verifyValidPolicyIssuesAreCreated() {
    AzureBoardsAlertIssuePropertiesManager azureBoardsAlertIssuePropertiesManager = new AzureBoardsAlertIssuePropertiesManager();
    LinkableItem providerConfig = new LinkableItem("providerConfigLabel", "providerConfigValue");
    ProviderDetails providerDetails = new ProviderDetails(1L, providerConfig);
    LinkableItem project = new LinkableItem("projectLabel", "projectValue");
    LinkableItem projectVersion = new LinkableItem("projectVersionLabel", "projectVersionValue");
    LinkableItem component = new LinkableItem("componentLabel", "componentValue");
    LinkableItem componentVersion = new LinkableItem("componentVersionLabel", "componentVersionValue");
    IssueBomComponentDetails issueBomComponentDetails = IssueBomComponentDetails.fromSearchResults(component, componentVersion);
    IssuePolicyDetails issuePolicyDetails = new IssuePolicyDetails("policy", ItemOperation.ADD, ComponentConcernSeverity.CRITICAL);
    ProjectIssueModel policy = ProjectIssueModel.policy(providerDetails, project, projectVersion, issueBomComponentDetails, issuePolicyDetails);
    List<WorkItemElementOperationModel> workItemRequestCustomFieldOperations = azureBoardsAlertIssuePropertiesManager.createWorkItemRequestCustomFieldOperations(policy);
    LinkableItem provider = providerDetails.getProvider();
    String providerKey = AzureBoardsSearchPropertiesUtils.createProviderKey(provider.getLabel(), provider.getUrl().orElse(null));
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_PROVIDER_KEY_FIELD_REFERENCE_NAME, providerKey);
    String additionalInfo = AzureBoardsAlertIssuePropertiesManager.POLICY_ADDITIONAL_KEY_COMPATIBILITY_LABEL + issuePolicyDetails.getName();
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_ADDITIONAL_INFO_KEY_FIELD_REFERENCE_NAME, additionalInfo);
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_CATEGORY_KEY_FIELD_REFERENCE_NAME, AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_POLICY_COMPATIBILITY_LABEL);
    String subTopicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(policy.getProjectVersion().orElse(null));
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME, subTopicKey);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) WorkItemElementOperationModel(com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemElementOperationModel) Test(org.junit.jupiter.api.Test)

Example 14 with IssuePolicyDetails

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

Example 15 with IssuePolicyDetails

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

the class ProjectIssueModelConverter method createTruncatedTitle.

private String createTruncatedTitle(ProjectIssueModel projectIssueModel) {
    LinkableItem provider = projectIssueModel.getProvider();
    LinkableItem project = projectIssueModel.getProject();
    LinkableItem projectVersion = projectIssueModel.getProjectVersion().orElse(MISSING_PROJECT_VERSION_PLACEHOLDER);
    IssueBomComponentDetails bomComponent = projectIssueModel.getBomComponentDetails();
    LinkableItem component = bomComponent.getComponent();
    Optional<String> optionalComponentVersionValue = bomComponent.getComponentVersion().map(LinkableItem::getValue);
    boolean isComponentVersionUnknown = projectIssueModel.getComponentUnknownVersionDetails().isPresent();
    StringBuilder componentPieceBuilder = new StringBuilder();
    componentPieceBuilder.append(component.getValue());
    if (optionalComponentVersionValue.isPresent() && !isComponentVersionUnknown) {
        componentPieceBuilder.append('[');
        componentPieceBuilder.append(optionalComponentVersionValue.get());
        componentPieceBuilder.append(']');
    }
    StringBuilder componentConcernPieceBuilder = new StringBuilder();
    Optional<String> optionalPolicyName = projectIssueModel.getPolicyDetails().map(IssuePolicyDetails::getName);
    if (optionalPolicyName.isPresent()) {
        componentConcernPieceBuilder.append(COMMA_SPACE);
        componentConcernPieceBuilder.append(ComponentConcernType.POLICY.getDisplayName());
        componentConcernPieceBuilder.append('[');
        componentConcernPieceBuilder.append(optionalPolicyName.get());
        componentConcernPieceBuilder.append(']');
    } else if (isComponentVersionUnknown) {
        componentConcernPieceBuilder.append(COMMA_SPACE);
        componentConcernPieceBuilder.append(ComponentConcernType.UNKNOWN_VERSION.getDisplayName());
    } else {
        componentConcernPieceBuilder.append(COMMA_SPACE);
        componentConcernPieceBuilder.append(ComponentConcernType.VULNERABILITY.getDisplayName());
    }
    String componentConcernPiece = componentConcernPieceBuilder.toString();
    String preConcernTitle = String.format("Alert - %s[%s], %s[%s], %s", provider.getLabel(), provider.getValue(), project.getValue(), projectVersion.getValue(), componentPieceBuilder);
    if (preConcernTitle.length() + componentConcernPieceBuilder.length() > formatter.getMaxTitleLength()) {
        if (formatter.getMaxTitleLength() > COMPONENT_CONCERN_TITLE_SECTION_CHAR_COUNT) {
            preConcernTitle = StringUtils.truncate(preConcernTitle, formatter.getMaxTitleLength() - COMPONENT_CONCERN_TITLE_SECTION_CHAR_COUNT);
            componentConcernPiece = StringUtils.truncate(componentConcernPieceBuilder.toString(), COMPONENT_CONCERN_TITLE_SECTION_CHAR_COUNT);
        } else {
            // If max title length is less than 3, then there are bigger concerns than an IllegalArgumentException
            preConcernTitle = StringUtils.truncate(preConcernTitle, formatter.getMaxTitleLength() - 3);
            componentConcernPiece = "...";
        }
    }
    return preConcernTitle + componentConcernPiece;
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)

Aggregations

IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)20 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)14 Test (org.junit.jupiter.api.Test)11 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)10 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)8 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)7 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)5 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)5 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)4 IssueCategoryRetriever (com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)4 Gson (com.google.gson.Gson)3 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)3 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)3 ActionableIssueSearchResult (com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult)3 IssueCategory (com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory)3 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)3 ItemOperation (com.synopsys.integration.alert.common.enumeration.ItemOperation)3 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)3 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)3