It's all about the answers!

Ask a question

Querying RTC workitem based on the value of a custom attribute


Kanagaraj Duraisamy (157) | asked Jul 29 '13, 1:01 p.m.
edited Jul 29 '13, 1:34 p.m. by Ralph Schoon (59.4k23642)
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

Comments
mark owusu-ansah commented 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.

3 answers



permanent link
Ralph Schoon (59.4k23642) | 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,
    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


permanent link
Kanagaraj Duraisamy (157) | answered Aug 20 '13, 12:11 a.m.
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,

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);


permanent link
Kanagaraj Duraisamy (157) | answered Aug 20 '13, 10:16 a.m.
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,
  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)


mark owusu-ansah commented Aug 21 '13, 11:55 a.m.

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

Your answer


Register or to post your answer.