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?
Comments
this is not a forum for programming help. many of the folks that contribute here, like me, do it because we can, and like to.. but we might not have direct experience with the exact scenario you are attempting.
there are samples of all kinds of code in Ralph's blog.. but we assume that you all have taking the developer assistance workshops, so you get started with the debugging and setup skills.
but there is NO training on using this object oriented system.. there is a lot of thinking that must be done to understand how the objects need to be structured..
at least for me..
You will not find an answer unless you follow my hints and set up your environment for debugging. If you want to do this you need development skills and you need to setup your environment as hinted. Otherwise you will stumble around and get nowhere. This is complex stuff and you can't just take it lightly. If you can't see the source and debug in your environment, again, follow https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/ and get that working first.
You can also not complain that others don't do the work for users that ask and publish that.
I published https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/ as a good starting point (that you can debug if you know how). But it will not be the exact solution for what you search.
Hint: you can search the SDK for Expressions with users as example.
Abraham, I empathize with your situation. Not a lot of developers frequent the forums so responses can be sporadic. I have seen excellent responses and dialog on occasion which have proven helpful. I recommend reading Ralph's page and a few of the other good web pages on development for RTC and the Jazz Platform in general.
Guys. Please don't mind me. I was simply frustrated and irritated. I'm swamped with 4 coding projects all in different languages, with this one being perhaps the most importance with the least amount of work to be able to do what I ultimately want to be able to do.
You guys have been great. Thanks again.
:-) Completely understand.