It's all about the answers!

Ask a question

Strange behaviour on link location. Bug?


Michele Pegoraro (1.8k14118103) | asked Aug 26 '09, 12:20 p.m.
Hi, I've find out a strange behaviour of ILinkServiceLibrary.findLinks method.
This is the scenario: I've developed a precondition plugin on save work item operation. This pre-condition fails if you are trying to reopen a work-item if it has a parent work-item in a defined workflow state. Everything seems to be ok if I do all things one at time, but if I try in the same "save" operation to change link (changing the parent work-item in an other one in the correct workflow state), when I run the findLinks method on a IReference instance obtained from a workitem which I've retrieve using ISaveParameter.getNewState() I got the old parent link instead of the new one.

Am I missing something or is it a bug?

2 answers



permanent link
Patrick Streule (4.9k21) | answered Aug 26 '09, 1:18 p.m.
JAZZ DEVELOPER
Hi, I've find out a strange behaviour of ILinkServiceLibrary.findLinks
method.
This is the scenario: I've developed a precondition plugin on save
work item operation. This pre-condition fails if you are trying to
reopen a work-item if it has a parent work-item in a defined workflow
state. Everything seems to be ok if I do all things one at time, but
if I try in the same "save" operation to change link
(changing the parent work-item in an other one in the correct
workflow state), when I run the findLinks method on a IReference
instance obtained from a workitem which I've retrieve using
ISaveParameter.getNewState() I got the old parent link instead of the
new one.

Am I missing something or is it a bug?

The LinkServiceLibrary queries the repository, but the new parent is not
saved yet (you are in the precondition). That's why you still get the old
parent.

I would suggest you use this code:

private IWorkItem getParentWorkItem(ISaveParameter param,
IAuditableCommon auditableCommon) throws TeamRepositoryException {
List<IReference> parentRefs= null;
IWorkItemReferences refs= param.getNewReferences();
if (refs.hasReferences(WorkItemEndPoints.PARENT_WORK_ITEM)) {
parentRefs= refs.getReferences(WorkItemEndPoints.PARENT_WORK_ITEM);
}
if (parentRefs != null && !parentRefs.isEmpty()) {
IReference parent= parentRefs.get(0);
if (parent.isItemReference()) {
IItemHandle refItem= ((IItemReference)parent).getReferencedItem();
if (refItem instanceof IWorkItemHandle) {
return (IWorkItem)
auditableCommon.resolveAuditable((IWorkItemHandle) refItem,
IWorkItem.DEFAULT_PROFILE, null);
}
}
}
return null;
}



--
Regards,
Patrick
Jazz Work Item Team

permanent link
Michele Pegoraro (1.8k14118103) | answered Aug 27 '09, 3:29 a.m.
Thank you for the answer, I was supposing that referring to the "newState" object I would had the entire new object. So I was wrong, as I can see from your snippet, informations related to links are still stored in ISaveParameter but in another location.

I'm going to try your code. Thanks.

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.