It's all about the answers!

Ask a question

(Java API) How Can I Access the Links of the OLD State?


Nate Decker (37814761) | asked May 20 '14, 3:52 p.m.

I am trying to create an Operation Participant that will keep track of whether or not work items are blocked by children. If the user modifies a work item, the script should check against the links on that work item for 2 things:

1) Did the user remove the last remaining link that was blocking this work item?
2) Did the user change the state of the current work item such that a parent work item is no longer being blocked?

I've got this working against the current state of the work item, but in order to tell whether or not a link was previously present and has now been removed, I need to be able to compare the current links against the previous ones.

I've seen posts indicating that I can do this by accessing the operation's "old state". I believe it should look something like this:

Object data = operation.getOperationData();
if(data instanceof ISaveParameter) {
     IAuditable auditable = ((ISaveParameter) data).getOldState();
....}

I found a blog posting by Ralph where he provided some code that is supposed to be able to provide all of the "old references" for a work item when given that work item's ISaveParameter. His code looks like this:

private IWorkItemReferences accessLinksInOldState(ISaveParameter saveParameter, IProgressMonitor monitor) throws TeamRepositoryException
{
     IWorkItemReferences oldReferences = null;
     IAuditable oldState = saveParameter.getOldState();
     if (oldState != null) {
          IAuditableCommon common = (IAuditableCommon) getService(IAuditableCommon.class);
          IWorkItem oldItem = (IWorkItem) common.resolveAuditable(oldState, IWorkItem.FULL_PROFILE, monitor);
          IWorkItemServer workItemServer = getService(IWorkItemServer.class);
          return oldReferences = workItemServer.resolveWorkItemReferences(oldItem, monitor);
      }
     return null;
}

I tried solving this my own way but when that didn't work I tried the code that Ralph posted. Nothing seems to be working. My code has a print statement where I basically iterate through the old references and print them out and then subsequently iterate through the new references and print those out as well. In all cases, the "before" links match the "after" links. For example, if I have remove an existing link, I would expect to see:

Before: <nothing>
After: <some work item number>

That's not happening. Anyone have any insight into this?

Note that I read another posting that indicated that when you resolve an old work item by using "resolveAuditable", you always get the current links. I thought maybe this would be occurring in my print routine where I iterate over the references to print out the work item IDs associated with those references, but that doesn't seem to be the problem (or at least, not the only problem). I also iterate through the references lists to compare their sizes. One list should be empty and the other should have a size of 1. Both lists are the same size in all instances.


Comments
Nate Decker commented May 20 '14, 4:57 p.m.

I posted a comment on this, but I don't see it so I'll try again.

I did a quick test and verified that I am not seeing the Old data at all irrespective of the references. I tried capturing the "old" description and the "new" description and then printing them out. When I change the value, the participant displays only the new data. Attempting to access the old data returns the new data instead.


Ralph Schoon commented May 21 '14, 8:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I think I tried it exactly your way and I think I was able to find references that way. I tried to detect changes to the references. Unfortunately in my case the participant would not have been triggered, because I was looking for tracks links that don't trigger the participant. I am not sure how far I got, but I think I was able to get the references and actually compare them. Is the list of references empty? What happens while debugging on Jetty?


Nate Decker commented May 21 '14, 8:28 a.m.

Unfortunately, I never did get Jetty set up. The instructions seemed a little confusing. I'm sure that would make all of this vastly easier.

Using the technique described above, I can definitely get references. The references are just the same as the new references there is no "old" data to be had (of any kind, reference or otherwise). It seems like I am just getting the current/new data (post-save).

Perhaps I'll see if I can get Jetty set up and switch gears a bit.


Ralph Schoon commented May 21 '14, 8:39 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You should set up Jetty. Try the new version of the Extensions Workshop. If you can't get that up, you can't really approach extending RTC. I was about to do an advisor anyway and will try to have a look at this as well.

One answer



permanent link
ko wontaek (1) | answered Oct 14 '14, 7:03 a.m.
I have experienced same case (can not detect changes in reference) although setup jetty completely.
Ralph, how is your result trying advisor ( or participants)?




Comments
Ralph Schoon commented Oct 14 '14, 7:10 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I tried that for an advisor looking at OSLC links and back then realized that OSLC links did not even trigger the advisor. I had no need to do this again since then. It is also worth noticing that link changes did not show in the history of a work item. Since 5.0.1 you can switch this feature on. So maybe there is a change in 5.0.1 or not. If I have the opportunity to, I will try it again eventually. I have no plans to do so immediately.

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.