[ofbiz-framework] branch trunk updated: Implemented: Convert createPayment service from mini-lang to groovy DSL

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Implemented: Convert createPayment service from mini-lang to groovy DSL

jleroux@apache.org
This is an automated email from the ASF dual-hosted git repository.

jleroux 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 aef9382  Implemented: Convert createPayment service from mini-lang to groovy DSL
aef9382 is described below

commit aef9382a9c8e242af0d629f331bb5c73ea4e4746
Author: Jacques Le Roux <[hidden email]>
AuthorDate: Thu Apr 9 14:27:16 2020 +0200

    Implemented: Convert createPayment service from mini-lang to groovy DSL
   
    (OFBIZ-11479)
   
    Better code with Groovy truth
   
    Thanks: Pawan Verma
---
 .../accounting/groovyScripts/payment/PaymentServices.groovy  | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index 2a3493f..56c653b 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -19,7 +19,6 @@
 import org.apache.ofbiz.base.util.Debug
 import org.apache.ofbiz.base.util.UtilDateTime
 import org.apache.ofbiz.base.util.UtilProperties
-import org.apache.ofbiz.base.util.UtilValidate
 import org.apache.ofbiz.entity.GenericValue
 
 MODULE = "PaymentServices.groovy"
@@ -27,25 +26,30 @@ def createPayment() {
     if (!security.hasEntityPermission("ACCOUNTING", "_CREATE", parameters.userLogin) && (!security.hasEntityPermission("PAY_INFO", "_CREATE", parameters.userLogin) && userLogin.partyId != parameters.partyIdFrom && userLogin.partyId != parameters.partyIdTo)) {
         return error(UtilProperties.getResourceBundleMap("AccountingUiLabels", locale)?.AccountingCreatePaymentPermissionError)
     }
+
     GenericValue payment = delegator.makeValue("Payment")
     payment.paymentId = parameters.paymentId ?: delegator.getNextSeqId("Payment")
     paymentId = payment.paymentId
     parameters.statusId = parameters.statusId ?: "PMNT_NOT_PAID"
-    if (UtilValidate.isNotEmpty(parameters.paymentMethodId)) {
+
+    if (parameters.paymentMethodId) {
         GenericValue paymentMethod = from("PaymentMethod").where("paymentMethodId", parameters.paymentMethodId).queryOne()
         if (parameters.paymentMethodTypeId != paymentMethod.paymentMethodTypeId) {
             Debug.logInfo("Replacing passed payment method type [" + parameters.paymentMethodTypeId + "] with payment method type [" + paymentMethod.paymentMethodTypeId + "] for payment method [" + parameters.paymentMethodId +"]", MODULE)
             parameters.paymentMethodTypeId = paymentMethod.paymentMethodTypeId
         }
     }
-    if (UtilValidate.isNotEmpty(parameters.paymentPreferenceId)) {
+
+    if (parameters.paymentPreferenceId) {
         GenericValue orderPaymentPreference = from("OrderPaymentPreference").where("orderPaymentPreferenceId", parameters.paymentPreferenceId).queryOne()
         parameters.paymentId = parameters.paymentId ?: orderPaymentPreference.paymentMethodId
         parameters.paymentMethodTypeId = parameters.paymentMethodTypeId ?: orderPaymentPreference.paymentMethodTypeId
     }
-    if (UtilValidate.isEmpty(parameters.paymentMethodTypeId)) {
+
+    if (!parameters.paymentMethodTypeId) {
         return error(UtilProperties.getResourceBundleMap("AccountingUiLabels", locale)?.AccountingPaymentMethodIdPaymentMethodTypeIdNullError)
     }
+
     payment.setNonPKFields(parameters)
     payment.effectiveDate = payment.effectiveDate ?: UtilDateTime.nowTimestamp()
     delegator.create(payment)