[ofbiz-framework] branch trunk updated: Improved: Converted createPaymentContent, updatePaymentContent services from mini-lang to groovy. (#155)

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: Converted createPaymentContent, updatePaymentContent services from mini-lang to groovy. (#155)

surajk
This is an automated email from the ASF dual-hosted git repository.

surajk 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 c21683e  Improved: Converted createPaymentContent, updatePaymentContent services from mini-lang to groovy. (#155)
c21683e is described below

commit c21683e30bafdfbf8f70c9c50cd21d1626530692
Author: Suraj Khurana <[hidden email]>
AuthorDate: Sat May 23 12:38:07 2020 +0530

    Improved: Converted createPaymentContent, updatePaymentContent services from mini-lang to groovy. (#155)
   
    (OFBIZ-11501)(OFBIZ-11502)
    Thanks Devanshu Vyas for reporting and Sourabh Punyani for providing the patch.
---
 .../groovyScripts/payment/PaymentServices.groovy   | 40 ++++++++++++++++++++++
 .../minilang/payment/PaymentServices.xml           | 31 -----------------
 .../accounting/servicedef/services_payment.xml     |  8 ++---
 3 files changed, 44 insertions(+), 35 deletions(-)

diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index b71c419..c28ce07 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -23,6 +23,8 @@ import org.apache.ofbiz.base.util.UtilProperties
 import org.apache.ofbiz.entity.condition.EntityCondition
 import org.apache.ofbiz.entity.condition.EntityOperator
 import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.service.ServiceUtil
+import java.sql.Timestamp
 
 MODULE = "PaymentServices.groovy"
 def createPayment() {
@@ -94,3 +96,41 @@ def getPaymentRunningTotal(){
     result.paymentRunningTotal = paymentRunningTotal
     return result
 }
+def createPaymentContent() {
+    GenericValue newEntity = delegator.makeValue("PaymentContent")
+    newEntity.setPKFields(parameters, true)
+    newEntity.setNonPKFields(parameters, true)
+
+    if (!newEntity.fromDate) {
+        Timestamp nowTimestamp = UtilDateTime.nowTimestamp()
+        newEntity.fromDate  = nowTimestamp
+    }
+    newEntity.create()
+
+    result = run service: 'updateContent', with: parameters
+    if (ServiceUtil.isError(result)) return result
+
+    Map result = success()
+    result.contentId = newEntity.contentId
+    result.paymentId = newEntity.paymentId
+    result.paymentContentTypeId = newEntity.paymentContentTypeId
+    return result
+}
+//TODO: This can be converted into entity-auto with a seca rule for updateContent
+def updatePaymentContent() {
+    serviceResult = success()
+    GenericValue lookupPKMap = delegator.makeValue("PaymentContent")
+    lookupPKMap.setPKFields(parameters, true)
+
+    GenericValue lookedUpValue = findOne("PaymentContent", lookupPKMap, false)
+    if (lookedUpValue) {
+        lookedUpValue.setNonPKFields(parameters)
+        lookedUpValue.store()
+        result = run service: 'updateContent', with: parameters
+        if (ServiceUtil.isError(result)) return result
+        return serviceResult
+    } else {
+        return ServiceUtil.returnError("Error getting Payment Content")
+    }
+}
+
diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml
index 3811bf7..1c32621 100644
--- a/applications/accounting/minilang/payment/PaymentServices.xml
+++ b/applications/accounting/minilang/payment/PaymentServices.xml
@@ -1074,35 +1074,4 @@ under the License.
             </if-not-empty>
         </if-not-empty>
     </simple-method>
-
-    <!-- PaymentContent -->
-    <simple-method method-name="createPaymentContent" short-description="Create Content For Payment">
-        <make-value entity-name="PaymentContent" value-field="newEntity"/>
-        <set-pk-fields map="parameters" value-field="newEntity"/>
-        <set-nonpk-fields map="parameters" value-field="newEntity"/>
-
-        <if-empty field="newEntity.fromDate">
-            <now-timestamp field="nowTimestamp"/>
-            <set field="newEntity.fromDate" from-field="nowTimestamp"/>
-        </if-empty>
-
-        <create-value value-field="newEntity"/>
-
-        <set-service-fields service-name="updateContent" map="parameters" to-map="updateContent"/>
-        <call-service service-name="updateContent" in-map-name="updateContent"/>
-
-        <field-to-result field="newEntity.contentId" result-name="contentId"/>
-        <field-to-result field="newEntity.paymentId" result-name="paymentId"/>
-        <field-to-result field="newEntity.paymentContentTypeId" result-name="paymentContentTypeId"/>
-    </simple-method>
-    <simple-method method-name="updatePaymentContent" short-description="Update Content For Payment">
-        <make-value entity-name="PaymentContent" value-field="lookupPKMap"/>
-        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
-        <find-by-primary-key map="lookupPKMap" value-field="lookedUpValue"/>
-        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
-        <store-value value-field="lookedUpValue"/>
-
-        <set-service-fields service-name="updateContent" map="parameters" to-map="updateContent"/>
-        <call-service service-name="updateContent" in-map-name="updateContent"/>
-    </simple-method>
 </simple-methods>
diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml
index a7d9554..dd9b2cd 100644
--- a/applications/accounting/servicedef/services_payment.xml
+++ b/applications/accounting/servicedef/services_payment.xml
@@ -253,16 +253,16 @@ under the License.
     </service>
 
     <!-- Payment content services -->
-    <service name="createPaymentContent" default-entity-name="PaymentContent" engine="simple"
-        location="component://accounting/minilang/payment/PaymentServices.xml" invoke="createPaymentContent" auth="true">
+    <service name="createPaymentContent" default-entity-name="PaymentContent" engine="groovy"
+             location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="createPaymentContent" auth="true">
         <description>Add Content To Payment</description>
         <auto-attributes include="pk" mode="INOUT" optional="false"/>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>
         <auto-attributes entity-name="Content" include="nonpk" mode="IN" optional="true"/>
         <override name="fromDate" optional="true"/>
     </service>
-    <service name="updatePaymentContent" default-entity-name="PaymentContent" engine="simple"
-        location="component://accounting/minilang/payment/PaymentServices.xml" invoke="updatePaymentContent" auth="true">
+    <service name="updatePaymentContent" default-entity-name="PaymentContent" engine="groovy"
+             location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="updatePaymentContent" auth="true">
         <description>Update Content To Payment</description>
         <auto-attributes include="pk" mode="IN" optional="false"/>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>