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

10 Tasks Service

The Tasks service allows you create, update, retrieve, list, and delete tasks and show which tasks are expired or unexpired.

Example: Create and Search for Tasks

The following sample creates three tasks of different start times (the first and second task have start times earlier than the third). The sample then searches for tasks that have start times within the first task's start time and the second task's start time. As a result, the third task will not appear in the search results.

Example 10-1 TasksServiceSample.java

package oracle.sample.workspaces.ws;
 
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.rpc.ServiceException;
import oracle.workspaces.ws.AuthenticationService;
import oracle.workspaces.ws.HomeService;
import oracle.workspaces.ws.TasksService;
import oracle.workspaces.ws.TasksServiceServiceLocator;
import oracle.workspaces.ws.TasksServiceSoapBindingStub;
import oracle.workspaces.ws.beans.TaskAssignee;
import oracle.workspaces.ws.beans.TaskDefinition;
import oracle.workspaces.ws.beans.TaskResourceItem;
import oracle.workspaces.ws.beans.WorkspaceItem;
import oracle.workspaces.ws.exceptions.CwWSException;
import org.apache.axis.transport.http.HTTPConstants;
 
public class TasksServiceSample 
{
  public static TasksService configureTasksService(
    String szAuthCookie) throws ServiceException 
  {
    TasksServiceServiceLocator tssl =
      new TasksServiceServiceLocator(); 
    TasksService tService = tssl.getTasksService();
    ((TasksServiceSoapBindingStub)tService).setMaintainSession(true);
    ((javax.xml.rpc.Stub)tService).
      _setProperty(HTTPConstants.HEADER_COOKIE,szAuthCookie);
    return tService;  
  }
  
  public static TaskResourceItem createTask(
    TasksService szTasksService,
    String szWorkspaceID,
    String szTaskName,
    String szTaskDesc,
    String szPriority,
    Calendar szStartTime,
    Calendar szEndTime,
    int szPercentComplete,
    String szUserNickname)
    throws RemoteException, CwWSException
  {
    TaskDefinition td1 = new TaskDefinition();
    td1.setName(szTaskName);
    td1.setDescription(szTaskDesc);
    td1.setStartTime(szStartTime);
    td1.setEndTime(szEndTime);
    td1.setPriority(szPriority);
    td1.setPercentComplete(szPercentComplete);
    TaskAssignee ta1  = new TaskAssignee();
    ta1.setAssignee(szUserNickname);
    td1.setAssigneeList(new TaskAssignee[]{ta1});
    
    return szTasksService.createTask(szWorkspaceID, td1);
  }
  
  public static TaskResourceItem[] outputTasksByDateRange(
    TasksService szTasksService,
    String szWorkspaceID,
    Calendar startDate,
    Calendar endDate) throws RemoteException, CwWSException
  {
    TaskResourceItem[] currentTasks = szTasksService.listTasksByRange(
      szWorkspaceID,
      startDate,
      endDate,
      true);
    
    if (currentTasks == null) 
    {
      System.out.println("No tasks found");
    } else {
      for (int i=0; i<currentTasks.length; i++) 
      {
        System.out.println("Task #" + i +
          ", Name: "+ currentTasks[i].getName());
      }
    }
    return currentTasks;
  }
  
  public static void main(String[] args)
  {
    String myUsername = "rg4";
    String myPassword = "welcome1";
    try {
      // Get authentication cookie
      
      AuthenticationService myAuthenticationService =
        AuthenticationSample.configureAuthenticationService(
          myUsername,
          myPassword);
          
      String authCookie = AuthenticationSample.getAuthenticationCookie
        (myAuthenticationService);
        
      System.out.println("Retrieved authentication cookie : " + authCookie);
      
      // Get TasksService and set authentication cookie
      TasksService myTasksService =
        TasksServiceSample.configureTasksService(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");
      
      // Create some tasks
      
      Calendar startTime1 = Calendar.getInstance();
      Calendar endTime1 = Calendar.getInstance();
      Calendar startTime2 = Calendar.getInstance();
      Calendar endTime2 = Calendar.getInstance();
      Calendar startTime3 = Calendar.getInstance();
      Calendar endTime3 = Calendar.getInstance();
    
      // Ignore seconds
    
      startTime1.set(Calendar.SECOND, 0);
      endTime1.set(Calendar.SECOND, 0);  
      startTime2.set(Calendar.SECOND, 0);
      endTime2.set(Calendar.SECOND, 0);  
      startTime3.set(Calendar.SECOND, 0);
      endTime3.set(Calendar.SECOND, 0);  
    
      endTime1.add(Calendar.HOUR_OF_DAY, 6);  
      endTime2.add(Calendar.HOUR_OF_DAY, 6);  
      endTime3.add(Calendar.HOUR_OF_DAY, 6);  
    
      startTime2.add(Calendar.DAY_OF_YEAR, 7); 
      endTime2.add(Calendar.DAY_OF_YEAR, 7);  
      startTime3.add(Calendar.DAY_OF_YEAR, 14);
      endTime3.add(Calendar.DAY_OF_YEAR, 14); 
 
      TasksServiceSample.createTask(
        myTasksService,
        myWorkspace.getWorkspaceUid(),
        "My first task",
        "My first task description",
        "PRIORITY_NORMAL",
        startTime1,
        endTime1,
        50,
        myUsername);
        
      System.out.println("Created first task");
 
      TasksServiceSample.createTask(
        myTasksService,
        myWorkspace.getWorkspaceUid(),
        "My second task",
        "My second task description",
        "PRIORITY_HIGH",
        startTime2,
        endTime2,
        25,
        myUsername);
        
      System.out.println("Created second task");        
      
      TasksServiceSample.createTask(
        myTasksService,
        myWorkspace.getWorkspaceUid(),
        "My third task",
        "My third task description",
        "PRIORITY_LOW",
        startTime3,
        endTime3,
        10,
        myUsername);
 
      System.out.println("Created third task");              
      
      // Retrieve tasks between the date range of
      // startTime1 and startTime2.
      // As a result, the third task will not
      // be retrieved.
      
      TasksServiceSample.outputTasksByDateRange(
        myTasksService,
        myWorkspace.getWorkspaceUid(),
        startTime1,
        startTime2);
        
      myAuthenticationService.logout();             
 
    } catch (CwWSException cwwse) 
    {
      System.out.println("CwWSException caught: " + cwwse.toString());
      cwwse.printStackTrace();
    } catch (Exception e) 
    {
      System.out.println("Exception caught: " + e.toString());
    }
  }
}