How to Create Expression for Planned for attribute using Java API
Hello All,
We are trying to create Query from Java API(we don't want to run the shared Query), the condition should include Project area, Modified Date and Planned For Attribute. we are trying the below code but we are getting below exception
Exception in thread "main" 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:175) at com.ibm.team.workitem.common.expression.AttributeExpression.saveState(AttributeExpression.java:165) 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:93) at com.ibm.team.workitem.common.internal.query.impl.QueryDescriptorCustomImpl.setExpression(QueryDescriptorCustomImpl.java:86)
The code we are trying is mentioned below for Planned for attribute
IQueryableAttribute workItemPlannedForAttribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE)
.findAttribute(projectArea, com.ibm.team.workitem.api.common.IWorkItem.PLANNED_FOR, auditableClient, null);
AttributeExpression workItemPlannedForExpression =
new AttributeExpression(workItemPlannedForAttribute, AttributeOperation.MATCHES, PlannedFor);
Accepted answer
You need to be careful with the operations. MATCHES is full text or text compare. Some example code:
IAuditableCommon auditableCommon = (IAuditableCommon) teamRepository .getClientLibrary(IAuditableCommon.class);DevelopmentLineHelper devLineHelper = new DevelopmentLineHelper(teamRepository, monitor); IIteration targetIteration = devLineHelper.findIteration(projectArea, Arrays.asList(iteration.split("/")), DevelopmentLineHelper.BYLABEL); IQueryableAttribute attribute = QueryableAttributes.getFactory( IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.PROJECT_AREA_PROPERTY, auditableCommon, monitor); Expression inProjectArea = new AttributeExpression(attribute, AttributeOperation.EQUALS, projectArea); IQueryableAttribute plannedFor = QueryableAttributes.getFactory( IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.TARGET_PROPERTY, auditableCommon, monitor); Expression isPlannedFor = new AttributeExpression(plannedFor, AttributeOperation.EQUALS, targetIteration); Term typeinProjectArea = new Term(Term.Operator.AND); typeinProjectArea.add(inProjectArea); typeinProjectArea.add(isPlannedFor);
See https://rsjazz.wordpress.com/2012/10/05/handling-iterations-automation-for-the-planned-for-attribute/ for the development line helper code.