Skip to content

Commit

Permalink
Improved: Converted createPaymentContent, updatePaymentContent servic…
Browse files Browse the repository at this point in the history
…es from mini-lang to groovy. (#155)

(OFBIZ-11501)(OFBIZ-11502)
Thanks Devanshu Vyas for reporting and Sourabh Punyani for providing the patch.
  • Loading branch information
surajkhurana committed May 23, 2020
1 parent 767390a commit c21683e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 35 deletions.
Expand Up @@ -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() {
Expand Down Expand Up @@ -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")
}
}

31 changes: 0 additions & 31 deletions applications/accounting/minilang/payment/PaymentServices.xml
Expand Up @@ -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>
8 changes: 4 additions & 4 deletions applications/accounting/servicedef/services_payment.xml
Expand Up @@ -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"/>
Expand Down

0 comments on commit c21683e

Please sign in to comment.