Querying RTC workitem based on the value of a custom attribute
Kanagaraj Duraisamy (1●5●7)
| asked Jul 29 '13, 1:01 p.m.
edited Jul 29 '13, 1:34 p.m. by Ralph Schoon (63.3k●3●36●46)
I have created a custom attribute in RTC. I would like to query the work item using plain java api based on the custom attribute's value.
I used the below code but it is bringing the work item presented in the different project area as well. But, i need the work item presented only in the project which i am passing.
String projectName = "XYZ";
IProjectArea projectArea = getProjectArea(projectName, repo);
IQueryClient queryClient = workItemService.getQueryClient();
IAuditableClient auditableClient = (IAuditableClient)repo.getClientLibrary(IAuditableClient.class);
IQueryableAttribute attribute=QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, propertyName, auditableClient, monitor);
Expression inProjectArea= new AttributeExpression(attribute,AttributeOperation.EQUALS, targetId);
IQueryResult<IResolvedResult<IWorkItem>> results=queryClient.getResolvedExpressionResults(projectArea, inProjectArea,IWorkItem.SMALL_PROFILE);
results.setLimit(Integer.MAX_VALUE);
while (results.hasNext(monitor))
{
IResolvedResult<IWorkItem> resresult = (IResolvedResult<IWorkItem>) results.next(monitor);
item = resresult.getItem();
}
Your help is highly appreciated.
Regards,
Kanagaraj
|
3 answers
Mark,
I forgot to give the private method which I used. private IQueryableAttribute findAttribute(IProjectAreaHandle projectArea, String attributeId, IProgressMonitor monitor, ITeamRepository repo) throws TeamRepositoryException { IQueryableAttributeFactory factory= QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE); IAuditableClient auditableClient = (IAuditableClient)repo.getClientLibrary(IAuditableClient.class); return factory.findAttribute(projectArea, attributeId, auditableClient, monitor); } I hope this should solve your problem. Regards, Kanagaraj Comments
mark owusu-ansah
commented Aug 20 '13, 10:59 a.m.
Kanagaraj,
mark owusu-ansah
commented Aug 21 '13, 11:55 a.m.
Kanagaraj,
|
Mark,
I got below code working for me. Please go through it and let me know if you need any assistance. import com.ibm.team.workitem.client.IAuditableClient; import com.ibm.team.workitem.client.IQueryClient; import com.ibm.team.workitem.client.IWorkItemClient; import com.ibm.team.workitem.common.IWorkItemCommon; import com.ibm.team.workitem.common.expression.AttributeExpression; import com.ibm.team.workitem.common.expression.IQueryableAttribute; import com.ibm.team.workitem.common.expression.IQueryableAttributeFactory; import com.ibm.team.workitem.common.expression.QueryableAttributes; import com.ibm.team.workitem.common.expression.Term; import com.ibm.team.workitem.common.expression.Term.Operator; import com.ibm.team.workitem.common.model.AttributeOperation; import com.ibm.team.workitem.common.model.IAttachment; import com.ibm.team.workitem.common.model.IAttachmentHandle; import com.ibm.team.workitem.common.model.IAttribute; import com.ibm.team.workitem.common.model.IAttributeHandle; import com.ibm.team.workitem.common.model.IEnumeration; import com.ibm.team.workitem.common.model.ILiteral; import com.ibm.team.workitem.common.model.IWorkItem; import com.ibm.team.workitem.common.model.IWorkItemReferences; import com.ibm.team.workitem.common.model.IWorkItemType; import com.ibm.team.workitem.common.model.WorkItemEndPoints; import com.ibm.team.workitem.common.query.IQueryResult; import com.ibm.team.workitem.common.query.IResolvedResult; public IWorkItem getWorkItemByTargetId(String projectName, String repositoryAddr, String userName, String password, String propertyName, int targetId) throws TeamRepositoryException, ConcordException { ITeamRepository repo = null; IProgressMonitor monitor = new ConcordSysoutMonitor(); repo = login(monitor); IWorkItemClient workItemService = (IWorkItemClient) repo .getClientLibrary(IWorkItemClient.class); IWorkItem item = null; if(projectName != null) { IProjectArea projectArea = getProjectArea(projectName, repo); IQueryClient queryClient = workItemService.getQueryClient(); IQueryableAttribute idAttribute = this.findAttribute(projectArea, propertyName, monitor,repo); AttributeExpression idExpression = new AttributeExpression(idAttribute, AttributeOperation.EQUALS, targetId); IQueryableAttribute projectAreaAttribute= this.findAttribute(projectArea, IWorkItem.PROJECT_AREA_PROPERTY, monitor, repo); AttributeExpression projectAreaExpression= new AttributeExpression(projectAreaAttribute, AttributeOperation.EQUALS, projectArea); Term term= new Term(Operator.AND); term.add(projectAreaExpression); term.add(idExpression); IQueryResult<IResolvedResult<IWorkItem>> results=queryClient.getResolvedExpressionResults(projectArea, term, IWorkItem.SMALL_PROFILE); results.setLimit(Integer.MAX_VALUE); while (results.hasNext(monitor)) { IResolvedResult<IWorkItem> resresult = (IResolvedResult<IWorkItem>) results.next(monitor); item = resresult.getItem(); } } return item; } Regards, Kanagaraj Comments
mark owusu-ansah
commented Aug 20 '13, 9:05 a.m.
Kanagaraj,
|
Ralph Schoon (63.3k●3●36●46)
| answered Jul 29 '13, 1:43 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I would suggest looking into providing the attribute ID of the custom attribute in a findAttribute and follow the rest of the pattern.
Comments
mark owusu-ansah
commented Aug 19 '13, 7:23 p.m.
Ralph,
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.
Comments
Kanagaraj,
Were you ever able to get this to work? I have never been able to JAZZ query to obtain a specific value for a custom attribute..
I see responses from Ralph in the post but I don`t think that works either ,
At least I have not been able to get it work,
Please pass your example if it is working for you.