Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to query defects for a secified iteration in Java Client

I want to query defects from RTC with a specific "planned For" (Iteration).
Below my code that i tried. But with that code i got an Exception.
I'm using RTC 4 based clients.

        AttributeExpression defectFilter     = new AttributeExpression(getQueryableAttribute(IWorkItem.TYPE_PROPERTY), AttributeOperation.EQUALS, "defect");
        AttributeExpression targetFilter     = new AttributeExpression(getQueryableAttribute(IWorkItem.TARGET_PROPERTY),AttributeOperation.EQUALS,plannedForToBeFiltered );
        Term term_List = new Term(Operator.AND);
        term_List.add(defectFilter);
        term_List.add(targetFilter);

        Term term = new Term(Operator.AND);
        term.add(term_List);

        IQueryResult<IResolvedResult<IWorkItem>> result =
                mQueryClient.getResolvedExpressionResults(mProcessArea.getProjectArea(), term, IWorkItem.FULL_PROFILE);

java.lang.IllegalArgumentException: Argument must be an instance of IAuditableHandle
    at com.ibm.team.workitem.common.internal.model.SetAttributeType.toString(SetAttributeType.java:73)
    at com.ibm.team.workitem.common.internal.expression.AttributeValueFactory$ConstantValue.saveState(AttributeValueFactory.java:58)
    at com.ibm.team.workitem.common.expression.AttributeExpression.saveValueProxy(AttributeExpression.java:174)
    at com.ibm.team.workitem.common.expression.AttributeExpression.saveState(AttributeExpression.java:164)
    at com.ibm.team.workitem.common.expression.Term.saveState(Term.java:209)
    at com.ibm.team.workitem.common.expression.Term.saveState(Term.java:209)
    at com.ibm.team.workitem.common.internal.expression.XMLExpressionSerializer.serialize(XMLExpressionSerializer.java:137)
    at com.ibm.team.workitem.common.internal.expression.XMLExpressionSerializer.serialize(XMLExpressionSerializer.java:56)
    at com.ibm.team.workitem.common.internal.query.impl.QueryDescriptorCustomImpl.setExpression(QueryDescriptorCustomImpl.java:56)
    at com.ibm.team.workitem.common.internal.query.QueryCommon.createQuery(QueryCommon.java:268)
    at com.ibm.team.workitem.common.internal.query.QueryCommon.getResolvedExpressionResults(QueryCommon.java:123)
    at RTCHandler.getServiceRequests(RTCHandler.java:256)
    at PTFClosingInfo.main(PTFClosingInfo.java:40)





0 votes

Comments

Hi Thomas,
Which line is causing the exception to be thrown?  If it's the second one, how are you getting plannedForToBeFiltered?  I'm wondering if you need to get the plannedForToBeFiltered in a different way. http://rsjazz.wordpress.com/2012/10/05/handling-iterations-automation-for-the-planned-for-attribute/ has a lot of information about the planned for attribute and may be helpful to you.

The Exception is thrown during call of :
  IQueryResult<iresolvedresult<iworkitem>> result =
                mQueryClient.getResolvedExpressionResults(mProcessArea.getProjectArea(), term, IWorkItem.FULL_PROFILE);

plannedForToBeFiltered is a usual java string and it's a parameter of the java program.

The Link was very useful, but don't hit my problem, because i don't want to read or set the iteration.
I want to filter defects by iteration.

I'm not sure what the problem is.  Perhaps something in this forum post will trigger an idea for you: https://jazz.net/forum/questions/56227/how-to-programmatically-retrieve-work-items-owned-by-a-user.  When someone was hitting the same error you are while querying based on contributor, Martin wrote, "The owner attribute is of type 'Contributor'. So you can compare the attribute against a string, but need to pass in a object of Contributor."  Maybe you need to pass in an object of type Iteration?

>plannedForToBeFiltered is a usual java string and it's a parameter of the java program 

Thomas, I think Lauren has identified the problem for you..


the thing must be the HANDLE to the iteration not its NAME (or path).
java.lang.IllegalArgumentException: Argument must be an instance of IAuditableHandle .

