Implementing Add Comments

This post is part of a series on building a custom worklist for BPM/SOA 11g.

We just have a Controller to add comments to a task, no View.  After adding comments to a task, we will return the user to the Task Details View for that task.  This controller will be called (invoked) from an HTML FORM on the Task Details View, as we saw in the last post.

Here is the code for the Add Comments Controller, com.oracle.ateam.AddCommentsController, I left some of the comments in here, but there are more in the file in Subversion.

package com.oracle.ateam;

import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.oracle.ateam.util.MLog;
import com.oracle.ateam.domain.MTaskList;
import com.oracle.xmlns.bpmn.bpmnprocess.createtesttasks.CreateTestTasksPortType;
import com.oracle.xmlns.bpmn.bpmnprocess.createtesttasks.CreateTestTasksService;

public class AddCommentController extends SimpleSuccessFailureController {

  @Override  protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    MLog.log("AddCommentController", "Entering handleInternalRequest()");

    // retrieve details from the request to identify the task and comment
    String taskNumber = request.getParameter("x_tasknumber");
    String comment = request.getParameter("x_comment");

    // check that data was provided
    if ((taskNumber == null) || (comment == null))
       return (new TaskDetailController()).handleRequest(request, response);

    // add the comment to the task
    MTaskList.addComment(request.getRemoteUser(), taskNumber, comment);

    // send the user back to the task detail page (where they came from)
    return (new TaskDetailController()).handleRequest(request, response);
  }
}

This Controller follows the same pattern as the others we have seen already: retrieve information that the caller placed in the request, in this case the x_tasknumber to identify the task and x_comment with the text of the new comment, check we have valid data, then call a method on our MTaskList object, in this case addComment(), to carry out the ‘business logic’, and then forward the user to the next view, in this case to the TaskDetailController.

Spring provides us with the ability to chain Controllers together like this, so that a user request can in fact pass through several Controllers to be handled.

That’s all for the Add Comment Controller!

In the next post, we will the Controller to process actions on a task.

About Mark Nelson

Mark Nelson is a Developer Evangelist at Oracle, focusing on microservices and messaging. Before this role, Mark was an Architect in the Enterprise Cloud-Native Java Team, the Verrazzano Enterprise Container Platform project, worked on Wercker, WebLogic and was a senior member of the A-Team since 2010, and worked in Sales Consulting at Oracle since 2006 and various roles at IBM since 1994.
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

1 Response to Implementing Add Comments

  1. Pingback: Implementing Add Comments

Leave a comment