[jbpm-commits] JBoss JBPM SVN: r3908 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/cmd and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Feb 17 15:07:30 EST 2009


Author: tom.baeyens at jboss.com
Date: 2009-02-17 15:07:30 -0500 (Tue, 17 Feb 2009)
New Revision: 3908

Modified:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/TaskService.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/AddParticipant.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/RemoveParticipant.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/SwimlaneImpl.java
   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/TaskServiceImpl.java
   jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/task/TaskParticipationsTest.java
Log:
adding task participant removal and adding swimlane participants

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/TaskService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/TaskService.java	2009-02-17 17:21:02 UTC (rev 3907)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/TaskService.java	2009-02-17 20:07:30 UTC (rev 3908)
@@ -23,9 +23,11 @@
 
 import java.util.List;
 
+import org.jbpm.task.GroupRef;
 import org.jbpm.task.IdentityRef;
 import org.jbpm.task.Participant;
 import org.jbpm.task.Task;
+import org.jbpm.task.UserRef;
 
 /**
  * Human task management facility.
@@ -56,7 +58,7 @@
   
 
   /** add a role to a given task.
-   * @param identityRef wither a new User(String) or a new Group(String)  
+   * @param identityRef wither a new {@link UserRef} or a new {@link GroupRef}  
    * @param participation specifies the kind of involvement of the participant 
    * in this task. see {@link Participant} for default constants. */
   void addTaskParticipant(long taskDbid, IdentityRef identityRef, String participation);
@@ -67,18 +69,27 @@
   
   /** removes a role to a given task.  Nothing happens (no exception) if 
    * the role does not exist.
-   * @param identityRef wither a new User(String) or a new Group(String)  
+   * @param identityRef wither a new {@link UserRef} or a new {@link GroupRef}  
    * @param participation specifies the kind of involvement of the participant 
    * in this task. see {@link Participant} for default constants. */
   void removeTaskParticipant(long taskDbid, IdentityRef identityRef, String participation);
   
-  /*
-  void addSwimlaneRole(long taskDbid, String refId, RoleType roleType, String role);
-  List<UserRole> getSwimlaneRoles(long taskDbid, RoleType roleType, String role);
-  void removeSwimlaneRole(long taskDbid, String refId, RoleType roleType, String userRoleType);
-  */
+  /** add a role from a given swimlane.
+   * @param identityRef wither a new {@link UserRef} or a new {@link GroupRef}  
+   * @param participation specifies the kind of involvement of the participant 
+   * in this swimlane. see {@link Participant} for default constants. */
+  void addSwimlaneParticipant(long szimlaneDbid, IdentityRef identityRef, String participation);
 
+  /** get roles related to a given swimlane. */
+  List<Participant> getSwimlaneParticipants(long szimlaneDbid);
 
+  /** remove a role from a given swimlane.
+   * @param identityRef wither a new {@link UserRef} or a new {@link GroupRef}  
+   * @param participation specifies the kind of involvement of the participant 
+   * in this swimlane. see {@link Participant} for default constants. */
+  void removeSwimlaneParticipant(long szimlaneDbid, IdentityRef identityRef, String participation);
+
+
   TaskQuery createTaskQuery();
 
   /** retrieves the personal task of the given user, which might be different 
@@ -90,5 +101,4 @@
    * The user id will be resolved to a set of candidate identities
    * by the identity spi. */
   List<Task> getGroupTaskList(String userId, int firstResult, int maxResults);
-
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/AddParticipant.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/AddParticipant.java	2009-02-17 17:21:02 UTC (rev 3907)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/AddParticipant.java	2009-02-17 20:07:30 UTC (rev 3908)
@@ -56,7 +56,7 @@
         throw new JbpmException("task "+taskDbid+" was not found");
       }
 
-      task.addRole(identityRef, participation);
+      task.addParticipant(identityRef, participation);
     }
 
     /*

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/RemoveParticipant.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/RemoveParticipant.java	2009-02-17 17:21:02 UTC (rev 3907)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/RemoveParticipant.java	2009-02-17 20:07:30 UTC (rev 3908)
@@ -21,8 +21,15 @@
  */
 package org.jbpm.pvm.internal.cmd;
 
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hibernate.Session;
+import org.jbpm.JbpmException;
 import org.jbpm.cmd.Command;
 import org.jbpm.env.Environment;
