[jboss-svn-commits] JBL Code SVN: r11607 - in labs/jbossesb/trunk/product/services/jbpm/src: main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed May 2 21:41:11 EDT 2007


Author: estebanschifman
Date: 2007-05-02 21:41:11 -0400 (Wed, 02 May 2007)
New Revision: 11607

Modified:
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Constants.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/FacadeUtil.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/NewProcessInstanceFacade.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/SignalFacade.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/TaskInstanceEndFacade.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/VariableMapping.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/VariablesFacade.java
   labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/BpmProcessorUnitTest.java
   labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/JbpmTestUtil.java
   labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testSingleCommands.xml
Log:
Handle body.getContent() in esb-jBPM mapping

Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Constants.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Constants.java	2007-05-03 01:08:51 UTC (rev 11606)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Constants.java	2007-05-03 01:41:11 UTC (rev 11607)
@@ -29,6 +29,9 @@
  */
 public class Constants {
 	
+	// 'Well known' names for action configuration
+	public static final String BODY_CONTENT_VARIABLE_NAME	="BODY_CONTENT";
+	
 	// Names to be used as keys both in the ESB message and in the Jbpm context (process & token)
 	public static final String COMMAND_CODE					="jbpmCommandCode";
 

Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/FacadeUtil.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/FacadeUtil.java	2007-05-03 01:08:51 UTC (rev 11606)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/FacadeUtil.java	2007-05-03 01:41:11 UTC (rev 11607)
@@ -1,5 +1,28 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.jboss.soa.esb.services.jbpm.actions.impl.facades;
 
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -8,8 +31,8 @@
 import org.jboss.soa.esb.message.Body;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.services.jbpm.Constants;
-import org.jboss.soa.esb.services.jbpm.actions.BpmProcessor;
 import org.jboss.soa.esb.util.Util;
+import org.jbpm.context.exe.VariableContainer;
 import org.jbpm.graph.exe.ProcessInstance;
 import org.jbpm.taskmgmt.exe.TaskInstance;
 
@@ -73,20 +96,20 @@
 							+Constants.ESB_VARNAME_TAG +"' must be specified");
 			}
 			String value = curr.getAttribute("value");
-			if (acceptValue)
-			{
-				if (null==value)
-					throw new ConfigurationException("'value' attribute is required for the '"
-							+tree.getAttribute(BpmProcessor.COMMAND_ATTRIBUTE_TAG)
-							+"' command");
-			}
-			else
-			{
-				if (null!=value)
-					throw new ConfigurationException("'value' attribute is incompatible with the '"
-							+tree.getAttribute(BpmProcessor.COMMAND_ATTRIBUTE_TAG)
-							+"' command");
-			}
+//			if (acceptValue)
+//			{
+//				if (null==value)
+//					throw new ConfigurationException("'value' attribute is required for the '"
+//							+tree.getAttribute(BpmProcessor.COMMAND_ATTRIBUTE_TAG)
+//							+"' command");
+//			}
+//			else
+//			{
+//				if (null!=value)
+//					throw new ConfigurationException("'value' attribute is incompatible with the '"
+//							+tree.getAttribute(BpmProcessor.COMMAND_ATTRIBUTE_TAG)
+//							+"' command");
+//			}
 			// add entry even if value is null, so we'll have mapping anyways
 			ret.setVariable(esbName, jbpmName, value);
 		}
@@ -137,6 +160,8 @@
 			map= ((ProcessInstance)obj).getContextInstance().getVariables();
 		else if	(obj instanceof TaskInstance)
 			map = ((TaskInstance)obj).getContextInstance().getVariables();
+		else if	(obj instanceof VariableContainer)
+			map = ((VariableContainer)obj).getContextInstance().getVariables();
 		else
 			throw new IllegalArgumentException("Unknown return jbpmObject in message");
 
@@ -145,9 +170,45 @@
 			Map.Entry curr = (Map.Entry)II.next();
 			String keyInMsg = (null==mapping) ? (String)curr.getKey()
 					: mapping.getEsbName((String)curr.getKey());
-			if (null!=curr.getValue())
-				body.add(keyInMsg, curr.getValue());
+			Object value = curr.getValue();
+			if (null!=keyInMsg && null!=value)
+			{
+				if (Constants.BODY_CONTENT_VARIABLE_NAME.equals(keyInMsg))
+				{
+					if (value instanceof byte[])
+						body.setContents((byte[])value);
+					else 
+						body.setContents(value.toString().getBytes());
+				}
+				else
+					body.add(keyInMsg, value);
+			}
 		}
