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

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jul 6 21:56:59 EDT 2010


Author: rebody
Date: 2010-07-06 21:56:58 -0400 (Tue, 06 Jul 2010)
New Revision: 6469

Added:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/NewLineConditionExpressionTest.java
   jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/bpmn/newLineConditionExpression.bpmn.xml
Modified:
   jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
Log:
JBPM-2829 trim expr before evaluate.

Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java	2010-07-07 01:23:40 UTC (rev 6468)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java	2010-07-07 01:56:58 UTC (rev 6469)
@@ -71,6 +71,7 @@
  * @author Tom Baeyens
  * @author Bernd Ruecker (bernd.ruecker at camunda.com)
  * @author Joram Barrez
+ * @author Huisheng Xu
  */
 public class BpmnParser extends Parser {
 
@@ -85,10 +86,10 @@
   static BindingsParser bindingsParser = new BindingsParser();
 
   public BpmnParser() {
-    
+
     initialize(); // initialises underlying SAX parser
     parseBindings(); // initialises bindings
-    
+
     // Setting BPMN2 xsd schema
     List<String> schemaResources = new ArrayList<String>();
     schemaResources.add("BPMN20.xsd");
@@ -96,7 +97,7 @@
     schemaResources.add("DiagramInterchange.xsd");
     schemaResources.add("BpmnDi.xsd");
     setSchemaResources(schemaResources);
-    
+
   }
 
   public Object parseDocumentElement(Element documentElement, Parse parse) {
@@ -120,9 +121,9 @@
 
       String id = XmlUtil.attribute(processElement, "id", parse);
       String name = XmlUtil.attribute(processElement, "name");
-      
+
       if (id != null && !"".equals(id)) {
-        processDefinition.setName(id);        
+        processDefinition.setName(id);
       } else {
         parse.addProblem("Process has no or an empty id");
       }
@@ -138,9 +139,9 @@
       }
 
       parseResources((Element)processElement.getParentNode(), parse, processDefinition);
-      
+
       parseInterfaces((Element)processElement.getParentNode(), parse, processDefinition);
-      
+
       parseItemDefinitions((Element)processElement.getParentNode(), parse, processDefinition);
 
       parseMessages((Element)processElement.getParentNode(), parse, processDefinition);
@@ -240,11 +241,11 @@
         activity.setType(activityBinding.getTagName());
         activity.setName(id);
         activity.setDescription(name);
-        
+
         if (log.isDebugEnabled()) {
-          log.debug("Parsing Activity: " + name + "(id=" + id + ")");          
+          log.debug("Parsing Activity: " + name + "(id=" + id + ")");
         }
-        
+
         ActivityBehaviour activityBehaviour = (ActivityBehaviour) activityBinding.parse(nestedElement, parse, this);
         activity.setActivityBehaviour(activityBehaviour);
       } finally {
@@ -256,7 +257,7 @@
   public void parseSequenceFlow(Element element, Parse parse, BpmnProcessDefinition processDefinition) {
     List<Element> transitionElements = XmlUtil.elements(element, "sequenceFlow");
     for (Element transitionElement : transitionElements) {
-      
+
       // Parse attributes
       String transitionName = XmlUtil.attribute(transitionElement, "name");
       String transitionId = XmlUtil.attribute(transitionElement, "id", parse);
@@ -264,9 +265,9 @@
       String targetRef = XmlUtil.attribute(transitionElement, "targetRef", parse);
 
       if (log.isDebugEnabled()) {
-        log.debug(transitionId + ": " + sourceRef + " -> " + targetRef);        
+        log.debug(transitionId + ": " + sourceRef + " -> " + targetRef);
       }
-     
+
       // Create new outgoing transition on sourceActivity
       ActivityImpl sourceActivity = processDefinition.findActivity(sourceRef);
       TransitionImpl transition = null;
@@ -277,7 +278,7 @@
       } else {
         parse.addProblem("SourceRef " + sourceRef + " cannot be found");
       }
-      
+
       // Create incoming transition on targetActivity
       ActivityImpl destinationActivity = processDefinition.findActivity(targetRef);
       if (destinationActivity != null) {
@@ -327,19 +328,23 @@
         String expr = conditionElement.getTextContent();
         String lang = XmlUtil.attribute(conditionElement, "language");
         // TODO: add looking up the default language in the document under definitions if lang  is null.
-        
+
+        if (expr != null) {
+          expr = expr.trim();
+        }
+
         SequenceflowCondition condition = new SequenceflowCondition();
         condition.setExpression(expr);
         condition.setLanguage(lang);
         transition.setCondition(condition);
 
       } else {
-        parse.addProblem("Type of the conditionExpression on sequenceFlow with id=" + 
+        parse.addProblem("Type of the conditionExpression on sequenceFlow with id=" +
                 transitionId + " is of onsupported type 'bpmn:tExpression'", transitionElement);
       }
     }
   }
-  
+
   public void parseDefinition(Element documentElement, Parse parse) {
     parseImports(documentElement, parse);
   }
@@ -359,39 +364,39 @@
 
     return taskDefinition;
   }
