svn commit: r1300965 - in /ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting: ContextHelper.java ScriptHelperImpl.java

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

svn commit: r1300965 - in /ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting: ContextHelper.java ScriptHelperImpl.java

adrianc
Author: adrianc
Date: Thu Mar 15 12:58:46 2012
New Revision: 1300965

URL: http://svn.apache.org/viewvc?rev=1300965&view=rev
Log:
Made the ScriptHelperImpl createServiceMap method behave more like mini-language. Error messages are saved in the result Map.

Modified:
    ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ContextHelper.java
    ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ScriptHelperImpl.java

Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ContextHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ContextHelper.java?rev=1300965&r1=1300964&r2=1300965&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ContextHelper.java (original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ContextHelper.java Thu Mar 15 12:58:46 2012
@@ -20,6 +20,7 @@ package org.ofbiz.common.scripting;
 
 import java.util.Iterator;
 import java.util.Locale;
+import java.util.List;
 import java.util.Map;
 import java.util.TimeZone;
 
@@ -28,6 +29,7 @@ import javax.script.ScriptEngine;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import javolution.util.FastList;
 import javolution.util.FastMap;
 
 import org.ofbiz.base.util.Assert;
@@ -40,6 +42,7 @@ import org.ofbiz.entity.GenericValue;
 import org.ofbiz.security.Security;
 import org.ofbiz.security.authz.Authorization;
 import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ModelService;
 
 /**
  * A set of <code>ScriptContext</code> convenience methods for scripting engines.
@@ -112,6 +115,24 @@ public final class ContextHelper {
         return getEnv(fma);
     }
 
+    public List<String> getErrorMessages() {
+        List<String> errorMessages = null;
+        if (isService()) {
+            errorMessages = UtilGenerics.checkList(getResults().get(ModelService.ERROR_MESSAGE_LIST));
+            if (errorMessages == null) {
+                errorMessages = FastList.newInstance();
+                getResults().put(ModelService.ERROR_MESSAGE_LIST, errorMessages);
+            }
+        } else {
+            errorMessages = UtilGenerics.checkList(getResults().get("_error_message_list_"));
+            if (errorMessages == null) {
+                errorMessages = FastList.newInstance();
+                getResults().put("_error_message_list_", errorMessages);
+            }
+        }
+        return errorMessages;
+    }
+
     public Iterator<Map.Entry<String, Object>> getEnvEntryIterator() {
         return getBindings().entrySet().iterator();
     }
@@ -142,8 +163,7 @@ public final class ContextHelper {
     }
 
     public Object getResult(String key) {
-        Map<?, ?> results = getResults();
-        return results != null ? results.get(key) : null;
+        return getResults().get(key);
     }
 
     public Map<String, Object> getResults() {

Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ScriptHelperImpl.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ScriptHelperImpl.java?rev=1300965&r1=1300964&r2=1300965&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ScriptHelperImpl.java (original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ScriptHelperImpl.java Thu Mar 15 12:58:46 2012
@@ -124,7 +124,7 @@ public final class ScriptHelperImpl impl
             Debug.logWarning(e, errMsg, module);
             throw new ScriptException(errMsg);
         }
-        toMap.putAll(modelService.makeValid(inputMap, "IN", true, null, ctxHelper.getTimeZone(), ctxHelper.getLocale()));
+        toMap.putAll(modelService.makeValid(inputMap, "IN", true, UtilGenerics.checkList(ctxHelper.getErrorMessages()), ctxHelper.getTimeZone(), ctxHelper.getLocale()));
         return toMap;
     }