You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/02/16 21:38:55 UTC

svn commit: r508566 - in /ofbiz/trunk/framework/service/src/org/ofbiz/service: ModelParam.java ModelService.java ModelServiceReader.java

Author: jaz
Date: Fri Feb 16 12:38:54 2007
New Revision: 508566

URL: http://svn.apache.org/viewvc?view=rev&rev=508566
Log:
fixed big bug in using default-value with override parameters; effected groups and implemented services w/ overrides

Modified:
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java?view=diff&rev=508566&r1=508565&r2=508566
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java Fri Feb 16 12:38:54 2007
@@ -63,7 +63,8 @@
     public List validators;
 
     /** Default value */
-    public Object defaultValue;
+    public String defaultValue;    
+    public Object defaultValueObj;
 
     /** Is this Parameter required or optional? Default to false, or required */
     public boolean optional = false;

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java?view=diff&rev=508566&r1=508565&r2=508566
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java Fri Feb 16 12:38:54 2007
@@ -128,7 +128,7 @@
     public String permissionMainAction;
     
     /** Permission service resource-description */
-    public String permissionResourceDescription;
+    public String permissionResourceDesc;
     
     /** Set of services this service implements */
     public Set implServices = new ListOrderedSet();
@@ -167,9 +167,14 @@
         this.useTransaction = model.useTransaction || true;
         this.requireNewTransaction = model.requireNewTransaction;
         this.transactionTimeout = model.transactionTimeout;
+        this.maxRetry = model.maxRetry;
+        this.permissionServiceName = model.permissionServiceName;
+        this.permissionMainAction = model.permissionMainAction;
+        this.permissionResourceDesc = model.permissionResourceDesc;
         this.implServices = model.implServices;
         this.overrideParameters = model.overrideParameters;
         this.inheritedParameters = model.inheritedParameters();
+        this.internalGroup = model.internalGroup;
 
         List modelParamList = model.getModelParamList();
         Iterator i = modelParamList.iterator();
@@ -775,11 +780,12 @@
                 if (UtilValidate.isNotEmpty(this.permissionMainAction)) {
                     ctx.put("mainAction", this.permissionMainAction);
                 }
