Show TOC

Creating WorkspacesLocate this document in the navigation structure

Use

The Workspace API enables you to create workspaces and set their properties.

The following example illustrates how to create a shared workspace and set its properties and ownership.

public void createSharedWorkspace(IPortalComponentRequest request, IUser workspaceOwnerUser)
    {
    	// Retrieve the workspace factory
    	IWorkspaceFactory workspacesFactory = (IWorkspaceFactory) RuntimeFactory.getWorkspacesRuntime().getService(IWorkspaceFactory.class);

    	WorkspaceProperties workspaceProperties = new WorkspaceProperties();

    	workspaceProperties.setName("Workspace Name");
    	workspaceProperties.setDescription("Workspace Description");
    	workspaceProperties.setPermissionPolicy(PermissionPolicy.RESTRICTED);

    	//Create shared workspace, setting the specified user as owner
    	workspacesFactory.createShared(workspaceOwnerUser, workspaceProperties);
    }

The following example illustrates how to create a personal workspace for a specific user.

public void createPersonalWorkspace(IPortalComponentRequest request, IUser workspaceOwnerUser)
{	
	try {
    	// Retrieve the workspace factory
    	IWorkspaceFactory workspacesFactory = (IWorkspaceFactory) RuntimeFactory.getWorkspacesRuntime().getService(IWorkspaceFactory.class);

    	//Create a personal workspace for the specified user
    	workspacesFactory.createPersonal(workspaceOwnerUser, request.getLocale());
    }

	//If the user already has a personal workspace or has no permissions to have one, a WorkspacesRuntimeException is thrown
    catch (WorkspacesRuntimeException e) {
		logger.traceThrowableT(Severity.WARNING, "Could not create personal workspace", e);
		response.setFailure(e);
	} 
}