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 f493eb25cd Improved: Add groovydsl method : failure to return a map
(OFBIZ-13195) (#867)
f493eb25cd is described below
commit f493eb25cd22bdf4a53e6c947a28bad4eaac3bd6
Author: Nicolas Malin <[email protected]>
AuthorDate: Wed Dec 18 09:55:37 2024 +0100
Improved: Add groovydsl method : failure to return a map (OFBIZ-13195)
(#867)
With groovy dsl we have possibility to return in one line when failure
appears but we can only sent a failure message like this :
****
return failure('bad state')
****
If we need to return information on out we need to realize it like :
****
Map result = failure('bad state')
result.statusId = 'BAD_STATUS'
return result
****
Like success() we improved it to do in one line:
****
return failure('bad state', [statusId: 'BAD_STATUS'])
****
By the way we align success function to refactoring them with default value
so remove two unnecessary
---
.../ofbiz/service/engine/GroovyBaseScript.groovy | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 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 fa7c9bae5a..6f10dbbe62 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
@@ -113,16 +113,10 @@ abstract class GroovyBaseScript extends Script {
}
/* codenarc-disable NoDef, MethodReturnTypeRequired */
- 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) {
+ 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"
@@ -144,12 +138,15 @@ abstract class GroovyBaseScript extends Script {
return result
}
/* codenarc-enable */
- Map failure(String message) {
+ Map failure(String message, Map returnValues = [:]) {
// TODO: implement some clever i18n mechanism based on the userLogin
and locale in the binding
- if (message) {
- return ServiceUtil.returnFailure(message)
+ Map result = message
+ ? ServiceUtil.returnFailure(message)
+ : ServiceUtil.returnFailure()
+ if (returnValues) {
+ result.putAll(returnValues)
}
- return ServiceUtil.returnFailure()
+ return result
}
/* codenarc-disable NoDef, MethodReturnTypeRequired */
def error(String message) {