RTC - IOperationParticipant - operation.workItemSave - Resolve IVersionable path
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:
run(){ IWorkItem workitem = (IWorkItem) ((ISaveParameter) data).getNewState();<-OK
List<IChange> changes = getIChangeSets(workitem);<-OK
List<IVersionable> versionables = getIVersionables();<-OK
resolvePath();<-?
};
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
So if all you have is a work item (and not a workspace, stream, or snapshot/baseline), you cannot compute a pathname.
Comments
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;
searchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);
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
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.
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
getService(IScmService.class)
note that you will need to reference this in your plugin.xml
@gmclemm
We know the correct way should be searching by UUID but one of the conditions when creating streams is the name must be unique.
@sdetweil
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".
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.
@mikyjpeg
Thank you, IScmQueryService can provide me the workspace (stream), now I can resolve the path.