svn commit: r792633 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/UtilMisc.java minilang/src/org/ofbiz/minilang/SimpleMethod.java minilang/src/org/ofbiz/minilang/method/callops/CallService.java service/src/org/ofbiz/service/ServiceUtil.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r792633 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/UtilMisc.java minilang/src/org/ofbiz/minilang/SimpleMethod.java minilang/src/org/ofbiz/minilang/method/callops/CallService.java service/src/org/ofbiz/service/ServiceUtil.java

jonesde
Author: jonesde
Date: Thu Jul  9 18:51:00 2009
New Revision: 792633

URL: http://svn.apache.org/viewvc?rev=792633&view=rev
Log:
Change to handling of error messages in simple-methods called as a service to pass errors through in List/Map and not combine into one big String, add text you can't change, etc; now logs details and passes errors as-is

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java?rev=792633&r1=792632&r2=792633&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java Thu Jul  9 18:51:00 2009
@@ -251,8 +251,8 @@
     /**
      * Assuming outerMap not null; if null will throw a NullPointerException
      */
-    public static <K, IK, V> Map<IK, V> getMapFromMap(Map<K, Map<IK, V>> outerMap, K key) {
-        Map<IK, V> innerMap = outerMap.get(key);
+    public static <K, IK, V> Map<IK, V> getMapFromMap(Map<K, Object> outerMap, K key) {
+        Map<IK, V> innerMap = UtilGenerics.<IK, V>checkMap(outerMap.get(key));
         if (innerMap == null) {
             innerMap = FastMap.newInstance();
             outerMap.put(key, innerMap);
@@ -263,8 +263,8 @@
     /**
      * Assuming outerMap not null; if null will throw a NullPointerException
      */
-    public static <K, V> List<V> getListFromMap(Map<K, List<V>> outerMap, K key) {
-        List<V> innerList = outerMap.get(key);
+    public static <K, V> List<V> getListFromMap(Map<K, Object> outerMap, K key) {
+        List<V> innerList = UtilGenerics.<V>checkList(outerMap.get(key));
         if (innerList == null) {
             innerList = FastList.newInstance();
             outerMap.put(key, innerList);
@@ -732,7 +732,8 @@
     }
 
     /** This is meant to be very quick to create and use for small sized maps, perfect for how we usually use UtilMisc.toMap */
-    protected static class SimpleMap<V> implements Map<String, V>, java.io.Serializable {
+    @SuppressWarnings("serial")
+ protected static class SimpleMap<V> implements Map<String, V>, java.io.Serializable {
         protected Map<String, V> realMapIfNeeded = null;
 
         String[] names;
@@ -951,7 +952,7 @@
             if (realMapIfNeeded != null) {
                 return realMapIfNeeded.equals(obj);
             } else {
-                Map mapObj = (Map) obj;
+                Map<String, V> mapObj = UtilGenerics.<String, V>checkMap(obj);
 
                 //first check the size
                 if (mapObj.size() != names.length) return false;

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java?rev=792633&r1=792632&r2=792633&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java Thu Jul  9 18:51:00 2009
@@ -89,19 +89,19 @@
  * SimpleMethod Mini Language Core Object
  */
 public class SimpleMethod {
-    private static final Map<String, MethodOperation.Factory> methodOperationFactories;
-    private static final Method simpleMethodExecMethod;
+    private static final Map<String, MethodOperation.Factory<MethodOperation>> methodOperationFactories;
+    // never read locally: private static final Method simpleMethodExecMethod;
     private static final Method methodOperationExecMethod;
     static {
-        Map<String, MethodOperation.Factory> mapFactories = new HashMap<String, MethodOperation.Factory>();
+        Map<String, MethodOperation.Factory<MethodOperation>> mapFactories = new HashMap<String, MethodOperation.Factory<MethodOperation>>();
         Iterator<MethodOperation.Factory> it = ServiceRegistry.lookupProviders(MethodOperation.Factory.class, SimpleMethod.class.getClassLoader());
         while (it.hasNext()) {
-            MethodOperation.Factory factory = it.next();
+            MethodOperation.Factory<MethodOperation> factory = it.next();
             mapFactories.put(factory.getName(), factory);
         }
         methodOperationFactories = Collections.unmodifiableMap(mapFactories);
         try {
-            simpleMethodExecMethod = SimpleMethod.class.getDeclaredMethod("exec", MethodContext.class);
+            // never read locally: simpleMethodExecMethod = SimpleMethod.class.getDeclaredMethod("exec", MethodContext.class);
             methodOperationExecMethod = MethodOperation.class.getDeclaredMethod("exec", MethodContext.class);
         } catch (NoSuchMethodException e) {
             throw UtilMisc.initCause(new InternalError(e.getMessage()), e);
@@ -449,6 +449,10 @@
         return this.serviceErrorMessageListName;
     }
 
+    public String getServiceErrorMessageMapName() {
+        return this.serviceErrorMessageMapName;
+    }
+
     public String getServiceSuccessMessageName() {
         return this.serviceSuccessMessageName;
     }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java?rev=792633&r1=792632&r2=792633&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java Thu Jul  9 18:51:00 2009
@@ -321,7 +321,10 @@
             if (methodContext.getMethodType() == MethodContext.EVENT) {
                 methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errorMessage);
             } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
-                methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errorMessage);
+                ServiceUtil.addErrors(UtilMisc.<String, String>getListFromMap(methodContext.getEnvMap(), this.simpleMethod.getServiceErrorMessageListName()),
+                 UtilMisc.<String, String, Object>getMapFromMap(methodContext.getEnvMap(), this.simpleMethod.getServiceErrorMessageMapName()), result);
+                // the old way, makes a mess of messages passed up the stack: methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errorMessage);
+                Debug.logError(new Exception(errorMessage), module);
             }
         }
 

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java?rev=792633&r1=792632&r2=792633&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java Thu Jul  9 18:51:00 2009
@@ -18,29 +18,38 @@
  *******************************************************************************/
 package org.ofbiz.service;
 
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.transaction.Transaction;
+
 import javolution.util.FastList;
 import javolution.util.FastMap;
-import org.ofbiz.base.util.*;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilGenerics;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.condition.EntityCondition;
-import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
 import org.ofbiz.entity.transaction.GenericTransactionException;
 import org.ofbiz.entity.transaction.TransactionUtil;
 import org.ofbiz.entity.util.EntityFindOptions;
 import org.ofbiz.entity.util.EntityListIterator;
-import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.security.Security;
 import org.ofbiz.service.config.ServiceConfigUtil;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.transaction.Transaction;
-import java.sql.Timestamp;
-import java.util.*;
-
 /**
  * Generic Service Utility Class
  */
@@ -318,13 +327,13 @@
      * @param targetMap The Map to add any Map error messages to
      * @param callResult The result from an invocation
      */
-    public static void addErrors(List<Object> targetList, Map<String, Object> targetMap, Map<String, ? extends Object> callResult) {
-        List<? extends Object> newList;
-        Map<String, ? extends Object> errorMsgMap;
+    public static void addErrors(List<String> targetList, Map<String, Object> targetMap, Map<String, ? extends Object> callResult) {
+        List<String> newList;
+        Map<String, Object> errorMsgMap;
 
         //See if there is a single message
         if (callResult.containsKey(ModelService.ERROR_MESSAGE)) {
-            targetList.add(callResult.get(ModelService.ERROR_MESSAGE));
+            targetList.add((String) callResult.get(ModelService.ERROR_MESSAGE));
         }
 
         //See if there is a message list