-	} // ________________________________ 
+	} // _______________________________
+	
+	static void populateVariableValues (Message message, VariableMapping mapping)
+	{
+		if (null==mapping || mapping.size()<1)
+			return;
 
+		Body body	= message.getBody();
+		HashMap<String,Object> map = new HashMap<String, Object>();
+		for (Map.Entry<String, Object> curr: mapping.esbVariables().entrySet())
+		{
+			String esbName	= curr.getKey();
+			String jbpmName = mapping.getJbpmName(esbName);
+			Object value	=
+				Constants.BODY_CONTENT_VARIABLE_NAME.equals(esbName)
+				? body.getContents()
+				: body.get(esbName);
+			// if object not found in body, use default value (from config)
+			if (null==value)
+				value = curr.getValue();
+			// only put it in the map if it's not null
+			if (null!=value)
+				map.put(jbpmName, value);
+		}
+		body.add(Constants.VARIABLE_VALUES, map);
+	}
+
 }

Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/NewProcessInstanceFacade.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/NewProcessInstanceFacade.java	2007-05-03 01:08:51 UTC (rev 11606)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/NewProcessInstanceFacade.java	2007-05-03 01:41:11 UTC (rev 11607)
@@ -73,14 +73,15 @@
 			body.add(Constants.PROCESS_DEFINITION_NAME	,_processName);
 		if (null!=_processId)
 			body.add(Constants.PROCESS_DEFINITION_ID	,_processId);
-		if (null!=_variables && _variables.size()>0)
-			body.add(Constants.VARIABLE_VALUES, _variables.jbpmVariables());
 		if (null!=_transitionName)
 			body.add(Constants.TRANSITION_NAME, _transitionName);
+
+		FacadeUtil.populateVariableValues(message,_variables);
 	} // _______________________________
     
 	public Message postFormat(Message response) 
 	{
+		FacadeUtil.jbpmVarsToMessage(response, _variables);
 		return response;
 	} // ________________________________
 

Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/SignalFacade.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/SignalFacade.java	2007-05-03 01:08:51 UTC (rev 11606)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/SignalFacade.java	2007-05-03 01:41:11 UTC (rev 11607)
@@ -53,8 +53,7 @@
 		Body body = message.getBody();
 		if (null!=_transition)
 			body.add(Constants.TRANSITION_NAME, _transition);
-		if (null!=_variables)
-			body.add(Constants.VARIABLE_VALUES, _variables.jbpmVariables());
+		FacadeUtil.populateVariableValues(message, _variables);
 	} // _______________________________
     
 	public Message postFormat(Message response) 
@@ -63,6 +62,7 @@
 		Object obj = body.get(Constants.JBPM_RETURN_OBJECT);
 		if (obj instanceof Token)
 			body.add(Constants.CURRENT_NODE_NAME,((Token)obj).getNode().getName());
+		FacadeUtil.jbpmVarsToMessage(response, _variables);
 		return response;
 	} // ________________________________
 

Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/TaskInstanceEndFacade.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/TaskInstanceEndFacade.java	2007-05-03 01:08:51 UTC (rev 11606)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/TaskInstanceEndFacade.java	2007-05-03 01:41:11 UTC (rev 11607)
@@ -47,14 +47,14 @@
 	public void preFormat(Message message) 
 	{
 		Body body = message.getBody();
-		if (null!=_variables && _variables.size()>0)
-			body.add(Constants.VARIABLE_VALUES, _variables.jbpmVariables());
 		if (null!=_transitionName)
 			body.add(Constants.TRANSITION_NAME, _transitionName);
+		FacadeUtil.populateVariableValues(message, _variables);
 	} // _______________________________
     
 	public Message postFormat(Message response) 
 	{
+		FacadeUtil.jbpmVarsToMessage(response, _variables);
 		return response;
 	} // ________________________________
 

Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/VariableMapping.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/VariableMapping.java	2007-05-03 01:08:51 UTC (rev 11606)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/VariableMapping.java	2007-05-03 01:41:11 UTC (rev 11607)
@@ -53,11 +53,4 @@
 	public Object getJbpmVariable(String key) { return _values.get(_jbpmNames.get(key)); }
 	
 	public Map<String,Object> esbVariables()  { return _values; }
-	public Map<String,Object> jbpmVariables() 
-	{ 
-		HashMap<String,Object> map = new HashMap<String, Object>();
-		for (Map.Entry<String, Object> curr: _values.entrySet())
-			map.put(getJbpmName(curr.getKey()), curr.getValue());
-		return map;
-	}
 }

Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/VariablesFacade.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/VariablesFacade.java	2007-05-03 01:08:51 UTC (rev 11606)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/facades/VariablesFacade.java	2007-05-03 01:41:11 UTC (rev 11607)
@@ -24,7 +24,6 @@
 
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.message.Body;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.services.jbpm.Constants;
 import org.jboss.soa.esb.services.jbpm.Constants.OpCode;
@@ -48,13 +47,12 @@
 	
 	public void preFormat(Message message) 
 	{
-		Body body = message.getBody();
-		if (null!=_variables && _variables.size()>0)
-			body.add(Constants.VARIABLE_VALUES, _variables.jbpmVariables());
+		FacadeUtil.populateVariableValues(message, _variables);
 	} // _______________________________
     
 	public Message postFormat(Message response) 
 	{
+		FacadeUtil.jbpmVarsToMessage(response, _variables);
 		return response;
 	} // ________________________________
 

