It's all about the answers!

Ask a question

How to Create Expression for Planned for attribute using Java API


Navin R S (13712) | asked Sep 19 '17, 7:39 a.m.
edited Sep 19 '17, 7:47 a.m.

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


permanent link
Ralph Schoon (63.5k33646) | answered Sep 19 '17, 10:08 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Sep 19 '17, 10:09 a.m.

 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.

Navin R S selected this answer as the correct answer

Comments
Navin R S commented Nov 24 '17, 12:51 a.m.

Thanks for the Reply. Its Working Now

Your answer


Register or 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.