Author: adrianc
Date: Sat Oct 4 13:11:49 2014 New Revision: 1629386 URL: http://svn.apache.org/r1629386 Log: Merged revision(s) 1629382 from ofbiz/trunk: Fixed a bug in Mini-language <field-to-result> element where nested expressions were not evaluated correctly. Reported by Jacopo on the dev mailing list. Modified: ofbiz/branches/release13.07/ (props changed) ofbiz/branches/release13.07/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java ofbiz/branches/release13.07/framework/minilang/src/org/ofbiz/minilang/test/MiniLangTests.java Propchange: ofbiz/branches/release13.07/ ------------------------------------------------------------------------------ Merged /ofbiz/trunk:r1629382 Modified: ofbiz/branches/release13.07/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java?rev=1629386&r1=1629385&r2=1629386&view=diff ============================================================================== --- ofbiz/branches/release13.07/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java (original) +++ ofbiz/branches/release13.07/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java Sat Oct 4 13:11:49 2014 @@ -19,6 +19,7 @@ package org.ofbiz.minilang.method.serviceops; import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.minilang.MiniLangException; import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; @@ -27,7 +28,7 @@ import org.ofbiz.minilang.method.MethodO import org.w3c.dom.Element; /** - * Implements the <field-to-request> element. + * Implements the <field-to-result> element. * * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Cfieldtoresult%3E}}">Mini-language Reference</a> */ @@ -60,7 +61,14 @@ public final class FieldToResult extends Object fieldVal = this.fieldFma.get(methodContext.getEnvMap()); if (fieldVal != null) { if (this.resultFma.containsNestedExpression()) { - String expression = (String) this.resultFma.get(methodContext.getEnvMap()); + /* + * Replace FMA nested expression functionality with our own. + * The nested expression must be evaluated once using the + * method context, [methodContext.getEnvMap()] then again to + * place the value in the result Map [methodContext.getResults()]. + */ + FlexibleStringExpander fse = FlexibleStringExpander.getInstance(this.resultFma.getOriginalName()); + String expression = fse.expandString(methodContext.getEnvMap()); FlexibleMapAccessor<Object> resultFma = FlexibleMapAccessor.getInstance(expression); resultFma.put(methodContext.getResults(), fieldVal); } else { Modified: ofbiz/branches/release13.07/framework/minilang/src/org/ofbiz/minilang/test/MiniLangTests.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/minilang/src/org/ofbiz/minilang/test/MiniLangTests.java?rev=1629386&r1=1629385&r2=1629386&view=diff ============================================================================== --- ofbiz/branches/release13.07/framework/minilang/src/org/ofbiz/minilang/test/MiniLangTests.java (original) +++ ofbiz/branches/release13.07/framework/minilang/src/org/ofbiz/minilang/test/MiniLangTests.java Sat Oct 4 13:11:49 2014 @@ -91,4 +91,18 @@ public class MiniLangTests extends OFBiz assertTrue("<assert> error message text", errorMessage.startsWith("Assertion failed:")); } + public void testFieldToResultOperation() throws Exception { + String simpleMethodXml = "<simple-method name=\"testFieldToResult\">" + + " <set field=\"resultValue\" value=\"someResultValue\"/>" + + " <set field=\"result1\" value=\"dynamicResultName\"/>" + + " <field-to-result field=\"resultValue\" result-name=\"constantResultName\"/>" + + " <field-to-result field=\"resultValue\" result-name=\"${result1}\"/>" + + "</simple-method>"; + SimpleMethod methodToTest = createSimpleMethod(simpleMethodXml); + MethodContext context = createServiceMethodContext(); + String result = methodToTest.exec(context); + assertEquals("testFieldToResult success result", methodToTest.getDefaultSuccessCode(), result); + assertEquals("Plain expression result name set", "someResultValue", context.getResult("constantResultName")); + assertEquals("Nested expression result name set", "someResultValue", context.getResult("dynamicResultName")); + } } |
Free forum by Nabble | Edit this page |