Search in sources :

Example 11 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 12 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 13 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 14 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)

Example 15 with ExistingIssueDetails

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

the class IssueTrackerTestAction method testConfig.

@Override
public MessageResult testConfig(DistributionJobModel testJobModel, String jobName, @Nullable String customTopic, @Nullable String customMessage) throws AlertException {
    D distributionDetails = (D) testJobModel.getDistributionJobDetails();
    IssueTrackerMessageSender<T> messageSender = messageSenderFactory.createMessageSender(distributionDetails);
    String topicString = Optional.ofNullable(customTopic).orElse("Alert Test Topic");
    String messageString = Optional.ofNullable(customMessage).orElse("Alert Test Message");
    // TODO determine if source should be required everywhere
    ProjectIssueModel testProjectIssueModel = createPlaceholderProjectIssueModel(testJobModel.getBlackDuckGlobalConfigId());
    String postCreateComment = String.format("Created by [ Test Configuration ] in the Alert Distribution Job: %s", testJobModel.getName());
    IssueCreationModel creationRequest = IssueCreationModel.simple(topicString, messageString, List.of(postCreateComment), testProjectIssueModel.getProvider());
    IssueTrackerModelHolder<T> creationRequestModelHolder = new IssueTrackerModelHolder<>(List.of(creationRequest), List.of(), List.of());
    IssueTrackerTestActionFieldStatusCreator fieldStatusCreator = new IssueTrackerTestActionFieldStatusCreator();
    List<IssueTrackerIssueResponseModel<T>> createdIssues;
    try {
        createdIssues = messageSender.sendMessages(creationRequestModelHolder);
    } catch (AlertFieldException e) {
        logger.error("Failed to create test issue", e);
        return new MessageResult("Failed to create issue: " + e.getMessage(), e.getFieldErrors());
    } catch (AlertException e) {
        logger.error("Failed to create test issue", e);
        return new MessageResult("Failed to create issue: " + e.getMessage(), fieldStatusCreator.createWithoutField(e.getMessage()));
    }
    int createdIssuesSize = createdIssues.size();
    if (createdIssuesSize != 1) {
        String errorMessage = String.format("Expected [1] issue to be created, but there were actually [%d]", createdIssuesSize);
        return new MessageResult(errorMessage, fieldStatusCreator.createWithoutField(errorMessage));
    }
    IssueTrackerIssueResponseModel<T> createdIssue = createdIssues.get(0);
    ExistingIssueDetails<T> existingIssueDetails = new ExistingIssueDetails<>(createdIssue.getIssueId(), createdIssue.getIssueKey(), createdIssue.getIssueTitle(), createdIssue.getIssueLink(), IssueStatus.RESOLVABLE, IssueCategory.BOM);
    if (!hasResolveTransition(distributionDetails)) {
        return createSuccessMessageResult(existingIssueDetails);
    }
    IssueTrackerTransitionTestAction<T> transitionTestAction = new IssueTrackerTransitionTestAction<>(messageSender, fieldStatusCreator);
    Optional<MessageResult> optionalResolveFailure = transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel);
    if (optionalResolveFailure.isPresent()) {
        return optionalResolveFailure.get();
    }
    if (!hasReopenTransition(distributionDetails)) {
        return createSuccessMessageResult(existingIssueDetails);
    }
    return transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.OPEN, existingIssueDetails, testProjectIssueModel).orElseGet(() -> transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel).orElse(createSuccessMessageResult(existingIssueDetails)));
}
Also used : IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

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