| Oracle® Content Services Application Developer's Guide 10g Release 1 (10.1.2.2) Part Number B25277-02 |
|
|
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 Oracle 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 author,
String reader) throws FdkException, RemoteException
{
// get the Manager instances
UserManager um = s_WsCon.getUserManager();
FileManager fm = s_WsCon.getFileManager();
SecurityManager scm = s_WsCon.getSecurityManager();
WorkspaceManager wm = s_WsCon.getWorkspaceManager();
// get the user Items
Item adminUser = um.getUser(admin, null);
Item authorUser = um.getUser(author, null);
Item readerUser = um.getUser(reader, null);
// 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, reader, 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 reader can view items in the workspace but not change them. The author can do all the tasks associated with adding and deleting content.
After creating each of the grant definitions, 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 authorUser = um.getUser(author, null);
Item readerUser = um.getUser(reader, null);
// get the Roles to grant for the Workspace's SecurityConfiguration
Item adminRole = scm.getRoleByName("ADMINISTRATOR", null);
Item authorRole = scm.getRoleByName("AUTHOR", null);
Item readerRole = scm.getRoleByName("READER", 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 we use 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 author
NamedValue[] wsAuthorGrant = WsUtility.newNamedValueArray(new Object[][] {
{ Attributes.GRANTEE, new Long( authorUser.getId()) },
{ Attributes.ROLES, new long[] { authorRole.getId() } } });
// create a Grant definition for the Workspace reader
NamedValue[] wsReaderGrant = WsUtility.newNamedValueArray(new Object[][] {
{ Attributes.GRANTEE, new Long( readerUser.getId()) },
{ Attributes.ROLES, new long[] { readerRole.getId() } } });
// create the Grant array definition
// -> notice that 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(wsAuthorGrant),
WsUtility.newNamedValueSet(wsReaderGrant)
};
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
// -> notice that 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 } }) } });
// workspace attribute request
AttributeRequest[] workspace_attr =
WsUtility.newAttributeRequestArray(new String[] {
Attributes.DESCRIPTION,
Attributes.TRASH_FOLDER,
Attributes.JOINABLE,
Attributes.JOINABLE_WORKSPACE_DESCRIPTION });
// create the Workspace using the Workspace definition
// -> no workflow parameters are required (second argument is null)
Item workspace = wm.createWorkspace(container.getId(), null, wsDef, workspace_ attr);
WsUtility.log("workspace attributes");
WsUtility.log(WsUtility.INDENT, workspace);
return workspace;
}
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 an Oracle 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
{
// get property object
Properties prop = WsUtility.getProperty(args[0]);
// authenticate to Oracle Content Services
String serverUrl = "http://" + prop.getProperty("hostname") + ":"
+ prop.getProperty("port") + "/content/ws";
s_WsCon = WsConnection.login(serverUrl, prop.getProperty("user"),
prop.getProperty("password"));
// URL to Oracle 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();
}
}