Java API: setting workspace visibility to project area scope
Hi,
What is the proper way, with the java API 4.0.3, to set the visibility of a repository workspace to scoped to a particular project area.
I tried something like the code below, with different combinations of parameters including with IScmService.NOOP_OWNER or IScmService.DEFAULT_VISIBILITY but it fails with different exceptions like "Invalid scope for Contributor owner", "Workspace may only have contributor owners" etc.
IWorkspaceConnection targetFlow = ...;
IWorkspaceConnection workspace = workspaceManager
.createWorkspace(repo.loggedInContributor(), "workspace name",
"description", targetFlow, targetFlow,
NULL_PROGRESS_MONITOR);
IProcessAreaHandle area = targetFlow
.getProcessArea(NULL_PROGRESS_MONITOR);
ProcessAreaScope scope = (ProcessAreaScope) IReadScope.FACTORY
.createProcessAreaScope();
scope.setProcessArea(area);
workspace.setOwnerAndVisibility(?,
?, NULL_PROGRESS_MONITOR);
Accepted answer
Using IScmService.NOOP_OWNER is correct since you don't want to change the owner. If you do change the owner, it must be a contributor for your repository workspace.
For the visibility, you want to change the scope to a project area so don't use the IScmService.DEFAULT_VISIBILITY. To define a new scope, use IReadScope.FACTORY.createContributorDeferringScope() to get an instance of a new scope. Then set the scope on it to your project area. This scope instance is what you pass in for the IWorkspaceConnection.setOwnerAndVisibility(...) call.
For the visibility, you want to change the scope to a project area so don't use the IScmService.DEFAULT_VISIBILITY. To define a new scope, use IReadScope.FACTORY.createContributorDeferringScope() to get an instance of a new scope. Then set the scope on it to your project area. This scope instance is what you pass in for the IWorkspaceConnection.setOwnerAndVisibility(...) call.