[jbpm-commits] JBoss JBPM SVN: r4391 - in jbpm4/trunk/modules: examples/src/test/java/org/jbpm/examples/task/candidates and 8 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Apr 2 08:34:29 EDT 2009


Author: tom.baeyens at jboss.com
Date: 2009-04-02 08:34:28 -0400 (Thu, 02 Apr 2009)
New Revision: 4391

Removed:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/mgmt/
Modified:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/TaskService.java
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/task/candidates/TaskCandidatesTest.java
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/task/swimlane/TaskSwimlaneTest.java
   jbpm4/trunk/modules/integration/console/src/main/java/org/jbpm/integration/console/TaskManagementImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/AssignTaskCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/TaskServiceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskImpl.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskCandidatesTest.java
   jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch04-Services.xml
Log:
introduce separate task take method

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/TaskService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/TaskService.java	2009-04-02 12:01:33 UTC (rev 4390)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/TaskService.java	2009-04-02 12:34:28 UTC (rev 4391)
@@ -62,6 +62,11 @@
   /** assigns this task to the given assignee. */
   void assignTask(long taskDbid, String userId);
 
+  /** taking this task will prevent all other candidates from 
+   * taking and working on this task. 
+   * @throws JbpmException if this task already has been taken. */
+  void takeTask(long taskDbid, String userId);
+
   /** Deletes this task, marks the related history task as completed.
    * If the task was created in the context 
    * of a process execution, this operation may result in a process instance 

Modified: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/task/candidates/TaskCandidatesTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/task/candidates/TaskCandidatesTest.java	2009-04-02 12:01:33 UTC (rev 4390)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/task/candidates/TaskCandidatesTest.java	2009-04-02 12:34:28 UTC (rev 4391)
@@ -78,7 +78,7 @@
     assertEquals(0, taskList.size());
 
     // lets assume that johndoe takes the task
-    taskService.assignTask(task.getDbid(), "johndoe");
+    taskService.takeTask(task.getDbid(), "johndoe");
 
     // johndoe's and joesmoe's takable task list is now empty  
     taskList = taskService.findTakableTasks("johndoe");

Modified: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/task/swimlane/TaskSwimlaneTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/task/swimlane/TaskSwimlaneTest.java	2009-04-02 12:01:33 UTC (rev 4390)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/task/swimlane/TaskSwimlaneTest.java	2009-04-02 12:34:28 UTC (rev 4391)
@@ -61,7 +61,7 @@
     assertEquals(0, taskService.findAssignedTasks("johndoe").size());
 
     // lets assume that johndoe takes the task
-    taskService.assignTask(taskDbid, "johndoe");
+    taskService.takeTask(taskDbid, "johndoe");
 
     // the next task will be created and assigned directly to johndoe
     // this is because johndoe was the person that took the previous task 

Modified: jbpm4/trunk/modules/integration/console/src/main/java/org/jbpm/integration/console/TaskManagementImpl.java
===================================================================
--- jbpm4/trunk/modules/integration/console/src/main/java/org/jbpm/integration/console/TaskManagementImpl.java	2009-04-02 12:01:33 UTC (rev 4390)
+++ jbpm4/trunk/modules/integration/console/src/main/java/org/jbpm/integration/console/TaskManagementImpl.java	2009-04-02 12:34:28 UTC (rev 4391)
@@ -21,16 +21,17 @@
  */
 package org.jbpm.integration.console;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.bpm.console.client.model.TaskRef;
 import org.jboss.bpm.console.server.integration.TaskManagement;
-import org.jboss.bpm.console.client.model.TaskRef;
+import org.jbpm.IdentityService;
 import org.jbpm.TaskService;
-import org.jbpm.IdentityService;
-import org.jbpm.identity.Group;
-import org.jbpm.task.*;
+import org.jbpm.task.GroupRef;
+import org.jbpm.task.Participation;
+import org.jbpm.task.Task;
 
-import java.util.List;
-import java.util.ArrayList;
-
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
  */
