This is an automated email from the ASF dual-hosted git repository.
pgil pushed a change to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git. from 27aa238 Improved: Convert createTextAndUploadedContent service from mini-lang to groovy DSL (OFBIZ-11368) new eba4157 Improved: Convert OrderServices.xml mini-lang to groovyDSL : getNextOrderId new 53a8b81 Improved: Convert OrderServices.xml mini-lang to groovyDSL : getOrderedSummaryInformation The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../order/groovyScripts/order/OrderServices.groovy | 142 +++++++++++++++++++++ .../order/minilang/order/OrderServices.xml | 119 ----------------- applications/order/servicedef/services.xml | 8 +- .../org/apache/ofbiz/order/test/OrderTest.java | 78 +++++++++++ applications/order/testdef/OrderTest.xml | 3 + 5 files changed, 227 insertions(+), 123 deletions(-) create mode 100644 applications/order/groovyScripts/order/OrderServices.groovy create mode 100644 applications/order/src/main/java/org/apache/ofbiz/order/test/OrderTest.java |
This is an automated email from the ASF dual-hosted git repository.
pgil pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git commit eba4157c59bcc0c34c4414e3667333177225c239 Author: Gil Portenseigne <[hidden email]> AuthorDate: Fri Feb 21 16:26:02 2020 +0100 Improved: Convert OrderServices.xml mini-lang to groovyDSL : getNextOrderId (OFBIZ-9984) Thanks Julien for your old patch, it has been improved. Add a new integration test for the service 'getNextOrderId' --- .../order/groovyScripts/order/OrderServices.groovy | 77 +++++++++++++++++++++ .../order/minilang/order/OrderServices.xml | 51 -------------- applications/order/servicedef/services.xml | 4 +- .../org/apache/ofbiz/order/test/OrderTest.java | 78 ++++++++++++++++++++++ applications/order/testdef/OrderTest.xml | 3 + 5 files changed, 160 insertions(+), 53 deletions(-) diff --git a/applications/order/groovyScripts/order/OrderServices.groovy b/applications/order/groovyScripts/order/OrderServices.groovy new file mode 100644 index 0000000..323b8a8 --- /dev/null +++ b/applications/order/groovyScripts/order/OrderServices.groovy @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +import org.apache.ofbiz.base.util.UtilDateTime +import org.apache.ofbiz.entity.GenericValue +import org.apache.ofbiz.entity.condition.EntityConditionBuilder + +import java.sql.Timestamp + +/** + * Service to get the next OrderId + */ +def getNextOrderId() { + GenericValue partyAcctgPreference + GenericValue customMethod + String customMethodName + + partyAcctgPreference = from('PartyAcctgPreference').where(context).queryOne() + logInfo "In getNextOrderId partyId is [$parameters.partyId], partyAcctgPreference: $partyAcctgPreference" + + if (partyAcctgPreference) { + customMethod = partyAcctgPreference.getRelatedOne('OrderCustomMethod', true) + } else { + logWarning "Acctg preference not defined for partyId [$parameters.partyId]" + } + + if (customMethod) { + customMethodName = customMethod.customMethodName + } else if (partyAcctgPreference.oldOrderSequenceEnumId == 'ODRSQ_ENF_SEQ') { + customMethodName = 'orderSequence_enforced' + } + + if (customMethodName) { + Map customMethodMap = [*: parameters] + Map result = run service: customMethodName, with: customMethodMap + orderIdTemp = result.orderId + } else { + logInfo 'In getNextOrderId sequence by Standard' + // default to the default sequencing: ODRSQ_STANDARD + orderIdTemp = parameters.orderId ?: delegator.getNextSeqId('OrderHeader') + } + + GenericValue productStore = null + if (parameters.productStoreId) { + productStore = from('ProductStore').where(context).queryOne() + } + + // use orderIdTemp along with the orderIdPrefix to create the real ID + String orderId = '' + if (productStore) orderId += productStore.orderNumberPrefix + if (partyAcctgPreference) orderId += partyAcctgPreference.orderIdPrefix + orderId += orderIdTemp.toString() + + Map result = success() + result.orderId = orderId + + return result +} + +} diff --git a/applications/order/minilang/order/OrderServices.xml b/applications/order/minilang/order/OrderServices.xml index 39bccb5..d357c0a 100644 --- a/applications/order/minilang/order/OrderServices.xml +++ b/applications/order/minilang/order/OrderServices.xml @@ -427,57 +427,6 @@ under the License. </iterate> </simple-method> - <simple-method method-name="getNextOrderId" short-description="Get Next orderId"> - <!-- try to find PartyAcctgPreference for parameters.partyId, see if we need any special order number sequencing --> - <entity-one entity-name="PartyAcctgPreference" value-field="partyAcctgPreference"/> - <log level="info" message="In getNextOrderId partyId is [${parameters.partyId}], partyAcctgPreference: ${partyAcctgPreference}"/> - - <if-not-empty field="partyAcctgPreference"> - <get-related-one relation-name="OrderCustomMethod" value-field="partyAcctgPreference" to-value-field="customMethod"/> - <else> - <log level="warning" message="Acctg preference not defined for partyId [${parameters.partyId}]"/> - </else> - </if-not-empty> - - <if-not-empty field="customMethod"> - <set field="customMethodName" from-field="customMethod.customMethodName"/> - <else><!-- retreive service from deprecated enumeration --> - <if-compare operator="equals" value="ODRSQ_ENF_SEQ" field="partyAcctgPreference.oldOrderSequenceEnumId"> - <set field="customMethodName" value="orderSequence_enforced"/> - </if-compare> - </else> - </if-not-empty> - - <if-not-empty field="customMethodName"> - <set-service-fields service-name="${customMethodName}" map="parameters" to-map="customMethodMap"/> - <set field="customMethodMap.partyAcctgPreference" from-field="partyAcctgPreference"/> - <call-service service-name="${customMethodName}" in-map-name="customMethodMap"> - <result-to-field result-name="orderId" field="orderIdTemp"/> - </call-service> - <else> - <!-- <log level="info" message="In getNextOrderId sequence by Standard"/> --> - <!-- default to the default sequencing: ODRSQ_STANDARD --> - <set from-field="parameters.orderId" field="orderIdTemp"/> - <if-empty field="orderIdTemp"> - <sequenced-id sequence-name="OrderHeader" field="orderIdTemp"/> - <else> - <!-- check the provided ID --> - <check-id field="orderIdTemp"/> - <check-errors/> - </else> - </if-empty> - </else> - </if-not-empty> - - <if-not-empty field="parameters.productStoreId"> - <entity-one entity-name="ProductStore" value-field="productStore"/> - </if-not-empty> - - <!-- use orderIdTemp along with the orderIdPrefix to create the real ID --> - <set field="orderId" value="${productStore.orderNumberPrefix}${partyAcctgPreference.orderIdPrefix}${str:toString(orderIdTemp)}"/> - <field-to-result field="orderId" result-name="orderId"/> - </simple-method> - <simple-method method-name="orderSequence_enforced" short-description="Enforced Sequence (no gaps, per organization)"> <log level="info" message="In getNextOrderId sequence enum Enforced"/> <set field="partyAcctgPreference" from-field="parameters.partyAcctgPreference"/> diff --git a/applications/order/servicedef/services.xml b/applications/order/servicedef/services.xml index 0771de3..25d68c0 100644 --- a/applications/order/servicedef/services.xml +++ b/applications/order/servicedef/services.xml @@ -623,8 +623,8 @@ under the License. <attribute name="screenLocation" type="String" mode="IN" optional="false"/> </service> - <service name="getNextOrderId" engine="simple" - location="component://order/minilang/order/OrderServices.xml" invoke="getNextOrderId"> + <service name="getNextOrderId" engine="groovy" + location="component://order/groovyScripts/order/OrderServices.groovy" invoke="getNextOrderId"> <description>Get the Next Order ID According to Settings on the PartyAcctgPreference Entity for the given Party</description> <implements service="storeOrder" optional="true"/> <attribute name="partyId" type="String" mode="IN" optional="false"/> diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/test/OrderTest.java b/applications/order/src/main/java/org/apache/ofbiz/order/test/OrderTest.java new file mode 100644 index 0000000..5295d75 --- /dev/null +++ b/applications/order/src/main/java/org/apache/ofbiz/order/test/OrderTest.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.ofbiz.order.test; + +import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.entity.GenericValue; +import org.apache.ofbiz.entity.util.EntityQuery; +import org.apache.ofbiz.service.ServiceUtil; +import org.apache.ofbiz.service.testtools.OFBizTestCase; + +import java.util.HashMap; +import java.util.Map; + +public class OrderTest extends OFBizTestCase { + public static final String module = OFBizTestCase.class.getName(); + + protected GenericValue userLogin = null; + + public OrderTest(String name) { + super(name); + } + + public void testAdminGetNextOrderSeqId() throws Exception { + Map <String, Object> ctx = new HashMap<>(); + ctx.put("partyId", "admin"); //party with no AcctgPref prefix + Map <String, Object> resp = dispatcher.runSync("getNextOrderId", ctx); + if (ServiceUtil.isError(resp)) { + Debug.logError(ServiceUtil.getErrorMessage(resp), module); + return; + } + String orderId = (String) resp.get("orderId"); + assertNotNull(orderId); + assertTrue(orderId.matches("\\d{5,}")); + } + + public void testCompanyGetNextOrderSeqId() throws Exception { + Map <String, Object> ctx = new HashMap<>(); + ctx.put("partyId", "Company"); //party with AcctgPref prefix : CO + Map <String, Object> resp = dispatcher.runSync("getNextOrderId", ctx); + if (ServiceUtil.isError(resp)) { + Debug.logError(ServiceUtil.getErrorMessage(resp), module); + return; + } + String orderId = (String) resp.get("orderId"); + assertNotNull(orderId); + assertTrue(orderId.startsWith("CO")); + } + + public void testCompleteGetNextOrderSeqId() throws Exception { + Map <String, Object> ctx = new HashMap<>(); + ctx.put("partyId", "Company"); //party with AcctgPref prefix : CO + ctx.put("productStoreId", "9000"); // prefix WS + Map <String, Object> resp = dispatcher.runSync("getNextOrderId", ctx); + if (ServiceUtil.isError(resp)) { + Debug.logError(ServiceUtil.getErrorMessage(resp), module); + return; + } + String orderId = (String) resp.get("orderId"); + assertNotNull(orderId); + assertTrue(orderId.startsWith("WSCO")); + } +} diff --git a/applications/order/testdef/OrderTest.xml b/applications/order/testdef/OrderTest.xml index e21a330..e55150a 100644 --- a/applications/order/testdef/OrderTest.xml +++ b/applications/order/testdef/OrderTest.xml @@ -24,6 +24,9 @@ under the License. <test-case case-name="order-tests-data-load"> <entity-xml action="load" entity-xml-url="component://order/testdef/data/OrderTestData.xml"/> </test-case> + <test-case case-name="order-test"> + <junit-test-suite class-name="org.apache.ofbiz.order.test.OrderTest"/> + </test-case> <test-case case-name="purchaseOrder-test"> <junit-test-suite class-name="org.apache.ofbiz.order.test.PurchaseOrderTest"/> </test-case> |
In reply to this post by pgil
This is an automated email from the ASF dual-hosted git repository.
pgil pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git commit 53a8b812607f9987a1063f18062a5318cafe444c Author: Gil Portenseigne <[hidden email]> AuthorDate: Fri Mar 6 15:17:47 2020 +0100 Improved: Convert OrderServices.xml mini-lang to groovyDSL : getOrderedSummaryInformation (OFBIZ-9984) Thanks Julien for your contribution --- .../order/groovyScripts/order/OrderServices.groovy | 67 ++++++++++++++++++++- .../order/minilang/order/OrderServices.xml | 68 ---------------------- applications/order/servicedef/services.xml | 4 +- 3 files changed, 68 insertions(+), 71 deletions(-) diff --git a/applications/order/groovyScripts/order/OrderServices.groovy b/applications/order/groovyScripts/order/OrderServices.groovy index 323b8a8..9fd9b8f 100644 --- a/applications/order/groovyScripts/order/OrderServices.groovy +++ b/applications/order/groovyScripts/order/OrderServices.groovy @@ -18,7 +18,7 @@ */ -import org.apache.ofbiz.base.util.UtilDateTime +import groovy.time.TimeCategory import org.apache.ofbiz.entity.GenericValue import org.apache.ofbiz.entity.condition.EntityConditionBuilder @@ -74,4 +74,69 @@ def getNextOrderId() { return result } +/** + * Service to get Summary Information About Orders for a Customer + */ +def getOrderedSummaryInformation() { + /* + // The permission checking is commented out to make this service work also when triggered from ecommerce + if (!security.hasEntityPermission('ORDERMGR', '_VIEW', session && !parameters.partyId.equals(userLogin.partyId))) { + Map result = error('To get order summary information you must have the ORDERMGR_VIEW permission, or + be logged in as the party to get the summary information for.') + return result + } + */ + Timestamp fromDate = null, thruDate = null + Date now = new Date() + if (monthsToInclude) { + use(TimeCategory) { + thruDate = now.toTimestamp() + fromDate = (now - monthsToInclude.months).toTimestamp() + } + } + + roleTypeId = roleTypeId ?: 'PLACING_CUSTOMER' + orderTypeId = orderTypeId ?: 'SALES_ORDER' + statusId = statusId ?: 'ORDER_COMPLETED' + + //find the existing exchange rates + exprBldr = new EntityConditionBuilder() + + def condition = exprBldr.AND() { + EQUALS(partyId: partyId) + EQUALS(roleTypeId: roleTypeId) + EQUALS(orderTypeId: orderTypeId) + EQUALS(statusId: statusId) + } + + if (fromDate) { + condition = exprBldr.AND(condition) { + condition + exprBldr.OR() { + GREATER_THAN_EQUAL_TO(orderDate: fromDate) + EQUALS(orderDate: null) + } + } + } + + if (thruDate) { + condition = exprBldr.AND(condition) { + condition + exprBldr.OR() { + LESS_THAN_EQUAL_TO(orderDate: thruDate) + EQUALS(orderDate: null) + } + } + } + + orderInfo = select('partyId', 'roleTypeId', 'totalGrandAmount', 'totalSubRemainingAmount', 'totalOrders') + .from('OrderHeaderAndRoleSummary').where(condition).queryFirst() + + // first set the required OUT fields to zero + result = success() + result.totalGrandAmount = orderInfo ? orderInfo.totalGrandAmount : BigDecimal.ZERO + result.totalSubRemainingAmount = orderInfo ? orderInfo.totalSubRemainingAmount : BigDecimal.ZERO + result.totalOrders = orderInfo ? orderInfo.totalOrders : 0l + + return result } diff --git a/applications/order/minilang/order/OrderServices.xml b/applications/order/minilang/order/OrderServices.xml index d357c0a..b4ab784 100644 --- a/applications/order/minilang/order/OrderServices.xml +++ b/applications/order/minilang/order/OrderServices.xml @@ -20,74 +20,6 @@ under the License. <simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd"> - <simple-method method-name="getOrderedSummaryInformation" short-description="Get Summary Information About Orders for a Customer"> - <!-- The permission checking is commented out to make this service work also when triggered from ecommerce --> - <!--if> - <condition> - <and> - <not><if-has-permission permission="ORDERMGR" action="_VIEW"/></not> - <if-compare-field field="parameters.partyId" to-field="userLogin.partyId" operator="not-equals"/> - </and> - </condition> - <then> - <string-to-list string="To get order summary information you must have the ORDERMGR_VIEW permission, or be logged in as the party to get the summary information for." list="error_list"/> - </then> - </if> - <check-errors/> - --> - <if-not-empty field="monthsToInclude"> - <now-timestamp field="nowTimestamp"/> - <!-- TODO: Change this to use the <set-calendar> operation --> - <script>groovy: - calendar = com.ibm.icu.util.Calendar.getInstance() - calendar.setTimeInMillis(nowTimestamp.getTime()) - calendar.add(com.ibm.icu.util.Calendar.MONTH, -monthsToInclude.intValue()) - parameters.put("fromDate", new Timestamp(calendar.getTimeInMillis())) - </script> - <set from-field="nowTimestamp" field="parameters.thruDate"/> - </if-not-empty> - - <if-empty field="parameters.roleTypeId"> - <set value="PLACING_CUSTOMER" field="parameters.roleTypeId"/> - </if-empty> - <if-empty field="parameters.orderTypeId"> - <set value="SALES_ORDER" field="parameters.orderTypeId"/> - </if-empty> - <if-empty field="parameters.statusId"> - <set value="ORDER_COMPLETED" field="parameters.statusId"/> - </if-empty> - - <entity-condition entity-name="OrderHeaderAndRoleSummary" list="orderInfoList"> - <condition-list combine="and"> - <condition-expr field-name="partyId" operator="equals" from-field="parameters.partyId"/> - <condition-expr field-name="roleTypeId" operator="equals" from-field="parameters.roleTypeId"/> - <condition-expr field-name="orderTypeId" operator="equals" from-field="parameters.orderTypeId"/> - <condition-expr field-name="statusId" operator="equals" from-field="parameters.statusId"/> - <condition-expr field-name="orderDate" operator="greater-equals" from-field="parameters.fromDate" ignore-if-null="true"/> - <condition-expr field-name="orderDate" operator="less-equals" from-field="parameters.thruDate" ignore-if-null="true"/> - </condition-list> - <select-field field-name="partyId"/> - <select-field field-name="roleTypeId"/> - <select-field field-name="totalGrandAmount"/> - <select-field field-name="totalSubRemainingAmount"/> - <select-field field-name="totalOrders"/> - </entity-condition> - - <!-- first set the required OUT fields to zero --> - <calculate field="plainDoubleZero"><number value="0.0"/></calculate> - <calculate field="plainLongZero" type="Long"><number value="0"/></calculate> - <field-to-result field="plainDoubleZero" result-name="totalGrandAmount"/> - <field-to-result field="plainDoubleZero" result-name="totalSubRemainingAmount"/> - <field-to-result field="plainLongZero" result-name="totalOrders"/> - - <!-- because we specified the partyId and the roleTypeId, should only be one item in list returned --> - <first-from-list list="orderInfoList" entry="orderInfo"/> - <if-not-empty field="orderInfo"> - <field-to-result field="orderInfo.totalGrandAmount" result-name="totalGrandAmount"/> - <field-to-result field="orderInfo.totalSubRemainingAmount" result-name="totalSubRemainingAmount"/> - <field-to-result field="orderInfo.totalOrders" result-name="totalOrders"/> - </if-not-empty> - </simple-method> <!-- order requirement methods --> <simple-method method-name="createRequirementAndCommitment" short-description="create a requirement and commitment for it"> diff --git a/applications/order/servicedef/services.xml b/applications/order/servicedef/services.xml index 25d68c0..7084e79 100644 --- a/applications/order/servicedef/services.xml +++ b/applications/order/servicedef/services.xml @@ -475,8 +475,8 @@ under the License. <attribute name="orderId" type="String" mode="IN"/> </service> <!-- Order View Services --> - <service name="getOrderedSummaryInformation" engine="simple" - location="component://order/minilang/order/OrderServices.xml" invoke="getOrderedSummaryInformation"> + <service name="getOrderedSummaryInformation" engine="groovy" + location="component://order/groovyScripts/order/OrderServices.groovy" invoke="getOrderedSummaryInformation"> <description>Get Ordered Summary Information</description> <attribute name="partyId" type="String" mode="IN" optional="false"/> <attribute name="roleTypeId" type="String" mode="IN" optional="true"/> <!-- defaults to PLACING_CUSTOMER --> |
Free forum by Nabble | Edit this page |