[jbpm-commits] JBoss JBPM SVN: r4868 - in jbpm4/branches/jimma/modules/migration/src: main/java/org/jbpm/jpdl/internal/convert/util and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu May 21 06:22:54 EDT 2009
Author: jim.ma
Date: 2009-05-21 06:22:53 -0400 (Thu, 21 May 2009)
New Revision: 4868
Added:
jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/ForkConverter.java
jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/JoinConverter.java
jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/NodeConverter.java
jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/SwimlaneConverter.java
jbpm4/branches/jimma/modules/migration/src/test/resources/businesstrip.xml
Modified:
jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/JpdlConverter.java
jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TaskNodeConverter.java
jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TransitionConverter.java
jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/JpdlConverterTest.java
Log:
Added swimlane,join,fork and node conveter
Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/JpdlConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/JpdlConverter.java 2009-05-21 09:29:36 UTC (rev 4867)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/JpdlConverter.java 2009-05-21 10:22:53 UTC (rev 4868)
@@ -22,20 +22,29 @@
package org.jbpm.jpdl.internal.convert;
import java.net.URL;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.jbpm.graph.def.Node;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.node.EndState;
+import org.jbpm.graph.node.Fork;
+import org.jbpm.graph.node.Join;
import org.jbpm.graph.node.StartState;
import org.jbpm.graph.node.State;
import org.jbpm.graph.node.TaskNode;
import org.jbpm.jpdl.internal.convert.util.EndStateConverter;
+import org.jbpm.jpdl.internal.convert.util.ForkConverter;
+import org.jbpm.jpdl.internal.convert.util.JoinConverter;
+import org.jbpm.jpdl.internal.convert.util.NodeConverter;
import org.jbpm.jpdl.internal.convert.util.StartStateConverter;
import org.jbpm.jpdl.internal.convert.util.StateConverter;
+import org.jbpm.jpdl.internal.convert.util.SwimlaneConverter;
import org.jbpm.jpdl.internal.convert.util.TaskNodeConverter;
import org.jbpm.jpdl4.model.Process;
+import org.jbpm.taskmgmt.def.Swimlane;
+import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
import org.xml.sax.InputSource;
public class JpdlConverter {
@@ -58,7 +67,20 @@
public Process mapProcessDef(ProcessDefinition def) {
Process process = new Process();
process.setName(def.getName());
-
+
+ //convert swimlane
+ TaskMgmtDefinition taskMgmtDefinition = def.getTaskMgmtDefinition();
+ Map swimlanesMap = taskMgmtDefinition.getSwimlanes();
+ if (swimlanesMap != null) {
+ Iterator iterator = swimlanesMap.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry<String, Swimlane> entry = (Map.Entry<String, Swimlane>) iterator
+ .next();
+ org.jbpm.jpdl4.model.Swimlane item = SwimlaneConverter
+ .run(entry.getValue());
+ process.getSwimlaneAndOnAndTimer().add(item);
+ }
+ }
for (Node node : def.getNodes()) {
// map start state node
if (node.getNodeType().equals(Node.NodeType.StartState)) {
@@ -80,6 +102,15 @@
Set<Process.Task> tasks = TaskNodeConverter.run(taskNode);
process.getSwimlaneAndOnAndTimer().addAll(tasks);
}
+ } else if (node.getNodeType().equals(Node.NodeType.Fork)) {
+ Fork fork = (Fork)node;
+ process.getSwimlaneAndOnAndTimer().add(ForkConverter.run(fork));
+ } else if (node.getNodeType().equals(Node.NodeType.Join)) {
+ Join join = (Join)node;
+ process.getSwimlaneAndOnAndTimer().add(JoinConverter.run(join));
+ } else if (node.getNodeType().equals(Node.NodeType.Node)) {
+ Node tmpNode = (Node)node;
+ process.getSwimlaneAndOnAndTimer().add(NodeConverter.run(tmpNode));
}
}
Added: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/ForkConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/ForkConverter.java (rev 0)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/ForkConverter.java 2009-05-21 10:22:53 UTC (rev 4868)
@@ -0,0 +1,40 @@
+/*
+ * 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.jpdl.internal.convert.util;
+
+import org.jbpm.graph.def.Transition;
+import org.jbpm.jpdl4.model.TransitionType;
+import org.jbpm.jpdl4.model.Process.Fork;;
+
+public class ForkConverter {
+ public static Fork run(org.jbpm.graph.node.Fork node) {
+ Fork result = new Fork();
+ result.setName(node.getName());
+
+ for(Transition trans : node.getLeavingTransitions()) {
+ TransitionType transType = TransitionConverter.run(trans, TransitionType.class);
+ result.getTransition().add(transType);
+ }
+ return result;
+ }
+
+}
Added: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/JoinConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/JoinConverter.java (rev 0)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/JoinConverter.java 2009-05-21 10:22:53 UTC (rev 4868)
@@ -0,0 +1,40 @@
+/*
+ * 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.jpdl.internal.convert.util;
+
+import org.jbpm.graph.def.Transition;
+import org.jbpm.jpdl4.model.TransitionType;
+import org.jbpm.jpdl4.model.Process.Join;
+
+public class JoinConverter {
+ public static Join run(org.jbpm.graph.node.Join node) {
+ Join join = new Join();
+ join.setName(node.getName());
+ for (Transition trans : node.getLeavingTransitions()) {
+ join.getTransition().add(
+ TransitionConverter.run(trans, TransitionType.class));
+ }
+ return join;
+
+ }
+
+}
Added: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/NodeConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/NodeConverter.java (rev 0)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/NodeConverter.java 2009-05-21 10:22:53 UTC (rev 4868)
@@ -0,0 +1,50 @@
+package org.jbpm.jpdl.internal.convert.util;
+
+import org.jbpm.graph.def.Action;
+import org.jbpm.graph.def.Node;
+import org.jbpm.instantiation.Delegation;
+import org.jbpm.jpdl4.model.Process;
+
+/*
+<action-type element="action" class="org.jbpm.graph.def.Action" />
+<action-type element="create-timer" class="org.jbpm.scheduler.def.CreateTimerAction" />
+<action-type element="cancel-timer" class="org.jbpm.scheduler.def.CancelTimerAction" />
+<action-type element="script" class="org.jbpm.graph.action.Script" />
+<action-type element="mail" class="org.jbpm.graph.action.MailAction" />*/
+public class NodeConverter {
+ public static Object run(Node node) {
+ String nodeName = node.getName();
+ Action action = node.getAction();
+ if (action instanceof Action) {
+ Process.Java result = new Process.Java();
+ result.setName(nodeName);
+ if (action.getActionExpression() != null) {
+ //REVISIT how to map expression
+ }
+ if (action.getActionDelegation() != null) {
+ result.setClazz(action.getActionDelegation().getClassName());
+ result.setMethod("execute");
+ }
+ return result;
+ }
+ //TODO:convert other action types
+ if (action instanceof org.jbpm.scheduler.def.CreateTimerAction) {
+
+ }
+ if (action instanceof org.jbpm.scheduler.def.CancelTimerAction) {
+
+ }
+ /*if (action instanceof org.jbpm.scheduler.def.Script) {
+
+ }
+
+ if (action instanceof org.jbpm.scheduler.def.MailAction) {
+
+ }*/
+
+ return null;
+
+
+ }
+
+}
Added: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/SwimlaneConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/SwimlaneConverter.java (rev 0)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/SwimlaneConverter.java 2009-05-21 10:22:53 UTC (rev 4868)
@@ -0,0 +1,56 @@
+package org.jbpm.jpdl.internal.convert.util;
+import org.jbpm.instantiation.Delegation;
+import org.jbpm.jpdl4.model.Swimlane;
+public class SwimlaneConverter {
+ public static Swimlane run(org.jbpm.taskmgmt.def.Swimlane swimlane) {
+ Swimlane result = new Swimlane();
+ result.setName(swimlane.getName());
+ String actoridExpress = swimlane.getActorIdExpression();
+ String pooledActorIdExpression = swimlane.getPooledActorsExpression();
+ if (actoridExpress != null) {
+ result.setAssignee(actoridExpress);
+ } else if (pooledActorIdExpression != null) {
+ result.setCandidateGroups(pooledActorIdExpression);
+ } else {
+ //process the expression
+ Delegation delegation = swimlane.getAssignmentDelegation();
+ //If this className need to be map
+ //className = delegation.getClassName();
+
+ if (delegation != null) {
+ String configuration = delegation.getConfiguration();
+ // if the expression attribute is not empty , ex.
+ // <expression>a->b->c</expression>
+ if (configuration.startsWith("<expression>")) {
+ mapExpression(result, configuration);
+ } else if (configuration.startsWith("<actorId>")) {
+ // TODO: figure out set it in actorId or candidate-users.
+ // The class is needed to map
+ int beginIndex = "<actorId>".length();
+ int endIndex = configuration.indexOf("</actorId>");
+ String actorId = configuration.substring(beginIndex,
+ endIndex);
+ result.setAssignee(actorId);
+ } else if (configuration.startsWith("<pooledActors>")) {
+ // TODO: figure out set it in actorId or candidate-users?
+ int beginIndex = "<pooledActors>".length();
+ int endIndex = configuration.indexOf("</pooledActors>");
+ String pooledActorId = configuration.substring(beginIndex,
+ endIndex);
+ result.setCandidateGroups(pooledActorId);
+ } else {
+ // TODO: look at if we need to handle the case that there is
+ // no actorId, pooledActors and expression
+ }
+ }
+ }
+
+ return result;
+ }
+
+ //TODO: map expression to swimlane
+ public static void mapExpression(Swimlane result, String expression) {
+
+ }
+
+}
Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TaskNodeConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TaskNodeConverter.java 2009-05-21 09:29:36 UTC (rev 4867)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TaskNodeConverter.java 2009-05-21 10:22:53 UTC (rev 4868)
@@ -4,6 +4,7 @@
import org.jbpm.graph.node.TaskNode;
import org.jbpm.instantiation.Delegation;
+import org.jbpm.jpdl4.model.ObjectFactory;
import org.jbpm.jpdl4.model.Process;
import org.jbpm.jpdl4.model.WireObjectType;
import org.jbpm.taskmgmt.def.Task;
@@ -11,6 +12,7 @@
public class TaskNodeConverter {
public static Set<Process.Task> run(TaskNode taskNode) {
+
String taskNodeName = taskNode.getName();
Set<Process.Task> result = new java.util.HashSet<Process.Task>();
Set<Task> tasks = taskNode.getTasks();
@@ -19,7 +21,22 @@
if (taskArray != null && taskArray.length > 0) {
for (int i = 0 ; i < taskArray.length; i++) {
Task tmpTask =taskArray[i];
+
Process.Task tmpNewTask = convert(tmpTask);
+ //convert the swimlane information
+ if (tmpTask.getActorIdExpression() != null) {
+ tmpNewTask.setAssignee(tmpTask.getActorIdExpression());
+ } else if(tmpTask.getPooledActorsExpression() != null) {
+ tmpNewTask.setCandidateGroups(tmpTask.getPooledActorsExpression());
+ } else if (tmpTask.getSwimlane() != null) {
+ tmpNewTask.setSwimlane(tmpTask.getSwimlane().getName());
+ } else if (tmpTask.getAssignmentDelegation() != null) {
+ //TODO:revisit it
+ WireObjectType wireObjectType = new ObjectFactory().createWireObjectType();
+ wireObjectType.setClazz(tmpTask.getAssignmentDelegation().getClassName());
+ tmpNewTask.setAssignmentHandler(wireObjectType);
+ }
+
if (i ==0 ) {
tmpNewTask.setName(taskNodeName);
}
Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TransitionConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TransitionConverter.java 2009-05-21 09:29:36 UTC (rev 4867)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TransitionConverter.java 2009-05-21 10:22:53 UTC (rev 4868)
@@ -39,8 +39,7 @@
try {
transType = claz.newInstance();
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+
}
// get the actions
if (transition.getEvents() != null) {
@@ -65,6 +64,7 @@
}
}
}
+ transType.setName(transition.getName());
transType.setTo(transition.getTo().getName());
return (T)transType;
}
Modified: jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/JpdlConverterTest.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/JpdlConverterTest.java 2009-05-21 09:29:36 UTC (rev 4867)
+++ jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/JpdlConverterTest.java 2009-05-21 10:22:53 UTC (rev 4868)
@@ -27,6 +27,7 @@
import org.jbpm.api.Problem;
import org.jbpm.jpdl.internal.xml.JpdlParser;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
public class JpdlConverterTest {
@@ -41,7 +42,12 @@
testConvert("assignment.xml");
}
+ @Test
+ public void runBusinessTrip() throws Exception {
+ testConvert("businesstrip.xml");
+ }
+
public void testConvert(String resourcefile) throws Exception {
URL url = getClass().getClassLoader().getResource(resourcefile);
ConverterContext context = new ConverterContext();
Added: jbpm4/branches/jimma/modules/migration/src/test/resources/businesstrip.xml
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/test/resources/businesstrip.xml (rev 0)
+++ jbpm4/branches/jimma/modules/migration/src/test/resources/businesstrip.xml 2009-05-21 10:22:53 UTC (rev 4868)
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition name="business trip request"
+ xmlns="urn:jbpm.org:jpdl-3.2">
+
+ <swimlane name="employee" />
+ <swimlane name="manager">
+ <assignment actor-id="manager" />
+ </swimlane>
+ <swimlane name="hr">
+ <assignment actor-id="hr" />
+ </swimlane>
+ <swimlane name="accountant">
+ <assignment actor-id="accountant" />
+ </swimlane>
+
+ <start-state name="submit business trip request">
+ <task swimlane="employee" />
+ <transition name="submit request" to="manager evaluation" />
+ </start-state>
+
+ <task-node name="manager evaluation">
+ <task swimlane="manager" />
+ <transition to="end" name="reject" />
+ <transition to="preparations" name="approve" />
+ </task-node>
+
+ <fork name="preparations">
+ <transition to="erp update" name="erp update"></transition>
+ <transition to="ticket purchase" name="book ticket"></transition>
+ </fork>
+
+ <node name="erp update">
+ <action
+ class="org.jbpm.examples.businesstrip.action.UpdateErpAction">
+ </action>
+ <transition to="join"></transition>
+ </node>
+
+ <node name="query travel agent db">
+ <action
+ class="org.jbpm.examples.businesstrip.action.QueryTravelAgentDbAction">
+ </action>
+ <transition to="join"></transition>
+ </node>
+
+ <task-node name="ticket purchase">
+ <task swimlane="accountant" />
+ <transition to="query travel agent db"></transition>
+ </task-node>
+
+ <join name="join">
+ <transition to="end"></transition>
+ </join>
+
+ <end-state name="end" />
+</process-definition>
\ No newline at end of file
More information about the jbpm-commits
mailing list