@@ -98,6 +99,12 @@
     return ModelAdaptor.adoptTask(t0);
   }
 
+  public void takeTask(long taskId, String idRef)
+  {
+    TaskService taskService = this.processEngine.get(TaskService.class);
+    taskService.takeTask(taskId, idRef);
+  }
+
   public void assignTask(long taskId, String idRef)
   {
     TaskService taskService = this.processEngine.get(TaskService.class);
@@ -122,5 +129,4 @@
     TaskService taskService = this.processEngine.get(TaskService.class);
     taskService.completeTask(taskId);
   }
-
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/AssignTaskCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/AssignTaskCmd.java	2009-04-02 12:01:33 UTC (rev 4390)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/AssignTaskCmd.java	2009-04-02 12:34:28 UTC (rev 4391)
@@ -36,19 +36,30 @@
   
   protected long taskDbid;
   protected String userId;
+  protected boolean take;
 
   public AssignTaskCmd(long taskDbid, String userId) {
     this.taskDbid = taskDbid;
     this.userId = userId;
   }
 
+  public AssignTaskCmd(long taskDbid, String userId, boolean take) {
+    this.taskDbid = taskDbid;
+    this.userId = userId;
+    this.take = take;
+  }
+
   public Void execute(Environment environment) {
     TaskDbSession taskDbession = environment.get(TaskDbSession.class);
     TaskImpl task = (TaskImpl) taskDbession.findTaskByDbid(taskDbid);
     if (task==null) {
       throw new JbpmException("task "+taskDbid+" does not exist");
     }
-    task.setAssignee(userId, true);
+    if (take) {
+      task.take(userId);
+    } else {
+      task.setAssignee(userId, true);
+    }
     return null;
   }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/TaskServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/TaskServiceImpl.java	2009-04-02 12:01:33 UTC (rev 4390)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/TaskServiceImpl.java	2009-04-02 12:34:28 UTC (rev 4391)
