How to query work-items with more than one status as condition via client API
We are aware we can query work-items on their single status as:
Identifier<IState> stateId = ...
IQueryableAttribute stateAttr = ...
AttributeExpression stateExpr = new AttributeExpression(stateAttr, AttributeOperation.EQUALS, state.getStringIdentifier());
or we can query work-items on their status group as:
IQueryableAttribute stateAttr = ...
AttributeExpression stateExpr = new VariableAttributeExpression(stateAttr, AttributeOperation.EQUALS, new StatusVariable(IWorkflowInfo.IN_PROGRESS_STATES));
but we would be able to query work-items for a set of status as condition:
Identifier<IState>[] stateIds = ...
IQueryableAttribute stateAttr = ...
AttributeExpression stateExpr = new VariableAttributeExpression(stateAttr, AttributeOperation.EQUALS, new StatusVariable(stateIds);
It seems to be pretty easy via UI: https://jazz.net/forum/questions/170377/how-to-build-complex-rtc-query-combining-and-or-conditions/170383
We tried to extend the com.ibm.team.workitem.common.expression.variables.StatusVariable class to achieve our desiderata, but then the override method IAttributeValue#evaluate was never call during the IQueryCommon#getResolvedExpressionResults execution.
Any advice? On QueryDevGuide we did not find any helpful example.
Thanks in advance.
One answer
Well, at least the naïve solution is working:
Term subterm = new Term(Operator.OR);Cheers.
for (Identifier<IState> stateId : stateIds) {
AttributeExpression stateExpr = new AttributeExpression(stateAttr, AttributeOperation.EQUALS, state.getStringIdentifier());
subterm.add(stateExpr);
}
Term term = new Term(Operator.AND);
term.add(subterm);