svn commit: r1866380 - in /ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service: ModelParam.java 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: r1866380 - in /ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service: ModelParam.java ModelService.java

nmalin
Author: nmalin
Date: Wed Sep  4 12:05:26 2019
New Revision: 1866380

URL: http://svn.apache.org/viewvc?rev=1866380&view=rev
Log:
Implemented: Service parameter default-value attribut can support flexible string
(OFBIZ-11180)

When you define a service with default-value, you can't set simple dynamic resolution for the value.
The improvement extend the default-value attribut on service parameter to support the FlexibleStringExpander syntax and realize the expand on service context.

Example :
     <service name=createPicklist default-entity-name=Picklist engine=entity-auto invoke=create auth=true>
        <auto-attributes include=pk mode=OUT optional=false/>
        <auto-attributes include=nonpk mode=IN optional=true/>
        <override name=statusId default-value=PICKLIST_INPUT/>
        <override name=picklistDate default-value=/>
     </service>

Thanks Jacques Le Roux and Swapnil M Mane for the review

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

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelParam.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelParam.java?rev=1866380&r1=1866379&r2=1866380&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelParam.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelParam.java Wed Sep  4 12:05:26 2019
@@ -21,6 +21,7 @@ package org.apache.ofbiz.service;
 import java.io.Serializable;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Objects;
 
 import javax.wsdl.Definition;
@@ -31,6 +32,7 @@ import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.ObjectType;
 import org.apache.ofbiz.base.util.UtilProperties;
 import org.apache.ofbiz.base.util.UtilValidate;
+import org.apache.ofbiz.base.util.string.FlexibleStringExpander;
 
 /**
  * Generic Service Model Parameter
@@ -77,7 +79,7 @@ public class ModelParam implements Seria
     public List<ModelParamValidator> validators;
 
     /** Default value */
-    private String defaultValue = null;
+    private FlexibleStringExpander defaultValue = null;
 
     /** Is this Parameter required or optional? Default to false, or required */
     public boolean optional = false;
@@ -109,7 +111,7 @@ public class ModelParam implements Seria
         this.stringListSuffix = param.stringListSuffix;
         this.validators = param.validators;
         if (param.defaultValue != null) {
-            this.setDefaultValue(param.defaultValue);
+            this.setDefaultValue(param.defaultValue.getOriginal());
         }
         this.optional = param.optional;
         this.overrideOptional = param.overrideOptional;
@@ -178,11 +180,15 @@ public class ModelParam implements Seria
         return this.optional;
     }
 
-    public Object getDefaultValue() {
+    public FlexibleStringExpander getDefaultValue() {
+        return this.defaultValue;
+    }
+
+    public Object getDefaultValue(Map<String, Object> context) {
         Object defaultValueObj = null;
         if (this.type != null) {
             try {
-                defaultValueObj = ObjectType.simpleTypeOrObjectConvert(this.defaultValue, this.type, null, null, false);
+                defaultValueObj = ObjectType.simpleTypeOrObjectConvert(this.defaultValue.expandString(context), this.type, null, null, false);
             } catch (Exception e) {
                 Debug.logWarning(e, "Service attribute [" + name + "] default value could not be converted to type [" + type + "]: " + e.toString(), module);
             }
@@ -196,14 +202,14 @@ public class ModelParam implements Seria
         return defaultValueObj;
     }
     public void setDefaultValue(String defaultValue) {
-        this.defaultValue = defaultValue;
+        this.defaultValue = FlexibleStringExpander.getInstance(defaultValue);
         if (this.defaultValue != null) {
             this.optional = true;
         }
         if (Debug.verboseOn()) Debug.logVerbose("Default value for attribute [" + this.name + "] set to [" + this.defaultValue + "]", module);
     }
     public void copyDefaultValue(ModelParam param) {
-        this.setDefaultValue(param.defaultValue);
+        this.setDefaultValue(param.defaultValue.getOriginal());
     }
 
     public boolean equals(ModelParam model) {

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java?rev=1866380&r1=1866379&r2=1866380&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java Wed Sep  4 12:05:26 2019
@@ -498,8 +498,9 @@ public class ModelService extends Abstra
     public void updateDefaultValues(Map<String, Object> context, String mode) {
         List<ModelParam> params = this.getModelParamList();
         for (ModelParam param: params) {
-            if (IN_OUT_PARAM.equals(param.mode) || mode.equals(param.mode)) {
-                Object defaultValueObj = param.getDefaultValue();
+            if (param.getDefaultValue() != null
+                    && (IN_OUT_PARAM.equals(param.mode) || mode.equals(param.mode))) {
+                Object defaultValueObj = param.getDefaultValue(context);
                 if (defaultValueObj != null && context.get(param.name) == null) {
                     context.put(param.name, defaultValueObj);
                     Debug.logInfo("Set default value [" + defaultValueObj + "] for parameter [" + param.name + "]", module);