Adding Collaboration Services Using the AquaLogic User Interaction Development Kit
Pages: 1, 2, 3

Portlet Code: Using the IDK Collaboration API

Let's now look at some portlet code. For the setup you'll need: Plumtree Portal 5.0.2, EDK 5.1, Collaboration 4.0, .NET Framework 1.1, and .NET Web Controls 2.1. The versions listed here are the minimum requirement. You can use newer versions as well. We'll be using C# in this example.

Obtaining the Collaboration factory and managers

To begin any development using the Collaboration remote API, you'll need to establish a remote session with the portal and obtain an IRemoteSession. From an IRemoteSession, you can then retrieve an ICollaborationFactory, which is a factory class for obtaining various Collaboration object managers. The managers are used to manipulate and manage the different kinds of collaboration objects.

This code sets up the portlet context, retrieves an IRemoteSession from the context, and initializes the various Collaboration managers that are needed to run this portlet:

// Retrieve the Portlet Context and Remote Session objects
IPortletContext portletContext = 
    PortletContextFactory.CreatePortletContext(Request, Response);
remoteSession = portletContext.GetRemotePortalSession();

// Initialize the different Collaboration managers
collabFactory = remoteSession.GetCollaborationFactory();
projectManager = collabFactory.GetProjectManager();
tasklistManager = collabFactory.GetTaskListManager();
discussionManager = collabFactory.GetDiscussionManager();

// Helper to retrieve an existing project or to populate a project
// with sample tasks and their corresponding discussions
sampleProject = GetSampleProject();

// Initialize the DataTable for the Task DataGrid
TaskTableData = new DataTable();

// Method to populate the Task Tree to generate 
// the Assignment Page
CreateTree(sampleProject);

Getting a collaboration project

As mentioned previously, all Collaboration projects exist inside the context of a project, therefore, in order to use any of the Collaboration features, you'll first need to create a Project. In this example, I use a sample project called PROJECT_NAME to house all the Collaboration objects that I am going to create.

The GetSampleProject() method below does one of two things: it create a new project and populates the project with appropriate content (such as a task list, or tasks and their corresponding discussions), or it retrieves an existing project. You want to create only a new project once and then reuse the same project from then on.

The following code illustrates how you can query projects with a ProjectFilter. The project filter allows you to optionally set a string as your search string, so you can query projects with names that contain the search string. If you do not provide a search string, then all projects will be returned. So in general, you should always set a search string to limit your results.

private IProject GetSampleProject()
{
  // First try to retrieve an existing project with the right name
  IProjectFilter projectFilter = 
          projectManager.CreateProjectFilter();
  projectFilter.NameSearchText = PROJECT_NAME;
  IProject[] sampleProjects =  
          projectManager.QueryProjects(projectFilter);
  IProject sampleProject = null;

  // Existing project(s) found, use the first one from the array.
  if (sampleProjects.Length > 0) {
    for (int i = 0; i < sampleProjects.Length; i++) {
       if  (PROJECT_NAME.Equals(sampleProjects[i].Name)) {
         sampleProject = sampleProjects[i];
         break;
       }
    }
  }
  // Otherwise create a new project and populate with content
  // (for example, task list, tasks, and their corresponding discussions)
  if (sampleProject == null)
    sampleProject = CreateAndPopulateSampleProject();
  return sampleProject;
}

Creating new projects

If no project with name PROJECT_NAME is found, the code will create a new project using the factory method IProjectManager.CreateProject(). The project created using this method is not yet persisted. You can set additional properties on the new project before persisting it with IProjectManager.Store():

private IProject CreateAndPopulateSampleProject() {
  IProject sampleProject = 
       projectManager.CreateProject(PROJECT_NAME, PROJECT_DESCRIPTION);
  sampleProject.SetStatus(ProjectStatuses.NotStarted);
  // Set additional properties on the project here
  sampleProject.Store();
}

Populating a task tree

Once a project is persisted, other collaboration objects can be created within that project. For this example, each question in the assignment can be represented as a separate task, and the sub-parts of a question can be represented as individual sub-tasks. This will allow us to build a tree structure to visualize the different tasks and sub-tasks once they are created, as shown in Figure 1.

The three helper methods below walk through the process and code on how to create, set properties for, and store a task list, a top-level task, and a sub-task, respectively.

1. Creating a task list

A task list is a grouping of tasks and their sub-tasks. The code below shows how to create a task list. The ITaskListManager.CreateTaskList() method creates a new task list that has not yet been persisted. You can set additional properties on the task list before persisting it with the Store() method.

public ITaskList CreateAndStoreTaskList(IProject project, String name, String description)
{
  ITaskList tasklist = tasklistManager.CreateTaskList(project, name, description);
  //Additional tasklist properties can be set before calling
  //Store(), such as security information.
  tasklist.Store();
  return tasklist;
}

2. Creating a top-level task

A task is like a "To Do" item that can be assigned to a user (not necessarily the same user who creates the task). A task can have one or more sub-tasks. Each of the sub-tasks can also have sub-tasks. You can easily access the tasks at different levels with the two task association methods provided in the APIs:

  • ITask.GetSubTasks() - Retrieves all sub-tasks of a task
  • ITask.GetParentTask() - Retrieves the parent task of a task

The code below shows how to create a top-level task with notes. You'll have to set a start time and end time upon task creation. Additional properties of the task should also be set before the task is persisted with the ITask.Store() method:

public ITask CreateAndStoreTopLevelTask(ITaskList tasklist, 
    String name, String description, DateTime startTime, 
    DateTime endTime, String notes) {
  ITask task = tasklist.CreateTask(name, description, startTime, endTime);
  //Additional task properties can be set before calling Store(),
  //such as notes, risk, status, and security information.
  task.Notes = notes;
  task.Store();
  return task;
}

3. Creating a sub-task

A sub-task is itself an ITask created from an existing ITask. The ITask.CreateSubTask() method is used to create a sub-task. Like a top-level task, a sub-task is created with a start time and end time, and can have other optional properties for ITask. This code sample shows how to create a sub-task from an existing task:

public ITask CreateAndStoreSubTask(ITask parentTask, String name, String description, DateTime startTime, DateTime endTime, String notes) {
  //CreateSubTask() will create a persisted task, so Store()
  //does not need to be called to persist the task unless
  // additional properties are set.
  ITask subtask = parentTask.CreateSubTask(name, description, startTime, endTime);
  subtask.Notes = notes;
  subtask.Store();
  return subtask;
}

Pages: 1, 2, 3

Next Page ยป