-  
+
   /**
    * Parses a <timerEventDefinition> element:
    *    * sets dueDate if 'timeDate' is used
    *    * sets duedateDescription if a duration expression is used
    *    * set cronExpression if a cron expression is used
-   * 
+   *
    * @param timerEventDefinitionElement The XML element that defines the timer definition
    * @param activity The activity on which the timer definition must be created
    * @param eventId The id of the event on which the timer is defined
    */
   public TimerDefinitionImpl parseTimerEventDefinition(Element timerEventDefinitionElement, Parse parse, String eventId) {
-    
+
     Element timeDate = XmlUtil.element(timerEventDefinitionElement, "timeDate");
     Element timeCycle = XmlUtil.element(timerEventDefinitionElement, "timeCycle");
-    
+
     if ( (timeDate != null && timeCycle != null)
             || (timeDate == null && timeCycle == null) ) {
       parse.addProblem("timerEventDefinition for event '" + eventId +
               "' requires either a timeDate or a timeCycle definition (but not both)");
       return null;
     }
-    
+
     TimerDefinitionImpl timerDefinition = new TimerDefinitionImpl();
-    
+
     if (timeDate != null) {
       parseTimeDate(eventId, parse, timeDate, timerDefinition);
     }
-    
+
     if (timeCycle != null) {
       parseTimeCycle(eventId, parse, timeCycle, timerDefinition);
-    } 
-    
+    }
+
     return timerDefinition;
   }
 
@@ -406,11 +411,11 @@
       Date duedatetimeDate = dateFormat.parse(dueDateTime);
       timerDefinition.setDueDate(duedatetimeDate);
     } catch (ParseException e) {
-      parse.addProblem("couldn't parse timeDate '"+ dueDateTime 
+      parse.addProblem("couldn't parse timeDate '"+ dueDateTime
               + "' on intermediate catch timer event " + catchEventId, e);
     }
   }
