How to search Work items which have certain "Approval type" AND that Approval type has certain "Approval status"
I want to search Work items which have certain "Approval type" AND that Approval type has certain "Approval status".
But that can't be possible by normal Work Item query.
I know there is an enhancement request "Enhancement 274343: Problem with query logic for approvals"
Can I make such a query using RTC Java SDK?
But that can't be possible by normal Work Item query.
I know there is an enhancement request "Enhancement 274343: Problem with query logic for approvals"
https://jazz.net/jazz/web/projects/Rational%20Team%20Concert#action=com.ibm.team.workitem.viewWorkItem&id=274343
Can I make such a query using RTC Java SDK?
Accepted answer
Hi,
It can be done by writing a custom Jazz client program like below. Hoping it would help you.
private static void run(ITeamRepository repository) throws TeamRepositoryException {
IItemManager itemManager = repository.itemManager();
IProcessItemService processItemService = (IProcessItemService)repository.getClientLibrary(IProcessItemService.class);
List<IProjectArea> projectArea = processItemService.findAllProjectAreas(null, null);
Iterator<IProjectArea> iter = projectArea.iterator();
while(iter.hasNext()){
IProjectArea area = (IProjectArea)iter.next();
IWorkItemClient workItemClient = (IWorkItemClient)repository.getClientLibrary(IWorkItemClient.class);
IQueryClient queryClient = workItemClient.getQueryClient();
IAuditableClient auditableClient = (IAuditableClient)repository.getClientLibrary(IAuditableClient.class);
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(area, IWorkItem.STATE_PROPERTY, auditableClient, null);
Expression expression = new AttributeExpression(attribute, AttributeOperation.NOT_EQUALS, "1");
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(area, expression, IWorkItem.FULL_PROFILE);
List<IResolvedResult<IWorkItem>> page = results.nextPage(null);
Iterator<IResolvedResult<IWorkItem>> iterResult = page.iterator();
while(iterResult.hasNext()){
IResolvedResult<IWorkItem> resolvedResult = iterResult.next();
IWorkItem workItem = resolvedResult.getItem();
IApprovals approvals = workItem.getApprovals();
List<IApproval> approvalList = approvals.getContents();
Iterator<IApproval> approvalListIter = approvalList.iterator();
while(approvalListIter.hasNext()){
IApproval approval = approvalListIter.next();
IContributor contributor = (IContributor)itemManager.fetchCompleteItem(approval.getApprover(), ItemManager.DEFAULT, null);
System.out.println("Approver: " + contributor.getName());
System.out.println("Name: " + approval.getDescriptor().getDueDate());
System.out.println("Type: " + approval.getDescriptor().getTypeIdentifier());
System.out.println("Due Date:" + approval.getDescriptor().getDueDate());
}
}
}
}
It can be done by writing a custom Jazz client program like below. Hoping it would help you.
private static void run(ITeamRepository repository) throws TeamRepositoryException {
IItemManager itemManager = repository.itemManager();
IProcessItemService processItemService = (IProcessItemService)repository.getClientLibrary(IProcessItemService.class);
List<IProjectArea> projectArea = processItemService.findAllProjectAreas(null, null);
Iterator<IProjectArea> iter = projectArea.iterator();
while(iter.hasNext()){
IProjectArea area = (IProjectArea)iter.next();
IWorkItemClient workItemClient = (IWorkItemClient)repository.getClientLibrary(IWorkItemClient.class);
IQueryClient queryClient = workItemClient.getQueryClient();
IAuditableClient auditableClient = (IAuditableClient)repository.getClientLibrary(IAuditableClient.class);
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(area, IWorkItem.STATE_PROPERTY, auditableClient, null);
Expression expression = new AttributeExpression(attribute, AttributeOperation.NOT_EQUALS, "1");
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(area, expression, IWorkItem.FULL_PROFILE);
List<IResolvedResult<IWorkItem>> page = results.nextPage(null);
Iterator<IResolvedResult<IWorkItem>> iterResult = page.iterator();
while(iterResult.hasNext()){
IResolvedResult<IWorkItem> resolvedResult = iterResult.next();
IWorkItem workItem = resolvedResult.getItem();
IApprovals approvals = workItem.getApprovals();
List<IApproval> approvalList = approvals.getContents();
Iterator<IApproval> approvalListIter = approvalList.iterator();
while(approvalListIter.hasNext()){
IApproval approval = approvalListIter.next();
IContributor contributor = (IContributor)itemManager.fetchCompleteItem(approval.getApprover(), ItemManager.DEFAULT, null);
System.out.println("Approver: " + contributor.getName());
System.out.println("Name: " + approval.getDescriptor().getDueDate());
System.out.println("Type: " + approval.getDescriptor().getTypeIdentifier());
System.out.println("Due Date:" + approval.getDescriptor().getDueDate());
}
}
}
}