[jbpm-commits] JBoss JBPM SVN: r6598 - in jbpm4/trunk/modules: test-db/src/test/java/org/jbpm/test and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Aug 16 04:12:41 EDT 2010


Author: rebody
Date: 2010-08-16 04:12:40 -0400 (Mon, 16 Aug 2010)
New Revision: 6598

Added:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/authenticateduser/
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/authenticateduser/AuthenticatedUserExprTest.java
Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmConstantsElResolver.java
Log:
JBPM-2870 expose environment to expression, so we could get authenticatedUserId directly.

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmConstantsElResolver.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmConstantsElResolver.java	2010-08-16 08:03:48 UTC (rev 6597)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmConstantsElResolver.java	2010-08-16 08:12:40 UTC (rev 6598)
@@ -27,6 +27,7 @@
 import javax.el.ELContext;
 import javax.el.ELResolver;
 
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
 import org.jbpm.pvm.internal.model.ScopeInstanceImpl;
 import org.jbpm.pvm.internal.task.TaskImpl;
@@ -40,16 +41,17 @@
   private static final String NAME_EXECUTION = "execution";
   private static final String NAME_PROCESSINSTANCE = "processInstance";
   private static final String NAME_TASK = "task";
+  private static final String NAME_ENVIRONMENT = "environment";
 
   ExecutionImpl execution;
   ExecutionImpl processInstance;
   TaskImpl task;
-  
+
   public JbpmConstantsElResolver(ScopeInstanceImpl scopeInstance) {
     if (scopeInstance instanceof ExecutionImpl) {
       this.execution = (ExecutionImpl) scopeInstance;
       this.processInstance = execution.getProcessInstance();
-      
+
     } else {
       this.task = (TaskImpl) scopeInstance;
       this.execution = task.getExecution();
@@ -58,29 +60,34 @@
       }
     }
   }
-  
+
   public Object getValue(ELContext context, Object base, Object property) {
     // this resolver only resolves top level variable names to execution variable names.
     // only handle if this is a top level variable
-    if (base==null) {
+    if (base == null) {
       // we assume a NPE-check for property is not needed
       // i don't think the next cast can go wrong.  can it?
       String name = (String) property;
 
-      if (execution!=null && NAME_EXECUTION.equals(name)) {
+      if (execution != null && NAME_EXECUTION.equals(name)) {
         context.setPropertyResolved(true);
         return execution;
       }
-        
-      if (processInstance!=null && NAME_PROCESSINSTANCE.equals(name)) {
+
+      if (processInstance != null && NAME_PROCESSINSTANCE.equals(name)) {
         context.setPropertyResolved(true);
         return processInstance;
       }
-        
-      if (task!=null && NAME_TASK.equals(name)) {
+
+      if (task != null && NAME_TASK.equals(name)) {
         context.setPropertyResolved(true);
         return task;
       }
+
+      if (NAME_ENVIRONMENT.equals(name)) {
+        context.setPropertyResolved(true);
+        return EnvironmentImpl.getCurrent();
+      }
     }
 
     return null;
@@ -89,14 +96,15 @@
   public boolean isReadOnly(ELContext context, Object base, Object property) {
     // this resolver only resolves top level variable names to execution variable names.
     // only handle if this is a top level variable
-    if (base==null) {
+    if (base == null) {
       // we assume a NPE-check for property is not needed
       // i don't think the next cast can go wrong.  can it?
       String name = (String) property;
 
       if (NAME_EXECUTION.equals(name)
           || NAME_PROCESSINSTANCE.equals(name)
-          || NAME_TASK.equals(name)) {
+          || NAME_TASK.equals(name)
+          || NAME_ENVIRONMENT.equals(name)) {
         return true;
       }
     }

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/authenticateduser/AuthenticatedUserExprTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/authenticateduser/AuthenticatedUserExprTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/authenticateduser/AuthenticatedUserExprTest.java	2010-08-16 08:12:40 UTC (rev 6598)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test.activity.task;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.model.OpenExecution;
+import org.jbpm.api.task.Assignable;
+import org.jbpm.api.task.AssignmentHandler;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Huisheng Xu
+ */
+public class AuthenticatedUserExprTest extends JbpmTestCase {
+
+  public void testTaskAssignmentHandlerExpr() {
+    deployJpdlXmlString(
+      "<process name='AuthenticatedUser'>" +
+      "  <start>" +
+      "    <transition to='review' />" +
+      "  </start>" +
+      "  <task name='review' assignee='#{environment.authenticatedUserId}'>" +
+      "    <transition to='wait' />" +
+      "  </task>" +
+      "  <state name='wait'/>" +
+      "</process>"
+    );
+    processEngine.setAuthenticatedUserId("johndoe");
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("AuthenticatedUser");
+
+    List<Task> taskList = taskService.findPersonalTasks("johndoe");
+    assertEquals("Expected a single task being created", 1, taskList.size());
+    Task task = taskList.get(0);
+    assertEquals("review", task.getName());
+  }
+}



More information about the jbpm-commits mailing list