Querying RTC workitem based on the value of a custom attribute
3 answers
Comments
Ralph,
Have you actually gotten to work? It sounds fairly straight forward but still failing for me
The problem with your suggestion , at least from my understanding is
the findattribute takes a string representation so using the attributeID wont work.
I posted a similar question months ago and eventually did not followup on it . I actually do now need it to work so I am a bit desperate..
If possible ,, would you test a simple scenario in your test environment to see if your suggestion works and or assist with another suggestion.
here is the initial post from february.
https://jazz.net/forum/questions/104326/java-client-api-expression-unable-to-query-and-retrieve-workitems-for-custom-attribute-value-from-repository-incorrectly-typed-parameter-submitted-to-query
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
Kanagaraj,
I am still failing but please clarify
What class has the findattribute method. Or rather would you attach the method you are using.
The default one has 3 parms and your example has 4 which is failing on my end.
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);
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
Kanagaraj,
I am implementing the same code you have and I am still failing with the same error.
The query without adding custom attributes works fine but it is always failing once the customer attribute is introduced.
What version of the jazz api are you using . I have 4.0.0.1 . This is baffling ..looks so straightforward but can figure it out
com.ibm.team.repository.common.TeamRepositoryException: Incorrectly typed parameter submitted to query; Parameter 2 was class java.lang.String but com.ibm.team.repository.common.UUID was expected
at com.ibm.team.repository.service.internal.AbstractQueryService.validateParameterTypes(AbstractQueryService.java:130)
Kanagaraj,
I may have figured out the problem.
My custom attribute was LARGE STRING .. i changed to SMALL STRING
I am still testing but I think I can now query based on that custom attribute ....
Thanks for all your assistance
Comments
mark owusu-ansah
Aug 19 '13, 7:14 p.m.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.