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

ashishvijaywargiya 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 1bdd5edb37 Adopt update() DSL in ImageManagementServicesScript and 
OrderServicesScript (#2050)
1bdd5edb37 is described below

commit 1bdd5edb37aab180dc64c631d8b190b4c535485c
Author: Ashish Vijaywargiya <[email protected]>
AuthorDate: Sat Sep 19 15:10:56 2026 +0530

    Adopt update() DSL in ImageManagementServicesScript and OrderServicesScript 
(#2050)
---
 .../ofbiz/order/order/OrderServicesScript.groovy   |   7 +-
 .../ImageManagementServicesScript.groovy           |  47 ++-----
 .../product/test/ImageManagementTests.groovy       | 153 +++++++++++++++++++++
 .../product/product/test/ShipmentTests.groovy      |  47 +++++++
 4 files changed, 215 insertions(+), 39 deletions(-)

diff --git 
a/applications/order/src/main/groovy/org/apache/ofbiz/order/order/OrderServicesScript.groovy
 
b/applications/order/src/main/groovy/org/apache/ofbiz/order/order/OrderServicesScript.groovy
index 3d8cfdecc9..038d7db87f 100644
--- 
a/applications/order/src/main/groovy/org/apache/ofbiz/order/order/OrderServicesScript.groovy
+++ 
b/applications/order/src/main/groovy/org/apache/ofbiz/order/order/OrderServicesScript.groovy
@@ -329,10 +329,6 @@ Map updateOrderContactMech() {
 Map updateOrderItemShipGroup() {
     require(security.hasEntityPermission('ORDERMGR', '_UPDATE', 
parameters.userLogin) as boolean,
             label('OrderErrorUiLabels', 
'OrderSecurityErrorToRunUpdateOrderItemShipGroup'))
-    GenericValue lookedUpValue =  from('OrderItemShipGroup')
-            .where(parameters)
-            .queryOne()
-
     // splitting shipmentMethod request parameter value that contains '@' 
symbol into
     // 'shipmentMethodTypeId', 'carrierPartyId' and 'carrierRoleTypeId'.
     String shipmentMethod = parameters.shipmentMethod
@@ -342,7 +338,6 @@ Map updateOrderItemShipGroup() {
         parameters.put('carrierPartyId', arr[1])
         parameters.put('carrierRoleTypeId', arr[2])
     }
-    lookedUpValue.setNonPKFields(parameters)
 
     Map inputMap = [orderId: parameters.orderId,
                     contactMechPurposeTypeId: 
parameters.contactMechPurposeTypeId]
@@ -356,7 +351,7 @@ Map updateOrderItemShipGroup() {
     if (!orderContactMechList && parameters.contactMechId) {
         run service: 'createOrderContactMech', with: [*: inputMap]
     }
-    lookedUpValue.store()
+    update('OrderItemShipGroup').where(parameters).set(parameters)
 
     // Remove the old values from OrderContactMech entity with the help of 
oldContactMechId
     Map shipGroupLookupMap = [orderId: parameters.orderId]
diff --git 
a/applications/product/src/main/groovy/org/apache/ofbiz/product/product/imagemanagement/ImageManagementServicesScript.groovy
 
b/applications/product/src/main/groovy/org/apache/ofbiz/product/product/imagemanagement/ImageManagementServicesScript.groovy
index de7fb02cac..62e3c3fd41 100644
--- 
a/applications/product/src/main/groovy/org/apache/ofbiz/product/product/imagemanagement/ImageManagementServicesScript.groovy
+++ 
b/applications/product/src/main/groovy/org/apache/ofbiz/product/product/imagemanagement/ImageManagementServicesScript.groovy
@@ -237,9 +237,7 @@ Map setImageDetail() {
     content.store()
 
     if (content.statusId == 'IM_APPROVED') {
-        GenericValue dataResource = from('DataResource').where(dataResourceId: 
content.dataResourceId).queryOne()
-        dataResource.isPublic = parameters.drIsPublic
-        dataResource.store()
+        update('DataResource').where(dataResourceId: 
content.dataResourceId).set([isPublic: parameters.drIsPublic])
     }
     return success()
 }
@@ -264,46 +262,33 @@ Map updateStatusImageManagement() {
             contentApproval.store()
         }
     } else {
-        GenericValue contentApproval = from('ContentApproval').where(partyId: 
userLogin.partyId, contentId: parameters.contentId,
-                roleTypeId: 'IMAGEAPPROVER').queryFirst()
-        contentApproval.approvalStatusId = parameters.checkStatusId
-        contentApproval.store()
+        update('ContentApproval').where(partyId: userLogin.partyId, contentId: 
parameters.contentId, roleTypeId: 'IMAGEAPPROVER')
+                .first().set([approvalStatusId: parameters.checkStatusId])
     }
     if (parameters.checkStatusId == 'IM_REJECTED') {
         List checkRejects = from('ContentApproval').where(contentId: 
parameters.contentId, roleTypeId: 'IMAGEAPPROVER').queryList()
         for (GenericValue checkReject : checkRejects) {
-            checkReject.statusId = 'IM_REJECTED'
+            checkReject.approvalStatusId = 'IM_REJECTED'
             checkReject.store()
         }
-        GenericValue content = from('Content').where(parameters).queryOne()
-        content.statusId = 'IM_REJECTED'
-        content.createdByUserLogin = userLogin.userLoginId
-        content.store()
+        update('Content').where(parameters).set([statusId: 'IM_REJECTED', 
createdByUserLogin: userLogin.userLoginId])
     } else {
         if (parameters.checkStatusId == 'IM_APPROVED') {
             if (multipleApproval == 'Y') {
                 Long countParty = from('ContentApproval').where(contentId: 
parameters.contentId, roleTypeId: 'IMAGEAPPROVER').queryCount()
                 if (countParty == (Long) 1) {
-                    GenericValue content = 
from('Content').where(parameters).queryOne()
-                    content.statusId = 'IM_APPROVED'
-                    content.store()
+                    update('Content').where(parameters).set([statusId: 
'IM_APPROVED'])
 
-                    GenericValue productContent = 
from('ProductContent').where(contentId: parameters.contentId, 
productContentTypeId: 'IMAGE')
-                            .queryFirst()
-                    productContent.purchaseFromDate = nowTimestamp
-                    productContent.store()
+                    update('ProductContent').where(contentId: 
parameters.contentId, productContentTypeId: 'IMAGE')
+                            .first().set([purchaseFromDate: nowTimestamp])
                 } else {
                     Long countApprove = 
from('ContentApproval').where(contentId: parameters.contentId, roleTypeId: 
'IMAGEAPPROVER',
                             approvalStatusId: 'IM_APPROVED').queryCount()
                     if (countApprove >= (Long) 2) {
-                        GenericValue content = 
from('Content').where(parameters).queryOne()
-                        content.statusId = 'IM_APPROVED'
-                        content.store()
+                        update('Content').where(parameters).set([statusId: 
'IM_APPROVED'])
 
-                        GenericValue productContent = 
from('ProductContent').where(contentId: parameters.contentId, 
productContentTypeId: 'IMAGE')
-                                .queryFirst()
-                        productContent.purchaseFromDate = nowTimestamp
-                        productContent.store()
+                        update('ProductContent').where(contentId: 
parameters.contentId, productContentTypeId: 'IMAGE')
+                                .first().set([purchaseFromDate: nowTimestamp])
 
                         List checkApproveList = 
from('ContentApproval').where(contentId: parameters.contentId, roleTypeId: 
'IMAGEAPPROVER')
                                 .queryList()
@@ -314,14 +299,10 @@ Map updateStatusImageManagement() {
                     }
                 }
             } else {
-                GenericValue content = 
from('Content').where(parameters).queryOne()
-                content.statusId = 'IM_APPROVED'
-                content.store()
+                update('Content').where(parameters).set([statusId: 
'IM_APPROVED'])
 
-                GenericValue productContent = from('ProductContent')
-                        .where(contentId: parameters.contentId, 
productContentTypeId: 'IMAGE').queryFirst()
-                productContent.purchaseFromDate = nowTimestamp
-                productContent.store()
+                update('ProductContent').where(contentId: 
parameters.contentId, productContentTypeId: 'IMAGE')
+                        .first().set([purchaseFromDate: nowTimestamp])
 
                 List checkApproveList = 
from('ContentApproval').where(contentId: parameters.contentId, roleTypeId: 
'IMAGEAPPROVER').queryList()
                 for (GenericValue checkApprove : checkApproveList) {
diff --git 
a/applications/product/src/test/groovy/org/apache/ofbiz/product/product/test/ImageManagementTests.groovy
 
b/applications/product/src/test/groovy/org/apache/ofbiz/product/product/test/ImageManagementTests.groovy
index 00a1433307..8eaedf18b5 100644
--- 
a/applications/product/src/test/groovy/org/apache/ofbiz/product/product/test/ImageManagementTests.groovy
+++ 
b/applications/product/src/test/groovy/org/apache/ofbiz/product/product/test/ImageManagementTests.groovy
@@ -22,8 +22,10 @@ import org.apache.ofbiz.entity.GenericValue
 import org.apache.ofbiz.service.ServiceUtil
 import org.apache.ofbiz.testtools.JunitJupiterTest
 import org.apache.ofbiz.testtools.JupiterTestHelper
+import org.junit.jupiter.api.Assertions
 import org.junit.jupiter.api.Order
 import org.junit.jupiter.api.Test
+import java.sql.Timestamp
 
 @JunitJupiterTest
 class ImageManagementTests implements JupiterTestHelper {
@@ -64,4 +66,155 @@ class ImageManagementTests implements JupiterTestHelper {
         assert productContentAfter.thruDate != null
     }
 
+    @Test
+    @Order(2)
+    void testUpdateStatusImageManagementSingleApproverPath() {
+        GenericValue userLogin = delegator.findOne('UserLogin', [userLoginId: 
'system'], false)
+
+        String internalName = testParams.internalName ?: 'Test Single Approver 
Product'
+        String contentName = testParams.contentName ?: 'Test Single Approver 
Image'
+        String statusId = testParams.statusId ?: 'IM_PENDING'
+        // checkStatusId is deliberately NOT testParams-driven - it selects 
which branch of
+        // updateStatusImageManagement() this test exercises (IM_APPROVED), 
and the assertions
+        // below (purchaseFromDate getting set) only hold for that branch. See
+        // testUpdateStatusImageManagementRejectedPath() for the IM_REJECTED 
branch's own test.
+        String checkStatusId = 'IM_APPROVED'
+
+        Map<String, Object> createProductResult = 
dispatcher.runSync('createProduct',
+                [productTypeId: 'FINISHED_GOOD', internalName: internalName, 
userLogin: userLogin])
+        assert ServiceUtil.isSuccess(createProductResult)
+        String productId = createProductResult.productId
+
+        Map<String, Object> createContentResult = 
dispatcher.runSync('createContent',
+                [contentName: contentName, statusId: statusId, userLogin: 
userLogin])
+        assert ServiceUtil.isSuccess(createContentResult)
+        String contentId = createContentResult.contentId
+
+        Map<String, Object> createProductContentResult = 
dispatcher.runSync('createProductContent',
+                [productId: productId, contentId: contentId, 
productContentTypeId: 'IMAGE', userLogin: userLogin])
+        assert ServiceUtil.isSuccess(createProductContentResult)
+
+        Map<String, Object> createContentApprovalResult = 
dispatcher.runSync('createContentApproval',
+                [contentId: contentId, partyId: userLogin.partyId, roleTypeId: 
'IMAGEAPPROVER',
+                 approvalStatusId: statusId, userLogin: userLogin])
+        assert ServiceUtil.isSuccess(createContentApprovalResult)
+
+        GenericValue contentBefore = from('Content').where('contentId', 
contentId).queryOne()
+        Assertions.assertEquals(statusId, contentBefore.statusId)
+
+        Map<String, Object> updateStatusResult = 
dispatcher.runSync('updateStatusImageManagement',
+                [productId: productId, contentId: contentId, checkStatusId: 
checkStatusId, userLogin: userLogin])
+        assert ServiceUtil.isSuccess(updateStatusResult)
+
+        GenericValue contentAfter = from('Content').where('contentId', 
contentId).queryOne()
+        Assertions.assertEquals(checkStatusId, contentAfter.statusId)
+
+        GenericValue productContentAfter = from('ProductContent')
+                .where('productId', productId, 'contentId', contentId, 
'productContentTypeId', 'IMAGE')
+                .queryOne()
+        assert productContentAfter.purchaseFromDate != null
+    }
+
+    @Test
+    @Order(3)
+    void testSetImageDetailUpdatesDataResourceIsPublic() {
+        GenericValue userLogin = delegator.findOne('UserLogin', [userLoginId: 
'system'], false)
+
+        String internalName = testParams.internalName ?: 'Test Set Image 
Detail Product'
+        String contentName = testParams.contentName ?: 'Test Set Image Detail 
Content'
+        String dataResourceName = testParams.dataResourceName ?: 'Test Set 
Image Detail DataResource'
+        String initialIsPublic = testParams.initialIsPublic ?: 'N'
+        String drIsPublic = testParams.drIsPublic ?: 'Y'
+        String description = testParams.description ?: 'Test image description'
+        // statusId is deliberately NOT testParams-driven - setImageDetail()'s 
DataResource update
+        // only runs when content.statusId == 'IM_APPROVED'; that's the one 
condition this test
+        // exists to exercise, not a value a caller should vary away.
+        String statusId = 'IM_APPROVED'
+
+        Map<String, Object> createDataResourceResult = 
dispatcher.runSync('createDataResource',
+                [dataResourceName: dataResourceName, isPublic: 
initialIsPublic, userLogin: userLogin])
+        assert ServiceUtil.isSuccess(createDataResourceResult)
+        String dataResourceId = createDataResourceResult.dataResourceId
+
+        Map<String, Object> createProductResult = 
dispatcher.runSync('createProduct',
+                [productTypeId: 'FINISHED_GOOD', internalName: internalName, 
userLogin: userLogin])
+        assert ServiceUtil.isSuccess(createProductResult)
+        String productId = createProductResult.productId
+
+        Map<String, Object> createContentResult = 
dispatcher.runSync('createContent',
+                [contentName: contentName, statusId: statusId, dataResourceId: 
dataResourceId, userLogin: userLogin])
+        assert ServiceUtil.isSuccess(createContentResult)
+        String contentId = createContentResult.contentId
+
+        Map<String, Object> createProductContentResult = 
dispatcher.runSync('createProductContent',
+                [productId: productId, contentId: contentId, 
productContentTypeId: 'IMAGE', userLogin: userLogin])
+        assert ServiceUtil.isSuccess(createProductContentResult)
+
+        // fromDate is part of ProductContent's PK and a required IN attribute 
of setImageDetail()
+        // (auto-attributes include="pk" mode="IN" optional="false") - must be 
the actual stored value.
+        GenericValue productContent = from('ProductContent')
+                .where('productId', productId, 'contentId', contentId, 
'productContentTypeId', 'IMAGE')
+                .queryOne()
+        Timestamp fromDate = productContent.fromDate
+
+        GenericValue dataResourceBefore = 
from('DataResource').where('dataResourceId', dataResourceId).queryOne()
+        Assertions.assertEquals(initialIsPublic, dataResourceBefore.isPublic)
+
+        Map<String, Object> setImageDetailResult = 
dispatcher.runSync('setImageDetail',
+                [productId: productId, contentId: contentId, 
productContentTypeId: 'IMAGE',
+                 fromDate: fromDate, description: description, drIsPublic: 
drIsPublic, userLogin: userLogin])
+        assert ServiceUtil.isSuccess(setImageDetailResult)
+
+        GenericValue dataResourceAfter = 
from('DataResource').where('dataResourceId', dataResourceId).queryOne()
+        Assertions.assertEquals(drIsPublic, dataResourceAfter.isPublic)
+    }
+
+    @Test
+    @Order(4)
+    void testUpdateStatusImageManagementRejectedPath() {
+        GenericValue userLogin = delegator.findOne('UserLogin', [userLoginId: 
'system'], false)
+
+        String internalName = testParams.internalName ?: 'Test Rejected Image 
Product'
+        String contentName = testParams.contentName ?: 'Test Rejected Image'
+        String statusId = testParams.statusId ?: 'IM_PENDING'
+        // checkStatusId is deliberately NOT testParams-driven - see
+        // testUpdateStatusImageManagementSingleApproverPath()'s note on the 
same pattern.
+        String checkStatusId = 'IM_REJECTED'
+
+        Map<String, Object> createProductResult = 
dispatcher.runSync('createProduct',
+                [productTypeId: 'FINISHED_GOOD', internalName: internalName, 
userLogin: userLogin])
+        assert ServiceUtil.isSuccess(createProductResult)
+        String productId = createProductResult.productId
+
+        Map<String, Object> createContentResult = 
dispatcher.runSync('createContent',
+                [contentName: contentName, statusId: statusId, userLogin: 
userLogin])
+        assert ServiceUtil.isSuccess(createContentResult)
+        String contentId = createContentResult.contentId
+
+        Map<String, Object> createProductContentResult = 
dispatcher.runSync('createProductContent',
+                [productId: productId, contentId: contentId, 
productContentTypeId: 'IMAGE', userLogin: userLogin])
+        assert ServiceUtil.isSuccess(createProductContentResult)
+
+        Map<String, Object> createContentApprovalResult = 
dispatcher.runSync('createContentApproval',
+                [contentId: contentId, partyId: userLogin.partyId, roleTypeId: 
'IMAGEAPPROVER',
+                 approvalStatusId: statusId, userLogin: userLogin])
+        assert ServiceUtil.isSuccess(createContentApprovalResult)
+
+        GenericValue contentBefore = from('Content').where('contentId', 
contentId).queryOne()
+        Assertions.assertEquals(statusId, contentBefore.statusId)
+
+        Map<String, Object> updateStatusResult = 
dispatcher.runSync('updateStatusImageManagement',
+                [productId: productId, contentId: contentId, checkStatusId: 
checkStatusId, userLogin: userLogin])
+        assert ServiceUtil.isSuccess(updateStatusResult)
+
+        GenericValue contentAfter = from('Content').where('contentId', 
contentId).queryOne()
+        Assertions.assertEquals(checkStatusId, contentAfter.statusId)
+        Assertions.assertEquals(userLogin.userLoginId, 
contentAfter.createdByUserLogin)
+
+        GenericValue checkRejectAfter = from('ContentApproval')
+                .where('contentId', contentId, 'partyId', userLogin.partyId, 
'roleTypeId', 'IMAGEAPPROVER')
+                .queryOne()
+        Assertions.assertEquals(checkStatusId, 
checkRejectAfter.approvalStatusId)
+    }
+
 }
diff --git 
a/applications/product/src/test/groovy/org/apache/ofbiz/product/product/test/ShipmentTests.groovy
 
b/applications/product/src/test/groovy/org/apache/ofbiz/product/product/test/ShipmentTests.groovy
index 52749abdef..bd4f7bfa4a 100644
--- 
a/applications/product/src/test/groovy/org/apache/ofbiz/product/product/test/ShipmentTests.groovy
+++ 
b/applications/product/src/test/groovy/org/apache/ofbiz/product/product/test/ShipmentTests.groovy
@@ -24,6 +24,7 @@ import org.apache.ofbiz.service.ServiceUtil
 import org.apache.ofbiz.testtools.JunitJupiterTest
 import org.apache.ofbiz.testtools.JupiterTestHelper
 import org.apache.ofbiz.shipment.packing.PackingSession
+import org.junit.jupiter.api.Assertions
 import org.junit.jupiter.api.Order
 import org.junit.jupiter.api.Test
 
@@ -493,6 +494,52 @@ class ShipmentTests implements JupiterTestHelper {
         assert itemIssuances*.shipGroupSeqId as Set == ['00001'] as Set
     }
 
+    @Test
+    @Order(10)
+    void testUpdateOrderItemShipGroupSplitsShipmentMethodIntoComponents() {
+        GenericValue userLogin = delegator.findOne('UserLogin', [userLoginId: 
'system'], false)
+
+        String productId = testParams.productId ?: 'GZ-2644'
+        String shipGroupSeqId = testParams.shipGroupSeqId ?: '00001'
+        String contactMechPurposeTypeId = testParams.contactMechPurposeTypeId 
?: 'SHIPPING_LOCATION'
+        String shipmentMethodTypeId = testParams.shipmentMethodTypeId ?: 
'STANDARD'
+        String carrierPartyId = testParams.carrierPartyId ?: 'UPS'
+        String carrierRoleTypeId = testParams.carrierRoleTypeId ?: 'CARRIER'
+
+        Map<String, Object> orderResult = 
dispatcher.runSync('createTestSalesOrderSingle',
+                [userLogin: userLogin, productId: productId])
+        assert ServiceUtil.isSuccess(orderResult)
+        String orderId = orderResult.orderId
+        assert orderId
+
+        GenericValue shipGroupBefore = from('OrderItemShipGroup')
+                .where('orderId', orderId, 'shipGroupSeqId', shipGroupSeqId)
+                .queryOne()
+        assert shipGroupBefore
+        assert shipGroupBefore.shipmentMethodTypeId != shipmentMethodTypeId || 
shipGroupBefore.carrierPartyId != carrierPartyId
+
+        // shipmentMethod is a combined 
'shipmentMethodTypeId@carrierPartyId@carrierRoleTypeId'
+        // convenience input that updateOrderItemShipGroup() splits apart 
before storing - not
+        // exercised by the other updateOrderItemShipGroup test above, which 
only changes
+        // contactMechId.
+        Map<String, Object> updateShipGroupResult = 
dispatcher.runSync('updateOrderItemShipGroup', [
+                orderId: orderId,
+                shipGroupSeqId: shipGroupSeqId,
+                contactMechId: shipGroupBefore.contactMechId,
+                contactMechPurposeTypeId: contactMechPurposeTypeId,
+                shipmentMethod: 
"${shipmentMethodTypeId}@${carrierPartyId}@${carrierRoleTypeId}".toString(),
+                userLogin: userLogin
+        ])
+        assert ServiceUtil.isSuccess(updateShipGroupResult)
+
+        GenericValue shipGroupAfter = from('OrderItemShipGroup')
+                .where('orderId', orderId, 'shipGroupSeqId', shipGroupSeqId)
+                .queryOne()
+        Assertions.assertEquals(shipmentMethodTypeId, 
shipGroupAfter.shipmentMethodTypeId)
+        Assertions.assertEquals(carrierPartyId, shipGroupAfter.carrierPartyId)
+        Assertions.assertEquals(carrierRoleTypeId, 
shipGroupAfter.carrierRoleTypeId)
+    }
+
     /**
      * Resolves a postal address in a different country/state/postal code than 
the demo customer's
      * default shipping address, returning its contactMechId.

Reply via email to