+import org.jbpm.pvm.internal.task.ParticipantImpl;
+import org.jbpm.pvm.internal.task.TaskImpl;
 import org.jbpm.task.IdentityRef;
 
 
@@ -46,6 +53,25 @@
   }
 
   public Object execute(Environment environment) throws Exception {
+    Session session = Environment.getFromCurrent(Session.class);
+    
+    
+    if (taskDbid!=null) {
+      TaskImpl task = (TaskImpl) session.get(TaskImpl.class, taskDbid);
+      if (task==null) {
+        throw new JbpmException("task "+taskDbid+" was not found");
+      }
+
+      Set<ParticipantImpl> participants = new HashSet<ParticipantImpl>(task.getParticipants());
+      for (ParticipantImpl participant : participants) {
+        if ( participant.getIdentityRef().equals(identityRef)
+             && participant.getParticipation().equals(participation)
+           ) {
+          task.removeParticipant(participant);
+        }
+      }
+    }
+    
     return null;
   }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/SwimlaneImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/SwimlaneImpl.java	2009-02-17 17:21:02 UTC (rev 3907)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/SwimlaneImpl.java	2009-02-17 20:07:30 UTC (rev 3908)
@@ -22,11 +22,13 @@
 package org.jbpm.pvm.internal.task;
 
 import java.io.Serializable;
-import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Set;
 
+import org.jbpm.JbpmException;
 import org.jbpm.pvm.internal.util.EqualsUtil;
+import org.jbpm.task.IdentityRef;
 import org.jbpm.task.Participant;
 import org.jbpm.task.Swimlane;
 
@@ -54,14 +56,43 @@
     this.assignee = assignee;
   }
 
-  // candidates ///////////////////////////////////////////////////////////////
+  // participants /////////////////////////////////////////////////////////////
 
-  public Collection<Participant> getParticipants() {
+  // participants /////////////////////////////////////////////////////////////
+  
+  public Set<ParticipantImpl> getParticipants() {
     if (participants==null) {
-      return Collections.EMPTY_LIST;
+      return Collections.emptySet();
     }
-    return (Collection)participants;
+    return participants;
   }
+
+  public Participant addParticipant(IdentityRef identityRef, String participation) {
+    if (identityRef==null) {
+      throw new JbpmException("identityRef is null");
+    }
+    if (participation==null) {
+      throw new JbpmException("participation is null");
+    }
+    ParticipantImpl participant = new ParticipantImpl(identityRef, participation);
+    participant.setSwimlane(this);
+    if (participants==null) {
+      participants = new HashSet<ParticipantImpl>();
+    }
+    participants.add(participant);
+    return participant;
+  }
+
+  public void removeParticipant(ParticipantImpl participant) {
+    if (participant==null) {
+      throw new JbpmException("participant is null");
+    }
+    if ( (participants!=null)
+         && (participants.remove(participant))
+       ) {
+      ((ParticipantImpl)participant).setSwimlane(null);
+    }
+  }
   
   // equals ///////////////////////////////////////////////////////////////////
   // hack to support comparing hibernate proxies against the real objects

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-02-17 17:21:02 UTC (rev 3907)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskImpl.java	2009-02-17 20:07:30 UTC (rev 3908)
@@ -138,7 +138,7 @@
     return null;
   }
 
