Search in sources :

Example 1 with WorkItemFieldsWrapper

use of com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemFieldsWrapper in project hub-alert by blackducksoftware.

the class AzureBoardsIssueTransitioner method isTransitionRequired.

@Override
protected boolean isTransitionRequired(ExistingIssueDetails<Integer> existingIssueDetails, IssueOperation issueOperation) throws AlertException {
    Integer issueId = existingIssueDetails.getIssueId();
    WorkItemResponseModel workItem = retrieveWorkItem(issueId);
    List<WorkItemTypeStateResponseModel> availableStates = retrieveAvailableStates(issueId);
    Map<String, String> stateNameToCategory = mapStateNameToCategory(availableStates);
    WorkItemFieldsWrapper fieldsWrapper = workItem.createFieldsWrapper(gson);
    Optional<String> optionalCurrentState = fieldsWrapper.getField(WorkItemResponseFields.System_State);
    if (optionalCurrentState.isPresent()) {
        String workItemStateCategory = stateNameToCategory.get(optionalCurrentState.get());
        boolean isOpen = WORK_ITEM_STATE_CATEGORY_PROPOSED.equals(workItemStateCategory);
        boolean isResolved = WORK_ITEM_STATE_CATEGORY_COMPLETED.equals(workItemStateCategory);
        if (IssueOperation.OPEN.equals(issueOperation)) {
            return !isOpen;
        } else if (IssueOperation.RESOLVE.equals(issueOperation)) {
            return !isResolved;
        } else {
            return true;
        }
    } else {
        logger.warn("Could not get the work item state. Work Item ID: {}", issueId);
    }
    return false;
}
Also used : WorkItemFieldsWrapper(com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemFieldsWrapper) WorkItemResponseModel(com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel) WorkItemTypeStateResponseModel(com.synopsys.integration.azure.boards.common.service.state.WorkItemTypeStateResponseModel)

Example 2 with WorkItemFieldsWrapper

use of com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemFieldsWrapper in project hub-alert by blackducksoftware.

the class AzureBoardsWorkItemTypeStateRetriever method retrieveAvailableWorkItemStates.

public List<WorkItemTypeStateResponseModel> retrieveAvailableWorkItemStates(String organizationName, Integer workItemId) throws HttpServiceException {
    WorkItemResponseModel workItem = azureWorkItemService.getWorkItem(organizationName, workItemId);
    WorkItemFieldsWrapper fieldsWrapper = workItem.createFieldsWrapper(gson);
    Optional<String> optionalWorkItemProject = fieldsWrapper.getTeamProject();
    Optional<String> optionalWorkItemType = fieldsWrapper.getWorkItemType();
    if (optionalWorkItemProject.isPresent() && optionalWorkItemType.isPresent()) {
        AzureArrayResponseModel<WorkItemTypeStateResponseModel> workItemTypeStates = azureWorkItemTypeStateService.getStatesForProject(organizationName, optionalWorkItemProject.get(), optionalWorkItemType.get());
        return workItemTypeStates.getValue();
    }
    return List.of();
}
Also used : WorkItemFieldsWrapper(com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemFieldsWrapper) WorkItemResponseModel(com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel) WorkItemTypeStateResponseModel(com.synopsys.integration.azure.boards.common.service.state.WorkItemTypeStateResponseModel)

Example 3 with WorkItemFieldsWrapper

use of com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemFieldsWrapper 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 4 with WorkItemFieldsWrapper

use of com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemFieldsWrapper in project hub-alert by blackducksoftware.

the class AzureBoardsProjectAndVersionIssueFinder method findWorkItemsAndConvertToSearchResults.

private List<ProjectIssueSearchResult<Integer>> findWorkItemsAndConvertToSearchResults(ProviderDetails providerDetails, LinkableItem project, @Nullable LinkableItem projectVersion, AzureSearchFieldMappingBuilder fieldReferenceNameToExpectedValue) throws AlertException {
    List<WorkItemResponseModel> workItems = workItemFinder.findWorkItems(providerDetails.getProvider(), project, fieldReferenceNameToExpectedValue);
    List<ProjectIssueSearchResult<Integer>> searchResults = new ArrayList<>(workItems.size());
    for (WorkItemResponseModel workItem : workItems) {
        WorkItemFieldsWrapper workItemFields = workItem.createFieldsWrapper(gson);
        ProjectIssueModel projectIssueModel = createProjectIssueModel(providerDetails, project, projectVersion, workItemFields);
        ExistingIssueDetails<Integer> issueDetails = issueDetailsCreator.createIssueDetails(workItem, workItemFields, projectIssueModel);
        ProjectIssueSearchResult<Integer> searchResult = new ProjectIssueSearchResult<>(issueDetails, projectIssueModel);
        searchResults.add(searchResult);
    }
    return searchResults;
}
Also used : WorkItemFieldsWrapper(com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemFieldsWrapper) ProjectIssueSearchResult(com.synopsys.integration.alert.api.channel.issue.search.ProjectIssueSearchResult) ArrayList(java.util.ArrayList) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) WorkItemResponseModel(com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel)

Aggregations

WorkItemFieldsWrapper (com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemFieldsWrapper)4 WorkItemResponseModel (com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel)3 WorkItemTypeStateResponseModel (com.synopsys.integration.azure.boards.common.service.state.WorkItemTypeStateResponseModel)2 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)1 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)1 ProjectIssueSearchResult (com.synopsys.integration.alert.api.channel.issue.search.ProjectIssueSearchResult)1 IssueCategory (com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory)1 ArrayList (java.util.ArrayList)1