ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jler...@apache.org
Subject svn commit: r1462977 - in /ofbiz/branches/release10.04: ./ applications/accounting/widget/GlForms.xml framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java
Date Sun, 31 Mar 2013 14:40:29 GMT
Author: jleroux
Date: Sun Mar 31 14:40:28 2013
New Revision: 1462977

URL: http://svn.apache.org/r1462977
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/release10.04/   (props changed)
    ofbiz/branches/release10.04/applications/accounting/widget/GlForms.xml
    ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java

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

Modified: ofbiz/branches/release10.04/applications/accounting/widget/GlForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release10.04/applications/accounting/widget/GlForms.xml?rev=1462977&r1=1462976&r2=1462977&view=diff
==============================================================================
--- ofbiz/branches/release10.04/applications/accounting/widget/GlForms.xml (original)
+++ ofbiz/branches/release10.04/applications/accounting/widget/GlForms.xml Sun Mar 31 14:40:28
2013
@@ -235,7 +235,7 @@ under the License.
         </field>
         <field name="invoiceId"><lookup target-form-name="LookupInvoice" size="20"
maxlength="20"/></field>
         <field name="paymentId"><lookup target-form-name="LookupPayment" size="20"
maxlength="20"/></field>
-        <field name="produtId"><lookup target-form-name="LookupProduct" size="20"
maxlength="20"/></field>
+        <field name="productId"><lookup target-form-name="LookupProduct" size="20"
maxlength="20"/></field>
         <field name="workEffortId"><lookup target-form-name="LookupWorkEffort" size="20"
maxlength="20"/></field>
         <field name="shipmentId"><lookup target-form-name="LookupShipment" size="20"
maxlength="20"/></field>
         <field name="fromDate"><date-time/></field>
@@ -452,7 +452,7 @@ under the License.
         </field>
         <field name="invoiceId" position="1"><lookup target-form-name="LookupInvoice"
size="20" maxlength="20"/></field>
         <field name="paymentId" position="2"><lookup target-form-name="LookupPayment"
size="20" maxlength="20"/></field>
-        <field name="produtId" position="1"><lookup target-form-name="LookupProduct"
size="20" maxlength="20"/></field>
+        <field name="productId" position="1"><lookup target-form-name="LookupProduct"
size="20" maxlength="20"/></field>
         <field name="workEffortId" position="2"><lookup target-form-name="LookupWorkEffort"
size="20" maxlength="20"/></field>
         <field name="shipmentId" position="1"><lookup target-form-name="LookupShipment"
size="20" maxlength="20"/></field>
         <field name="fixedAssetId" position="2">
@@ -540,7 +540,7 @@ under the License.
                 <sub-hyperlink target="paymentOverview?paymentId=${acctgTrans.paymentId}"
description="${acctgTrans.paymentId}"/>
             </lookup>
         </field>
-        <field name="produtId"><lookup target-form-name="LookupProduct" size="20"
maxlength="20"/></field>
+        <field name="productId"><lookup target-form-name="LookupProduct" size="20"
maxlength="20"/></field>
         <field name="shipmentId"><lookup target-form-name="LookupShipment" size="20"
maxlength="20"/></field>
         <field name="inventoryItemId"><text/></field>
         <field name="groupStatusId" title="${uiLabelMap.FormFieldTitle_groupStatus}">

Modified: ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java?rev=1462977&r1=1462976&r2=1462977&view=diff
==============================================================================
--- ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java
(original)
+++ ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java
Sun Mar 31 14:40:28 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;
 
 /**
@@ -99,28 +99,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);
@@ -157,4 +163,3 @@ public class PrimaryKeyFinder extends Fi
         }
     }
 }
-



Mime
View raw message