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;
}
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();
}
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);
}
}
Aggregations