-  
+
   protected void parseTimeCycle(String catchEventId, Parse parse, Element timeCycle, TimerDefinitionImpl timerDefinition) {
     String cycleExpression = timeCycle.getTextContent();
     if (Duration.isValidExpression(cycleExpression)) {
@@ -418,7 +423,7 @@
     } else if (CronExpression.isValidExpression(cycleExpression)) {
       timerDefinition.setCronExpression(cycleExpression);
     } else {
-      parse.addProblem("couldn't parse timeDate duration '"+ cycleExpression 
+      parse.addProblem("couldn't parse timeDate duration '"+ cycleExpression
               + "' on intermediate catch timer event " + catchEventId);
     }
   }
@@ -448,7 +453,7 @@
   }
 
   public void parseInterfaces(Element documentElement, Parse parse, BpmnProcessDefinition processDefinition) {
-    
+
     for (Element interfaceElement : XmlUtil.elements(documentElement, "interface")) {
       for (Element operationElement : XmlUtil.elements(interfaceElement, "operation")) {
         processDefinition.getOperations().put(XmlUtil.attribute(operationElement, "id"), operationElement);
@@ -475,5 +480,5 @@
   public void parseImports(Element documentElement, Parse parse) {
 
   }
-  
+
 }

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/NewLineConditionExpressionTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/NewLineConditionExpressionTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/NewLineConditionExpressionTest.java	2010-07-07 01:56:58 UTC (rev 6469)
@@ -0,0 +1,64 @@
+package org.jbpm.bpmn;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.TaskQuery;
+import org.jbpm.api.task.Task;
+import org.jbpm.bpmn.parser.BpmnParser;
+import org.jbpm.pvm.internal.xml.Problem;
+import org.jbpm.test.JbpmTestCase;
+
+
+public class NewLineConditionExpressionTest extends JbpmTestCase {
+  static BpmnParser bpmnParser = new BpmnParser();
+
+  public List<Problem> parse(String resource) {
+
+    List<Problem> problems = bpmnParser.createParse().setResource(resource).execute().getProblems();
+
+    return problems;
+  }
+
+  public void testNormalExecuteDecisionCondition() {
+
+    String deploymentId = repositoryService.createDeployment()
+      .addResourceFromClasspath("org/jbpm/bpmn/newLineConditionExpression.bpmn.xml").deploy();
+
+    try {
+      ProcessInstance pi = executionService.startProcessInstanceByKey("newLineConditionExpression");
+      String pid = pi.getId();
+
+      TaskQuery taskQuery = taskService.createTaskQuery();
+      List<Task> allTasks = taskQuery.list();
+
+      assertEquals(1, allTasks.size());
+      assertEquals("testTask1", allTasks.get(0).getActivityName());
+      taskService.completeTask(allTasks.get(0).getId());
+
+      allTasks = taskQuery.list();
+      assertEquals(1, allTasks.size());
+      assertEquals("testTask2", allTasks.get(0).getActivityName());
+
+      HashMap vars = new HashMap();
+      vars.put("bewertungen", 3);
+
+      taskService.completeTask(allTasks.get(0).getId(), vars);
+
+      allTasks = taskQuery.list();
+      assertEquals(1, allTasks.size());
+
+      taskService.completeTask(allTasks.get(0).getId());
+
+      // process instance should be ended
+      pi = executionService.findProcessInstanceById(pid);
+      assertNull(pi);
+
+    }
+    finally {
+      repositoryService.deleteDeploymentCascade(deploymentId);
+    }
+  }
+}

Added: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/bpmn/newLineConditionExpression.bpmn.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/bpmn/newLineConditionExpression.bpmn.xml	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/bpmn/newLineConditionExpression.bpmn.xml	2010-07-07 01:56:58 UTC (rev 6469)
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<definitions id="newLineConditionExpressionProcesses"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://schema.omg.org/spec/BPMN/2.0 BPMN20.xsd"
+    xmlns="http://schema.omg.org/spec/BPMN/2.0" typeLanguage="http://www.w3.org/2001/XMLSchema"
+    expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://vitras.com/rwar"
+    xmlns:jbpm="http://jbpm.org/bpmn2">
+
+    <process id="newLineConditionExpression" name="newLineConditionExpression">
+
+        <startEvent id="start" />
+
+        <sequenceFlow id="initial" name="toTestTask1" sourceRef="start"
+            targetRef="testTask1" />
+
+        <userTask id="testTask1" name="testTask1" implementation="other" />
+
+        <sequenceFlow id="toTestTask1" sourceRef="testTask1"
+            targetRef="testTask2" />
+
+        <userTask id="testTask2" name="testTask2" implementation="other" />
+
+        <sequenceFlow id="toExclusiveGateway1" sourceRef="testTask2"
+            targetRef="exclusiveGateway1" />
+
+        <exclusiveGateway id="exclusiveGateway1" name="exclusiveGateway1" />
+
+        <sequenceFlow id="toTestTask3" sourceRef="exclusiveGateway1"
+            targetRef="testTask3">
+            <conditionExpression xsi:type="tFormalExpression">${bewertungen&gt;2}
+            </conditionExpression>
+        </sequenceFlow>
+
+        <sequenceFlow id="toTestTask1Again" sourceRef="exclusiveGateway1"
+            targetRef="testTask1" />
+
+        <userTask id="testTask3" name="TestTask3" implementation="other" />
+
+        <sequenceFlow id="toEnd" name="to End" sourceRef="testTask3"
+            targetRef="ende" />
+
+        <endEvent id="ende" name="Ende" />
+
+    </process>
+</definitions>



More information about the jbpm-commits mailing list