How to get IWorkspaceConnection from FileItemWrapper/FolderItemWrapper using RTC SDK?
Hi,
I´m developing an Eclipse plugin using the RTC SDK. I need to get the Workspace or Stream given a FileItemWrapper or a FolderItemWrapper. How can I do that?
Most of the examples that I found require the name of the workspace/stream (IWorkspaceSearchCriteria) to get it. I don't have the name of the workspace (or I don't know how to get it from the plugin); but I have the workspace id: FolderItemWrapper.getWorkspace().
How can I get the IWorkspaceConnection using the workspace id instead of the workspace' name?
I´ll appreciate your help.
Thank you,
|
Accepted answer
The wrapper has a namespace, which would be a workspace namespace for a FolderItemWrapper/FileItemWrapper. With the namespace, you can call #getWorkspaceConnection (cast to WorkspaceNamespace first) or #getConnection (then cast to IWorkspaceConnection).
Leonardo Marzo selected this answer as the correct answer
Comments
Leonardo Marzo
commented May 08 '14, 10:34 a.m.
Thanks Tim! That's the shortest way :)
IWorkspaceConnection con = (IWorkspaceConnection) folderWrapper.getWorkspace().getConnection(null);
How can I get the Component now ??
|
One other answer
Thanks for your answers Ralph and Tim. I was able to get the Stream with this code:
IWorkspaceHandle wpHandle = (IWorkspaceHandle) IWorkspace.ITEM_TYPE.createItemHandle(UUID.valueOf(folderSelection.getWorkspace().getContextHandle().getItemId().getUuidValue()), null);Now I need to get the Component the FileItemWrapper/FolderItemWrapper is in. Do you know how to get it?
Thanks,
Comments The way I suggest to get the workspace connection would look like this:
(IWorkspaceConnection) FileItemWrapper.getWorkspace().getConnection(); (IWorkspaceConnection) FileItemWrapper.getWorkspace().fetchComponentId().toHandle();
Leonardo Marzo
commented May 08 '14, 12:04 p.m.
Almost there. That line shows me the following warning in Eclipse:
Discouraged access: The method toHandle() from the type ItemId<IComponent> is not accessible due to restriction on required library RTC405Dev\installs\rtc-sdk\plugins\com.ibm.team.scm.common_3.2.0.v20131019_0328.jar
and when I try to debug that line, I get a "Source not found" error. It seems that something in the configuration of my plugin is wrong. I tried with the following solution http://stackoverflow.com/questions/860187/access-restriction-on-class-due-to-restriction-on-required-library-rt-jar, but the problem is still there. I checked the plugin dependencies, and everything seem to be ok.
Any thoughts? Thank you
Ralph Schoon
commented May 08 '14, 12:15 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
This is only a warning and means that the method is not in a public package (which means internal API, I think). This does not necessarily mean, it does not work, it only means this API could change without notice. If the source can not be found that can mean the SDK/Plain Java is not set up correctly.
Leonardo Marzo
commented May 08 '14, 1:21 p.m.
I figured it out! It was a ClassCastException. The final code to get the component is this:
IComponentHandle componentHandle = folderSelection.getWorkspace().fetchComponentId(null).toHandle();
IComponent component = (IComponent) teamRepository.itemManager().fetchCompleteItem(componentHandle, IItemManager.DEFAULT, monitor);
Hope it helps. Thank you guys!
|
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.
Comments
How/where did you get the FileItemWrapper or FolderItemWrapper class? I can't find them in the RTC SDK.
Please see: http://rsjazz.wordpress.com/2014/02/21/adding-context-menus-for-jazz-objects-to-the-rtc-eclipse-client/
They are part of the Client SDK and the elements you get for UI selections in some of the views/editors.
Leonardo,
I don't have time to look into your question right now. Some hints I could provide:
https://jazz.net/library/article/807 shows how you can use the AuditableClient to find elements with the UUID. You will likely get an IWorkspaceHandle back and have to get what you need from that.
http://rsjazz.wordpress.com/2013/09/24/managing-workspaces-streams-and-components-using-the-plain-java-client-libraries/
and
http://rsjazz.wordpress.com/2013/09/30/delivering-change-sets-and-baselines-to-a-stream-using-the-plain-java-client-libraries/
have some hints, as far as I remember.
I have not played with the other ItemWrapper classes, so I don't know what you get from them. I would try to see what I get and then look into the SDK to find my way around. That is the way I usually do it, if I am in your situation.