@@ -41,29 +41,23 @@
 public class TaskServiceImpl extends AbstractServiceImpl implements TaskService {
 
   public Task newTask() {
-    NewTaskCmd cmd = new NewTaskCmd(null);
-    addTxWireObjects(cmd);
-    return commandService.execute(cmd);
+    return commandService.execute(new NewTaskCmd(null));
   }
 
   public Task getTask(long taskDbid) {
-    GetTaskCmd cmd = new GetTaskCmd(taskDbid);
-    return commandService.execute(cmd);
+    return commandService.execute(new GetTaskCmd(taskDbid));
   }
 
   public long saveTask(Task task) {
-    SaveTaskCmd cmd = new SaveTaskCmd((TaskImpl) task);
-    return commandService.execute(cmd);
+    return commandService.execute(new SaveTaskCmd((TaskImpl) task));
   }
 
   public void cancelTask(long taskDbid) {
-    CancelTaskCmd cmd = new CancelTaskCmd(taskDbid);
-    commandService.execute(cmd);
+    commandService.execute(new CancelTaskCmd(taskDbid));
   }
 
   public void cancelTask(long taskDbid, String reason) {
-    CancelTaskCmd cmd = new CancelTaskCmd(taskDbid, reason);
-    commandService.execute(cmd);
+    commandService.execute(new CancelTaskCmd(taskDbid, reason));
   }
 
   public void completeTask(long taskDbid) {
@@ -71,8 +65,7 @@
   }
 
   public void completeTask(long taskDbid, String outcome) {
-    CompleteTaskCmd cmd = new CompleteTaskCmd(taskDbid, outcome);
-    commandService.execute(cmd);
+    commandService.execute(new CompleteTaskCmd(taskDbid, outcome));
   }
 
   public void addTaskParticipatingUser(long taskDbid, String userId, String participation) {
@@ -116,41 +109,37 @@
   }
 
   public List<Task> getSubTasks(long taskDbid) {
-    GetSubTasksCmd cmd = new GetSubTasksCmd(taskDbid);
-    return commandService.execute(cmd);
+    return commandService.execute(new GetSubTasksCmd(taskDbid));
   }
 
   public Task newTask(long parentTaskDbid) {
-    NewTaskCmd cmd = new NewTaskCmd(parentTaskDbid);
-    return commandService.execute(cmd);
+    return commandService.execute(new NewTaskCmd(parentTaskDbid));
   }
 
   public Comment addTaskComment(long taskDbid, String message) {
-    AddTaskCommentCmd cmd = new AddTaskCommentCmd(taskDbid, message);
-    return commandService.execute(cmd);
+    return commandService.execute(new AddTaskCommentCmd(taskDbid, message));
   }
 
   public List<Comment> getTaskComments(long taskDbid) {
-    GetTaskCommentsCmd cmd = new GetTaskCommentsCmd(taskDbid);
-    return commandService.execute(cmd);
+    return commandService.execute(new GetTaskCommentsCmd(taskDbid));
   }
 
   public void deleteComment(long commentDbid) {
-    DeleteCommentCmd cmd = new DeleteCommentCmd(commentDbid);
-    commandService.execute(cmd);
+    commandService.execute(new DeleteCommentCmd(commentDbid));
   }
 
   public Comment addReplyComment(long commentDbid, String message) {
-    AddReplyCommentCmd cmd = new AddReplyCommentCmd(commentDbid, message);
-    return commandService.execute(cmd);
+    return commandService.execute(new AddReplyCommentCmd(commentDbid, message));
   }
 
   public void assignTask(long taskDbid, String userId) {
-    AssignTaskCmd cmd = new AssignTaskCmd(taskDbid, userId);
-    addTxWireObjects(cmd);
-    commandService.execute(cmd);
+    commandService.execute(new AssignTaskCmd(taskDbid, userId));
   }
 
+  public void takeTask(long taskDbid, String userId) {
+    commandService.execute(new AssignTaskCmd(taskDbid, userId, true));
+  }
+
   public Object getVariable(long taskDbid, String variableName) {
     Set<String> variableNames = new HashSet<String>();
     variableNames.add(variableName);

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskImpl.java	2009-04-02 12:01:33 UTC (rev 4390)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskImpl.java	2009-04-02 12:34:28 UTC (rev 4391)
@@ -109,12 +109,19 @@
   
   // assignment ///////////////////////////////////////////////////////////////
   
-  public void setAssignee(String assignee) {
-    this.assignee = assignee;
+  public void take(String userId) {
+    if (assignee!=null) {
+      throw new JbpmException("task already taken by "+this.assignee);
+    }
+    setAssignee(userId, true);
   }
+  
+  public void setAssignee(String userId) {
+    this.assignee = userId;
+  }
 
-  public void setAssignee(String assignee, boolean propagateToSwimlane) {
-    this.assignee = assignee;
+  public void setAssignee(String userId, boolean propagateToSwimlane) {
+    this.assignee = userId;
     if (propagateToSwimlane) {
       propagateAssigneeToSwimlane();
     }

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskCandidatesTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskCandidatesTest.java	2009-04-02 12:01:33 UTC (rev 4390)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskCandidatesTest.java	2009-04-02 12:34:28 UTC (rev 4391)
@@ -26,6 +26,7 @@
 import java.util.Map;
 
 import org.jbpm.Execution;
+import org.jbpm.JbpmException;
 import org.jbpm.task.Task;
 import org.jbpm.test.JbpmTestCase;
 
@@ -72,7 +73,7 @@
     assertEquals(0, taskList.size());
 
     // lets assume that johndoe takes the task
-    taskService.assignTask(task.getDbid(), "johndoe");
+    taskService.takeTask(task.getDbid(), "johndoe");
     
     // johndoe's and joesmoe's takable task list is now empty  
     taskList = taskService.findTakableTasks("johndoe");
@@ -144,7 +145,7 @@
     assertEquals(0, taskList.size());
 
     // lets assume that johndoe takes the task
-    taskService.assignTask(task.getDbid(), "johndoe");
+    taskService.takeTask(task.getDbid(), "johndoe");
     
     // johndoe's and joesmoe's takable task list is now empty  
     taskList = taskService.findTakableTasks("johndoe");
@@ -175,4 +176,33 @@
     execution = executionService.findExecution(executionId);
     assertEquals("wait", execution.getActivityName());
   }
+
+  public void testDoubleTake() {
+    deployJpdlXmlString(
+      "<process name='DoubleTake'>" +
+      "  <start>" +
+      "    <transition to='review' />" +
+      "  </start>" +
+      "  <task name='review' " +
+      "        candidate-users='johndoe, joesmoe'>" +
+      "    <transition to='wait' />" +
+      "  </task>" +
+      "  <state name='wait'/>" +
+      "</process>"
+    );
+    
+    Execution execution = executionService.startProcessInstanceByKey("DoubleTake");
+    String executionId = execution.getId();
+    
+    // both johndoe and joesmoe will see the task in their *takable* task list 
+    long taskDbid = taskService.findTakableTasks("johndoe").get(0).getDbid();
+
+    taskService.takeTask(taskDbid, "johndoe");
+
+    try {
+      taskService.takeTask(taskDbid, "joesmoe");
+    } catch (JbpmException e) {
+      assertTextPresent("task already taken by johndoe", e.getMessage());
+    }
+  }
 }

Modified: jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch04-Services.xml
===================================================================
--- jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch04-Services.xml	2009-04-02 12:01:33 UTC (rev 4390)
+++ jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch04-Services.xml	2009-04-02 12:34:28 UTC (rev 4391)
@@ -305,12 +305,50 @@
 
   <section id="taskservice">
     <title>TaskService</title>
-    <para></para>
+    <para>The primary purpose of the TaskService is to provide access to 
+    task lists.  The code sample will show how to get the task list for 
+    the user with id <literal>johndoe</literal>.  
+    </para>
+    <programlisting>List&lt;Task&gt; taskList = taskService.findAssignedTasks(&quot;johndoe&quot;);</programlisting>
+    <para>Typically tasks are associated with a form and displayed in some user 
+    interface.  The form needs to be able to read and write data related to the task.   
+    </para>
+    <programlisting>long taskDbid = task.getDbid();
+
+Set&lt;String&gt; variableNames = taskService.getVariableNames(taskDbid);
+variables = taskService.getVariables(taskDbid, variableNames);
+
+variables = new HashMap&lt;String, Object&gt;();
+variables.put(&quot;category&quot;, &quot;small&quot;);
+variables.put(&quot;lires&quot;, 923874893);
+taskService.setVariables(taskDbid, variables);</programlisting>
+    <para>and complete tasks</para>
+    <programlisting>taskService.completeTask(taskDbid);</programlisting>
+    <para>Tasks can also be offered to a set of candidates.  Candidates can be 
+    users or groups.  Users can take tasks for which they are a candidate.  Taking 
+    a task means that this user will be set as the assignee.  After that, other users 
+    will be blocked from taking the task.
+    </para>
+    <programlisting></programlisting>
+    <para>
+    People should not work on 
+    a task unless they are assigned to that task.  The user interface should display 
+    forms and allow users to complete tasks if they are assigned to it.
+    For unassigned tasks for which the user is a candidate, the only action that 
+    should be exposed is 'take'.  Since taking a task boiles down to setting the 
+    assignee to the current user, we didn't introduce a separate method for that.    
+    </para>
+    <para>More on tasks in <xref linkend="tasks" /> </para>
   </section>
 
+  <section id="historyservice">
+    <title>HistoryService</title>
+    <para>TODO</para>
+  </section>
+
   <section id="managementservice">
     <title>ManagementService</title>
-    <para></para>
+    <para>TODO</para>
   </section>
 
 </chapter>
\ No newline at end of file




More information about the jbpm-commits mailing list