[jboss-svn-commits] JBL Code SVN: r28363 - in labs/jbossrules/trunk/drools-process/drools-jpdl/src: test/java/org/drools and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 23 16:02:54 EDT 2009
Author: salaboy21
Date: 2009-07-23 16:02:53 -0400 (Thu, 23 Jul 2009)
New Revision: 28363
Added:
labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2decision/
labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2decision/gpd.xml
labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2decision/processdefinition.xml
labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestJoinComplex/
labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestJoinComplex/gpd.xml
labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestJoinComplex/processdefinition.xml
labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestSplitInActionNode/
labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestSplitInActionNode/gpd.xml
labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestSplitInActionNode/processdefinition.xml
Modified:
labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/EpdlWriter.java
labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/java/org/drools/ParseSimpleProcessTest.java
labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2states/processdefinition.xml
Log:
suggest Joins and Split nodes when more than one leaving or arriving transition appears
Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/EpdlWriter.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/EpdlWriter.java 2009-07-23 19:37:17 UTC (rev 28362)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/EpdlWriter.java 2009-07-23 20:02:53 UTC (rev 28363)
@@ -17,6 +17,8 @@
package org.drools.jpdl;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -24,7 +26,11 @@
import org.drools.definition.process.Node;
import org.drools.jpdl.core.JpdlProcess;
+import org.drools.workflow.core.Constraint;
+import org.drools.workflow.core.impl.ConnectionImpl;
+import org.drools.workflow.core.impl.ConnectionRef;
import org.drools.workflow.core.impl.NodeImpl;
+import org.drools.workflow.core.node.StateNode;
import org.jbpm.graph.def.Action;
import org.jbpm.instantiation.Delegation;
@@ -33,11 +39,12 @@
* @author salaboy
*/
public class EpdlWriter {
-
+ private static int suggestedNodeId = 99;
public static void write(JpdlProcess process) {
Node[] nodes = process.getNodes();
int id = 0;
-
+
+ String generatedConnections = "";
System.out.println("<process xmlns=\"http://drools.org/drools-5.0/process\""+
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\" "+
"xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\" " +
@@ -57,19 +64,51 @@
System.out.println("<join id=\""+node.getId()+"\" name=\""+node.getName()+"\" type=\"1\" />");
}
else if(node instanceof org.drools.jpdl.core.node.State){
+ generatedConnections= suggestJoinNode(node);
+
+
+
System.out.println("<state id=\""+node.getId()+"\" name=\""+node.getName()+"\" >");
System.out.println(" <constraints>");
- for (Connection connection: node.getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)) {
- System.out.println(" <constraint toNodeId=\""+connection.getTo().getId()+"\" name=\"signalTo"+connection.getTo().getName()+"\" />");
+ Set<String> keys = node.getOutgoingConnections().keySet();
+ for(String key: keys){
+ for (Connection connection: node.getOutgoingConnections(key)) {
+ System.out.println(" <constraint toNodeId=\""+connection.getTo().getId()+"\" name=\"signalTo"+connection.getTo().getName()+"\" />");
+ }
}
System.out.println(" </constraints>");
System.out.println("</state>");
}
+ else if(node instanceof org.drools.jpdl.core.node.Decision){
+ System.out.println("<split id=\""+node.getId()+"\" name=\""+node.getName()+"\" type=\"2\" >");
+ System.out.println(" <constraints>");
+ Set<String> keys = node.getOutgoingConnections().keySet();
+ for(String key: keys){
+
+ for (Connection connection: node.getOutgoingConnections(key)) {
+ System.out.println(" <constraint toNodeId=\""+connection.getTo().getId()+"\" name=\"signalTo"+connection.getTo().getName()+
+ "\" toType=\"DROOLS_DEFAULT\" type=\"rule\" dialect=\"java\" >");
+ //System.out.println(" "+"There is no way to get the conditions in each leavingTransition (depracated since 3.2 - http://docs.jboss.com/jbpm/v3.2/userguide/html_single/#condition.element)");
+ //System.out.println(" "+"There is no way to access the decision expresion or the decision delegation class through the APIs");
+ System.out.println(" </constraint>");
+
+ }
+ }
+ System.out.println(" </constraints>");
+ System.out.println("</split>");
+ }
else if(node instanceof org.drools.jpdl.core.node.EndState){
+ generatedConnections += suggestJoinNode(node);
+
+
System.out.println("<end id=\""+node.getId()+"\" name=\""+node.getName()+"\" />");
+
}
else if(node instanceof org.drools.jpdl.core.node.JpdlNode){
+ generatedConnections += suggestSplitNode(node);
+ generatedConnections += suggestJoinNode(node);
+
System.out.println("<actionNode id=\""+node.getId()+"\" name=\""+node.getName()+"\">");
System.out.println(" <action type=\"expression\" dialect=\"java\" >");
Action action = ((org.drools.jpdl.core.node.JpdlNode)node).getAction();
@@ -103,10 +142,105 @@
}
}
- System.out.println("</connections>");
+ System.out.println("<!-- Generated Connection for suggested nodes -->");
+ System.out.println(generatedConnections);
+ System.out.println("<!-- END - Generated Connection for suggested nodes -->");
+ System.out.println("</connections>");
+ System.out.println("</process>");
+ }
- System.out.println("</process>");
+ private static String suggestJoinNode(Node node) {
+ String resultGeneratedConnection = "";
+ Set<String> incomingConnectionsTypes = node.getIncomingConnections().keySet();
+ String firstKey = incomingConnectionsTypes.iterator().next();
+ boolean suggestJoinNode = false;
+ if (incomingConnectionsTypes.size() > 1) {
+ suggestJoinNode = true;
+ } else if (incomingConnectionsTypes.size() == 1 && node.getIncomingConnections().get(firstKey).size() > 1) {
+ suggestJoinNode = true;
+ }
+ if (suggestJoinNode) {
+ System.out.println("<!-- This is a suggested Join Node -->");
+ System.out.println("<join id=\"" + (suggestedNodeId) + "\" name=\"Join XOR - "+suggestedNodeId+"\" type=\"2\" />");
+
+ for (String key : incomingConnectionsTypes) {
+ Iterator<Connection> itConnections = node.getIncomingConnections(key).iterator();
+ long fromNodeId = 0;
+ while (itConnections.hasNext()) {
+ Connection connection = itConnections.next();
+ Node fromNode = connection.getFrom();
+
+ fromNodeId = connection.getTo().getId();
+ if(fromNode instanceof org.drools.jpdl.core.node.State){
+ System.out.println("<!-- Take a look at the State Node that is pointing here, " +
+ "you will need to change the constraint for signal it to the new JoinNode id -->");
+ System.out.println("<!-- in node id: "+fromNode.getId()+ "-- name: "+fromNode.getName()+" -->");
+ System.out.println("<!-- you should change the fromId ("+fromNodeId+") attribute to: "+suggestedNodeId+"-->");
+ System.out.println("<!-- you can also change the name for something that reference the JoinNode -->");
+ }
+ fromNode.getOutgoingConnections(key).remove(connection);
+ resultGeneratedConnection += " <connection from=\"" + fromNode.getId() + "\" to=\"" + suggestedNodeId + "\" />\n";
+ }
+ resultGeneratedConnection += " <connection from=\"" + suggestedNodeId + "\" to=\"" + fromNodeId + "\" />\n";
+ }
+ System.out.println("<!-- END - This is a suggested Join Node -->");
+ suggestedNodeId++;
+ }
+ return resultGeneratedConnection;
}
+ private static String suggestSplitNode(Node node) {
+ String resultGeneratedConnection = "";
+ Set<String> outgoingConnectionsTypes = node.getOutgoingConnections().keySet();
+ String firstKey = outgoingConnectionsTypes.iterator().next();
+ boolean suggestSplitNode = false;
+ if (outgoingConnectionsTypes.size() > 1) {
+ suggestSplitNode = true;
+ } else if (outgoingConnectionsTypes.size() == 1 && node.getOutgoingConnections().get(firstKey).size() > 1) {
+ suggestSplitNode = true;
+ }
+ if(suggestSplitNode){
+ System.out.println("<!-- This is a suggested Split Node -->");
+ System.out.println("<split id=\"" + (suggestedNodeId) + "\" name=\"Split XOR\" type=\"2\" >");
+ System.out.println(" <constraints>");
+ Set<String> keys = node.getOutgoingConnections().keySet();
+ for(String key: keys){
+ for (Connection connection: node.getOutgoingConnections(key)) {
+ System.out.println(" <constraint toNodeId=\""+connection.getTo().getId()+"\" name=\"signalTo"+connection.getTo().getName()+
+ "\" toType=\"DROOLS_DEFAULT\" type=\"rule\" dialect=\"java\" >");
+ //System.out.println(" "+"There is no way to get the conditions in each leavingTransition (depracated since 3.2 - http://docs.jboss.com/jbpm/v3.2/userguide/html_single/#condition.element)");
+ //System.out.println(" "+"There is no way to access the decision expresion or the decision delegation class through the APIs");
+ System.out.println(" </constraint>");
+ }
+ }
+ System.out.println(" </constraints>");
+ System.out.println("</split>");
+ System.out.println("<!-- END - This is a suggested Split Node -->");
+ List<Connection> removeConnections = new ArrayList<Connection>();
+ for (String key : outgoingConnectionsTypes) {
+ Iterator<Connection> itConnections = node.getOutgoingConnections(key).iterator();
+ while (itConnections.hasNext()) {
+ Connection connection = itConnections.next();
+ Node toNode = connection.getTo();
+ removeConnections.add(connection);
+ resultGeneratedConnection += " <connection from=\"" + suggestedNodeId + "\" to=\"" + toNode.getId() + "\" />\n";
+ }
+
+
+ }
+ resultGeneratedConnection += " <connection from=\"" + node.getId() + "\" to=\"" + suggestedNodeId + "\" />\n";
+ suggestedNodeId++;
+ for(Connection conn : removeConnections){
+
+ node.getOutgoingConnections(conn.getFromType()).remove(conn);
+
+ }
+
+ }
+
+ return resultGeneratedConnection;
+ }
+
+
}
Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/java/org/drools/ParseSimpleProcessTest.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/java/org/drools/ParseSimpleProcessTest.java 2009-07-23 19:37:17 UTC (rev 28362)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/java/org/drools/ParseSimpleProcessTest.java 2009-07-23 20:02:53 UTC (rev 28363)
@@ -72,7 +72,7 @@
}
}
- public void testWriteEPDL() throws Exception {
+ public void testWriteEPDLStateNodes() throws Exception {
JpdlParser parser = new JpdlParser();
JpdlProcess process = parser.loadJpdlProcess("simple2states/processdefinition.xml");
ProcessValidationError[] errors = parser.getErrors();
@@ -80,5 +80,29 @@
EpdlWriter.write(process);
}
+ public void testWriteEPDLDecisionNodes() throws Exception {
+ JpdlParser parser = new JpdlParser();
+ JpdlProcess process = parser.loadJpdlProcess("simple2decision/processdefinition.xml");
+ ProcessValidationError[] errors = parser.getErrors();
+ EpdlWriter.write(process);
+
+ }
+ public void testWriteEPDLSuggestJoinNode() throws Exception {
+ JpdlParser parser = new JpdlParser();
+ JpdlProcess process = parser.loadJpdlProcess("simple2suggestJoinComplex/processdefinition.xml");
+ ProcessValidationError[] errors = parser.getErrors();
+
+ EpdlWriter.write(process);
+
+ }
+ public void testWriteEPDLSuggestSplitNode() throws Exception {
+ JpdlParser parser = new JpdlParser();
+ JpdlProcess process = parser.loadJpdlProcess("simple2suggestSplitInActionNode/processdefinition.xml");
+ ProcessValidationError[] errors = parser.getErrors();
+
+ EpdlWriter.write(process);
+
+ }
+
}
Added: labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2decision/gpd.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2decision/gpd.xml (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2decision/gpd.xml 2009-07-23 20:02:53 UTC (rev 28363)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root-container name="DecisionTest" width="1051" height="499">
+ <node name="start-state1" x="166" y="59" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="decision1" x="165" y="136" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="node1" x="62" y="219" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="node2" x="280" y="229" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="end-state1" x="165" y="322" width="132" height="36"/>
+</root-container>
Added: labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2decision/processdefinition.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2decision/processdefinition.xml (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2decision/processdefinition.xml 2009-07-23 20:02:53 UTC (rev 28363)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition xmlns="urn:jbpm.org:jpdl-3.2" name="DecisionTest">
+
+
+ <start-state name="start-state1">
+ <transition to="decision1"></transition>
+ </start-state>
+
+
+ <decision name="decision1">
+ <transition to="node1" ></transition>
+ <transition to="node2" name="to node2" ></transition>
+ </decision>
+
+ <node name="node1">
+ <transition to="end-state1"></transition>
+ </node>
+
+ <node name="node2">
+ <transition to="end-state1"></transition>
+ </node>
+
+
+ <end-state name="end-state1"></end-state>
+
+
+</process-definition>
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2states/processdefinition.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2states/processdefinition.xml 2009-07-23 19:37:17 UTC (rev 28362)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2states/processdefinition.xml 2009-07-23 20:02:53 UTC (rev 28363)
@@ -4,7 +4,7 @@
xmlns="urn:jbpm.org:jpdl-3.2"
name="simple">
<start-state name="start">
- <transition to="fork1"></transition>
+ <transition to="first state"></transition>
</start-state>
<state name="first state">
<transition to="fork1"></transition>
Added: labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestJoinComplex/gpd.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestJoinComplex/gpd.xml (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestJoinComplex/gpd.xml 2009-07-23 20:02:53 UTC (rev 28363)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root-container name="DecisionTest" width="846" height="499">
+ <node name="start-state1" x="166" y="59" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="decision1" x="165" y="136" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="node1" x="108" y="218" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="node2" x="301" y="221" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="end-state1" x="155" y="406" width="132" height="36"/>
+ <node name="node3" x="356" y="316" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+</root-container>
Added: labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestJoinComplex/processdefinition.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestJoinComplex/processdefinition.xml (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestJoinComplex/processdefinition.xml 2009-07-23 20:02:53 UTC (rev 28363)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition xmlns="urn:jbpm.org:jpdl-3.2" name="DecisionTest">
+
+
+ <start-state name="start-state1">
+ <transition to="decision1"></transition>
+ </start-state>
+
+
+ <decision name="decision1" expression="$var">
+ <transition to="node1"></transition>
+ <transition to="decision2" name="to decision2"></transition>
+ </decision>
+
+ <node name="node1">
+ <transition to="end-state1"></transition>
+ </node>
+
+ <node name="node3">
+ <transition to="node4"></transition>
+ </node>
+
+ <decision name="decision2">
+ <transition to="node3"></transition>
+ <transition to="node2" name="to node2"></transition>
+ </decision>
+
+ <node name="node2">
+ <transition to="node4"></transition>
+ </node>
+
+ <node name="node4">
+ <transition to="end-state1"></transition>
+ </node>
+
+
+ <end-state name="end-state1"></end-state>
+
+
+</process-definition>
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestSplitInActionNode/gpd.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestSplitInActionNode/gpd.xml (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestSplitInActionNode/gpd.xml 2009-07-23 20:02:53 UTC (rev 28363)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root-container name="TwoLeavingTransitionOnActionNodes" width="846" height="499">
+ <node name="start-state1" x="173" y="45" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="end-state1" x="189" y="383" width="132" height="36"/>
+ <node name="node1" x="171" y="114" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="state1" x="131" y="181" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="state2" x="303" y="182" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="node2" x="178" y="273" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="node3" x="31" y="274" width="132" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+</root-container>
Added: labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestSplitInActionNode/processdefinition.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestSplitInActionNode/processdefinition.xml (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2suggestSplitInActionNode/processdefinition.xml 2009-07-23 20:02:53 UTC (rev 28363)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition xmlns="urn:jbpm.org:jpdl-3.2" name="TwoLeavingTransitionOnActionNodes">
+
+
+ <start-state name="start-state1">
+ <transition to="node1"></transition>
+ </start-state>
+
+
+ <node name="node1">
+ <transition to="state1"></transition>
+ <transition to="state2" name="to state2"></transition>
+ </node>
+
+ <state name="state1">
+ <transition to="node2"></transition>
+ <transition to="node3" name="to node3"></transition>
+ </state>
+
+ <state name="state2">
+ <transition to="end-state1"></transition>
+ </state>
+
+ <node name="node2">
+ <transition to="end-state1"></transition>
+ </node>
+
+ <node name="node3">
+ <transition to="end-state1"></transition>
+ </node>
+
+
+ <end-state name="end-state1"></end-state>
+
+
+</process-definition>
\ No newline at end of file
More information about the jboss-svn-commits
mailing list