Search in sources :

Example 1 with WorkItemTypeStateResponseModel

use of com.synopsys.integration.azure.boards.common.service.state.WorkItemTypeStateResponseModel 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 WorkItemTypeStateResponseModel

use of com.synopsys.integration.azure.boards.common.service.state.WorkItemTypeStateResponseModel 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 WorkItemTypeStateResponseModel

use of com.synopsys.integration.azure.boards.common.service.state.WorkItemTypeStateResponseModel in project hub-alert by blackducksoftware.

the class AzureBoardsIssueTransitioner method findAndPerformTransition.

@Override
protected void findAndPerformTransition(ExistingIssueDetails<Integer> existingIssueDetails, String transitionName) throws AlertException {
    WorkItemElementOperationModel replaceSystemStateField = WorkItemElementOperationModel.fieldElement(WorkItemElementOperation.REPLACE, WorkItemResponseFields.System_State, transitionName);
    WorkItemRequest request = new WorkItemRequest(List.of(replaceSystemStateField));
    Integer issueId = existingIssueDetails.getIssueId();
    try {
        workItemService.updateWorkItem(organizationName, distributionDetails.getProjectNameOrId(), issueId, request);
    } catch (HttpServiceException e) {
        List<String> availableStates = retrieveAvailableStates(existingIssueDetails.getIssueId()).stream().map(WorkItemTypeStateResponseModel::getName).collect(Collectors.toList());
        throw new IssueMissingTransitionException(existingIssueDetails.getIssueKey(), transitionName, availableStates);
    }
}
Also used : HttpServiceException(com.synopsys.integration.azure.boards.common.http.HttpServiceException) WorkItemRequest(com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemRequest) IssueMissingTransitionException(com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException) List(java.util.List) WorkItemElementOperationModel(com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemElementOperationModel) WorkItemTypeStateResponseModel(com.synopsys.integration.azure.boards.common.service.state.WorkItemTypeStateResponseModel)

Aggregations

WorkItemTypeStateResponseModel (com.synopsys.integration.azure.boards.common.service.state.WorkItemTypeStateResponseModel)3 WorkItemFieldsWrapper (com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemFieldsWrapper)2 WorkItemResponseModel (com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel)2 IssueMissingTransitionException (com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException)1 HttpServiceException (com.synopsys.integration.azure.boards.common.http.HttpServiceException)1 WorkItemElementOperationModel (com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemElementOperationModel)1 WorkItemRequest (com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemRequest)1 List (java.util.List)1