It's all about the answers!

Ask a question

[closed] How to get IChangeSet from IItemHandle


Thomas Foyle (12) | asked May 28 '10, 10:18 a.m.
closed Oct 20 '21, 5:48 a.m. by Ralph Schoon (63.1k33645)
Hi all,

I'm trying to use the Plain Java Client to get change set information from a work item. I've got to the point where I have a List of IItemHandles for all the change sets linked with the work item. Now I need to use these handles to get a List of IChangeSets.


public static void getChangeSets(ITeamRepository repository, IWorkItem workItem, IProgressMonitor monitor) {

//Get an IReference to the work item.
ILinkManager linkManager = (ILinkManager) repository.getClientLibrary(ILinkManager.class);
IReferenceFactory referenceFactory = linkManager.referenceFactory();
IReference workItemReference = referenceFactory.createReferenceToItem(workItem.getItemHandle());

//Find all ILinks which attach a change set to the work item.
ILinkQueryPage linkQueryPage = linkManager.findLinksByTarget("com.ibm.team.filesystem.workitems.change_set", workItemReference, monitor);
ILinkCollection linkCollection = linkQueryPage.getAllLinksFromHereOn();

//Put the ILinks in a list.
List<ILink> changeSetLinks = (List<ILink>)linkCollection.getLinksById("com.ibm.team.filesystem.workitems.change_set");

//Convert each ILink to an IReference to the change set.
List<IReference> changeSetReferences = new ArrayList<IReference>();
for (ILink link : changeSetLinks) {
changeSetReferences.add(link.getSourceRef());
}

//Convert each IReference to an IItemHandle.
List<IItemHandle> itemHandles = new ArrayList<IItemHandle>();
for (IReference reference : changeSetReferences) {
itemHandles.add((IItemHandle)reference.resolve());
}

//Convert each IItemHandle to an IChangeSet.
List<IChangeSet> changeSets = new ArrayList<IChangeSet>();
for (IItemHandle itemHandle : itemHandles) {
changeSets.add((IChangeSet)repository.itemManager().fetchCompleteItem(itemHandle, 0, monitor)); //ERROR HERE.
}

return;
}


When I run this I get the following PermissionDeniedException error.


Exception in thread "main" java.lang.RuntimeException: com.ibm.team.repository.common.PermissionDeniedException: CRJAZ1319E Illegal read access: User "tom.foyle@uk.ibm.com" attempted to read item(s) having the following type(s): ChangeSet
at snippets.RtcAccess.getChangeSets(RtcAccess.java:231)
at snippets.RtcAccess.main(RtcAccess.java:87)
Caused by: com.ibm.team.repository.common.PermissionDeniedException: CRJAZ1319E Illegal read access: User "tom.foyle@uk.ibm.com" attempted to read item(s) having the following type(s): ChangeSet
at com.ibm.team.repository.client.internal.ItemManager.internalFetchItem(ItemManager.java:1579)
at com.ibm.team.repository.client.internal.ItemManager.access$0(ItemManager.java:1538)
at com.ibm.team.repository.client.internal.ItemManager$AbstractStore.retrieveItem(ItemManager.java:186)
at com.ibm.team.repository.client.internal.ItemManager$CurrentStore.fetchItem(ItemManager.java:311)
at com.ibm.team.repository.client.internal.ItemManager.fetchCompleteItem(ItemManager.java:824)
at snippets.RtcAccess.getChangeSets(RtcAccess.java:226)


Is there some way I can get the required permission to access change sets? Or is there something else I'm doing wrong? Thanks for any help or suggestions.

Tom

The question has been closed for the following reason: "Problem is not reproducible or outdated" by rschoon Oct 20 '21, 5:48 a.m.

2 answers



permanent link
Ralph Schoon (63.1k33645) | answered Oct 20 '21, 5:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Oct 20 '21, 5:49 a.m.
I close this due to the age of the post.

With respect to the question, one would usually have a change set and try to access the contained changes and the related items. That is a supported and useful direction.

Trying to find the change set that an item is related to from an IItem/IItemHandle as described above does not make a lot of sense. The Item could be affected by several change stets linked to the work item.

You also can not just cast stuff from one class to another, obviously. There must be a subclass or interface relationship to be able to do that.

permanent link
Peter Moraza (481924) | answered Oct 19 '21, 10:30 p.m.

Hi Tom,


I am trying to achieve the same objective you are, retrieving an IChangeSet object from an IItemHandle, but I get a ClassCastException calling the same method you did. I know it has been a long time since you posted your question, but did you overcome your issue? Pasting my method call for comparison with yours. "iref" is an IReference to an IItemHandle.

IChangeSet changeSet = (IChangeSet) repo.itemManager().fetchCompleteItem((ChangeSetHandleImpl) iref.resolve(), IItemManager.DEFAULT, monitor);

My exception:

java.lang.ClassCastException: com.ibm.team.filesystem.common.internal.impl.FileItemHandleImpl incompatible with com.ibm.team.scm.common.internal.impl.ChangeSetHandleImpl

I'll post my code in a new query. TIA

Peter


Comments
Ralph Schoon commented Oct 20 '21, 1:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 Please do not ask questions, as answers to other authors questions. Especially if they are 11 years old. Please ask your own question. In your particular case, please check the method signatures, e.g. if they return compatible object types.