Strange behaviour on link location. Bug?
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?
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
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
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.
I'm going to try your code. Thanks.