You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2013/03/31 16:22:29 UTC

svn commit: r1462970 - in /ofbiz/branches/release11.04: ./ framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java

Author: jleroux
Date: Sun Mar 31 14:22:29 2013
New Revision: 1462970

URL: http://svn.apache.org/r1462970
Log:
"Applied fix from trunk for revision: 1462948" 
------------------------------------------------------------------------
r1462948 | jleroux | 2013-03-31 15:41:34 +0200 (dim., 31 mars 2013) | 13 lines

A refactored patch from Leon for "Bug introduced by OFBIZ-4769, it makes <entity-one> failed if the context contains incorrect data" https://issues.apache.org/jira/browse/OFBIZ-5148

How to reproduce:
1. open "https://demo-trunk.ofbiz.apache.org/partymgr/control/editpartygroup?create_new=Y" (try to create a new party group)
2. input any words in group name field, input any "incorrect" non-digits characters (e.g. "abcd" blah blah) to field "Annual revenue"
3. click save
It leads to an "exception" page instead of original input form with error message.

I digged some codes and found it's related to r1426231 commit (of OFBIZ-4769).

jleroux: the logic of code seemed good to me, I just refactored the cod a bit (in a previous refactoring attempt I missed the point that parametersObjExists might not be present. This new code is a simplified version of what does setAllFields internally. The PK fieldValues are set before being possibly overriden by context values. There is no Map casting. I tested the previous issues, all are resolved. 


------------------------------------------------------------------------


Modified:
    ofbiz/branches/release11.04/   (props changed)
    ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java

Propchange: ofbiz/branches/release11.04/
------------------------------------------------------------------------------
  Merged /ofbiz/trunk:r1462948

Modified: ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java?rev=1462970&r1=1462969&r2=1462970&view=diff
==============================================================================
--- ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java (original)
+++ ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java Sun Mar 31 14:22:29 2013
@@ -18,6 +18,7 @@
  */
 package org.ofbiz.entity.finder;
 
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -26,8 +27,6 @@ import javolution.util.FastMap;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
-import org.ofbiz.base.util.UtilGenerics;
-import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
 import org.ofbiz.base.util.string.FlexibleStringExpander;
@@ -36,6 +35,7 @@ import org.ofbiz.entity.GenericEntityExc
 import org.ofbiz.entity.GenericPK;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.model.ModelEntity;
+import org.ofbiz.entity.model.ModelField;
 import org.w3c.dom.Element;
 
 /**
@@ -103,28 +103,34 @@ public class PrimaryKeyFinder extends Fi
         // assemble the field map
         Map<String, Object> entityContext = FastMap.newInstance();
         if (autoFieldMap) {
-            GenericValue tempVal = delegator.makeValue(modelEntity.getEntityName());
-
             // try a map called "parameters", try it first so values from here are overridden by values in the main context
             Object parametersObj = context.get("parameters");
-            if (parametersObj != null && parametersObj instanceof Map<?, ?>) {
-                Map<String, Object> parameters = UtilMisc.<String, Object>toMap(UtilGenerics.checkMap(parametersObj));
-                // need the timeZone and locale for conversion, so add here and remove after
-                parameters.put("locale", context.get("locale"));
-                parameters.put("timeZone", context.get("timeZone"));
-                modelEntity.convertFieldMapInPlace(parameters, delegator);
-                parameters.remove("timeZone");
-                parameters.remove("locale");
-                tempVal.setAllFields(parameters, true, null, Boolean.TRUE);
+            Boolean parametersObjExists = parametersObj != null && parametersObj instanceof Map<?, ?>;
+            // only need PK fields
+            Iterator<ModelField> iter = modelEntity.getPksIterator();
+            while (iter.hasNext()) {
+                ModelField curField = iter.next();
+                String fieldName = curField.getName();
+                Object fieldValue = null;
+                if (parametersObjExists) {        
+                    fieldValue = ((Map<?, ?>) parametersObj).get(fieldName);
+                }
+                if (context.containsKey(fieldName)) {
+                    fieldValue = context.get(fieldName);
+                }
+                entityContext.put(fieldName, fieldValue);
             }
-
-            // just get the primary keys, and hopefully will get all of them, if not they must be manually filled in below in the field-maps
-            modelEntity.convertFieldMapInPlace(context, delegator);
-            tempVal.setAllFields(context, true, null, Boolean.TRUE);
-
-            entityContext.putAll(tempVal);
         }
         EntityFinderUtil.expandFieldMapToContext(fieldMap, context, entityContext);
+        //Debug.logInfo("PrimaryKeyFinder: entityContext=" + entityContext, module);
+        // then convert the types...
+        
+        // need the timeZone and locale for conversion, so add here and remove after
+        entityContext.put("locale", context.get("locale"));
+        entityContext.put("timeZone", context.get("timeZone"));
+        modelEntity.convertFieldMapInPlace(entityContext, delegator);
+        entityContext.remove("locale");
+        entityContext.remove("timeZone");
 
         // get the list of fieldsToSelect from selectFieldExpanderList
         Set<String> fieldsToSelect = EntityFinderUtil.makeFieldsToSelect(selectFieldExpanderList, context);
@@ -161,4 +167,3 @@ public class PrimaryKeyFinder extends Fi
         }
     }
 }
-