Search in sources :

Example 51 with LinkableItem

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

the class BomComponentDetails method combine.

@Override
public List<BomComponentDetails> combine(BomComponentDetails otherDetails) {
    List<BomComponentDetails> uncombinedDetails = List.of(this, otherDetails);
    if (!getComponent().equals(otherDetails.getComponent())) {
        return uncombinedDetails;
    }
    LinkableItem nullableComponentVersion = getComponentVersion().orElse(null);
    LinkableItem nullableOtherComponentVersion = otherDetails.getComponentVersion().orElse(null);
    if (!EqualsBuilder.reflectionEquals(nullableComponentVersion, nullableOtherComponentVersion)) {
        return uncombinedDetails;
    }
    if (hasComponentConcerns() != otherDetails.hasComponentConcerns()) {
        return uncombinedDetails;
    }
    return combineComponentConcerns(otherDetails);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem)

Example 52 with LinkableItem

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

the class AzureBoardsAlertIssuePropertiesManager method createWorkItemRequestCustomFieldOperations.

public List<WorkItemElementOperationModel> createWorkItemRequestCustomFieldOperations(ProjectIssueModel alertIssueSource) {
    LinkableItem provider = alertIssueSource.getProvider();
    String providerKey = AzureBoardsSearchPropertiesUtils.createProviderKey(provider.getLabel(), provider.getUrl().orElse(null));
    String topicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(alertIssueSource.getProject());
    String subTopicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(alertIssueSource.getProjectVersion().orElse(null));
    IssueBomComponentDetails bomComponentDetails = alertIssueSource.getBomComponentDetails();
    String componentKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(bomComponentDetails.getComponent());
    String subComponentKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(bomComponentDetails.getComponentVersion().orElse(null));
    AzureSearchFieldBuilder azureSearchFieldBuilder = AzureSearchFieldBuilder.create().addProviderKey(providerKey).addTopicKey(topicKey).addSubTopicKey(subTopicKey).addComponentKey(componentKey).addSubComponentKey(subComponentKey);
    String categoryKey = CATEGORY_TYPE_VULNERABILITY_COMPATIBILITY_LABEL;
    Optional<String> optionalPolicyName = alertIssueSource.getPolicyDetails().map(IssuePolicyDetails::getName);
    if (optionalPolicyName.isPresent()) {
        String additionalInfoKey = POLICY_ADDITIONAL_KEY_COMPATIBILITY_LABEL + optionalPolicyName.get();
        azureSearchFieldBuilder.addAdditionalInfoKey(additionalInfoKey);
        categoryKey = CATEGORY_TYPE_POLICY_COMPATIBILITY_LABEL;
    }
    boolean unknownVersionCategory = alertIssueSource.getComponentUnknownVersionDetails().isPresent();
    if (unknownVersionCategory) {
        categoryKey = CATEGORY_TYPE_COMPONENT_UNKNOWN_VERSION_COMPATIBILITY_LABEL;
    }
    azureSearchFieldBuilder.addCategoryKey(categoryKey);
    return azureSearchFieldBuilder.build();
}
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)

Example 53 with LinkableItem

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

the class AzureBoardsWorkItemFinderTest method verifyQueryWhereStatementExists.

@Test
public void verifyQueryWhereStatementExists() throws AlertException {
    AzureBoardsIssueTrackerQueryManager azureBoardsIssueTrackerQueryManager = Mockito.mock(AzureBoardsIssueTrackerQueryManager.class);
    ArgumentCaptor<WorkItemQuery> workItemQueryArgumentCaptor = ArgumentCaptor.forClass(WorkItemQuery.class);
    String teamProjectName = "team project name";
    AzureBoardsWorkItemFinder azureBoardsWorkItemFinder = new AzureBoardsWorkItemFinder(azureBoardsIssueTrackerQueryManager, teamProjectName);
    LinkableItem provider = new LinkableItem("providerLabel", "providerValue");
    LinkableItem project = new LinkableItem("projectLabel", "projectValue");
    String componentKey = "componentKey";
    String subTopicKey = "subTopicKey";
    String additionalInfoKey = "additionalInfoKey";
    AzureSearchFieldMappingBuilder azureSearchFieldMappingBuilder = AzureSearchFieldMappingBuilder.create().addComponentKey(componentKey).addSubTopic(subTopicKey).addAdditionalInfoKey(additionalInfoKey);
    Mockito.doReturn(List.of()).when(azureBoardsIssueTrackerQueryManager).executeQueryAndRetrieveWorkItems(Mockito.any());
    azureBoardsWorkItemFinder.findWorkItems(provider, project, azureSearchFieldMappingBuilder);
    Mockito.verify(azureBoardsIssueTrackerQueryManager).executeQueryAndRetrieveWorkItems(workItemQueryArgumentCaptor.capture());
    WorkItemQuery workItemQuery = workItemQueryArgumentCaptor.getValue();
    assertNotNull(workItemQuery);
    assertFalse(workItemQuery.exceedsCharLimit());
    Map<String, String> whereClauseValues = extractValuesFromWhereClause(workItemQuery.rawQuery());
    assertTrue(whereClauseValues.size() > 3);
    assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME, subTopicKey);
    assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_ADDITIONAL_INFO_KEY_FIELD_REFERENCE_NAME, additionalInfoKey);
    assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_COMPONENT_KEY_FIELD_REFERENCE_NAME, componentKey);
}
Also used : WorkItemQuery(com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) AzureBoardsIssueTrackerQueryManager(com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager) Test(org.junit.jupiter.api.Test)

Example 54 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem 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 55 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem 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)

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