How to programmatically retrieve work items owned by a user?
//------------------------------------------------------------------------------------
IQueryableAttribute projectAreaAttribute= findAttribute(projectArea, auditableClient, IWorkItem.PROJECT_AREA_PROPERTY, null);
AttributeExpression projectAreaExpression= new AttributeExpression(projectAreaAttribute, AttributeOperation.EQUALS, projectArea);
IQueryableAttribute assignedToAttribute= findAttribute(projectArea, auditableClient, IWorkItem.OWNER_PROPERTY, null);
AttributeExpression assignedToExpression= new AttributeExpression(assignedToAttribute, AttributeOperation.EQUALS, "test");
Term term= new Term(Operator.AND);
term.add(projectAreaExpression);
term.add(assignedToExpression);
return queryClient.getResolvedExpressionResults(projectArea, term, IWorkItem.SMALL_PROFILE);
//------------------------------------------------------------------------------------
I get the following error while retrieving results:
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:69)
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:165)
at com.ibm.team.workitem.common.expression.AttributeExpression.saveState(AttributeExpression.java:155)
at com.ibm.team.workitem.common.expression.Term.saveState(Term.java:189)
at com.ibm.team.workitem.common.internal.expression.XMLExpressionSerializer.serialize(XMLExpressionSerializer.java:132)
at com.ibm.team.workitem.common.internal.expression.XMLExpressionSerializer.serialize(XMLExpressionSerializer.java:57)
at com.ibm.team.workitem.common.internal.query.impl.QueryDescriptorCustomImpl.setExpression(QueryDescriptorCustomImpl.java:40)
at com.ibm.team.workitem.common.internal.query.QueryCommon.createQuery(QueryCommon.java:258)
at com.ibm.team.workitem.common.internal.query.QueryCommon.getResolvedExpressionResults(QueryCommon.java:123)
Can someone help?
4 answers
Full source code of a similar class (with no query on OWNER_PROPERTY) is available here: https://jazz.net/wiki/pub/Main/QueryDevGuide/DupeFinder.java
This works fine without any exception. But adding the query on OWNER_PROPERTY throws the exception!
Created a work item for this problem here: https://jazz.net/jazz/web/projects/Jazz%20Foundation#action=com.ibm.team.workitem.viewWorkItem&id=167710
I have now tried the following:
// ---------------------------------------------------------------
IContributor user = repository.contributorManager().fetchContributorByUserId("myuser", null);
IQueryableAttribute assignedToAttribute= findAttribute(projectArea, auditableClient, IWorkItem.OWNER_PROPERTY, null);
AttributeExpression assignedToExpression= new AttributeExpression(assignedToAttribute, AttributeOperation.EQUALS, user);
Term term= new Term(Operator.AND);
term.add(projectAreaExpression);
term.add(typeExpression);
term.add(assignedToExpression);
// ---------------------------------------------------------------
Now I do not get an exception but the search does not result in any results (even though there are!). I have also tried to use the following:
// ---------------------------------------------------------------
AttributeExpression assignedToExpression= new AttributeExpression(assignedToAttribute, AttributeOperation.EQUALS, repository.loggedInContributor());
// ---------------------------------------------------------------
But still, it does not work. What am I missing here?