Server Side API : saveParameter.getNewReferences() is not able to identify Contributes To (trackedBy) link
Hello All,
We are developing a server side plugin, which checks for the linked type and its workitems.
we are able to get all the link types and its linked workitems, but not "Contributes To" link.
following is the code :
IWorkItemReferences ref = saveParameter.getNewReferences();
List<IReference> listReferences = ref.getReferences(linkDescriptor);
Here the listReference, size is zero, though we have added the workitem using "Contributes To" link.
Is there any issue with the cross project and the link type "Contribute to" link ?
but, with the same cross project, the code is working for tracks link :(
please assist me on this.
Regards,
Shwetha
Accepted answer
Shwetha,
I would try these code snippets to retrieve source and target endpoints:
IEndPointDescriptor tracks = ILinkTypeRegistry.INSTANCE.getLinkType("com.ibm.team.workitem.linktype.trackedworkitem").getSourceEndPointDescriptor(); IEndPointDescriptor contributesTo = ILinkTypeRegistry.INSTANCE.getLinkType("com.ibm.team.workitem.linktype.trackedworkitem").getTargetEndPointDescriptor();
Comments
Thanks a lot Luca....This worked for me.
Hello Luca,
I would like to know how this mapping is happening :
For tracks com.ibm.team.workitem.linktype.trackedworkitem").getSourceEndPointDescriptor();
For Contributes to :com.ibm.team.workitem.linktype.trackedworkitem").getTargetEndPointDescriptor();
Here com.ibm.team.workitem.linktype.trackedworkitem is for Contributes to.
How you decide as which is source and target ?
I had applied the similar way using com.ibm.team.workitem.linktype.tracksworkitem. :
Tracks : com.ibm.team.workitem.linktype.tracksworkitem.getSourceEndPointDescriptor();
Contributes To : com.ibm.team.workitem.linktype.tracksworkitem.getTargetEndPointDescriptor();
The above didnt work for me.
Please help me understand this.
Shwetha,
using the Java SDK (see my other answer) I retrieved the list of link types and their enpoints.
So, I found:
LINK TYPE ID: com.ibm.team.workitem.linktype.trackedworkitem
SOURCE: Tracks (tracks)
SOURCE ITEM TYPE: WorkItem (com.ibm.team.repository.common.model.impl.ItemTypeImpl@1ae0fbd5 (namespaceURI: com.ibm.team.workitem, name: WorkItem, abstract: false))
TARGET: Contributes To (trackedBy)
LINK TYPE ID: com.ibm.team.workitem.linktype.tracksworkitem
SOURCE: Contributes To (trackedBy)
SOURCE ITEM TYPE: WorkItem (com.ibm.team.repository.common.model.impl.ItemTypeImpl@1ae0fbd5 (namespaceURI: com.ibm.team.workitem, name: WorkItem, abstract: false))
TARGET: Tracks (tracks)
It seems that com.ibm.team.workitem.linktype.tracksworkitem and com.ibm.team.workitem.linktype.trackedworkitem are complementary.
If you start from com.ibm.team.workitem.linktype.tracksworkitem, "Tracks" is the target, "Contributes To" is the source.
1 vote
3 other answers
This post explains the link API for these kinds of links: https://rsjazz.wordpress.com/2012/10/20/following-calm-links-using-the-java-client-or-server-api/
Shwetha, this is code with which I retrieved the links types:
Collection linkTypesCollection = ILinkTypeRegistry.INSTANCE.allEntries();
Iterator linkTypesCollectionIterator = linkTypesCollection.iterator();
while (linkTypesCollectionIterator.hasNext()) {
ILinkType currentLinkType = (ILinkType) linkTypesCollectionIterator.next();
String linkTypeID = currentLinkType.getLinkTypeId();
IEndPointDescriptor source = currentLinkType.getSourceEndPointDescriptor();
IEndPointDescriptor target = currentLinkType.getTargetEndPointDescriptor();
System.out.println("LINK TYPE ID: " + linkTypeID);
System.out.println("SOURCE: " + source.getDisplayName() + " (" + source.getId() + ")");
if (source.isItemReference()) {
IItemType referencedItemType = source.getReferencedItemType();
String referencedItemTypeName = referencedItemType.getName();
System.out.println("SOURCE ITEM TYPE: " + referencedItemTypeName + " (" + referencedItemType.toString() + ")");
}
System.out.println("TARGET: " + target.getDisplayName() + " (" + target.getId() + ")");
if (target.isItemReference()) {
IItemType referencedItemType = target.getReferencedItemType();
String referencedItemTypeName = referencedItemType.getName();
System.out.println("TARGET ITEM TYPE: " + referencedItemTypeName + " (" + referencedItemType.toString() + ")");
}
}
The Link types and endpoints are defined as follows:
Comments
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Feb 23 '17, 7:14 a.m."Contributes To" is basically the other direction of "Tracks" so I would assume both would work. I think I tried it in direction tracks and it worked for me back then.
Shwetha G
Feb 27 '17, 3:36 a.m.Thanks for the reply Ralph.
But the following code,is not able to identify the workitems that are linked using "Contributes to".
IEndPointDescriptor linkDescriptor = WorkItemEndPoints.TRACKS_ITEMS;
IWorkItemReferences ref = saveParameter.getNewReferences();
List<IReference> listReferences =ref.getReferences(linkDescriptor);
though i have linked two workitems using "contributes to" link, the
listReferences size is zero.
Could you please suggest me, if there are any other APIs, for fetching the list of workitems that works for all the link types.