Modified: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/BpmProcessorUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/BpmProcessorUnitTest.java	2007-05-03 01:08:51 UTC (rev 11606)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/BpmProcessorUnitTest.java	2007-05-03 01:41:11 UTC (rev 11607)
@@ -143,7 +143,8 @@
 					.getChildren(Constants.ONE_VARIABLE_TAG);
 
     		command = new BpmProcessor(actions[index++]);
-			response = command.process(Helper.commandMessageTemplate());
+    		request	= Helper.commandMessageTemplate();
+			response = command.process(request);
 			_logger.info(JbpmTestUtil.dumpResponse(response, command.getOpCode()));
 			ret = Helper.getStringValue(response, Constants.RETURN_CODE);
 			assertTrue(Constants.RETCODE_OK.equals(ret));
@@ -161,11 +162,21 @@
 			
 			// we've mapped differently, so check if mapping worked both ways
 			Body body = response.getBody();
-			assertTrue(vars[0].getAttribute("value").equals(body.get("xxx")));
-			assertTrue(vars[1].getAttribute("value").equals(body.get("yyy")));
+			assertTrue(vars[1].getAttribute("value").equals(body.get("xxx")));
+			assertTrue(vars[2].getAttribute("value").equals(body.get("yyy")));
 			
 			command	= new BpmProcessor(actions[index++]);
 			request	= Helper.commandMessageTemplate();
+			Helper.setLongValue(request, Constants.TOKEN_ID, tokenId);
+			String myContent = "My content travels in the message";
+			request.getBody().setContents(myContent.getBytes());
+			response	= command.process(request);
+			_logger.info(JbpmTestUtil.dumpResponse(response, command.getOpCode()));
+			ret = Helper.getStringValue(response, Constants.RETURN_CODE);
+			assertTrue(Constants.RETCODE_OK.equals(ret));
+			
+			command	= new BpmProcessor(actions[index++]);
+			request	= Helper.commandMessageTemplate();
 			Helper.setLongValue(request, Constants.PROCESS_INSTANCE_ID, processId);
 			response	= command.process(request);
 			_logger.info(JbpmTestUtil.dumpResponse(response, command.getOpCode()));

Modified: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/JbpmTestUtil.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/JbpmTestUtil.java	2007-05-03 01:08:51 UTC (rev 11606)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/JbpmTestUtil.java	2007-05-03 01:41:11 UTC (rev 11607)
@@ -79,13 +79,23 @@
 		sb.append(getObject(message,Constants.TASK_INSTANCE_ID));
 		sb.append(getObject(message,Constants.TOKEN_ID));
 		sb.append(getObject(message,Constants.HAS_ENDED));
+		sb.append(getObject(message,Constants.BODY_CONTENT_VARIABLE_NAME));
 		return sb.append("_______________________________________________________________________")
 			.toString();		
 	}
 	
 	public static String getObject(Message message, String key)
 	{
-		Object obj = message.getBody().get(key);
+		Object obj = null;
+		if(Constants.BODY_CONTENT_VARIABLE_NAME.equals(key))
+		{
+			obj = message.getBody().getContents();
+			return "Message body content = "
+				+((null==obj) ? "<null>" : new String((byte[])obj))
+				+"\n";
+		}
+		
+		obj = message.getBody().get(key);
 		if (null==obj)
 			return "";
 		if (!(obj instanceof Exception))

Modified: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testSingleCommands.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testSingleCommands.xml	2007-05-03 01:08:51 UTC (rev 11606)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testSingleCommands.xml	2007-05-03 01:41:11 UTC (rev 11607)
@@ -29,6 +29,7 @@
 			actor="FrankSinatra"
 			>
 			<variables>
+				<variable esb-name="BODY_CONTENT" jbpm-name="theBody" value="DEF DEF DEF"/>
 				<variable esb-name="eVar1" jbpm-name="j1"  value="AAAbbb111" />
 				<variable esb-name="eVar2" jbpm-name="vJ22"  value="998877" />
 			</variables>
@@ -39,11 +40,21 @@
 			command="GetProcessInstanceCommand"
 			>
 			<variables>
+				<variable esb-name="BODY_CONTENT" jbpm-name="theBody" />
 				<variable esb-name="yyy" jbpm-name="vJ22" />
 				<variable esb-name="xxx" jbpm-name="j1"  />
 			</variables>
 	</action>
 
+	<action	name="testBodyContent" 
+			class="org.jboss.soa.esb.services.jbpm.actions.BpmProcessor"
+			command="VariablesCommand"
+			>
+			<variables>
+				<variable esb-name="BODY_CONTENT" jbpm-name="theBody" />
+			</variables>
+	</action>
+
 	<action	name="nowCancelIt" 
 			class="org.jboss.soa.esb.services.jbpm.actions.BpmProcessor"
 			command="CancelProcessInstanceCommand"
@@ -55,6 +66,9 @@
 			command="GetProcessInstanceCommand"
 			include-all-variables="true"
 			>
+			<variables>
+				<variable esb-name="BODY_CONTENT" jbpm-name="theBody" />
+			</variables>
 	</action>
 
 </testActions>




More information about the jboss-svn-commits mailing list