-  // roles ////////////////////////////////////////////////////////////////////
+  // participants /////////////////////////////////////////////////////////////
   
   public Set<ParticipantImpl> getParticipants() {
     if (participants==null) {
@@ -147,7 +147,7 @@
     return participants;
   }
 
-  public Set<ParticipantImpl> getAllRoles() {
+  public Set<ParticipantImpl> getAllParticipants() {
     Set<ParticipantImpl> allRoles = null;
     if (participants!=null) {
       allRoles = new HashSet<ParticipantImpl>(participants);
@@ -160,27 +160,30 @@
     return allRoles;
   }
 
-  public Participant addRole(IdentityRef identityRef, String participation) {
+  public Participant addParticipant(IdentityRef identityRef, String participation) {
     if (identityRef==null) {
-      throw new JbpmException("identity is null");
+      throw new JbpmException("identityRef is null");
     }
-    ParticipantImpl role = new ParticipantImpl(identityRef, participation);
-    role.setTask(this);
+    if (participation==null) {
+      throw new JbpmException("participation is null");
+    }
+    ParticipantImpl participant = new ParticipantImpl(identityRef, participation);
+    participant.setTask(this);
     if (participants==null) {
       participants = new HashSet<ParticipantImpl>();
     }
-    participants.add(role);
-    return role;
+    participants.add(participant);
+    return participant;
   }
 
-  public void removeRole(ParticipantImpl role) {
-    if (role==null) {
-      throw new JbpmException("role is null");
+  public void removeParticipant(ParticipantImpl participant) {
+    if (participant==null) {
+      throw new JbpmException("participant is null");
     }
     if ( (participants!=null)
-         && (participants.remove(role))
+         && (participants.remove(participant))
        ) {
-      ((ParticipantImpl)role).setTask(null);
+      ((ParticipantImpl)participant).setTask(null);
     }
   }
   

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskServiceImpl.java	2009-02-17 17:21:02 UTC (rev 3907)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskServiceImpl.java	2009-02-17 20:07:30 UTC (rev 3908)
@@ -31,6 +31,7 @@
 import org.jbpm.pvm.internal.cmd.GetParticipants;
 import org.jbpm.pvm.internal.cmd.GetTaskCmd;
 import org.jbpm.pvm.internal.cmd.NewTaskCmd;
+import org.jbpm.pvm.internal.cmd.RemoveParticipant;
 import org.jbpm.pvm.internal.cmd.SaveTaskCmd;
 import org.jbpm.pvm.internal.cmd.SubmitTaskCmd;
 import org.jbpm.task.IdentityRef;
@@ -92,10 +93,21 @@
   }
 
   public void removeTaskParticipant(long taskDbid, IdentityRef identityRef, String participation) {
-    throw new UnsupportedOperationException();
-    // commandService.execute(new RemoveRole(taskDbid, identityType, identityId, roleName));
+    commandService.execute(new RemoveParticipant(taskDbid, null, identityRef, participation));
   }
 
+  public void addSwimlaneParticipant(long szimlaneDbid, IdentityRef identityRef, String participation) {
+    commandService.execute(new AddParticipant(null, szimlaneDbid, identityRef, participation));
+  }
+
+  public List<Participant> getSwimlaneParticipants(long szimlaneDbid) {
+    return commandService.execute(new GetParticipants(null, szimlaneDbid));
+  }
+
+  public void removeSwimlaneParticipant(long szimlaneDbid, IdentityRef identityRef, String participation) {
+    commandService.execute(new RemoveParticipant(null, szimlaneDbid, identityRef, participation));
+  }
+
   public List<Task> getPersonalTaskList(String assignee, int firstResult, int maxResults) {
     return createTaskQuery()
       .assignee(assignee)

Modified: jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/task/TaskParticipationsTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/task/TaskParticipationsTest.java	2009-02-17 17:21:02 UTC (rev 3907)
+++ jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/task/TaskParticipationsTest.java	2009-02-17 20:07:30 UTC (rev 3908)
@@ -69,8 +69,34 @@
     expectedIdentityRefs.add(new UserRef("joesmoe"));
 
     assertEquals(expectedIdentityRefs, candidateIdentityRefs);
+    
+    taskService.removeTaskParticipant(taskDbid, new UserRef("joesmoe"), Participant.OWNER);
+    taskService.removeTaskParticipant(taskDbid, new GroupRef("losers"), Participant.CANDIDATE);
+
+    
+    taskParticipants = taskService.getTaskParticipants(taskDbid);
+
+    candidateIdentityRefs = getIdentityRefs(taskParticipants, Participant.CANDIDATE);
+
+    expectedIdentityRefs = new HashSet<IdentityRef>();
+    expectedIdentityRefs.add(new UserRef("johndoe"));
+    expectedIdentityRefs.add(new UserRef("joesmoe"));
+    expectedIdentityRefs.add(new GroupRef("dummies"));
+
+    assertEquals(expectedIdentityRefs, candidateIdentityRefs);
+    
+    candidateIdentityRefs = getIdentityRefs(taskParticipants, Participant.OWNER);
+
+    expectedIdentityRefs = new HashSet<IdentityRef>();
+
+    assertEquals(expectedIdentityRefs, candidateIdentityRefs);
   }
 
+  public void testSwimlaneParticipants() {
+    
+  }
+
+    
   public Set<IdentityRef> getIdentityRefs(List<Participant> taskParticipants, String participation) {
     Set<IdentityRef> identityRefs = new HashSet<IdentityRef>();
     for (Participant participant: taskParticipants) {




More information about the jbpm-commits mailing list