How to change the ownership of a component ?
I have found one code snippet from somewhere but it is not working for me. Can you please help me on this
IScmService scmService = null;
IRepositoryItemService itemService;
IComponentHandle componentH;
ComponentOwnerHandle componentOwnerH = scmService.getComponentOwnerRecord((ComponentHandle) componentH);
ComponentOwner componentOwner = (ComponentOwner) itemService.fetchItem(componentOwnerH, IRepositoryRemoteService.COMPLETE);
IAuditableHandle ownerH = componentOwner.getOwner();
if (componentHandle == null) {
// Rename component
componentHandle = wm.createComponent(componentName,
teamRepository.loggedInContributor(), monitor);
wm.setComponentOwner(componentHandle, ownerH, monitor);
} else {
// Rename component
wm.renameComponent(componentHandle, componentName, monitor);
wm.setComponentOwner(componentHandle, ownerH, monitor);
}
One answer
- " I have found one code snippet from somewhere but it is not working for me." This is a pointless statement.
- The snippet is from https://rsjazz.wordpress.com/2013/09/24/managing-workspaces-streams-and-components-using-the-plain-java-client-libraries/ it basically works
- The code to get a component owner in your example seems to be pretty pointless and does not seem to do anything useful. If you had a reasonable value in ownerH your code might even do something. Since you seem to get the old owner and set that, what do you expect?
Comments
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(teamRepository); wm.setComponentOwner(componentHandle, newOwnerHandle , monitor);
newOwnerHandle the new owner; must be either a IContributorHandle or a IProcessAreaHandle; must not be null (IProcessAreaHandle = ProjectAreaHandle or TeamAreaHandle)