How to get User ID who has loaded RTC component to sandbox ?
We are trying to fetch the user details who has loaded the RTC component into sandbox (Local Workspace).
Is the below approach correct? or do we have any better way to get the user details?
Thanks in advance.
try {
TeamPlatformUtils.startupTeamPlatform();
ITeamRepository teamRepository =
accessProvider.logIn(RepositoryURL, new NullProgressMonitor());
final IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(teamRepository);
final IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(
(IWorkspaceHandle) connectionHandle, new NullProgressMonitor());
IAuditableHandle auditableHandle = workspaceConnection.getOwner();
final IContributor contributorDetails = RTCUtils.getCompleteItem((IContributorHandle) auditableHandle,
IContributor.class, false, teamRepository, new NullProgressMonitor());
this.loggerStorage.getLogger().info("Component Owned By User ID - " + contributorDetails.getUserId());
}
finally {
TeamPlatformUtils.shutdownTeamPlatform();
}
Accepted answer
With your added comment it looks like you are just trying to get the owner of the repository workspace (and not really who loaded it into some arbitrary sandbox location).
Your code would work for that purpose, however fetching the IWorkspaceConnection (using workspaceManager.getWorkspaceConnection) is a little heavy-weight for what you are trying to achieve. This is because the IWorkspaceConnection has to compute a lot of other details (such as the component hierarchy) that would not be needed if the only thing you care about is the workspace owner.
Just like you are already fetching the full IContributor from a given IContributorHandle, you would fetch the full IWorkspace from the IWorkspaceHandle. Once you have the IWorkspace, you would use workspace.getOwner() and use that to fetch the IContributor. Note: Streams and repository workspaces are both IWorkspace instances. So
the .getOwner() call will always return an IProcessAreaHandle, and it will always return an IContributorHandle for repository workspaces (something to keep in might to avoid possible ClassCastExceptions if your code might even have Streams in the future...)
Another minor note is that your code snippet says: "Component Owned By User ID - " when you probably mean to write: "Repository workspace owned by user ID - "
Comments
Praveen Kalawad
Oct 09 '18, 11:13 a.m.I would like to rephrase the question here!. We were actually looking for the user who is owning the repository workspace and with the help of the above code snippet it is possible to get the repository owner and not the User ID who loaded the repository workspace to sandbox.