It's all about the answers!

Ask a question

How to fetch change set data from links


Rinkal Garg (1719) | asked Mar 27 '18, 5:24 a.m.

 I am using the below code :

for(Object wI : links){
ILink link = (ILink) wI;
Object source = link.getTargetRef().resolve();
IItemHandle changeSetHandle = (IItemHandle) link.getTargetRef().resolve();
if (source instanceof IChangeSetHandle) {
changeSet = (IChangeSet) repo.itemManager().fetchCompleteItem(changeSetHandle,
IItemManager.DEFAULT, monitor);
System.out.println("changeset---1"+changeSet);
}
}

But there is some exception like : 
com.ibm.team.repository.common.ItemNotFoundException: CRJAZ0215E The following record was not found in the database: com.ibm.team.scm.common.internal.impl.ChangeSetHandleImpl

2 answers



permanent link
Ralph Schoon (63.1k33646) | answered Mar 27 '18, 5:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

The source code is totally messy; source and changeSetHandle seem to be the same thing and why would you test the instance for one and then use the other item to resolve?

Cast the item you want to look up to IChangeSetHandle and use the casted interface in the lookup.


permanent link
Ralph Schoon (63.1k33646) | answered Mar 27 '18, 5:52 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

This is code that worked for me

        IWorkItemReferences wiReferences = workItemCommon
                .resolveWorkItemReferences(workItem, monitor);
        List<ichangesethandle> changeSetHandles = new ArrayList<ichangesethandle>();
        List<ireference> references = wiReferences
                .getReferences(ILinkTypeRegistry.INSTANCE.getLinkType(
                        WorkItemLinkTypes.CHANGE_SET)
                        .getSourceEndPointDescriptor());
        for (IReference reference : references) {
            if (reference.isItemReference()) {
                IItemHandle refItem = (IItemHandle) reference.resolve();
                if (refItem instanceof IChangeSetHandle) {
                    changeSetHandles.add((IChangeSetHandle) refItem);
                }
            }
        }

    @SuppressWarnings("rawtypes")
    List changeSets = itemManager.fetchCompleteItems(changeSetHandles,
            IItemManager.DEFAULT, monitor);
    for (Object object : changeSets) {
        if (object instanceof IChangeSet) {
            IChangeSet changeSet = (IChangeSet) object;

......... </ireference></ichangesethandle></ichangesethandle>


Comments
Rinkal Garg commented Mar 28 '18, 3:00 a.m.

 @Ralph I have some change sets which have link type id : com.ibm.team.workitem.linktype.scm.tracksChanges
 and then I am using the code which you have shared but it returns null value and exception that the item is not found in the database even though the change set is there.
Any help would be appreciable.


Rinkal Garg commented Mar 28 '18, 3:08 a.m.

 Surely there is some issue in this line : 

List changeSets = repo.itemManager().fetchCompleteItems(changeSetHandles,
                IItemManager.DEFAULT, monitor);
I have URIReference of change sets. Is there any other way to fetch URI references?


Ralph Schoon commented Mar 28 '18, 5:01 a.m. | edited Mar 28 '18, 5:03 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

The code I shared works for me. I don't get null pointers and I am passing an array of the IChangeSetHandles to the call you surely say to be wrong and NOT the references.

I can not remote debug.


Rinkal Garg commented Mar 28 '18, 5:15 a.m.

 I have reference.isURIReference() type, shall I use the same code to fetch complete change set?

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.