-                if (UtilValidate.isNotEmpty(this.permissionResourceDescription)) {
-                    ctx.put("resourceDescription", this.permissionResourceDescription);
+                if (UtilValidate.isNotEmpty(this.permissionResourceDesc)) {
+                    ctx.put("resourceDescription", this.permissionResourceDesc);
                 } else if (thisService != null) {
                     ctx.put("resourceDescription", thisService.name);
                 }
+                
                 LocalDispatcher dispatcher = dctx.getDispatcher();
                 Map resp;
                 try {
@@ -963,21 +969,31 @@
 
                     if (existingParam != null) {
                         // now re-write the parameters
-                        if (overrideParam.type != null && overrideParam.type.length() > 0) {
+                        if (UtilValidate.isNotEmpty(overrideParam.type)) {
                             existingParam.type = overrideParam.type;
                         }
-                        if (overrideParam.mode != null && overrideParam.mode.length() > 0) {
+                        if (UtilValidate.isNotEmpty(overrideParam.mode)) {
                             existingParam.mode = overrideParam.mode;
                         }
-                        if (overrideParam.entityName != null && overrideParam.entityName.length() > 0) {
+                        if (UtilValidate.isNotEmpty(overrideParam.entityName)) {
                             existingParam.entityName = overrideParam.entityName;
                         }
-                        if (overrideParam.fieldName != null && overrideParam.fieldName.length() > 0) {
+                        if (UtilValidate.isNotEmpty(overrideParam.fieldName)) {
                             existingParam.fieldName = overrideParam.fieldName;
                         }
-                        if (overrideParam.formLabel != null && overrideParam.formLabel.length() > 0) {
+                        if (UtilValidate.isNotEmpty(overrideParam.formLabel)) {
                             existingParam.formLabel = overrideParam.formLabel;
                         }
+                        if (overrideParam.defaultValue != null) {
+                            existingParam.defaultValue = overrideParam.defaultValue;
+                            existingParam.optional = true;
+                            if (overrideParam.defaultValueObj == null) {
+                                existingParam.defaultValueObj = this.convertDefaultValue(this.name, overrideParam.name,
+                                        existingParam.type, overrideParam.defaultValue);
+                            } else {
+                                existingParam.defaultValueObj = overrideParam.defaultValueObj;
+                            }
+                        }
                         if (overrideParam.overrideFormDisplay) {
                             existingParam.formDisplay = overrideParam.formDisplay;
                         }
@@ -994,6 +1010,18 @@
             // set the flag so we don't do this again
             this.inheritedParameters = true;
         }
+    }
+
+    protected Object convertDefaultValue(String serviceName, String name, String type, String value) {
+        Object converted;
+        try {
+            converted = ObjectType.simpleTypeConvert(value, type, null, null, false);
+        } catch (Exception e) {
+            Debug.logWarning("Service [" + serviceName + "] attribute [" + name + "] default value could not be converted to type [" + type + "]", module);
+            return value;
+        }
+
+        return converted;
     }
 
     public Document toWSDL(String locationURI) throws WSDLException {

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java?view=diff&rev=508566&r1=508565&r2=508566
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java Fri Feb 16 12:38:54 2007
@@ -68,7 +68,7 @@
     protected DispatchContext dctx = null;
 
     public static ModelServiceReader getModelServiceReader(URL readerURL, DispatchContext dctx) {
-        ModelServiceReader reader = null;
+        ModelServiceReader reader;
 
         // if ( readersUrl.containsKey(readerURL) ) <-- this is unnecessary as it will return null below if not found
         reader = (ModelServiceReader) readersUrl.get(readerURL);
@@ -87,7 +87,7 @@
     }
 
     public static ModelServiceReader getModelServiceReader(ResourceHandler handler, DispatchContext dctx) {
-        ModelServiceReader reader = null;
+        ModelServiceReader reader;
 
         reader = (ModelServiceReader) readersLoader.get(handler);
         if (reader == null) { // don't want to block here
@@ -131,7 +131,7 @@
 
                     UtilTimer utilTimer = new UtilTimer();
 
-                    Document document = null;
+                    Document document;
 
                     if (this.isFromURL) {
                         // utilTimer.timerString("Before getDocument in file " + readerURL);
@@ -170,7 +170,7 @@
                             utilTimer.timerString("Before start of service loop in file " + readerURL);
                         } else {
                             utilTimer.timerString("Before start of service loop in " + handler);
-                        }                        ;
+                        }
 
                         do {
                             if (curChild.getNodeType() == Node.ELEMENT_NODE && "service".equals(curChild.getNodeName())) {
@@ -321,20 +321,12 @@
                        
         service.description = getCDATADef(serviceElement, "description");
         service.nameSpace = getCDATADef(serviceElement, "namespace");  
-
-        // check or an internal group
-        List group = UtilXml.childElementList(serviceElement, "group");
-        if (group != null && group.size() > 0) {
-            Element groupElement = (Element) group.get(0);
-            groupElement.setAttribute("name", "_" + service.name + ".group");
-            service.internalGroup = new GroupModel(groupElement);
-            service.invoke = service.internalGroup.getGroupName();
-        }
-
+        
         // contruct the context
         service.contextInfo = FastMap.newInstance();
         this.createPermission(serviceElement, service);
         this.createPermGroups(serviceElement, service);
+        this.createGroupDefs(serviceElement, service);
         this.createImplDefs(serviceElement, service);
         this.createAutoAttrDefs(serviceElement, service);
         this.createAttrDefs(serviceElement, service);
@@ -366,7 +358,7 @@
         if (e != null) {
             model.permissionServiceName = e.getAttribute("service-name");
             model.permissionMainAction = e.getAttribute("main-action");
-            model.permissionResourceDescription = e.getAttribute("resource-description");
+            model.permissionResourceDesc = e.getAttribute("resource-description");
             model.auth = true; // auth is always required when permissions are set
         }
     }
@@ -416,6 +408,17 @@
         }
     }
 
+    protected void createGroupDefs(Element baseElement, ModelService service) {
+        List group = UtilXml.childElementList(baseElement, "group");
+        if (group != null && group.size() > 0) {
+            Element groupElement = (Element) group.get(0);
+            groupElement.setAttribute("name", "_" + service.name + ".group");
+            service.internalGroup = new GroupModel(groupElement);
+            service.invoke = service.internalGroup.getGroupName();
+            Debug.logWarning("Created INTERNAL GROUP model [" + service.internalGroup + "]", module);
+        }
+    }
+    
     protected void createImplDefs(Element baseElement, ModelService service) {
         List implElements = UtilXml.childElementList(baseElement, "implements");
         Iterator implIter = implElements.iterator();
@@ -539,7 +542,10 @@
             // default value
             String defValue = attribute.getAttribute("default-value");
             if (UtilValidate.isNotEmpty(defValue)) {
-                param.defaultValue = this.convertDefaultValue(service.name, param.name, param.type, defValue);
+                param.defaultValue = defValue;
+                if (param.type != null) {
+                    param.defaultValueObj = service.convertDefaultValue(service.name, param.name, param.type, defValue);
+                }
                 param.optional = true;
             }
             
@@ -559,7 +565,7 @@
         }
 
         // Add the default optional parameters
-        ModelParam def = null;
+        ModelParam def;
 
         // responseMessage
         def = new ModelParam();
@@ -629,7 +635,7 @@
             ModelParam param = service.getParam(name);
             boolean directToParams = true;
             if (param == null) {
-                if (service.implServices.size() > 0 && !service.inheritedParameters) {                
+                if (!service.inheritedParameters && (service.implServices.size() > 0 || "group".equals(service.engineName))) {                 
                     // create a temp def to place in the ModelService
                     // this will get read when we read implemented services 
                     directToParams = false;               
@@ -669,7 +675,10 @@
                 // default value
                 String defValue = attribute.getAttribute("default-value");
                 if (UtilValidate.isNotEmpty(defValue)) {
-                    param.defaultValue = this.convertDefaultValue(service.name, param.name, param.type, defValue);
+                    param.defaultValue = defValue;
+                    if (param.type != null) {
+                        param.defaultValueObj = service.convertDefaultValue(service.name, param.name, param.type, defValue);
+                    }                    
                     param.optional = true;
                 }
 
@@ -733,17 +742,5 @@
         }
 
         return document;
-    }
-
-    protected Object convertDefaultValue(String serviceName, String name, String type, String value) {
-        Object converted;
-        try {
-            converted = ObjectType.simpleTypeConvert(value, type, null, null, false);
-        } catch (Exception e) {
-            Debug.logWarning("Service [" + serviceName + "] attribute [" + name + "] default value could not be converted to type [" + type + "]", module);
-            return value;
-        }
-
-        return converted;
     }
 }