Return-Path: X-Original-To: apmail-ofbiz-commits-archive@www.apache.org Delivered-To: apmail-ofbiz-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 11DE4FFBB for ; Sun, 31 Mar 2013 14:40:55 +0000 (UTC) Received: (qmail 87631 invoked by uid 500); 31 Mar 2013 14:40:54 -0000 Delivered-To: apmail-ofbiz-commits-archive@ofbiz.apache.org Received: (qmail 87419 invoked by uid 500); 31 Mar 2013 14:40:54 -0000 Mailing-List: contact commits-help@ofbiz.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ofbiz.apache.org Delivered-To: mailing list commits@ofbiz.apache.org Received: (qmail 87403 invoked by uid 99); 31 Mar 2013 14:40:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 31 Mar 2013 14:40:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 31 Mar 2013 14:40:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2C04D2388906; Sun, 31 Mar 2013 14:40:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@ofbiz.apache.org From: jleroux@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130331144029.2C04D2388906@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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. - + @@ -452,7 +452,7 @@ under the License. - + @@ -540,7 +540,7 @@ under the License. - + 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 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 parameters = UtilMisc.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 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 fieldsToSelect = EntityFinderUtil.makeFieldsToSelect(selectFieldExpanderList, context); @@ -157,4 +163,3 @@ public class PrimaryKeyFinder extends Fi } } } -