This is an automated email from the ASF dual-hosted git repository. nmalin pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new 5bd3ccf Improved: Groovy DSL add success(Map) method (OFBIZ-12317) 5bd3ccf is described below commit 5bd3ccfa40b1d26ba4858fc4ed40a79f78bcb888 Author: Nicolas Malin <nicolas.ma...@nereide.fr> AuthorDate: Wed Sep 15 14:26:05 2021 +0200 Improved: Groovy DSL add success(Map) method (OFBIZ-12317) Improve the groovy dsl with a success method that return directly all fields Previously we used: Map result = success() result.myId = myId return result Now we can write: return success(myId: myId) Or Previously we used: Map result = success('Wonderful !') result.myId = myId return result Now we can write: return success('Wonderful !', myId: myId) --- .../ofbiz/service/engine/GroovyBaseScript.groovy | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy b/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy index d2d247d..08b4cd9 100644 --- a/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy +++ b/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy @@ -84,21 +84,35 @@ abstract class GroovyBaseScript extends Script { return from(entityName).where(fields).cache(useCache).queryOne() } + def success() { + return success(null, null) + } def success(String message) { + return success(message, null) + } + def success(Map returnValues) { + return success(null, returnValues) + } + def success(String message, Map returnValues) { // TODO: implement some clever i18n mechanism based on the userLogin and locale in the binding if (this.binding.hasVariable('request')) { // the script is invoked as an "event" if (message) { this.binding.getVariable('request').setAttribute("_EVENT_MESSAGE_", message) } + if (returnValues) { + returnValues.each { + this.binding.getVariable('request').setAttribute(it.getKey(), it.getValue()) + } + } return 'success' } else { // the script is invoked as a "service" - if (message) { - return ServiceUtil.returnSuccess(message) - } else { - return ServiceUtil.returnSuccess() + Map result = message ? ServiceUtil.returnSuccess(message) : ServiceUtil.returnSuccess() + if (returnValues) { + result.putAll(returnValues) } + return result } } Map failure(String message) { @@ -125,6 +139,7 @@ abstract class GroovyBaseScript extends Script { } } } + def logInfo(String message) { Debug.logInfo(message, getModule()) }