Oracle® Content Services Application Developer's Guide 10g Release 1 (10.1.1) Part Number B14494-01 |
|
|
View PDF |
Oracle Content Services Web Services allows creation of Workspaces, which are special folders that store content, have a trash folder, and can have an associated quota.
For this example you will need (in addition to the Workspace Manager):
File Manager - For resolving path names
Security Manager - For setting the security policy of a Workspace
Session Manager - To access administrator mode
User Manager - To fetch user IDs for setting permissions on the manager
Also, you will need a container in which to create the workspace. This must be a container on which the user has LibraryAdministrator access. You can also create Workspaces directly inside a Domain.
Note:
The "Workspaces" referred to in this chapter are called "Libraries" in the rest of Content Services.A Workspace must be created inside a container or domain. You can retrieve the Container by resolving its path with the resolvePath
method of the FileManager
.
/** * Creates a Workspace in the specified Container and assigns the * WorkspaceAdministrator, WorkspaceManager, and WorkspaceAuthor Roles * to the specified users. * * Note: The logged-in user calling this method must have the * LibraryAdministrator or WorkspaceCreator Role and the * logged-in session must be in domain-administration mode. */ public static Item createWorkspace(String containerPath, String workspaceName, String workspaceDesc, String admin, String manager, String author) throws FdkException, RemoteException { // get the Manager instances we need UserManager um = WsConnection.getUserManager(); FileManager fm = WsConnection.getFileManager(); SecurityManager scm = WsConnection.getSecurityManager(); WorkspaceManager wm = WsConnection.getWorkspaceManager(); // get the Container Item from its path Item container = fm.resolvePath(containerPath, null);
The roles for each workspace are specified by a security configuration, which is composed of a set of grants. A grant consists of a grantee user and a set of roles for that user. Each grant is represented by two name/value pairs (stored in NamedValue
objects). The first pair associates the GRANTEE
Attribute with the user ID for the grantee user. The second pair associates the ROLES
Attribute with the set of role IDs being granted to that user (adminstrator, manager, or author). Note that more than one role can be granted to each user, so the ROLES
Attribute can be associated with an array of roles.
In this example there are three users being granted access to the workspace. The administrator role is the least restricted, and allows all workspace actions, such as creating and deleting, version control, and others. The manager can add items, create folders, and change the security policy of the workspace. The author can do all the tasks associated with adding and deleting content.
After creating each of the grant definition, create the security configuration by forming a set from the grants. This set is stored as an array of NamedValueSet
objects.
Note that when creating the grant definitions, this example uses the newNamedValueArray
and the newNamedValueSet
methods of the WsUtility
class. These methods are simple wrappers for object instantiation.
// get the user Items Item adminUser = um.getUser(admin, null); Item managerUser = um.getUser(manager, null); Item authorUser = um.getUser(author, null); // get the Roles to grant for the Workspace's SecurityConfiguration Item adminRole = scm.getRoleByName("ADMINISTRATOR", null); Item managerRole = scm.getRoleByName("MANAGER", null); Item authorRole = scm.getRoleByName("AUTHOR", null); // create a Grant definition for the Workspace administrator // -> notice that a Grant definition is made up of a // GRANTEE and a set of ROLES (here, just one Role) NamedValue[] wsAdminGrant = WsUtility.newNamedValueArray(new Object[][] { { Attributes.GRANTEE, new Long(adminUser.getId()) }, { Attributes.ROLES, new long[] { adminRole.getId() } } }); // create a Grant definition for the Workspace manager NamedValue[] wsManagerGrant = WsUtility.newNamedValueArray(new Object[][] { { Attributes.GRANTEE, new Long(managerUser.getId()) }, { Attributes.ROLES, new long[] { managerRole.getId() } } }); // create a Grant definition for the Workspace author NamedValue[] wsAuthorGrant = WsUtility.newNamedValueArray(new Object[][] { { Attributes.GRANTEE, new Long(authorUser.getId()) }, { Attributes.ROLES, new long[] { authorRole.getId() } } }); // create the Grant array definition // -> the Grant array definition is made up of three // NamedValue arrays, one for each Grant definition // -> each Grant definition (NamedValue[]) is wrapped in a // NamedValueSet instance to avoid the use of two-dimensional arrays NamedValueSet[] wsGrants = new NamedValueSet[] { WsUtility.newNamedValueSet(wsAdminGrant), WsUtility.newNamedValueSet(wsManagerGrant), WsUtility.newNamedValueSet(wsAuthorGrant) };
Once the security configuration is set up, pass it as the parameter for the Attributes.SECURITY_CONFIGURATION
constant, along with the Name and Description for the workspace, as shown below. Then, create the workspace using the createWorkspace()
method of the WorkspaceManager
, as shown.
// create the Workspace definition // -> the Grant array definition is a nested definition // passed in as the value of the SECURITY_CONFIGURATION NamedValue NamedValue[] wsDef = WsUtility.newNamedValueArray(new Object[][] { { Attributes.NAME, workspaceName }, { Attributes.DESCRIPTION, workspaceDesc }, { Attributes.SECURITY_CONFIGURATION, WsUtility.newNamedValueArray(new Object[][] { { Attributes.GRANTS, wsGrants } }) } }); // create the Workspace using the Workspace definition // -> no workflow parameters are required (second argument is null) // -> no AttributeRequest is specified (fourth argument is null) return wm.createWorkspace(container.getId(), null, wsDef, null); }
To delete a workspace, fetch the Workspace ID and call the deleteWorkspace()
method on the WorkspaceManager
.
/** * Deletes the specified Workspace. * * Note: The logged-in user calling this method must have the * LibraryAdministrator or WorkspaceCreator Role and the * logged-in session must be in domain-administration mode. */ public static void deleteWorkspace(Item workspace) throws FdkException, RemoteException { // delete the Workspace // -> no definition is required WorkspaceManager wm = WsConnection.getWorkspaceManager(); wm.deleteWorkspace(workspace.getId(), null); }
To run the code, connect to a Content Services instance, and call the create and delete methods on a Workspace. Remember to switch to domain administrator mode before performing any operations.
private static WsConnection s_WsCon; public static void main(String[] args) { try { try { // URL to content services web services servlet String serverUrl = "http://yourserver.com:7777/content/ws"; // authenticate to content services s_WsCon = WsConnection.login(serverUrl, "jon", "welcome1"); // switch to admin mode SessionManager sm = s_WsCon.getSessionManager(); sm.setSessionMode(FdkConstants.SESSION_MODE_DOMAIN_ADMINISTRATION, null); // create a Workspace Item newWorkspace = createWorkspace("/oracle/ifs/dev", "MyWorkspace", "this is an example Workspace", "ray", "tanya", "ellie"); // delete the Workspace deleteWorkspace(newWorkspace); } finally { s_WsCon.logout(); } } catch (Throwable t) { t.printStackTrace(); } }