[ofbiz-framework] branch trunk updated: Improved: Convert cancelCheckRunPayments service from mini-lang to groovy DSL (OFBIZ-11494)

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: Improved: Convert cancelCheckRunPayments service from mini-lang to groovy DSL (OFBIZ-11494)

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 cc61673  Improved: Convert cancelCheckRunPayments service from mini-lang to groovy DSL (OFBIZ-11494)
cc61673 is described below

commit cc6167319863a3ae2c8b6670fb5ff5bf8add6d2a
Author: Jacques Le Roux <[hidden email]>
AuthorDate: Sun Aug 9 20:07:51 2020 +0200

    Improved: Convert cancelCheckRunPayments service from mini-lang to groovy DSL (OFBIZ-11494)
   
    Thanks: Devanshu Vyas for report, Yogesh Naroliya for the patch
---
 .../groovyScripts/payment/PaymentServices.groovy   | 21 +++++++++++++++++
 .../minilang/payment/PaymentServices.xml           | 26 ----------------------
 .../accounting/servicedef/services_payment.xml     |  4 ++--
 3 files changed, 23 insertions(+), 28 deletions(-)

diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index b3b6b6a..40ab002 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -439,3 +439,24 @@ def getPayments() {
     result.payments = payments
     return result
 }
+
+def cancelCheckRunPayments() {
+    paymentGroupMemberAndTransList = from("PmtGrpMembrPaymentAndFinAcctTrans").where("paymentGroupId", parameters.paymentGroupId).queryList()
+    if (paymentGroupMemberAndTransList) {
+        paymentGroupMemberAndTrans = EntityUtil.getFirst(paymentGroupMemberAndTransList)
+        if ("FINACT_TRNS_APPROVED" != paymentGroupMemberAndTrans.finAccountTransStatusId) {
+            for (GenericValue paymentGroupMemberAndTrans : paymentGroupMemberAndTransList) {
+                payment = from("Payment").where("paymentId", paymentGroupMemberAndTrans.paymentId).queryOne()
+                Map voidPaymentMap = dispatcher.getDispatchContext().makeValidContext("voidPayment", "IN", payment)
+                result = runService("voidPayment", voidPaymentMap)
+                if (ServiceUtil.isError(result)) return result
+                Map expirePaymentGroupMemberMap = dispatcher.getDispatchContext().makeValidContext("expirePaymentGroupMember", "IN", paymentGroupMemberAndTrans)
+                result = runService("expirePaymentGroupMember", expirePaymentGroupMemberMap)
+                if (ServiceUtil.isError(result)) return result
+            }
+        } else {
+            return error(UtilProperties.getMessage("AccountingErrorUiLabels", "AccountingCheckIsAlreadyIssued", locale))
+        }
+    }
+    return success()
+}
diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml
index eb05f11..4d7bc1e 100644
--- a/applications/accounting/minilang/payment/PaymentServices.xml
+++ b/applications/accounting/minilang/payment/PaymentServices.xml
@@ -388,32 +388,6 @@ under the License.
         </iterate>
     </simple-method>
 
-    <simple-method method-name="cancelCheckRunPayments" short-description="Cancel all payments for payment group">
-        <entity-and entity-name="PmtGrpMembrPaymentAndFinAcctTrans"  list="paymentGroupMemberAndTransList">
-            <field-map field-name="paymentGroupId" from-field="parameters.paymentGroupId"/>
-        </entity-and>
-        <first-from-list list="paymentGroupMemberAndTransList" entry="paymentGroupMemberAndTrans"/>
-        <if-compare field="paymentGroupMemberAndTrans.finAccountTransStatusId" operator="not-equals" value="FINACT_TRNS_APPROVED">
-        <iterate list="paymentGroupMemberAndTransList" entry="paymentGroupMemberAndTrans">
-            <entity-one entity-name="Payment" value-field="payment">
-                <field-map field-name="paymentId" from-field="paymentGroupMemberAndTrans.paymentId"/>
-            </entity-one>
-            <set-service-fields service-name="voidPayment" map="payment" to-map="voidPaymentMap"/>
-            <call-service service-name="voidPayment" in-map-name="voidPaymentMap"/>
-            <set-service-fields service-name="expirePaymentGroupMember" map="paymentGroupMemberAndTrans" to-map="expirePaymentGroupMemberMap"/>
-            <call-service service-name="expirePaymentGroupMember" in-map-name="expirePaymentGroupMemberMap"/>
-            <clear-field field="voidPaymentMap"/>
-            <clear-field field="expirePaymentGroupMemberMap"/>
-        </iterate>
-        <else>
-            <add-error>
-                <fail-property resource="AccountingUiLabels" property="AccountingCheckIsAlreadyIssued"/>
-            </add-error>
-            <check-errors/>
-        </else>
-        </if-compare>
-    </simple-method>
-
     <simple-method method-name="checkAndCreateBatchForValidPayments" short-description="Check the valid(unbatched) payment and create batch for same">
         <set field="paymentIds" from-field="parameters.paymentIds"/>
         <entity-condition entity-name="Payment" list="payments">
diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml
index 5a4d03a..5579568 100644
--- a/applications/accounting/servicedef/services_payment.xml
+++ b/applications/accounting/servicedef/services_payment.xml
@@ -196,8 +196,8 @@ under the License.
         <attribute name="paymentGroupName" type="String" mode="IN" optional="true"/>
         <attribute name="paymentGroupId" type="String" mode="OUT" optional="false"/>
     </service>
-    <service name="cancelCheckRunPayments" engine="simple"
-            location="component://accounting/minilang/payment/PaymentServices.xml" invoke="cancelCheckRunPayments" auth="true">
+    <service name="cancelCheckRunPayments" engine="groovy"
+            location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="cancelCheckRunPayments" auth="true">
         <description>Cancel all payments for payment group</description>
         <attribute name="paymentGroupId" type="String" mode="IN" optional="false"/>
     </service>