Skip Headers
Oracle® Workspaces Web Services Application Developer's Guide
10g Release 1 (10.1.2.2)

Part Number B28207-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

7 Workspaces Service

The Workspaces service allows you to create, update, and remove resources and manage users of a workspace.

Example: Add Members and Resources to a Workspace

The following sample retrieves users from a specified group in Oracle Internet Directory and adds them as members of a workspace. Each newly added member is given writer role. Afterwards, the sample adds a calendar, library, discussions, and inbox resource to the same workspace. An exception is thrown if any of these resources already exist.

Example 7-1 WorkspacesServiceSample.java

package oracle.sample.workspaces.ws;
 
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import oracle.workspaces.ws.AuthenticationService;
import oracle.workspaces.ws.HomeService;
import oracle.workspaces.ws.UsersService;
import oracle.workspaces.ws.WorkspacesService;
import oracle.workspaces.ws.WorkspacesServiceServiceLocator;
import oracle.workspaces.ws.WorkspacesServiceSoapBindingStub;
import oracle.workspaces.ws.beans.CalendarResourceDefinition;
import oracle.workspaces.ws.beans.DiscussionResourceDefinition;
import oracle.workspaces.ws.beans.InboxResourceDefinition;
import oracle.workspaces.ws.beans.LibraryResourceDefinition;
import oracle.workspaces.ws.beans.Member;
import oracle.workspaces.ws.beans.User;
import oracle.workspaces.ws.beans.WorkspaceItem;
import oracle.workspaces.ws.exceptions.CwWSException;
import org.apache.axis.transport.http.HTTPConstants;
 
public class WorkspacesServiceSample 
{
  public static WorkspacesService configureWorkspacesService(
    String szAuthCookie) throws ServiceException
  {
    WorkspacesServiceServiceLocator wssl =
      new WorkspacesServiceServiceLocator(); 
    WorkspacesService wService = wssl.getWorkspacesService();
    ((WorkspacesServiceSoapBindingStub)wService).setMaintainSession(true);
    ((javax.xml.rpc.Stub)wService).
      _setProperty(HTTPConstants.HEADER_COOKIE,szAuthCookie);
    return wService;
  }
  
  public static void createResources(
    WorkspacesService szWorkspacesService,
    String szWorkspaceID)
  {
    // This method attempts to add a calendar, discussions,
    // library, and inbox resource in the specified workspace.
    // An exception is thrown if any of these resources exist
    // in the workspace.
  
    System.out.println("Adding calendar resource");
    CalendarResourceDefinition rDef = new CalendarResourceDefinition();
    rDef.setDescription("Calendar resource");
    rDef.setName("Calendar1");
 
    try {
      
      // Create calendar resource
    
      szWorkspacesService.createCalendarResource(szWorkspaceID, rDef);
      System.out.println("Added calendar resource");
    } catch (CwWSException e) {
     System.out.println("CwWSException caught while adding " +
       "Calendar resource: "
        + e.getErrorMessage());
    } catch (RemoteException re) {
      System.out.println("RemoteException caught while " +
      "adding Calendar resource: "
      + re.toString());
    }
          
    try {
    
      // Create discussion resource
    
      System.out.println("Adding discussions resource");
      DiscussionResourceDefinition dDef = new DiscussionResourceDefinition();
      dDef.setDescription("Discussion resource");
      dDef.setName("Discussion1");
      szWorkspacesService.createDiscussionResource(szWorkspaceID, dDef);
      System.out.println("Added discussion resource");
 
    } catch (CwWSException e2) {
      System.out.println("CwWSException caught while adding "
        + "Discussion resource: "
        + e2.getErrorMessage());
    } catch (RemoteException re2) {
      System.out.println("RemoteException caught while adding " +
      "Discussion resource: "
      + re2.toString());
    }
 
    try {
    
      // Create library resource
    
      System.out.println("Adding library resource");
      LibraryResourceDefinition libDef = new LibraryResourceDefinition();
      libDef.setDescription("Library resource");
      libDef.setName("Library1");
      libDef.setMappedFolderName("FolderLibrary1");
      szWorkspacesService.createLibraryResource(szWorkspaceID, libDef);
      System.out.println("Added library resource");
 
         
    } catch (CwWSException e3) 
    {
      System.out.println("CwWSException caught while adding " +
        "Library resource: "
        + e3.getErrorMessage());
    } catch (RemoteException re3) {
      System.out.println("RemoteException caught while adding " +
        "Library resource: "
        + re3.toString());
    }
    
    try 
    {
    
      // Create inbox resource
    
      System.out.println("Adding inbox resource");
      InboxResourceDefinition iDef = new InboxResourceDefinition();
          
      iDef.setName("My Inbox");          
      iDef.setEmailInboundPolicy("NONE");
      iDef.setEmailSubscriptionFormat(
        "My message posted to <a href='${inbox-url}'>Inbox</a> " +
        "in workspace <a href='${workspace-url}'>" +
        "${workspace-display-name}</a>)</p><BR>${msg-body}" +
        "<BR><a href='${workspaces-home-url}'>");
      iDef.setEmailSubscriptionPolicy("disabled");
      szWorkspacesService.createEmailResource(szWorkspaceID, iDef);
      System.out.println("Added inbox resource");
    } catch (CwWSException e4) 
    {
      System.out.println("CwWSException caught while adding " +
        "inbox resource: "
        + e4.getErrorMessage());
    } catch (RemoteException re4) {
      System.out.println("RemoteException caught while adding " +
        "inbox resource: "
        + re4.toString());
    }
  }
  
