Why does this code not return any changesets for the supplied IWorkItem (RTC 4.0)?
Following the advice from this thread I tried to get the changesets for a workitem programmatically. It doesn't seem to be returning anything for a workitem which I've verified does have a changeset. I'm wondering if something changed in the link API for this since 2012? The code snippet I'm using is shown below. What's strange is that if I debug I can see that there is a changeset link in the contents field of the ILinkQueryPage but it does not appear in the ILinkCollection obtained from it, which is an empty array in my example.
Any thoughts?
Thanks,
Tim
The code:
1. rtcConnection.getRepository() returns the ITeamRepository I'm using.
2. workItem is the IWorkItem for which I'm trying to get changesets
ILinkManager fLinkManager = (ILinkManager)rtcConnection.getRepository().getClientLibrary(ILinkManager.class); IReferenceFactory fReferenceFactory = fLinkManager.referenceFactory(); IReference reference = fReferenceFactory.createReferenceToItem(workItem.getItemHandle()); ILinkQueryPage page = fLinkManager.findLinksByTarget("com.ibm.team.filesystem.workitems.change_set", reference, null); ILinkCollection linkCollection = page.getAllLinksFromHereOn();
2 answers
There is some code here https://rsjazz.wordpress.com/2012/11/01/restrict-delivery-of-changesets-to-workitem-types-advisordelivery-of-changesets-associated-to-wrong-work-item-types-advisor/ that follows change set links. Maybe that helps.
Comments
Hey Ralph,
Thanks for the pointer. That code looks like it uses the server-side API. I'm on the client side here. I don't see a solution to this problem there...
Tim
Tim, here is information on the client link API and the snippets shipped with the Plain Java Client Libraries mentioned here provide some entry points for the SCM client API.
I've cobbled together the following code to retrieve the changeset links for a supplied workitem. It came from a variety of sources including "Defect178748Snippet" (in the SDK snippets). As usual it is difficult to find documentation so your milage may vary but it works for me.
--Tim
repository is an ITeamRepository
mgr is an IItemManager
workItem is the IWorkItem for which we want changesets
items holds the set of associated changeset links for the workitem
IClientLibraryContext ctx = (IClientLibraryContext)repository;
IQueryService svc = (IQueryService)ctx.getServiceInterface(IQueryService.class);
AuditableLinkQueryModel alqr = AuditableLinkQueryModel.ROOT;
IItemQuery iq = IItemQuery.FACTORY.newInstance(alqr);
iq.filter(alqr.name()._eq("com.ibm.team.filesystem.workitems.change_set")._and(
alqr.targetRef().referencedItem().itemId()._eq(iq.newUUIDArg())));
IItemQueryPage itemQueryPage = svc.queryItems(iq,
new Object[] { workItem.getItemId() }, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE);
List items = mgr.fetchCompleteItems(itemQueryPage.getItemHandles(), mgr.DEFAULT, null);