This is an automated email from the ASF dual-hosted git repository.
nmalin 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 0ee46845db Improved: slim down groovy scriptlet on minilang
(OFBIZ-13146)
0ee46845db is described below
commit 0ee46845db512c91e1c1f552f4a45951cf409bc0
Author: Nicolas Malin <[email protected]>
AuthorDate: Thu Jan 2 18:08:00 2025 +0100
Improved: slim down groovy scriptlet on minilang (OFBIZ-13146)
Convert to groovy natural language or uel function (third pass)
---
.../commonext/minilang/setup/SetupEvents.xml | 9 ++--
.../marketing/contact/ContactListServices.xml | 2 +-
.../order/minilang/test/ShoppingCartTests.xml | 12 +++--
.../party/minilang/customer/CustomerEvents.xml | 9 ++--
applications/party/minilang/user/UserEvents.xml | 13 +++---
.../product/inventory/InventoryReserveServices.xml | 21 +++------
.../product/inventory/InventoryServices.xml | 4 +-
.../minilang/product/test/GroupOrderTest.xml | 52 +++++++++++-----------
8 files changed, 55 insertions(+), 67 deletions(-)
diff --git a/applications/commonext/minilang/setup/SetupEvents.xml
b/applications/commonext/minilang/setup/SetupEvents.xml
index b8287c2f18..e2924365a4 100644
--- a/applications/commonext/minilang/setup/SetupEvents.xml
+++ b/applications/commonext/minilang/setup/SetupEvents.xml
@@ -286,12 +286,9 @@
<entity-one entity-name="PartyGroup" value-field="partyGroup"/>
<script>groovy:
- groupName = partyGroup.get("groupName")
- if (groupName != null) {
- parameters.put("invoiceIdPrefix",
groupName.toUpperCase().substring(0, 2)+"CI")
- } else {
- parameters.put("invoiceIdPrefix", "CI")
- }
+ parameters.invoiceIdPrefix = (partyGroup.groupName
+ ? partyGroup.groupName.toUpperCase().substring(0, 2)
+ : "") + "CI"
</script>
<entity-one entity-name="PartyAcctgPreference"
value-field="partyAcctgPreference"/>
diff --git
a/applications/marketing/minilang/marketing/contact/ContactListServices.xml
b/applications/marketing/minilang/marketing/contact/ContactListServices.xml
index 0bb7117b4e..caf02e0de3 100644
--- a/applications/marketing/minilang/marketing/contact/ContactListServices.xml
+++ b/applications/marketing/minilang/marketing/contact/ContactListServices.xml
@@ -287,7 +287,7 @@ under the License.
<if>
<condition><if-compare field="newEntity.statusId"
operator="equals" value="CLPT_PENDING"/></condition>
<then>
- <script>groovy:newEntity.set("optInVerifyCode",
Long.toString(Math.round(9999999999L * Math.random())))</script>
+ <script>groovy: newEntity.optInVerifyCode =
Long.toString(Math.round(9999999999L * Math.random()))</script>
</then>
<else-if>
<condition><if-compare field="newEntity.statusId"
operator="equals" value="CLPT_ACCEPTED"/></condition>
diff --git a/applications/order/minilang/test/ShoppingCartTests.xml
b/applications/order/minilang/test/ShoppingCartTests.xml
index 3d4826c498..8cb5abeb05 100644
--- a/applications/order/minilang/test/ShoppingCartTests.xml
+++ b/applications/order/minilang/test/ShoppingCartTests.xml
@@ -51,8 +51,7 @@ under the License.
<set field="currencyUom" value="USD" type="String"/>
<script>groovy:
- shoppingCart = new
org.apache.ofbiz.order.shoppingcart.ShoppingCart(delegator, productStoreId,
locale, currencyUom);
- parameters.put("shoppingCart", shoppingCart);
+ parameters.shoppingCart = new
org.apache.ofbiz.order.shoppingcart.ShoppingCart(delegator, productStoreId,
locale, currencyUom)
</script>
<set field="orderTypeId" value="SALES_ORDER" type="String"/>
@@ -263,9 +262,8 @@ under the License.
<!-- Shopping Cart checkout and create order -->
<script>groovy:
- checkOutHelper = new
org.apache.ofbiz.order.shoppingcart.CheckOutHelper(dispatcher, delegator,
shoppingCart);
- java.util.Map orderMap = checkOutHelper.createOrder(userLogin);
- parameters.put("orderMap", orderMap);
+ checkOutHelper = new
org.apache.ofbiz.order.shoppingcart.CheckOutHelper(dispatcher, delegator,
shoppingCart)
+ parameters.orderMap = checkOutHelper.createOrder(userLogin)
</script>
<!-- Clear Shopping Cart -->
@@ -629,8 +627,8 @@ under the License.
<field-map field-name="userLoginId" value="DemoCustomer"/>
</entity-one>
<script>groovy:
- session = request.getSession();
- session.setAttribute("userLogin", userLogin);
+ session = request.getSession()
+ session.setAttribute("userLogin", userLogin)
</script>
<call-class-method method-name="initializeOrderEntry"
class-name="org.apache.ofbiz.order.shoppingcart.ShoppingCartEvents"
ret-field="result">
<field field="request"
type="javax.servlet.http.HttpServletRequest"/>
diff --git a/applications/party/minilang/customer/CustomerEvents.xml
b/applications/party/minilang/customer/CustomerEvents.xml
index 87f902837a..a38e590ac6 100644
--- a/applications/party/minilang/customer/CustomerEvents.xml
+++ b/applications/party/minilang/customer/CustomerEvents.xml
@@ -77,10 +77,11 @@ under the License.
<!-- Check the password, etc for validity -->
<script>groovy:
- String password = (String) userLoginContext.get("currentPassword")
- String confirmPassword = (String)
userLoginContext.get("currentPasswordVerify")
- String passwordHint = (String) userLoginContext.get("passwordHint")
-
org.apache.ofbiz.common.login.LoginServices.checkNewPassword(newUserLogin,
null, password, confirmPassword, passwordHint, error_list, true, locale)
+
org.apache.ofbiz.common.login.LoginServices.checkNewPassword(newUserLogin, null,
+ userLoginContext.currentPassword,
+ userLoginContext.currentPasswordVerify,
+ userLoginContext.passwordHint,
+ error_list, true, locale)
</script>
<!-- Create the Person -->
diff --git a/applications/party/minilang/user/UserEvents.xml
b/applications/party/minilang/user/UserEvents.xml
index 6a3fa5098d..6348bac79f 100644
--- a/applications/party/minilang/user/UserEvents.xml
+++ b/applications/party/minilang/user/UserEvents.xml
@@ -112,10 +112,11 @@ under the License.
<!-- Check the password, etc for validity -->
<script>groovy:
- String password = (String)
userLoginContext.get("currentPassword")
- String confirmPassword = (String)
userLoginContext.get("currentPasswordVerify")
- String passwordHint = (String)
userLoginContext.get("passwordHint")
-
org.apache.ofbiz.common.login.LoginServices.checkNewPassword(newUserLogin,
null, password, confirmPassword, passwordHint, error_list, true, locale)
+
org.apache.ofbiz.common.login.LoginServices.checkNewPassword(newUserLogin, null,
+ userLoginContext.currentPassword,
+ userLoginContext.currentPasswordVerify,
+ userLoginContext.passwordHint,
+ error_list, true, locale)
</script>
<else>
<if-compare field="require_login" operator="equals" value="true">
@@ -318,10 +319,10 @@ under the License.
<!-- If password encryption is enabled, encrpyt it now -->
<set field="delegator" from-field="parameters.delegator"
type="Object"/>
<script>groovy:
- boolean useEncryption =
"true".equals(org.apache.ofbiz.entity.util.EntityUtilProperties.getPropertyValue("security",
"password.encrypt", delegator))
+ boolean useEncryption = "true" ==
org.apache.ofbiz.entity.util.EntityUtilProperties.getPropertyValue("security",
"password.encrypt", delegator)
if (useEncryption) {
String hashType =
org.apache.ofbiz.common.login.LoginServices.getHashType()
- newUserLogin.set("currentPassword",
org.apache.ofbiz.base.crypto.HashCrypt.digestHash(hashType, null,
newUserLogin.get("currentPassword")))
+ newUserLogin.currentPassword =
org.apache.ofbiz.base.crypto.HashCrypt.digestHash(hashType, null,
newUserLogin.currentPassword)
}
</script>
diff --git
a/applications/product/minilang/product/inventory/InventoryReserveServices.xml
b/applications/product/minilang/product/inventory/InventoryReserveServices.xml
index 5146bec889..41f05fef3c 100644
---
a/applications/product/minilang/product/inventory/InventoryReserveServices.xml
+++
b/applications/product/minilang/product/inventory/InventoryReserveServices.xml
@@ -201,11 +201,8 @@ under the License.
</if-not-empty>
</if-empty>
<script>groovy:
- java.sql.Timestamp orderDate =
orderHeader.getTimestamp("orderDate")
- com.ibm.icu.util.Calendar cal =
com.ibm.icu.util.Calendar.getInstance()
- cal.setTimeInMillis(orderDate.getTime())
- cal.add(com.ibm.icu.util.Calendar.DAY_OF_YEAR,
daysToShip.intValue())
- return
org.apache.ofbiz.base.util.UtilMisc.toMap("promisedDatetime", new
java.sql.Timestamp(cal.getTimeInMillis()))
+ [promisedDatetime:
org.apache.ofbiz.base.util.UtilDateTime.adjustTimestamp(
+ orderHeader.orderDate, Calendar.DAY_OF_YEAR,
daysToShip as int)]
</script>
<!-- create or update OrderItemShipGrpInvRes
record -->
@@ -268,11 +265,8 @@ under the License.
</if-not-empty>
</if-empty>
<script>groovy:
- java.sql.Timestamp orderDate =
orderHeader.getTimestamp("orderDate")
- com.ibm.icu.util.Calendar cal =
com.ibm.icu.util.Calendar.getInstance()
- cal.setTimeInMillis(orderDate.getTime())
- cal.add(com.ibm.icu.util.Calendar.DAY_OF_YEAR,
daysToShip.intValue())
- return
org.apache.ofbiz.base.util.UtilMisc.toMap("promisedDatetime", new
java.sql.Timestamp(cal.getTimeInMillis()))
+ [promisedDatetime:
org.apache.ofbiz.base.util.UtilDateTime.adjustTimestamp(
+ orderHeader.orderDate, Calendar.DAY_OF_YEAR,
daysToShip as int)]
</script>
<!-- create OrderItemShipGrpInvRes record -->
@@ -510,11 +504,8 @@ under the License.
<set field="daysToShip" value="30" type="Long"/>
</if-empty>
<script>groovy:
- java.sql.Timestamp orderDate = orderHeader.getTimestamp("orderDate")
- com.ibm.icu.util.Calendar cal = com.ibm.icu.util.Calendar.getInstance()
- cal.setTimeInMillis(orderDate.getTime())
- cal.add(com.ibm.icu.util.Calendar.DAY_OF_YEAR, daysToShip.intValue())
- return org.apache.ofbiz.base.util.UtilMisc.toMap("promisedDatetime",
new java.sql.Timestamp(cal.getTimeInMillis()))
+ [promisedDatetime:
org.apache.ofbiz.base.util.UtilDateTime.adjustTimestamp(
+ orderHeader.orderDate, Calendar.DAY_OF_YEAR, daysToShip as int)]
</script>
</simple-method>
diff --git
a/applications/product/minilang/product/inventory/InventoryServices.xml
b/applications/product/minilang/product/inventory/InventoryServices.xml
index bf3525e132..985f449b9f 100644
--- a/applications/product/minilang/product/inventory/InventoryServices.xml
+++ b/applications/product/minilang/product/inventory/InventoryServices.xml
@@ -812,7 +812,7 @@ under the License.
<set from-field="parameters.quantity"
field="quantityNotTransferred"/>
<set field="locationTypeMap.enumTypeId" value="FACLOC_TYPE"/>
<find-by-and entity-name="Enumeration"
list="locationTypeEnums" map="locationTypeMap"/>
- <set field="locationTypeEnumIds" value="${groovy: return
org.apache.ofbiz.entity.util.EntityUtil.getFieldListFromEntityList(locationTypeEnums,
'enumId', true);}" type="List"/>
+ <set field="locationTypeEnumIds" value="${groovy:
locationTypeEnums*.enumId}" type="List"/>
<set field="nothing" value="${groovy:
locationTypeEnumIds.add(null)}" type="List"/>
<iterate list="locationTypeEnumIds" entry="locationTypeEnumId">
<find-by-and entity-name="InventoryItemAndLocation"
map="lookupFieldMap" list="inventoryItemAndLocations" use-iterator="true"
order-by-list="orderByList"/>
@@ -870,7 +870,7 @@ under the License.
<field-to-result field="quantityNotTransferred"/>
<if-compare operator="greater" value="0"
field="quantityNotTransferred">
<add-error>
- <fail-message message="${groovy: import
org.apache.ofbiz.base.util.UtilProperties; return
(UtilProperties.getMessage('ProductUiLabels',
'ProductInventoryATPNotAvailable', ['unavailableQuantity' :
quantityNotTransferred, 'xferQty': parameters.quantity], locale))}"/>
+ <fail-message message="${groovy: label('ProductUiLabels',
'ProductInventoryATPNotAvailable', ['unavailableQuantity' :
quantityNotTransferred, 'xferQty': parameters.quantity], locale)}"/>
</add-error>
<check-errors/>
</if-compare>
diff --git a/applications/product/minilang/product/test/GroupOrderTest.xml
b/applications/product/minilang/product/test/GroupOrderTest.xml
index 78c7a6b863..f264a6f5d2 100644
--- a/applications/product/minilang/product/test/GroupOrderTest.xml
+++ b/applications/product/minilang/product/test/GroupOrderTest.xml
@@ -62,12 +62,12 @@ under the License.
<field-map field-name="userLoginId" value="admin"/>
</entity-one>
<script>groovy:
- request.setParameter("orderMode", "SALES_ORDER");
- request.setParameter("productStoreId", "9000");
- request.setParameter("partyId", "DemoCustomer");
- request.setParameter("currencyUom", "USD");
- session = request.getSession();
- session.setAttribute("userLogin", userLogin);
+ request.setParameter("orderMode", "SALES_ORDER")
+ request.setParameter("productStoreId", "9000")
+ request.setParameter("partyId", "DemoCustomer")
+ request.setParameter("currencyUom", "USD")
+ session = request.getSession()
+ session.setAttribute("userLogin", userLogin)
</script>
<call-class-method method-name="initializeOrderEntry"
class-name="org.apache.ofbiz.order.shoppingcart.ShoppingCartEvents"
ret-field="result">
<field field="request"
type="javax.servlet.http.HttpServletRequest"/>
@@ -80,7 +80,7 @@ under the License.
</call-class-method>
<log level="info" message="===== >>> Event :
setOrderCurrencyAgreementShipDates, Response : ${result}"/>
<script>groovy:
- request.setParameter("add_product_id", "GZ-1000");
+ request.setParameter("add_product_id", "GZ-1000")
</script>
<call-class-method method-name="addToCart"
class-name="org.apache.ofbiz.order.shoppingcart.ShoppingCartEvents"
ret-field="result">
<field field="request"
type="javax.servlet.http.HttpServletRequest"/>
@@ -88,12 +88,12 @@ under the License.
</call-class-method>
<log level="info" message="===== >>> Event : addToCart, Response :
${result}"/>
<script>groovy:
- request.setParameter("checkoutpage", "quick");
- request.setParameter("shipping_contact_mech_id", "9015");
- request.setParameter("shipping_method", "GROUND@UPS");
- request.setParameter("checkOutPaymentId", "EXT_PAYPAL");
- request.setParameter("is_gift", "false");
- request.setParameter("may_split", "false");
+ request.setParameter("checkoutpage", "quick")
+ request.setParameter("shipping_contact_mech_id", "9015")
+ request.setParameter("shipping_method", "GROUND@UPS")
+ request.setParameter("checkOutPaymentId", "EXT_PAYPAL")
+ request.setParameter("is_gift", "false")
+ request.setParameter("may_split", "false")
</script>
<field-to-request field="nullField" request-name="shoppingCart"/>
<call-class-method method-name="setQuickCheckOutOptions"
class-name="org.apache.ofbiz.order.shoppingcart.CheckOutEvents"
ret-field="result">
@@ -184,12 +184,12 @@ under the License.
<field-map field-name="userLoginId" value="admin"/>
</entity-one>
<script>groovy:
- request.setParameter("orderMode", "SALES_ORDER");
- request.setParameter("productStoreId", "9000");
- request.setParameter("partyId", "DemoCustomer");
- request.setParameter("currencyUom", "USD");
- session = request.getSession();
- session.setAttribute("userLogin", userLogin);
+ request.setParameter("orderMode", "SALES_ORDER")
+ request.setParameter("productStoreId", "9000")
+ request.setParameter("partyId", "DemoCustomer")
+ request.setParameter("currencyUom", "USD")
+ session = request.getSession()
+ session.setAttribute("userLogin", userLogin)
</script>
<call-class-method method-name="initializeOrderEntry"
class-name="org.apache.ofbiz.order.shoppingcart.ShoppingCartEvents"
ret-field="result">
<field field="request"
type="javax.servlet.http.HttpServletRequest"/>
@@ -202,7 +202,7 @@ under the License.
</call-class-method>
<log level="info" message="===== >>> Event :
setOrderCurrencyAgreementShipDates, Response : ${result}"/>
<script>groovy:
- request.setParameter("add_product_id", "GZ-1001");
+ request.setParameter("add_product_id", "GZ-1001")
</script>
<call-class-method method-name="addToCart"
class-name="org.apache.ofbiz.order.shoppingcart.ShoppingCartEvents"
ret-field="result">
<field field="request"
type="javax.servlet.http.HttpServletRequest"/>
@@ -210,12 +210,12 @@ under the License.
</call-class-method>
<log level="info" message="===== >>> Event : addToCart, Response :
${result}"/>
<script>groovy:
- request.setParameter("checkoutpage", "quick");
- request.setParameter("shipping_contact_mech_id", "9015");
- request.setParameter("shipping_method", "GROUND@UPS");
- request.setParameter("checkOutPaymentId", "EXT_PAYPAL");
- request.setParameter("is_gift", "false");
- request.setParameter("may_split", "false");
+ request.setParameter("checkoutpage", "quick")
+ request.setParameter("shipping_contact_mech_id", "9015")
+ request.setParameter("shipping_method", "GROUND@UPS")
+ request.setParameter("checkOutPaymentId", "EXT_PAYPAL")
+ request.setParameter("is_gift", "false")
+ request.setParameter("may_split", "false")
</script>
<field-to-request field="nullField" request-name="shoppingCart"/>
<call-class-method method-name="setQuickCheckOutOptions"
class-name="org.apache.ofbiz.order.shoppingcart.CheckOutEvents"
ret-field="result">