(Java API) How Can I Access the Links of the OLD State?
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
May 20 '14, 4:57 p.m.Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER May 21 '14, 8:04 a.m.Nate Decker
May 21 '14, 8:28 a.m.Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER May 21 '14, 8:39 a.m.