so, given the 'string', you will have to search for the specific iteration in the list of iterations in this project.   be careful, as the Name is not necessarily unique.. (sprint 1 in release 1 could be the same as sprint 1 in release 2.





Accepted answer

Permanent link
Solved .

We used some of the code from the link above to find the correct iteration and use the iterationhandle as input for the AttributeExpression.

        IIterationHandle iterationHandle = findIteration (mProcessArea.getProjectArea(), l, RTCHandler.BYNAME);
        if (iterationHandle != null) {
            AttributeExpression targetFilter     = new AttributeExpression(getQueryableAttribute(IWorkItem.TARGET_PROPERTY),AttributeOperation.EQUALS,iterationHandle );
            term_List.add(targetFilter);
        }


Ralph Schoon selected this answer as the correct answer

0 votes

Comments

Glad you got it working!

 Hi Thomos,

 I am also facing java.lang.IllegalArgumentException: Argument must be an instance of IAuditableHandle .
 Please provide the solution. Hope you Solved above exception .
in below your code
IIterationHandle iterationHandle = findIteration (mProcessArea.getProjectArea(), l, RTCHandler.BYNAME); 
Please copy the findIteration method as well.

and what is l , RTCHandler.BYNAME you are passing to that method.


Hope, that you found it useful.
2 methods for findIteration are implemented.
One for look at all iterations. Second look at a given set of iterations.

/
      Find an iteration with a specific name
     

      @param iProjectAreaHandle
     
            - the project area handle
      @param lookFor
     
            - the name of the iteration
      @return
     
@throws TeamRepositoryException
     */
    private IIteration findIteration(IProjectAreaHandle iProjectAreaHandle, String lookFor)
            throws TeamRepositoryException {
        IProjectArea projectArea = (IProjectArea) mRepository.itemManager().fetchCompleteItem(
                iProjectAreaHandle, IItemManager.REFRESH, mMonitor);
        return findIterationInAllDevelopmentLines(projectArea, lookFor);
    }

    /

      Find an iteration in all development lines.
     

      @param projectArea
     
            - the project area
      @param planedFor
     
            - the target iteration
      @return a development line found or null.
     
@throws TeamRepositoryException
     /
    private IIteration findIterationInAllDevelopmentLines(IProjectArea projectArea, String planedFor)
            throws TeamRepositoryException {
        IDevelopmentLineHandle[] developmentLineHandles = projectArea.getDevelopmentLines();
        for (IDevelopmentLineHandle developmentLineHandle : developmentLineHandles) {
            IDevelopmentLine developmentLine = mAuditableClient.resolveAuditable(
                    developmentLineHandle, ItemProfile.DEVELOPMENT_LINE_DEFAULT, mMonitor);

            IIteration targetIteration = findIteration(developmentLine.getIterations(), planedFor);
            if (targetIteration != null) {
                return targetIteration;
            }
        }
        return null;
    }

    /

     
Find an iteration with a specific name recursively
     
     
@param iterations
                 an array of iteration
     
@param planeFor
                 - the target iteration
     
@return - the iteration if found or null
      @throws TeamRepositoryException
     
/
    private IIteration findIteration(IIterationHandle[] iterations, String planeFor)
            throws TeamRepositoryException {

        for (IIterationHandle iIterationHandle : iterations) {

            IIteration iteration = mAuditableClient.resolveAuditable(iIterationHandle,
                    ItemProfile.ITERATION_DEFAULT, mMonitor);
            String compare = iteration.getName();

            // base case 1: found iteration
            if (planeFor.equals(compare)) {
                return iteration;
            }

            // recursive step: look in children iterations
            IIterationHandle[] iterationHandlers = iteration.getChildren();
            if (iterationHandlers != null) {

                IIteration found = findIteration(iteration.getChildren(), planeFor);
                if (found != null) {
                    return found;
                }
            }
        }

        // no iteration found
        return null;
    }


One other answer

Permanent link
see comment below.

0 votes

Your answer

Register or log in to post 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937

Question asked: Jan 19 '14, 7:23 p.m.

Question was seen: 5,850 times

Last updated: Nov 16 '15, 9:25 a.m.

Confirmation Cancel Confirm