[jboss-svn-commits] JBL Code SVN: r36413 - in labs/jbossrules/trunk: drools-core/src/main/java/org/drools/command/runtime/process and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Dec 15 11:04:19 EST 2010


Author: lucazamador
Date: 2010-12-15 11:04:18 -0500 (Wed, 15 Dec 2010)
New Revision: 36413

Modified:
   labs/jbossrules/trunk/drools-camel/src/test/java/org/drools/camel/component/CamelEndpointWithJaxbTest.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/runtime/process/StartProcessCommand.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/help/impl/XStreamXML.java
Log:
JBRULES-2830 StartProcessCommand should return the ProcessInstanceId
	- the StartProcessCommand now returns the processInstanceId into the ExecutionResult object when an out-identifier is added.

Modified: labs/jbossrules/trunk/drools-camel/src/test/java/org/drools/camel/component/CamelEndpointWithJaxbTest.java
===================================================================
--- labs/jbossrules/trunk/drools-camel/src/test/java/org/drools/camel/component/CamelEndpointWithJaxbTest.java	2010-12-15 11:47:24 UTC (rev 36412)
+++ labs/jbossrules/trunk/drools-camel/src/test/java/org/drools/camel/component/CamelEndpointWithJaxbTest.java	2010-12-15 16:04:18 UTC (rev 36413)
@@ -290,7 +290,7 @@
         BatchExecutionCommandImpl cmd = new BatchExecutionCommandImpl();
         cmd.setLookup( "ksession1" );
 
-        StartProcessCommand start = new StartProcessCommand( "org.drools.actions" );
+        StartProcessCommand start = new StartProcessCommand( "org.drools.actions" , "process-instance-id" );
         start.putParameter( "person",
                             new Person( "lucaz",
                                         25 ) );
@@ -316,8 +316,9 @@
                                                         xmlReq.toString() );
         assertNotNull( xmlResp );
         System.out.println( new String( xmlResp ) );
-        Object resp = getJaxbContext().createUnmarshaller().unmarshal( new ByteArrayInputStream( xmlResp ) );
+        ExecutionResults resp = (ExecutionResults) getJaxbContext().createUnmarshaller().unmarshal( new ByteArrayInputStream( xmlResp ) );
         assertNotNull( resp );
+        assertNotNull( resp.getValue( "process-instance-id" ) );
     }
 
     public void testProcessInstanceSignalEvent() throws Exception {

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/runtime/process/StartProcessCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/runtime/process/StartProcessCommand.java	2010-12-15 11:47:24 UTC (rev 36412)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/runtime/process/StartProcessCommand.java	2010-12-15 16:04:18 UTC (rev 36413)
@@ -31,6 +31,7 @@
 import org.drools.command.impl.GenericCommand;
 import org.drools.command.impl.KnowledgeCommandContext;
 import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.impl.ExecutionResultImpl;
 import org.drools.runtime.process.ProcessInstance;
 import org.drools.xml.jaxb.util.JaxbMapAdapter;
 
@@ -46,6 +47,8 @@
 	
 	@XmlElementWrapper(name="data")
 	private List<Object> data = null;
+	@XmlAttribute(name="out-identifier")
+    private String outIdentifier;
 
 	public StartProcessCommand() {
 	}
@@ -53,12 +56,21 @@
 	public StartProcessCommand(String processId) {
 		this.processId = processId;
 	}
-	
+
+	public StartProcessCommand(String processId, String outIdentifier) {
+	    this(processId);
+        this.outIdentifier = outIdentifier;
+    }
+
 	public StartProcessCommand(String processId, Map<String, Object> parameters) {
 		this(processId);
 		this.parameters = parameters; 
 	}
 
+	public StartProcessCommand(String processId, Map<String, Object> parameters, String outIdentifier) {
+        this(processId, outIdentifier);
+        this.parameters = parameters; 
+    }
 
 	public String getProcessId() {
 		return processId;
@@ -88,7 +100,15 @@
 		this.data = data;
 	}
 
-	public ProcessInstance execute(Context context) {
+	public void setOutIdentifier(String outIdentifier) {
+        this.outIdentifier = outIdentifier;
+    }
+
+    public String getOutIdentifier() {
+        return outIdentifier;
+    }
+
+    public ProcessInstance execute(Context context) {
 		StatefulKnowledgeSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession();
 
 		if (data != null) {
@@ -97,6 +117,10 @@
 			}
 		}
 		ProcessInstance processInstance = (ProcessInstance) ksession.startProcess(processId, parameters);
+		if ( this.outIdentifier != null ) {
+		    ((ExecutionResultImpl) ((KnowledgeCommandContext) context).getExecutionResults()).getResults().put(this.outIdentifier,
+		                                                                                                       processInstance.getId());
+		}
 		return processInstance;
 	}
 

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/help/impl/XStreamXML.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/help/impl/XStreamXML.java	2010-12-15 11:47:24 UTC (rev 36412)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/help/impl/XStreamXML.java	2010-12-15 16:04:18 UTC (rev 36413)
@@ -616,6 +616,8 @@
       StartProcessCommand cmd = (StartProcessCommand) object;
       writer.addAttribute( "processId",
                            cmd.getProcessId() );
+      writer.addAttribute( "out-identifier",
+              cmd.getOutIdentifier() );
 
       for ( Entry<String, Object> entry : cmd.getParameters().entrySet() ) {
           writer.startNode( "parameter" );
@@ -631,6 +633,7 @@
   public Object unmarshal(HierarchicalStreamReader reader,
                           UnmarshallingContext context) {
       String processId = reader.getAttribute( "processId" );
+      String outIdentifier = reader.getAttribute( "out-identifier" );
 
       HashMap<String, Object> params = new HashMap<String, Object>();
       while ( reader.hasMoreChildren() ) {
@@ -648,6 +651,7 @@
       StartProcessCommand cmd = new StartProcessCommand();
       cmd.setProcessId( processId );
       cmd.setParameters( params );
+      cmd.setOutIdentifier( outIdentifier );
 
       return cmd;
   }



More information about the jboss-svn-commits mailing list