[jboss-svn-commits] JBL Code SVN: r24390 - in labs/jbossrules/trunk: drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/action and 8 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Dec 15 19:09:32 EST 2008
Author: KrisVerlaenen
Date: 2008-12-15 19:09:32 -0500 (Mon, 15 Dec 2008)
New Revision: 24390
Added:
labs/jbossrules/trunk/drools-process/drools-bam/src/test/java/org/drools/process/audit/WorkingMemoryDbLoggerTest.java
labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/TaskUtils.java
Modified:
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/action/ActionCompletionProcessor.java
labs/jbossrules/trunk/drools-process/drools-bam/.classpath
labs/jbossrules/trunk/drools-process/drools-bam/.project
labs/jbossrules/trunk/drools-process/drools-bam/pom.xml
labs/jbossrules/trunk/drools-process/drools-bam/src/main/resources/hibernate.cfg.xml
labs/jbossrules/trunk/drools-process/drools-bam/src/test/java/org/drools/process/audit/ProcessInstanceDbLogTest.java
labs/jbossrules/trunk/drools-process/drools-bam/src/test/resources/ruleflow.rf
labs/jbossrules/trunk/drools-process/drools-bam/src/test/resources/ruleflow2.rf
labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/JpdlParser.java
labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/JpdlProcessValidator.java
labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/core/JpdlProcess.java
labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/core/node/StartState.java
labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/ForkInstance.java
labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/JpdlNodeInstance.java
labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/StartStateInstance.java
labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/StateInstance.java
labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/TaskNodeInstance.java
Log:
- updated jPDL code
- updated BAM
JBRULES-1896: Support kcontext variable in rules and processes
- adding support in IDE
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -343,9 +343,11 @@
}
if (useDrools) {
javaTextWithParams.append( "org.drools.spi.KnowledgeHelper drools;" );
+ javaTextWithParams.append( "org.drools.runtime.rule.RuleContext kcontext;" );
}
if (useContext) {
javaTextWithParams.append( "org.drools.spi.ProcessContext context;" );
+ javaTextWithParams.append( "org.drools.runtime.process.ProcessContext kcontext;" );
}
javaTextWithParams.append( javaText );
String jtext = javaTextWithParams.toString();
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -25,6 +25,7 @@
import org.drools.lang.descr.GlobalDescr;
import org.drools.rule.builder.dialect.mvel.MVELConsequenceBuilder;
import org.drools.rule.builder.dialect.mvel.MVELDialect;
+import org.drools.runtime.rule.RuleContext;
import org.drools.spi.KnowledgeHelper;
import org.drools.util.asm.ClassFieldInspector;
import org.eclipse.jdt.core.CompletionProposal;
@@ -1210,6 +1211,8 @@
context.setInputs( params );
context.addInput( "drools",
KnowledgeHelper.class );
+ context.addInput( "kcontext",
+ RuleContext.class );
context.setCompiled( true );
return context;
}
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/action/ActionCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/action/ActionCompletionProcessor.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/action/ActionCompletionProcessor.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -82,7 +82,7 @@
String prefix = doc.get(startPart, documentOffset - startPart);
return "rule dummy "
+ (dialect == null ? "" : " dialect \"" + dialect + "\" ")
- + "\n when \n then \n org.drools.spi.ProcessContext context = null; \n " + prefix;
+ + "\n when \n then \n org.drools.spi.ProcessContext context = null; \n org.drools.runtime.process.ProcessContext kcontext = null; \n " + prefix;
}
public List<String> getImports() {
Modified: labs/jbossrules/trunk/drools-process/drools-bam/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-bam/.classpath 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-bam/.classpath 2008-12-16 00:09:32 UTC (rev 24390)
@@ -1,24 +1,33 @@
-<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/main/resources"/>
- <classpathentry kind="src" path="src/test/java"/>
- <classpathentry kind="src" path="src/test/resources"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
- <classpathentry combineaccessrules="false" kind="src" path="/drools-compiler"/>
- <classpathentry combineaccessrules="false" kind="src" path="/drools-core"/>
- <classpathentry kind="var" path="M2_REPO/antlr/antlr/2.7.6/antlr-2.7.6.jar"/>
- <classpathentry kind="var" path="M2_REPO/asm/asm/1.5.3/asm-1.5.3.jar"/>
- <classpathentry kind="var" path="M2_REPO/asm/asm-attrs/1.5.3/asm-attrs-1.5.3.jar"/>
- <classpathentry kind="var" path="M2_REPO/cglib/cglib/2.1_3/cglib-2.1_3.jar"/>
- <classpathentry kind="var" path="M2_REPO/commons-collections/commons-collections/2.1.1/commons-collections-2.1.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar"/>
- <classpathentry kind="var" path="M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/hibernate/hibernate/3.2.6.ga/hibernate-3.2.6.ga.jar"/>
- <classpathentry kind="var" path="M2_REPO/hsqldb/hsqldb/1.8.0.7/hsqldb-1.8.0.7.jar"/>
- <classpathentry kind="var" path="M2_REPO/javax/transaction/jta/1.1/jta-1.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
- <classpathentry combineaccessrules="false" kind="src" path="/drools-api"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
+ <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
+ <classpathentry kind="src" path="src/test/resources" output="target/test-classes" including="**" excluding="**/*.java"/>
+ <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var" path="M2_REPO/antlr/antlr/2.7.6/antlr-2.7.6.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/antlr/antlr-runtime/3.1.1/antlr-runtime-3.1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-collections/commons-collections/3.1/commons-collections-3.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.4.2.v_883_R34x/core-3.4.2.v_883_R34x.jar"/>
+ <classpathentry kind="var" path="M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/drools/drools-api/5.0.0.SNAPSHOT/drools-api-5.0.0.SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/drools/drools-compiler/5.0.0.SNAPSHOT/drools-compiler-5.0.0.SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/drools/drools-core/5.0.0.SNAPSHOT/drools-core-5.0.0.SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/hibernate/ejb3-persistence/1.0.2.GA/ejb3-persistence-1.0.2.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/h2database/h2/1.0.77/h2-1.0.77.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-library/1.1/hamcrest-library-1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/hibernate/hibernate-annotations/3.4.0.GA/hibernate-annotations-3.4.0.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/hibernate/hibernate-commons-annotations/3.1.0.GA/hibernate-commons-annotations-3.1.0.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/hibernate/hibernate-core/3.3.0.SP1/hibernate-core-3.3.0.SP1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/hibernate/hibernate-entitymanager/3.4.0.GA/hibernate-entitymanager-3.4.0.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.15/janino-2.5.15.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javassist/javassist/3.4.GA/javassist-3.4.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jmock/jmock/2.5.0.1/jmock-2.5.0.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/joda-time/joda-time/1.5.2/joda-time-1.5.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javax/transaction/jta/1.1/jta-1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mvel/mvel2/2.0.4-SNAPSHOT/mvel2-2.0.4-SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.5.2/slf4j-api-1.5.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-jdk14/1.5.2/slf4j-jdk14-1.5.2.jar"/>
+</classpath>
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-process/drools-bam/.project
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-bam/.project 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-bam/.project 2008-12-16 00:09:32 UTC (rev 24390)
@@ -1,17 +1,13 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>drools-bam</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+<projectDescription>
+ <name>drools-bam</name>
+ <comment>A rule production system</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-process/drools-bam/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-bam/pom.xml 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-bam/pom.xml 2008-12-16 00:09:32 UTC (rev 24390)
@@ -37,13 +37,28 @@
<version>3.4.0.GA</version>
</dependency>
- <!-- HSQLDB -->
+ <!-- H2 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.0.77</version>
+ <scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
+ <version>1.5.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.2</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
Modified: labs/jbossrules/trunk/drools-process/drools-bam/src/main/resources/hibernate.cfg.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-bam/src/main/resources/hibernate.cfg.xml 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-bam/src/main/resources/hibernate.cfg.xml 2008-12-16 00:09:32 UTC (rev 24390)
@@ -8,8 +8,9 @@
<session-factory>
<!-- Database connection settings -->
- <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
- <property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
+ <property name="connection.driver_class">org.h2.Driver</property>
+ <!--property name="connection.url">jdbc:h2:mem:mydb</property-->
+ <property name="connection.url">jdbc:h2:file:/NotBackedUp/data/mydb</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
@@ -17,7 +18,7 @@
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
- <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
+ <property name="dialect">org.hibernate.dialect.H2Dialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
@@ -29,7 +30,7 @@
<property name="show_sql">false</property>
<!-- Drop and re-create the database schema on startup -->
- <property name="hbm2ddl.auto">create</property>
+ <!-- property name="hbm2ddl.auto">create</property-->
<mapping resource="AuditLog.hbm.xml"/>
Modified: labs/jbossrules/trunk/drools-process/drools-bam/src/test/java/org/drools/process/audit/ProcessInstanceDbLogTest.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-bam/src/test/java/org/drools/process/audit/ProcessInstanceDbLogTest.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-bam/src/test/java/org/drools/process/audit/ProcessInstanceDbLogTest.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -6,8 +6,8 @@
public static final void main(String[] args) {
try {
System.out.println("Checking process instances for process 'com.sample.ruleflow'");
- for (Object result: ProcessInstanceDbLog.findProcessInstances("com.sample.ruleflow")) {
- System.out.println(result);
+ for (ProcessInstanceLog processInstance: ProcessInstanceDbLog.findProcessInstances("com.sample.ruleflow")) {
+ System.out.println(processInstance);
}
} catch (Throwable t) {
t.printStackTrace();
Added: labs/jbossrules/trunk/drools-process/drools-bam/src/test/java/org/drools/process/audit/WorkingMemoryDbLoggerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-bam/src/test/java/org/drools/process/audit/WorkingMemoryDbLoggerTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-bam/src/test/java/org/drools/process/audit/WorkingMemoryDbLoggerTest.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -0,0 +1,52 @@
+package org.drools.process.audit;
+
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.drools.RuleBase;
+import org.drools.RuleBaseFactory;
+import org.drools.StatefulSession;
+import org.drools.compiler.PackageBuilder;
+import org.drools.process.instance.impl.demo.SystemOutWorkItemHandler;
+import org.drools.rule.Package;
+
+public class WorkingMemoryDbLoggerTest extends TestCase {
+
+ public void testLogger() {
+ // load the process
+ RuleBase ruleBase = createKnowledgeBase();
+ // create a new session
+ StatefulSession session = ruleBase.newStatefulSession();
+ new WorkingMemoryDbLogger(session);
+ session.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
+
+ // start process instance
+ session.startProcess("com.sample.ruleflow");
+ session.startProcess("com.sample.ruleflow");
+
+ System.out.println("Checking process instances for process 'com.sample.ruleflow'");
+ List<ProcessInstanceLog> processInstances
+ = ProcessInstanceDbLog.findProcessInstances("com.sample.ruleflow");
+ for (Object result: processInstances) {
+ System.out.println(result);
+ }
+ assertEquals(2, processInstances.size());
+ }
+
+ private static RuleBase createKnowledgeBase() {
+ // create a builder
+ PackageBuilder builder = new PackageBuilder();
+ // load the process
+ Reader source = new InputStreamReader(
+ ProcessInstanceExecutor.class.getResourceAsStream("/ruleflow.rf"));
+ builder.addProcessFromXml(source);
+ // create the knowledge base
+ Package pkg = builder.getPackage();
+ RuleBase ruleBase = RuleBaseFactory.newRuleBase();
+ ruleBase.addPackage(pkg);
+ return ruleBase;
+ }
+}
Modified: labs/jbossrules/trunk/drools-process/drools-bam/src/test/resources/ruleflow.rf
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-bam/src/test/resources/ruleflow.rf 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-bam/src/test/resources/ruleflow.rf 2008-12-16 00:09:32 UTC (rev 24390)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<process xmlns="http://drools.org/drools-4.0/process"
+<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
- xs:schemaLocation="http://drools.org/drools-4.0/process drools-processes-4.0.xsd"
+ xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
type="RuleFlow" name="ruleflow" id="com.sample.ruleflow" package-name="org.drools.process.workflow" >
<header>
@@ -11,10 +11,19 @@
<start id="1" name="Start" />
<workItem id="2" name="Task" >
<work name="Human Task" >
- <parameter name="ActorId" type="org.drools.process.core.datatype.impl.type.StringDataType" />
- <parameter name="TaskName" type="org.drools.process.core.datatype.impl.type.StringDataType" >Task</parameter>
- <parameter name="Comment" type="org.drools.process.core.datatype.impl.type.StringDataType" />
- <parameter name="Priority" type="org.drools.process.core.datatype.impl.type.StringDataType" />
+ <parameter name="ActorId" >
+ <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
+ </parameter>
+ <parameter name="TaskName" >
+ <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
+ <value>Task</value>
+ </parameter>
+ <parameter name="Comment" >
+ <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
+ </parameter>
+ <parameter name="Priority" >
+ <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
+ </parameter>
</work>
</workItem>
<end id="3" name="End" />
Modified: labs/jbossrules/trunk/drools-process/drools-bam/src/test/resources/ruleflow2.rf
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-bam/src/test/resources/ruleflow2.rf 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-bam/src/test/resources/ruleflow2.rf 2008-12-16 00:09:32 UTC (rev 24390)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<process xmlns="http://drools.org/drools-4.0/process"
+<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
- xs:schemaLocation="http://drools.org/drools-4.0/process drools-processes-4.0.xsd"
+ xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
type="RuleFlow" name="ruleflow2" id="com.sample.ruleflow2" package-name="org.drools.process.workflow" >
<header>
@@ -11,10 +11,19 @@
<start id="1" name="Start" />
<workItem id="2" name="Task" >
<work name="Human Task" >
- <parameter name="ActorId" type="org.drools.process.core.datatype.impl.type.StringDataType" />
- <parameter name="TaskName" type="org.drools.process.core.datatype.impl.type.StringDataType" >Task</parameter>
- <parameter name="Comment" type="org.drools.process.core.datatype.impl.type.StringDataType" />
- <parameter name="Priority" type="org.drools.process.core.datatype.impl.type.StringDataType" />
+ <parameter name="ActorId" >
+ <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
+ </parameter>
+ <parameter name="TaskName" >
+ <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
+ <value>Task</value>
+ </parameter>
+ <parameter name="Comment" >
+ <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
+ </parameter>
+ <parameter name="Priority" >
+ <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
+ </parameter>
</work>
</workItem>
<end id="3" name="End" />
Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/JpdlParser.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/JpdlParser.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/JpdlParser.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -26,6 +26,7 @@
import org.drools.process.core.datatype.impl.type.StringDataType;
import org.drools.process.core.impl.ParameterDefinitionImpl;
import org.drools.process.core.validation.ProcessValidationError;
+import org.drools.process.instance.context.swimlane.SwimlaneContextInstance;
import org.drools.workflow.core.Node;
import org.jbpm.graph.def.Event;
import org.jbpm.graph.def.ExceptionHandler;
@@ -61,8 +62,8 @@
process.setId(processDefinition.getName());
process.setName(processDefinition.getName());
process.setPackageName("org.drools");
- SwimlaneContext swimlaneContext = new SwimlaneContext();
- process.addContext(swimlaneContext);
+ SwimlaneContext swimlaneContext = (SwimlaneContext)
+ process.getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
process.setDefaultContext(swimlaneContext);
org.jbpm.graph.def.Node startState = processDefinition.getStartState();
String startStateName = startState == null ? null : startState.getName();
@@ -73,7 +74,23 @@
for (org.jbpm.graph.def.Node jPDLnode: nodes) {
JpdlNode node = null;
if (jPDLnode instanceof org.jbpm.graph.node.StartState) {
- node = new StartState();
+ StartState newNode = new StartState();
+ Task task = processDefinition.getTaskMgmtDefinition().getStartTask();
+ if (task != null) {
+ newNode.setTask(task);
+ org.jbpm.taskmgmt.def.Swimlane jPDLswimlane = task.getSwimlane();
+ if (jPDLswimlane != null) {
+ String swimlaneName = jPDLswimlane.getName();
+ if (swimlaneContext.getSwimlane(swimlaneName) == null) {
+ Swimlane swimlane = new Swimlane();
+ swimlane.setName(swimlaneName);
+ swimlane.setActorId(jPDLswimlane.getActorIdExpression());
+ // TODO support other types of actor expressions as well
+ swimlaneContext.addSwimlane(swimlane);
+ }
+ }
+ }
+ node = newNode;
} else if (jPDLnode instanceof org.jbpm.graph.node.EndState) {
node = new EndState();
} else if (org.jbpm.graph.def.Node.class.equals(jPDLnode.getClass())) {
Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/JpdlProcessValidator.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/JpdlProcessValidator.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/JpdlProcessValidator.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -88,19 +88,21 @@
final Node node = nodes[i];
if (node instanceof StartState) {
final StartState startState = (StartState) node;
- if (startState.getOutgoingConnections().size() != 1) {
+ if (startState.getOutgoingConnections().size() == 0) {
errors.add(new ProcessValidationErrorImpl(process,
- "Start state '" + node.getName() + "' [" + node.getId() + "] has more than one type of outgoing connections."));
+ "Start state '" + node.getName() + "' [" + node.getId() + "] has no outgoing connections."));
}
- List<Connection> connections = startState.getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE);
- if (connections == null || connections.size() == 0) {
+ boolean outgoingConnection = false;
+ for (List<Connection> connections: startState.getOutgoingConnections().values()) {
+ if (connections.size() > 0) {
+ outgoingConnection = true;
+ break;
+ }
+ }
+ if (!outgoingConnection) {
errors.add(new ProcessValidationErrorImpl(process,
- "Start state '" + node.getName() + "' [" + node.getId() + "] has no default outgoing connections."));
+ "Start state '" + node.getName() + "' [" + node.getId() + "] has no outgoing connections."));
}
- if (connections.size() != 1) {
- errors.add(new ProcessValidationErrorImpl(process,
- "Start state '" + node.getName() + "' [" + node.getId() + "] has more than one default outgoing connection."));
- }
} else if (node instanceof EndState) {
final EndState endState = (EndState) node;
if (endState.getIncomingConnections().size() != 1) {
@@ -112,10 +114,6 @@
errors.add(new ProcessValidationErrorImpl(process,
"End state '" + node.getName() + "' [" + node.getId() + "] has no default incoming connections."));
}
- if (connections.size() != 1) {
- errors.add(new ProcessValidationErrorImpl(process,
- "End state '" + node.getName() + "' [" + node.getId() + "] has more than one default incoming connection."));
- }
} else if (node instanceof RuleSetNode) {
final RuleSetNode ruleSetNode = (RuleSetNode) node;
if (ruleSetNode.getFrom() == null) {
Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/core/JpdlProcess.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/core/JpdlProcess.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/core/JpdlProcess.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -2,6 +2,7 @@
import org.drools.definition.process.Node;
import org.drools.jpdl.core.node.StartState;
+import org.drools.process.core.context.swimlane.SwimlaneContext;
import org.drools.process.core.context.variable.VariableScope;
import org.drools.workflow.core.impl.WorkflowProcessImpl;
@@ -18,6 +19,9 @@
VariableScope variableScope = new VariableScope();
addContext(variableScope);
setDefaultContext(variableScope);
+ SwimlaneContext swimlaneContext = new SwimlaneContext();
+ addContext(swimlaneContext);
+ setDefaultContext(swimlaneContext);
}
public void setStartState(Node startState) {
Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/core/node/StartState.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/core/node/StartState.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/core/node/StartState.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -1,11 +1,22 @@
package org.drools.jpdl.core.node;
import org.drools.workflow.core.Connection;
+import org.jbpm.taskmgmt.def.Task;
-public class StartState extends JpdlNode {
+public class StartState extends State {
private static final long serialVersionUID = 1L;
+
+ private Task task;
+ public void setTask(Task task) {
+ this.task = task;
+ }
+
+ public Task getTask() {
+ return task;
+ }
+
public void validateAddIncomingConnection(final String type, final Connection connection) {
throw new UnsupportedOperationException(
"A start state does not have an incoming connection!");
@@ -15,5 +26,5 @@
throw new UnsupportedOperationException(
"A start state does not have an incoming connection!");
}
-
+
}
Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/ForkInstance.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/ForkInstance.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/ForkInstance.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -4,7 +4,7 @@
import java.util.Map;
import org.drools.jpdl.core.node.Fork;
-import org.drools.workflow.instance.NodeInstance;
+import org.drools.runtime.process.NodeInstance;
import org.jbpm.JbpmException;
import org.jbpm.graph.action.Script;
Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/JpdlNodeInstance.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/JpdlNodeInstance.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/JpdlNodeInstance.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -19,9 +19,11 @@
import org.drools.workflow.core.Node;
import org.drools.workflow.instance.NodeInstanceContainer;
import org.drools.workflow.instance.impl.NodeInstanceImpl;
+import org.drools.workflow.instance.node.EventBasedNodeInstanceInterface;
import org.jbpm.JbpmException;
import org.jbpm.calendar.BusinessCalendar;
import org.jbpm.calendar.Duration;
+import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.def.Action;
import org.jbpm.graph.def.DelegationException;
import org.jbpm.graph.def.Event;
@@ -34,7 +36,7 @@
import org.jbpm.scheduler.def.CancelTimerAction;
import org.jbpm.scheduler.def.CreateTimerAction;
-public class JpdlNodeInstance extends NodeInstanceImpl implements EventListener {
+public class JpdlNodeInstance extends NodeInstanceImpl implements EventBasedNodeInstanceInterface, EventListener {
private static final long serialVersionUID = 1L;
private static final BusinessCalendar BUSINESS_CALENDAR = new BusinessCalendar();
@@ -87,6 +89,7 @@
throw new JbpmException("transition '" + type
+ "' is not a leaving transition of node '" + this + "'");
}
+ removeEventListeners();
fireEvent(Event.EVENTTYPE_NODE_LEAVE);
((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
Event event = connection.getEvent(Event.EVENTTYPE_TRANSITION);
@@ -174,7 +177,7 @@
timer.setPeriod(period);
}
if (timerActions.isEmpty()) {
- registerTimerListener();
+ addTimerListener();
}
getProcessInstance().getWorkingMemory().getTimerManager()
.registerTimer(timer, getProcessInstance());
@@ -226,14 +229,6 @@
}
}
- public void registerTimerListener() {
- getProcessInstance().addEventListener("timerTriggered", this, false);
- }
-
- public void removeTimerListener() {
- getProcessInstance().removeEventListener("timerTriggered", this, false);
- }
-
public String[] getEventTypes() {
return new String[] { "timerTriggered" };
}
@@ -269,8 +264,21 @@
public Object getVariable(String name) {
VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
resolveContextInstance(VariableScope.VARIABLE_SCOPE, name);
+ if (variableScopeInstance == null) {
+ variableScopeInstance = (VariableScopeInstance)
+ ((ProcessInstance) JpdlNodeInstance.this.getProcessInstance())
+ .getContextInstance(VariableScope.VARIABLE_SCOPE);
+ }
return variableScopeInstance.getVariable(name);
}
+ public ContextInstance getContextInstance() {
+ ContextInstance contextInstance = new ContextInstance() {
+ public Object getVariable(String name) {
+ return JpdlExecutionContext.this.getVariable(name);
+ }
+ };
+ return contextInstance;
+ }
public ProcessInstance getDroolsProcessInstance() {
return JpdlNodeInstance.this.getProcessInstance();
}
@@ -282,4 +290,24 @@
}
}
+ public void addEventListeners() {
+ if (timers.size() > 0) {
+ addTimerListener();
+ }
+ }
+
+ public void addTimerListener() {
+ ((ProcessInstance) getProcessInstance()).addEventListener("timerTriggered", this, false);
+ }
+
+ public void removeEventListeners() {
+ if (timers.size() > 0) {
+ removeTimerListener();
+ }
+ }
+
+ public void removeTimerListener() {
+ ((ProcessInstance) getProcessInstance()).removeEventListener("timerTriggered", this, false);
+ }
+
}
Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/StartStateInstance.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/StartStateInstance.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/StartStateInstance.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -1,7 +1,124 @@
package org.drools.jpdl.instance.node;
-public class StartStateInstance extends JpdlNodeInstance {
+import org.drools.jpdl.core.node.StartState;
+import org.drools.process.core.context.swimlane.SwimlaneContext;
+import org.drools.process.instance.ProcessInstance;
+import org.drools.process.instance.WorkItem;
+import org.drools.process.instance.WorkItemManager;
+import org.drools.process.instance.context.swimlane.SwimlaneContextInstance;
+import org.drools.process.instance.impl.WorkItemImpl;
+import org.drools.runtime.process.NodeInstance;
+import org.jbpm.graph.def.Event;
+import org.jbpm.jpdl.el.impl.JbpmExpressionEvaluator;
+import org.jbpm.taskmgmt.def.Task;
+public class StartStateInstance extends StateInstance {
+
private static final long serialVersionUID = 1L;
+
+ private long workItemId = -1;
+ private transient WorkItem workItem;
+
+ public StartState getStartState() {
+ return (StartState) getJpdlNode();
+ }
+
+ public void execute(NodeInstance from, String type) {
+ super.execute(from, type);
+ Task task = getStartState().getTask();
+ if (task != null) {
+ if (evaluateTaskCondition(task.getCondition())) {
+ addWorkItemListener();
+ workItem = (WorkItemImpl) TaskUtils.createWorkItem(task, this);
+ getProcessInstance().getWorkingMemory()
+ .getWorkItemManager().internalExecuteWorkItem(workItem);
+ }
+ }
+ }
+ private boolean evaluateTaskCondition(String condition) {
+ if (condition == null) {
+ return true;
+ }
+ Object result = JbpmExpressionEvaluator.evaluate(
+ condition, new JpdlExecutionContext());
+ if (Boolean.TRUE.equals(result)) {
+ return true;
+ }
+ return false;
+ }
+
+ public WorkItem getWorkItem() {
+ if (workItem == null && workItemId >= 0) {
+ workItem = ((WorkItemManager) ((ProcessInstance) getProcessInstance())
+ .getWorkingMemory().getWorkItemManager()).getWorkItem(workItemId);
+ }
+ return workItem;
+ }
+
+ public void addEventListeners() {
+ super.addEventListeners();
+ addWorkItemListener();
+ }
+
+ private void addWorkItemListener() {
+ ((ProcessInstance) getProcessInstance()).addEventListener("workItemCompleted", this, false);
+ ((ProcessInstance) getProcessInstance()).addEventListener("workItemAborted", this, false);
+ }
+
+ public void removeEventListeners() {
+ super.removeEventListeners();
+ ((ProcessInstance) getProcessInstance()).removeEventListener("workItemCompleted", this, false);
+ ((ProcessInstance) getProcessInstance()).removeEventListener("workItemAborted", this, false);
+ }
+
+ public void signalEvent(String type, Object event) {
+ if ("workItemCompleted".equals(type)) {
+ workItemCompleted((WorkItem) event);
+ } else if ("workItemAborted".equals(type)) {
+ workItemAborted((WorkItem) event);
+ } else {
+ super.signalEvent(type, event);
+ }
+ }
+
+ public void workItemAborted(WorkItem workItem) {
+ if ( getWorkItem().getId() == workItem.getId() ) {
+ removeEventListeners();
+ leave();
+ }
+ }
+
+ public void workItemCompleted(WorkItem workItem) {
+ if ( getWorkItem().getId() == workItem.getId() ) {
+ removeEventListeners();
+ Task task = getStartState().getTask();
+ TaskUtils.restoreVariables((WorkItemImpl) workItem, task, this);
+ if (task.getSwimlane() != null) {
+ String swimlaneName = task.getSwimlane().getName();
+ SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance)
+ resolveContextInstance(SwimlaneContext.SWIMLANE_SCOPE, swimlaneName);
+ if (swimlaneContextInstance.getActorId(swimlaneName) == null) {
+ String actorId = (String) workItem.getResult("ActorId");
+ if (actorId != null) {
+ swimlaneContextInstance.setActorId(swimlaneName,
+ (String) workItem.getResult("ActorId"));
+ }
+ }
+ }
+ Event event = task.getEvent(Event.EVENTTYPE_TASK_END);
+ if (event != null) {
+ JpdlExecutionContext context = new JpdlExecutionContext();
+ context.setTask(task);
+ executeActions(event.getActions(), context);
+ }
+ String result = (String) workItem.getResult("Result");
+ if (result != null) {
+ leave(result);
+ } else {
+ leave();
+ }
+ }
+ }
+
}
Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/StateInstance.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/StateInstance.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/StateInstance.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -1,13 +1,39 @@
package org.drools.jpdl.instance.node;
-import org.drools.workflow.instance.NodeInstance;
+import org.drools.runtime.process.NodeInstance;
+import org.drools.workflow.instance.node.EventBasedNodeInstanceInterface;
-public class StateInstance extends JpdlNodeInstance {
+public class StateInstance extends JpdlNodeInstance implements EventBasedNodeInstanceInterface {
private static final long serialVersionUID = 1L;
public void execute(NodeInstance from, String type) {
// Do nothing
+ addSignalListener();
}
+ public void addEventListeners() {
+ addSignalListener();
+ }
+
+ private void addSignalListener() {
+ getProcessInstance().addEventListener("signal", this, false);
+ }
+
+ public void removeEventListeners() {
+ getProcessInstance().removeEventListener("signal", this, false);
+ }
+
+ public void signalEvent(String type, Object event) {
+ if ("signal".equals(type)) {
+ if (event instanceof String) {
+ leave((String) event);
+ } else {
+ leave();
+ }
+ } else {
+ super.signalEvent(type, event);
+ }
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/TaskNodeInstance.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/TaskNodeInstance.java 2008-12-16 00:05:10 UTC (rev 24389)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/TaskNodeInstance.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -1,32 +1,21 @@
package org.drools.jpdl.instance.node;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
import java.util.Set;
import org.drools.jpdl.core.node.TaskNode;
import org.drools.process.core.context.swimlane.SwimlaneContext;
-import org.drools.process.core.context.variable.VariableScope;
import org.drools.process.instance.ProcessInstance;
-import org.drools.process.instance.WorkItemListener;
-import org.drools.process.instance.WorkItemManager;
import org.drools.process.instance.context.swimlane.SwimlaneContextInstance;
-import org.drools.process.instance.context.variable.VariableScopeInstance;
import org.drools.process.instance.impl.WorkItemImpl;
import org.drools.runtime.process.NodeInstance;
import org.drools.runtime.process.WorkItem;
-import org.jbpm.JbpmException;
-import org.jbpm.calendar.BusinessCalendar;
-import org.jbpm.calendar.Duration;
-import org.jbpm.context.def.VariableAccess;
import org.jbpm.graph.def.Event;
-import org.jbpm.instantiation.Delegation;
import org.jbpm.jpdl.el.impl.JbpmExpressionEvaluator;
import org.jbpm.taskmgmt.def.Task;
-import org.jbpm.taskmgmt.def.TaskController;
-public class TaskNodeInstance extends JpdlNodeInstance implements WorkItemListener {
+public class TaskNodeInstance extends JpdlNodeInstance {
private static final long serialVersionUID = 1L;
@@ -42,46 +31,10 @@
addEventListeners();
for (Task task: tasks) {
if (evaluateTaskCondition(task.getCondition())) {
- WorkItemManager workItemManager = getProcessInstance().getWorkingMemory().getWorkItemManager();
- WorkItemImpl workItem = new WorkItemImpl();
- workItem.setName("JpdlTask");
- workItem.setProcessInstanceId(getProcessInstance().getId());
- workItem.setParameter("name", task.getName());
- String description = task.getDescription();
- workItem.setParameter("signalling", task.isSignalling());
- workItem.setParameter("blocking", task.isBlocking());
- if ((description != null) && (description.indexOf("#{") != -1)) {
- Object result = JbpmExpressionEvaluator.evaluate(
- description, new JpdlExecutionContext());
- if (result != null) {
- description = result.toString();
- }
- }
- workItem.setParameter("Description", description);
- initializeVariables(workItem, task);
- if (task.getDueDate() != null) {
- BusinessCalendar businessCalendar = new BusinessCalendar();
- workItem.setParameter("dueDate",
- businessCalendar.add(new Date(), new Duration(task.getDueDate())));
- }
- if (task.getSwimlane() != null) {
- String swimlaneName = task.getSwimlane().getName();
- SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance)
- resolveContextInstance(SwimlaneContext.SWIMLANE_SCOPE, swimlaneName);
- String actorId = swimlaneContextInstance.getActorId(swimlaneName);
- if (actorId == null) {
- actorId = assignTask(task);
- }
- workItem.setParameter("ActorId", actorId);
- }
+ WorkItemImpl workItem = (WorkItemImpl) TaskUtils.createWorkItem(task, this);
workItems.add(workItem);
- Event event = task.getEvent(Event.EVENTTYPE_TASK_CREATE);
- if (event != null) {
- // TODO this doesn't take event handlers of task itself
- // into account
- executeActions(event.getActions(), new JpdlTaskExecutionContext(task));
- }
- workItemManager.internalExecuteWorkItem(workItem);
+ getProcessInstance().getWorkingMemory()
+ .getWorkItemManager().internalExecuteWorkItem(workItem);
}
}
}
@@ -116,59 +69,6 @@
return false;
}
- private void initializeVariables(WorkItemImpl workItem, Task task) {
- TaskController taskController = task.getTaskController();
- if (taskController != null) {
- Delegation taskControllerDelegation = taskController.getTaskControllerDelegation();
- if (taskControllerDelegation != null) {
- // TODO: delegation (API mismatch!)
- } else {
- List<VariableAccess> variableAccesses = taskController.getVariableAccesses();
- if (variableAccesses != null) {
- for (VariableAccess variableAccess: variableAccesses) {
- String mappedName = variableAccess.getMappedName();
- if (variableAccess.isReadable()) {
- String variableName = variableAccess.getVariableName();
- VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
- resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
- Object value = variableScopeInstance.getVariable(variableName);
- workItem.setParameter(mappedName, value);
- }
- }
- }
- }
- }
- }
-
- private String assignTask(Task task) {
- Event event = task.getEvent(Event.EVENTTYPE_TASK_ASSIGN);
- if (event != null) {
- executeActions(event.getActions(), new JpdlTaskExecutionContext(task));
- }
- if (task.getActorIdExpression() != null) {
- return resolveActor(task.getActorIdExpression());
- } else if (task.getSwimlane().getActorIdExpression() != null) {
- return resolveActor(task.getSwimlane().getActorIdExpression());
- }
- // TODO support other assignment types
- return null;
- }
-
- private String resolveActor(String expression) {
- Object result = JbpmExpressionEvaluator.evaluate(expression, new JpdlExecutionContext());
- if (result == null) {
- throw new JbpmException("actor-id expression '" + expression + "' returned null");
- }
- if (result instanceof String) {
- return (String) result;
- } else {
- throw new JbpmException(
- "actor-id expression '" + expression +
- "' didn't resolve to a java.lang.String: '" + result +
- "' (" + result.getClass().getName() + ")");
- }
- }
-
private boolean hasSignallingWorkItems() {
for (WorkItem workItem: workItems) {
if ((Boolean) workItem.getParameter("signalling") == true) {
@@ -187,49 +87,6 @@
return false;
}
- private void restoreVariables(WorkItemImpl workItem, Task task) {
- TaskController taskController = task.getTaskController();
- if (taskController != null) {
- Delegation taskControllerDelegation = taskController.getTaskControllerDelegation();
- if (taskControllerDelegation != null) {
- // TODO: delegation (API mismatch!)
- } else {
- List<VariableAccess> variableAccesses = taskController.getVariableAccesses();
- if (variableAccesses != null) {
- String missingTaskVariables = null;
- for (VariableAccess variableAccess: variableAccesses) {
- String mappedName = variableAccess.getMappedName();
- Object value = workItem.getParameter(mappedName);
- if (variableAccess.isRequired() && (value != null)) {
- if (missingTaskVariables == null) {
- missingTaskVariables = mappedName;
- } else {
- missingTaskVariables += ", "+mappedName;
- }
- }
- }
- if (missingTaskVariables != null) {
- throw new IllegalArgumentException(
- "missing task variables: " + missingTaskVariables);
- }
-
- for (VariableAccess variableAccess: variableAccesses) {
- String mappedName = variableAccess.getMappedName();
- String variableName = variableAccess.getVariableName();
- if (variableAccess.isWritable()) {
- Object value = workItem.getParameter(mappedName);
- if (value != null) {
- VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
- resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
- variableScopeInstance.setVariable(variableName, value);
- }
- }
- }
- }
- }
- }
- }
-
public void addEventListeners() {
((ProcessInstance) getProcessInstance()).addEventListener("workItemCompleted", this, false);
((ProcessInstance) getProcessInstance()).addEventListener("workItemAborted", this, false);
@@ -240,6 +97,16 @@
((ProcessInstance) getProcessInstance()).removeEventListener("workItemAborted", this, false);
}
+ public void signalEvent(String type, Object event) {
+ if ("workItemCompleted".equals(type)) {
+ workItemCompleted((WorkItem) event);
+ } else if ("workItemAborted".equals(type)) {
+ workItemAborted((WorkItem) event);
+ } else {
+ super.signalEvent(type, event);
+ }
+ }
+
public void workItemAborted(WorkItem workItem) {
if (workItems.remove(workItem)) {
if (!hasBlockingWorkItems()) {
@@ -255,7 +122,7 @@
Set<Task> tasks = getTaskNode().getTasks();
for (Task task: tasks) {
if (taskName.equals(task.getName())) {
- restoreVariables((WorkItemImpl) workItem, task);
+ TaskUtils.restoreVariables((WorkItemImpl) workItem, task, this);
if (task.getSwimlane() != null) {
String swimlaneName = task.getSwimlane().getName();
SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance)
@@ -270,7 +137,9 @@
}
Event event = task.getEvent(Event.EVENTTYPE_TASK_END);
if (event != null) {
- executeActions(event.getActions(), new JpdlTaskExecutionContext(task));
+ JpdlExecutionContext context = new JpdlExecutionContext();
+ context.setTask(task);
+ executeActions(event.getActions(), context);
}
break;
}
@@ -310,13 +179,4 @@
super.leave(type);
}
- public class JpdlTaskExecutionContext extends JpdlExecutionContext {
- private Task task;
- public JpdlTaskExecutionContext(Task task) {
- this.task = task;
- }
- public Task getTask() {
- return task;
- }
- }
}
Added: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/TaskUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/TaskUtils.java (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/instance/node/TaskUtils.java 2008-12-16 00:09:32 UTC (rev 24390)
@@ -0,0 +1,177 @@
+package org.drools.jpdl.instance.node;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.jpdl.instance.node.JpdlNodeInstance.JpdlExecutionContext;
+import org.drools.process.core.context.swimlane.SwimlaneContext;
+import org.drools.process.core.context.variable.VariableScope;
+import org.drools.process.instance.WorkItem;
+import org.drools.process.instance.context.swimlane.SwimlaneContextInstance;
+import org.drools.process.instance.context.variable.VariableScopeInstance;
+import org.drools.process.instance.impl.WorkItemImpl;
+import org.jbpm.JbpmException;
+import org.jbpm.calendar.BusinessCalendar;
+import org.jbpm.calendar.Duration;
+import org.jbpm.context.def.VariableAccess;
+import org.jbpm.graph.def.Event;
+import org.jbpm.instantiation.Delegation;
+import org.jbpm.jpdl.el.impl.JbpmExpressionEvaluator;
+import org.jbpm.taskmgmt.def.Task;
+import org.jbpm.taskmgmt.def.TaskController;
+
+public final class TaskUtils {
+
+ private TaskUtils() {
+ }
+
+ public static WorkItem createWorkItem(Task task, JpdlNodeInstance nodeInstance) {
+ WorkItemImpl workItem = new WorkItemImpl();
+ workItem.setName("JpdlTask");
+ workItem.setProcessInstanceId(nodeInstance.getProcessInstance().getId());
+ workItem.setParameter("name", task.getName());
+ String description = task.getDescription();
+ workItem.setParameter("signalling", task.isSignalling());
+ workItem.setParameter("blocking", task.isBlocking());
+ if ((description != null) && (description.indexOf("#{") != -1)) {
+ Object result = JbpmExpressionEvaluator.evaluate(
+ description, nodeInstance.new JpdlExecutionContext());
+ if (result != null) {
+ description = result.toString();
+ }
+ }
+ workItem.setParameter("Description", description);
+ initializeVariables(workItem, task, nodeInstance);
+ if (task.getDueDate() != null) {
+ BusinessCalendar businessCalendar = new BusinessCalendar();
+ workItem.setParameter("dueDate",
+ businessCalendar.add(new Date(), new Duration(task.getDueDate())));
+ }
+ if (task.getSwimlane() != null) {
+ String swimlaneName = task.getSwimlane().getName();
+ SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance)
+ nodeInstance.resolveContextInstance(SwimlaneContext.SWIMLANE_SCOPE, swimlaneName);
+ String actorId = swimlaneContextInstance.getActorId(swimlaneName);
+ if (actorId == null) {
+ actorId = assignTask(task, nodeInstance);
+ }
+ workItem.setParameter("ActorId", actorId);
+ }
+ Event event = task.getEvent(Event.EVENTTYPE_TASK_CREATE);
+ if (event != null) {
+ // TODO this doesn't take event handlers of task itself
+ // into account
+ JpdlExecutionContext context = nodeInstance.new JpdlExecutionContext();
+ context.setTask(task);
+ nodeInstance.executeActions(event.getActions(), context);
+ }
+ return workItem;
+ }
+
+ private static void initializeVariables(WorkItemImpl workItem, Task task, JpdlNodeInstance nodeInstance) {
+ TaskController taskController = task.getTaskController();
+ if (taskController != null) {
+ Delegation taskControllerDelegation = taskController.getTaskControllerDelegation();
+ if (taskControllerDelegation != null) {
+ // TODO: delegation (API mismatch!)
+ } else {
+ List<VariableAccess> variableAccesses = taskController.getVariableAccesses();
+ if (variableAccesses != null) {
+ for (VariableAccess variableAccess: variableAccesses) {
+ String mappedName = variableAccess.getMappedName();
+ if (variableAccess.isReadable()) {
+ String variableName = variableAccess.getVariableName();
+ VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
+ nodeInstance.resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
+ Object value = variableScopeInstance.getVariable(variableName);
+ workItem.setParameter(mappedName, value);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private static String assignTask(Task task, JpdlNodeInstance nodeInstance) {
+ Event event = task.getEvent(Event.EVENTTYPE_TASK_ASSIGN);
+ if (event != null) {
+ JpdlExecutionContext context = nodeInstance.new JpdlExecutionContext();
+ context.setTask(task);
+ nodeInstance.executeActions(event.getActions(), context);
+ }
+ if (task.getActorIdExpression() != null) {
+ return resolveActor(task.getActorIdExpression(), nodeInstance);
+ } else if (task.getSwimlane().getActorIdExpression() != null) {
+ return resolveActor(task.getSwimlane().getActorIdExpression(), nodeInstance);
+ }
+ // TODO support other assignment types
+ return null;
+ }
+
+ private static String resolveActor(String expression, JpdlNodeInstance nodeInstance) {
+ Object result = JbpmExpressionEvaluator.evaluate(expression, nodeInstance.new JpdlExecutionContext());
+ if (result == null) {
+ throw new JbpmException("actor-id expression '" + expression + "' returned null");
+ }
+ if (result instanceof String) {
+ return (String) result;
+ } else {
+ throw new JbpmException(
+ "actor-id expression '" + expression +
+ "' didn't resolve to a java.lang.String: '" + result +
+ "' (" + result.getClass().getName() + ")");
+ }
+ }
+
+ public static void restoreVariables(WorkItemImpl workItem, Task task, JpdlNodeInstance nodeInstance) {
+ TaskController taskController = task.getTaskController();
+ if (taskController != null) {
+ Delegation taskControllerDelegation = taskController.getTaskControllerDelegation();
+ if (taskControllerDelegation != null) {
+ // TODO: delegation (API mismatch!)
+ } else {
+ List<VariableAccess> variableAccesses = taskController.getVariableAccesses();
+ if (variableAccesses != null) {
+ String missingTaskVariables = null;
+ for (VariableAccess variableAccess: variableAccesses) {
+ String mappedName = variableAccess.getMappedName();
+ Object value = workItem.getParameter(mappedName);
+ if (variableAccess.isRequired() && (value != null)) {
+ if (missingTaskVariables == null) {
+ missingTaskVariables = mappedName;
+ } else {
+ missingTaskVariables += ", "+mappedName;
+ }
+ }
+ }
+ if (missingTaskVariables != null) {
+ throw new IllegalArgumentException(
+ "missing task variables: " + missingTaskVariables);
+ }
+
+ for (VariableAccess variableAccess: variableAccesses) {
+ String mappedName = variableAccess.getMappedName();
+ String variableName = variableAccess.getVariableName();
+ if (variableAccess.isWritable()) {
+ Object value = workItem.getParameter(mappedName);
+ if (value != null) {
+ VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
+ nodeInstance.resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
+ variableScopeInstance.setVariable(variableName, value);
+ }
+ }
+ }
+ }
+ }
+ } else {
+ // the default behaviour is that all task-local variables are flushed to the process
+ VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
+ nodeInstance.getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE);
+ for (Map.Entry<String, Object> entry: workItem.getResults().entrySet()) {
+ variableScopeInstance.setVariable(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+}
More information about the jboss-svn-commits
mailing list