What is the best way to process results using plain Java API?
I'm embarrassed to ask this since @rschoon has done such a great job describing how to run a query using the plain Java API. Where he iterates the results and says to 'do something with the workitem', I am using this method:
public static void processResolvedResults(IProjectArea projectArea,IQueryResult<IResolvedResult<IWorkItem>> resolvedResults,
My WorkitemResultProcessor is an interface, in this case, it's not even making it to that point. My debugging output does show that I have a valid result (i.e., at least it shows the ID and summary).
I am getting an assertion error in WorkItemWorkingCopyRegistry.getWorkingCopy while making the working copy:
org.eclipse.core.runtime.AssertionFailedException: null argument:
The work item in question was also created via the plain Java API and I noticed while debugging that some of the fields that I assumed would be set automatically (e.g., create date and owner) were null. They appear just fine in the UI but maybe one of these (or one of several others) is causing this failure?
Does anyone have any ideas what might be causing this? Perhaps some fields are not required for creating the workitem but required for creating a working copy of it??
- Andy
|
2 answers
Ok, I RTFM'ed and discovered that you can't use getWorkingCopy unless you already have a connection:
WorkItemWorkingCopy getWorkingCopy(IWorkItemHandle handle)Returns the working copy corresponding to the given handle. The working copy must have been connected to before.
(Emphasis added). So I changed the update method to this:
public static void processResolvedResults(IProjectArea projectArea,IQueryResult<IResolvedResult<IWorkItem>> resolvedResults,
And it works.
Comments
sam detweiler
commented Jan 06 '14, 8:17 p.m.
Sorry, what is the value of this mechanism?
Andy Jewell
commented Jan 07 '14, 10:52 a.m.
Actually, the working copy isn't required after all (when using WorkItemOperation). I was confused because the WorkItemOperation execute takes a WorkItemWorkingCopy argument which I thought meant that I had to create a working copy. But this is actually an interface which is satisfied by a WorkItem as well. So the value is that you can iterate the (resolved) results list of a query without creating a new WorkItem copy for every result. I will post the updated code. |
Updated code - once I realized that the WorkItemOperation execute method could be passed a WorkItem and not a workitem copy, then Ralph's original article (referenced above) makes a lot more sense.
Processing results from a query:
public static void processResolvedResults(IProjectArea projectArea,IQueryResult<IResolvedResult<IWorkItem>> resolvedResults,WorkitemResultProcessor processor) throws TeamRepositoryException, RtcException {
This is my convenience wrapper/interface. I use it to help in other parts of my particular implementation but included here to better follow the code above.
WorkitemResultProcessor.java:
public interface WorkitemResultProcessor {
As Ralph suggests in the article, my updater uses an inner class to set up the WorkItemOperation:
UpdateWorkItemStatus.java:
public class UpdateWorkItemStatus implements WorkitemResultProcessor { |
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.
Comments
see my workitng sample here
Thanks, Sam - do you have an example that creates a working copy? Reason being, I need to create a working copy in order to use a sub-class of WorkItemOperation. I am extracting the work item from the query with no problem and I think I could iterate the attributes. Basically, what I'm trying to do is create a type of action-query where I pass in an object that will run an update operation on each row of the query results. But I'm having a problem creating a working copy.