It's all about the answers!

Ask a question

RTC - IOperationParticipant - operation.workItemSave - Resolve IVersionable path

Rogério Moreira (738) | asked Jan 21 '16, 12:15 p.m.

I'm trying to read the full path from the files associated via changeset to a workitem. In this case it will trigger as a participant on an operation.workItemSave operation. After getting the path it will do some modifications on the work item attributes.

Right now I can get the list changesets and its changes. But I don't know how to resolve the path.

The code I have:

IWorkItem workitem = (IWorkItem) ((ISaveParameter) data).getNewState();<-OK
List<IChange> changes = getIChangeSets(workitem);<-OK
List<IVersionable> versionables = getIVersionables();<-OK

I managed to get the iversionable, but don't know how to resolve IFolderHandle

private String resolvePath(IVersionable versionable){    
    IFolderHandle folderHandle = versionable.getParent();
    //How do i resolve ifolderHandle? 

After getting the IFolder i would climb the tree and build the path.

From the examples I found in the forum.
There is a "IScmService.configurationResolvePath" method to resolve the path, but it needs a ServiceConfigurationProvider which in turn is provided by a IWorkspace.

If this was a DeliverOperationData I could get the configuration, but this "data" is a IWorkItem.

Is it possible to get the full path of a file associated to a workitem?

Any help is welcome. Thanks!

2 answers

permanent link
Michele Pegoraro (1.8k14117103) | answered Jan 21 '16, 12:27 p.m.
The IVersionableItemHandle could be either a IFolderHandle or a IFileItemHandle so you can just cast it after an "if instanceof" check.

permanent link
Geoffrey Clemm (30.1k33035) | answered Jan 21 '16, 12:42 p.m.
The only way to compute a pathname from an IVersionableHandle is to provide  a Workspace (or Stream or Snapshot/Baseline) context, because the pathname for a file depends on what folder versions are selected for the parent folders (a file version only knows the UUID of its immediate parent folder, and it's name relative to that parent folder ... the additional folders and relative names for the rest of the pathname can only be determined if you know what version to use of those parent folders.

So if all you have is a work item (and not a workspace, stream, or snapshot/baseline), you cannot compute a pathname.

Rogério Moreira commented Jan 21 '16, 1:19 p.m.

Hello Geoffrey and thank you for providing feedback.
I was thinking about this, provide a stream. Server side -  is there any way to search for a stream based on name? (one of the attributes of the workitem is the exact name of the stream)
Client side I would use:
IWorkspaceSearchCriteria searchCriteria;
List<IWorkspaceHandle> results = IWorkspaceManager.findWorkspaces(searchCriteria);
Iterate the result and find the match.

But I can't find how to do this server-side.
Thank you

Geoffrey Clemm commented Jan 21 '16, 2:20 p.m.

I know there must be a way to find a stream by name on the server, but we'll need one of the API experts to provide a pointer.   Note that stream names are not guaranteed to be unique, so it might return multiple streams.

sam detweiler commented Jan 21 '16, 4:47 p.m.

but remember, streams are not located anywhere in the file system, so the path i useless there too.

you 'might' be able to get the path from the root of the workspace(aka stream).
but you will probably have to go thru the component to get it.

you will have to find the ScmService on the server side, like ScmPlatform on the client side. not all the apis are symetrical

note that you will need to reference this in your plugin.xml

Rogério Moreira commented Jan 22 '16, 5:34 a.m. | edited Jan 22 '16, 5:35 a.m.

We know the correct way should be searching by UUID but one of the conditions when creating streams is the name must be unique.

We use IScmService to fetch the IVersionables (IScmService.fetchState(handle)) but none of the methods provided by IScmService is able to search for IWorkspace. We are using RTC 4.0.6, probably a newer API can provide this.

Thank you all for helping, I'll leave the question open in case someone knows a "workaround".

Michele Pegoraro commented Jan 22 '16, 7:01 a.m.

Streams (and workspace) could be searched using IScmQueryService.findWorkspaces method. You need a IWorkspaceSearchCriteria that you can get using its factory. In this object you can set which type of workspace (stream or not) you are searching and the name of the searched object.
In order to search for the complete path (relative to the workspace) I suggest you to use  scmService.configurationDetermineAncestorsInHistory method that gives you a more reliable INameItemPair list. Every object of this list is a node of the path from the component root. You have to get the name of the element and using concatenation to obtain a full path.

Rogério Moreira commented Jan 25 '16, 6:12 a.m.

Thank you, IScmQueryService can provide me the workspace (stream), now I can resolve the path.

showing 5 of 6 show 1 more comments

Your answer

Register or to post your answer.