Search in sources :

Example 6 with ExistingIssueDetails

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

the class JiraExactIssueFinder method findExistingIssuesByProjectIssueModel.

@Override
public List<ExistingIssueDetails<String>> findExistingIssuesByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
    LinkableItem provider = projectIssueModel.getProvider();
    LinkableItem project = projectIssueModel.getProject();
    IssueBomComponentDetails bomComponent = projectIssueModel.getBomComponentDetails();
    ComponentConcernType concernType = ComponentConcernType.VULNERABILITY;
    String policyName = null;
    Optional<IssuePolicyDetails> policyDetails = projectIssueModel.getPolicyDetails();
    Optional<String> optionalPolicyName = policyDetails.map(IssuePolicyDetails::getName);
    if (optionalPolicyName.isPresent()) {
        concernType = ComponentConcernType.POLICY;
        policyName = optionalPolicyName.get();
    }
    if (projectIssueModel.getComponentUnknownVersionDetails().isPresent()) {
        concernType = ComponentConcernType.UNKNOWN_VERSION;
    }
    String jqlString = JqlStringCreator.createBlackDuckComponentConcernIssuesSearchString(jiraProjectKey, provider, project, projectIssueModel.getProjectVersion().orElse(null), bomComponent.getComponent(), bomComponent.getComponentVersion().orElse(null), concernType, policyName);
    logger.debug("Searching for Jira issues with this Query: {}", jqlString);
    IssueCategory issueCategory = issueCategoryRetriever.retrieveIssueCategoryFromComponentConcernType(concernType);
    return jqlQueryExecutor.executeQuery(jqlString).stream().map(jiraSearcherResponseModel -> searchResultCreator.createExistingIssueDetails(jiraSearcherResponseModel, issueCategory)).collect(Collectors.toList());
}
Also used : Logger(org.slf4j.Logger) ExactIssueFinder(com.synopsys.integration.alert.api.channel.issue.search.ExactIssueFinder) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) LoggerFactory(org.slf4j.LoggerFactory) IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) List(java.util.List) Optional(java.util.Optional) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssueCategoryRetriever(com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)

Example 7 with ExistingIssueDetails

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

the class AzureBoardsIssueCreator method extractIssueDetails.

private ExistingIssueDetails<Integer> extractIssueDetails(WorkItemResponseModel workItem, IssueCreationModel alertIssueCreationModel) {
    WorkItemFieldsWrapper workItemFields = workItem.createFieldsWrapper(gson);
    String workItemKey = Objects.toString(workItem.getId());
    String workItemTitle = workItemFields.getField(WorkItemResponseFields.System_Title).orElse("Unknown Title");
    String workItemUILink = AzureBoardsUILinkUtils.extractUILink(organizationName, workItem);
    IssueCategory issueCategory = alertIssueCreationModel.getSource().map(issueCategoryRetriever::retrieveIssueCategoryFromProjectIssueModel).orElse(IssueCategory.BOM);
    return new ExistingIssueDetails<>(workItem.getId(), workItemKey, workItemTitle, workItemUILink, IssueStatus.RESOLVABLE, issueCategory);
}
Also used : WorkItemFieldsWrapper(com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemFieldsWrapper) IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)

Example 8 with ExistingIssueDetails

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

the class AzureBoardsExistingIssueDetailsCreator method createIssueDetails.

public ExistingIssueDetails<Integer> createIssueDetails(WorkItemResponseModel workItem, WorkItemFieldsWrapper workItemFields, ProjectIssueModel projectIssueModel) {
    Integer workItemId = workItem.getId();
    String workItemTitle = workItemFields.getField(WorkItemResponseFields.System_Title).orElse("Unknown Title");
    String workItemUILink = AzureBoardsUILinkUtils.extractUILink(organizationName, workItem);
    IssueCategory issueCategory = issueCategoryRetriever.retrieveIssueCategoryFromProjectIssueModel(projectIssueModel);
    String workItemState = workItemFields.getField(WorkItemResponseFields.System_State).orElse("Unknown");
    IssueStatus issueStatus = issueStatusResolver.resolveIssueStatus(workItemState);
    return new ExistingIssueDetails<>(workItemId, Objects.toString(workItemId), workItemTitle, workItemUILink, issueStatus, issueCategory);
}
Also used : IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) IssueStatus(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueStatus)

Example 9 with ExistingIssueDetails

use of com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails 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 10 with ExistingIssueDetails

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

Aggregations

ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)13 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)8 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)6 Test (org.junit.jupiter.api.Test)5 IssueCategory (com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)4 Gson (com.google.gson.Gson)3 IssueCategoryRetriever (com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever)3 WorkItemResponseModel (com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel)3 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)2 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)2 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)2 IssueTrackerIssueResponseModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel)2 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)2 IssueTransitionModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel)2 ActionableIssueSearchResult (com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult)2 ExactIssueFinder (com.synopsys.integration.alert.api.channel.issue.search.ExactIssueFinder)2 IssueStatus (com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueStatus)2 AzureBoardsIssueTrackerQueryManager (com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager)2 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)2