[jboss-svn-commits] JBL Code SVN: r38234 - in labs/jbossesb/branches/JBESB_4_11_CP/product/services/jbpm5/src: test/java/org/jboss/soa/esb/services/jbpm5 and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Oct 24 15:10:49 EDT 2012


Author: tcunning
Date: 2012-10-24 15:10:48 -0400 (Wed, 24 Oct 2012)
New Revision: 38234

Modified:
   labs/jbossesb/branches/JBESB_4_11_CP/product/services/jbpm5/src/main/java/org/jboss/soa/esb/services/jbpm5/actions/BpmParameterMapper.java
   labs/jbossesb/branches/JBESB_4_11_CP/product/services/jbpm5/src/test/java/org/jboss/soa/esb/services/jbpm5/Bpm5ParameterMapperUnitTest.java
Log:
JBESB-3866
Allow mappings of different parts of the message using the ObjectMapper.   


Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/services/jbpm5/src/main/java/org/jboss/soa/esb/services/jbpm5/actions/BpmParameterMapper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/services/jbpm5/src/main/java/org/jboss/soa/esb/services/jbpm5/actions/BpmParameterMapper.java	2012-10-19 17:01:13 UTC (rev 38233)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/jbpm5/src/main/java/org/jboss/soa/esb/services/jbpm5/actions/BpmParameterMapper.java	2012-10-24 19:10:48 UTC (rev 38234)
@@ -27,6 +27,10 @@
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.message.Message;
 
+import org.jboss.soa.esb.message.mapping.ObjectMapper;
+import org.jboss.soa.esb.message.mapping.ObjectMappingException;
+
+
 /**
  * Maps BPM parameters from either values in the configuration or ESB
  * message properties.
@@ -40,7 +44,7 @@
 	private static final String ESB_TAG = "esb";
 	private static final String BPM_TAG = "bpm";
 	private static final String VALUE_TAG = "value";
-	
+		
 	/**
 	 * Map ESB properties to BPM properties.    If a value attribute exists,
 	 * use the value attribute as the value of the BPM property.    If no
@@ -52,15 +56,16 @@
 	 */
 	public static Map<String,Object> mapPropertiesToParams(Message msg, 
 			ConfigTree tree) {
-		
+	    ObjectMapper objectMapper = new ObjectMapper();
+
 		HashMap<String,String> mappingsOfParams = new HashMap<String, String>();
 		Map<String, Object> params = new HashMap<String,Object>();
 		
 		ConfigTree[] mappings = tree.getChildren(MAPPING_TAG);
 		for (int i = 0; i < mappings.length; i++) {
-			ConfigTree mapTree = mappings[i];
+			ConfigTree mapTree = mappings[i];			
 			String value = mapTree.getAttribute(VALUE_TAG);
-
+			
 			// If value isn't set, include the esb->bpm mapping in the mappings we
 			// check message properties for.    If value is set, use it instead.
 			if (value == null) {
@@ -72,7 +77,17 @@
 
 		// Now that we have the mapping, add the bpm key and the message property value
 		for (String esb : mappingsOfParams.keySet()) {
-			params.put(mappingsOfParams.get(esb), msg.getProperties().getProperty(esb));
+			try {
+				if (esb != null) {
+					if (esb.startsWith("body") || esb.startsWith("attachment") || esb.startsWith("header")) {
+						params.put(mappingsOfParams.get(esb), objectMapper.getObjectFromMessage(msg, esb));
+					} else {
+						params.put(mappingsOfParams.get(esb), msg.getProperties().getProperty(esb));						
+					}
+				}
+			} catch (ObjectMappingException e) {
+				params.put(mappingsOfParams.get(esb), msg.getProperties().getProperty(esb));
+			}
 		}
 		
 		return params;

Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/services/jbpm5/src/test/java/org/jboss/soa/esb/services/jbpm5/Bpm5ParameterMapperUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/services/jbpm5/src/test/java/org/jboss/soa/esb/services/jbpm5/Bpm5ParameterMapperUnitTest.java	2012-10-19 17:01:13 UTC (rev 38233)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/jbpm5/src/test/java/org/jboss/soa/esb/services/jbpm5/Bpm5ParameterMapperUnitTest.java	2012-10-24 19:10:48 UTC (rev 38234)
@@ -1,5 +1,6 @@
 package org.jboss.soa.esb.services.jbpm5;
 
+import java.net.URI;
 import java.util.Map;
 
 import static org.junit.Assert.assertEquals;
@@ -12,7 +13,9 @@
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.addressing.Call;
 
+
 import org.junit.Test;
 import org.junit.BeforeClass;
 import org.apache.log4j.Logger;
@@ -63,8 +66,42 @@
     	assertEquals(employee, "joe");
     	assertEquals(reason, "theheckofit");    	
 	}
-        
+
     @Test
+	public void testEsbToBpmObjectMapperBody() throws Exception
+	{
+        config = ConfigTree.fromXml("<property name=\"esbToBpmParams\">"
+        		+ "<mapping esb=\"body.employee\" bpm=\"employee\"/>"
+        		+ "<mapping esb=\"attachment.function\" bpm=\"function\"/>"
+        		+ "<mapping esb=\"header.badgenumber\" bpm=\"badgenumber\"/>"
+                + "<mapping esb=\"reason\" bpm=\"reason\"/>"
+                + "</property>");
+
+    	Message message = MessageFactory.getInstance().getMessage() ;
+    	message.getBody().add("employee", "joe");
+    	message.getAttachment().put("function", "foobar");
+    	message.getProperties().setProperty("reason", "theheckofit");
+    	Call call = new Call();
+    	call.setAction(new URI("foo"));
+    	message.getHeader().setCall(call);
+    	
+    	Map<String, Object> map = BpmParameterMapper.mapPropertiesToParams(message, config);
+
+    	String employee = (String)map.get("employee");
+    	String reason = (String)map.get("reason");
+    	String function = (String)map.get("function");
+    	Call badge = (Call) map.get("badgenumber");
+    	
+    	System.out.println("EMPLOYEE=" + employee + " REASON=" + reason + " FUNCTION=" + function 
+    			+ "C ALL [" + call.getAction().toString() + "]");
+    	
+    	assertEquals(employee, "joe");
+    	assertEquals(function, "foobar");
+    	assertEquals(reason, "theheckofit");    	
+    	assertEquals(call.getAction().toString(), "foo");
+	}
+    
+    @Test
 	public void testValue() throws Exception
 	{
         config = ConfigTree.fromXml("<property name=\"esbToBpmParams\">"



More information about the jboss-svn-commits mailing list