How to query defects for a secified iteration in Java Client
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)
Accepted answer
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);
}
Comments
Glad you got it working!
Hi Thomos,
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;
}
Comments
Lauren Hayward Schaefer
JAZZ DEVELOPER Jan 20 '14, 7:13 a.m.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.
Thomas Immel
Jan 20 '14, 8:43 a.m.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.
Thomas Immel
Jan 20 '14, 8:45 a.m.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.
Lauren Hayward Schaefer
JAZZ DEVELOPER Jan 21 '14, 7:05 a.m.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?
sam detweiler
Jan 21 '14, 7:58 a.m.Thomas, I think Lauren has identified the problem for you..