use of com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel in project hub-alert by blackducksoftware.
the class AzureBoardsComponentIssueFinderTest method findExistingIssuesByProjectIssueModelForUnknownVersionTest.
@Test
public void findExistingIssuesByProjectIssueModelForUnknownVersionTest() 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);
IssueComponentUnknownVersionDetails componentUnknownVersionDetails = new IssueComponentUnknownVersionDetails(ItemOperation.ADD, createRiskModels());
IssuePolicyDetails testPolicy = new IssuePolicyDetails("Test Policy", ItemOperation.ADD, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
ProjectIssueModel projectIssueModel = ProjectIssueModel.componentUnknownVersion(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ISSUE_BOM_COMPONENT_DETAILS, componentUnknownVersionDetails);
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.BOM, existingIssueDetails.getIssueCategory());
}
use of com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel 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.workitem.response.WorkItemResponseModel 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.workitem.response.WorkItemResponseModel 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;
}
use of com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel 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());
}
Aggregations