svn commit: r1776243 - /ofbiz/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java

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

svn commit: r1776243 - /ofbiz/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java

jleroux@apache.org
Author: jleroux
Date: Wed Dec 28 08:47:25 2016
New Revision: 1776243

URL: http://svn.apache.org/viewvc?rev=1776243&view=rev
Log:
Implemented: Add a isValid() method to the ModelService class
(OFBIZ-9158)

The idea is to use validate() to render a boolean result. I needed that in a
custom project, I think it's worth contributing.

Modified:
    ofbiz/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java

Modified: ofbiz/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java?rev=1776243&r1=1776242&r2=1776243&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java (original)
+++ ofbiz/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java Wed Dec 28 08:47:25 2016
@@ -600,6 +600,32 @@ public class ModelService extends Abstra
     }
 
     /**
+     * Validates a Map against the IN or OUT parameter information
+     * Same than validate() with same signature but returns a boolean instead of exceptions
+     * @param context the context
+     * @param mode Test either mode IN or mode OUT
+     * @param locale the actual locale to use
+     */
+    public boolean isValid(Map<String, Object> context, String mode, Locale locale) {
+        boolean verboseOn = Debug.verboseOn();
+        if (verboseOn) Debug.logVerbose("[ModelService.validate] : {" + this.name + "} : Validating context - " + context, module);
+
+        // do not validate results with errors
+        if (mode.equals(OUT_PARAM) && context != null && context.containsKey(RESPONSE_MESSAGE)) {
+            if (RESPOND_ERROR.equals(context.get(RESPONSE_MESSAGE)) || RESPOND_FAIL.equals(context.get(RESPONSE_MESSAGE))) {
+                if (verboseOn) Debug.logVerbose("[ModelService.validate] : {" + this.name + "} : response was an error, not validating.", module);
+                return false;
+            }
+        }
+        try {
+            validate(context, mode, locale);
+        } catch (ServiceValidationException e) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
      * Validates a map of name, object types to a map of name, objects
      * @param info The map of name, object types
      * @param test The map to test its value types.