Search in sources :

Example 6 with ItemOperation

use of com.synopsys.integration.alert.common.enumeration.ItemOperation in project hub-alert by blackducksoftware.

the class IssueTrackerModelExtractorTest method extractProjectMessageIssueModelsTransitionTest.

@Test
public void extractProjectMessageIssueModelsTransitionTest() throws AlertException {
    ItemOperation itemOperation = ItemOperation.DELETE;
    IssueOperation issueOperation = IssueOperation.RESOLVE;
    ProjectMessage projectMessage = Mockito.mock(ProjectMessage.class);
    ExistingIssueDetails<String> existingIssueDetails = new ExistingIssueDetails<>("issue-id", "issue-key", "issue summary", "https://ui-link", IssueStatus.UNKNOWN, IssueCategory.POLICY);
    IssuePolicyDetails policyDetails = new IssuePolicyDetails("A policy", itemOperation, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
    ProjectIssueModel projectIssueModel = ProjectIssueModel.policy(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, ISSUE_BOM_COMPONENT_DETAILS, policyDetails);
    ActionableIssueSearchResult<String> searchResult = new ActionableIssueSearchResult<>(existingIssueDetails, projectIssueModel, itemOperation);
    MockIssueTrackerMessageFormatter formatter = MockIssueTrackerMessageFormatter.withIntegerMaxValueLength();
    IssueTrackerSearcher<String> searcher = Mockito.mock(IssueTrackerSearcher.class);
    Mockito.when(searcher.findIssues(Mockito.eq(projectMessage))).thenReturn(List.of(searchResult));
    IssueTrackerModelExtractor<String> extractor = new IssueTrackerModelExtractor<>(formatter, searcher);
    IssueTrackerModelHolder<String> modelHolder = extractor.extractProjectMessageIssueModels(projectMessage, "jobName");
    List<IssueTransitionModel<String>> issueTransitionModels = modelHolder.getIssueTransitionModels();
    assertEquals(0, modelHolder.getIssueCreationModels().size());
    assertEquals(1, issueTransitionModels.size());
    assertEquals(0, modelHolder.getIssueCommentModels().size());
    IssueTransitionModel<String> transitionModel = issueTransitionModels.get(0);
    assertEquals(issueOperation, transitionModel.getIssueOperation());
}
Also used : IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) MockIssueTrackerMessageFormatter(com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ActionableIssueSearchResult(com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) Test(org.junit.jupiter.api.Test)

Example 7 with ItemOperation

use of com.synopsys.integration.alert.common.enumeration.ItemOperation in project hub-alert by blackducksoftware.

the class IssueTrackerSearcher method findIssueByProjectIssueModel.

private ActionableIssueSearchResult<T> findIssueByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
    ExistingIssueDetails<T> existingIssue = null;
    ItemOperation searchResultOperation = ItemOperation.UPDATE;
    List<ExistingIssueDetails<T>> existingIssues = exactIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel);
    int foundIssuesCount = existingIssues.size();
    if (foundIssuesCount == 1) {
        existingIssue = existingIssues.get(0);
        Optional<ItemOperation> policyOperation = projectIssueModel.getPolicyDetails().map(IssuePolicyDetails::getOperation);
        Optional<IssueVulnerabilityDetails> optionalVulnerabilityDetails = projectIssueModel.getVulnerabilityDetails();
        Optional<ItemOperation> componentUnknownOperation = projectIssueModel.getComponentUnknownVersionDetails().map(IssueComponentUnknownVersionDetails::getItemOperation);
        if (policyOperation.isPresent()) {
            searchResultOperation = policyOperation.get();
        } else if (optionalVulnerabilityDetails.isPresent()) {
            IssueVulnerabilityDetails issueVulnerabilityDetails = optionalVulnerabilityDetails.get();
            searchResultOperation = findVulnerabilitySearchResultOperation(existingIssue, issueVulnerabilityDetails);
        } else if (componentUnknownOperation.isPresent()) {
            searchResultOperation = componentUnknownOperation.get();
        }
    } else if (foundIssuesCount > 1) {
        Set<String> issueKeys = existingIssues.stream().map(ExistingIssueDetails::getIssueKey).collect(Collectors.toSet());
        String issueKeyString = StringUtils.join(issueKeys, ", ");
        throw new AlertException("Expected to find a unique issue, but more than one was found. " + issueKeyString);
    } else {
        searchResultOperation = ItemOperation.ADD;
    }
    return new ActionableIssueSearchResult<>(existingIssue, projectIssueModel, searchResultOperation);
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) Set(java.util.Set) 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) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

ItemOperation (com.synopsys.integration.alert.common.enumeration.ItemOperation)7 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)4 LinkedList (java.util.LinkedList)3 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)2 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)2 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)2 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)1 IssueEstimatedRiskModel (com.synopsys.integration.alert.api.channel.issue.model.IssueEstimatedRiskModel)1 IssueTransitionModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel)1 IssueVulnerabilityModel (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityModel)1 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)1 ActionableIssueSearchResult (com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult)1 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)1 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)1 ComponentVulnerabilities (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)1 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)1 ComponentUnknownVersionStatus (com.synopsys.integration.blackduck.api.manual.enumeration.ComponentUnknownVersionStatus)1 Set (java.util.Set)1 Test (org.junit.jupiter.api.Test)1