  public static Member[] addMembersToWorkspace(
    WorkspacesService szWorkspacesService,
    String szWorkspaceID,
    User[] szUsersToBeAdded,
    String[] szRoles) throws CwWSException, RemoteException
  {
    int numberOfUsers = szUsersToBeAdded.length;
    Member[] myMembers = new Member[numberOfUsers];
 
    // Create a member from each user      
    for (int i = 0; i < numberOfUsers; i++) 
    {
      Member currentMember = new Member();
      currentMember.setMemberRoleType(szRoles);
      currentMember.setUser(szUsersToBeAdded[i]);
      myMembers[i] = currentMember;
    }
 
    // Add the members to the workspace
    szWorkspacesService.addMembers(szWorkspaceID, myMembers);
    System.out.println("Added members");
      
    return myMembers;
  }
 
  public static void main(String[] args)
  {
    try {
    
      // Get authentication cookie
      //
      // Ensure that the user has been provisioned for Oracle
      // Mail; Oracle Discussions requires this.
      
      AuthenticationService myAuthenticationService =
        AuthenticationSample.configureAuthenticationService(
          "rg4",
          "welcome1");
          
      String authCookie = AuthenticationSample.getAuthenticationCookie
        (myAuthenticationService);
        
      System.out.println("Retrieved authentication cookie : " + authCookie);
      
      // Get WorkspacesService and set authentication cookie
      WorkspacesService myWorkspacesService =
        WorkspacesServiceSample.configureWorkspacesService(authCookie);
      // Get UsersService and set authentication cookie
      UsersService myUsersService =
        UsersServiceSample.configureUsersService(authCookie);
      // Retrieve HomeService and set authentication cookie
      HomeService myHomeService =
        HomeServiceSample.configureHomeService(authCookie);
        
      // Create new workspace (or retrieve it if it already exists)
      WorkspaceItem myWorkspace =
        HomeServiceSample.createOrRetrieveWorkspace(
          myHomeService,
          "NewWorkspace",
          "My New Workspace",
          "Description of My New Workspace",
          "WRITER",
          "ENABLED");
          
      System.out.println("Retrieved or created workspace");
        
      // Retrieve Oracle Collaboration Suite users
      // from Oracle Internet Directory from
      // the specified group DN
      
      User[] myUsers = UsersServiceSample.getUsersFromGroupDN(
        myUsersService,
        "cn=raymond_group,cn=Groups,dc=us,dc=oracle,dc=com");
      
      System.out.println("Retrieved users");
      
      // Make the users members of the workspace and give each
      // of them writer role
      
      WorkspacesServiceSample.addMembersToWorkspace(
        myWorkspacesService,
        myWorkspace.getWorkspaceUid(),
        myUsers,
        new String[]{"WRITER"});
        
      System.out.println("Added members to the workspace");
      
      // Create resources
        
      WorkspacesServiceSample.createResources(
        myWorkspacesService,
        myWorkspace.getWorkspaceUid());
      
      System.out.println("Added resources");
        
      myAuthenticationService.logout();             
 
    } catch (CwWSException cwwse) 
    {
      System.out.println("CwWSException caught: " + cwwse.getMessage());
    } catch (Exception e) 
    {
      System.out.println("Exception caught: " + e.toString());
    }
  }
}