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

ashish pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 2ac26ce8d Improved: deleteExample service was failing because there 
can be additional records present in the connected entities:
2ac26ce8d is described below

commit 2ac26ce8d98dd52bd5f5cb0bf9e6216c7f671bff
Author: Ashish Vijaywargiya <[email protected]>
AuthorDate: Thu Jan 29 13:14:58 2026 +0530

    Improved: deleteExample service was failing because there can be additional 
records present in the connected entities:
    
    ExampleItem
    ExampleStatus
    ExampleFeatureAppl
    
    And in such cases "entity-auto" will not work as expected.
---
 example/api/example.rest.xml                       |  3 +-
 example/servicedef/services.xml                    | 11 +++---
 .../ofbiz/example/ExampleAdditionalServices.groovy | 42 ++++++++++++++++++++++
 3 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/example/api/example.rest.xml b/example/api/example.rest.xml
index 02b296056..83a808ac7 100644
--- a/example/api/example.rest.xml
+++ b/example/api/example.rest.xml
@@ -35,10 +35,11 @@ under the License.
             <service name="createExample"/>
         </operation>
 
-        <operation verb="delete" description="delete Example"
+        <operation verb="delete" description="Delete Example"
                    consumes="application/json">
             <service name="deleteExample"/>
         </operation>
+
         <operation verb="put" description="Update Example"
                    consumes="application/json">
             <service name="updateExample"/>
diff --git a/example/servicedef/services.xml b/example/servicedef/services.xml
index a1822e899..97f5c0bf4 100644
--- a/example/servicedef/services.xml
+++ b/example/servicedef/services.xml
@@ -26,7 +26,7 @@ under the License.
 
     <!-- Example & Related Services -->
     <service name="createExample" default-entity-name="Example" 
engine="entity-auto" invoke="create" auth="true">
-        <description>Create a Example</description>
+        <description>Create an Example</description>
         <permission-service service-name="exampleGenericPermission" 
main-action="CREATE"/>
         <auto-attributes include="pk" mode="OUT" optional="false"/>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>
@@ -35,16 +35,17 @@ under the License.
         <override name="exampleName" optional="false"/>
     </service>
     <service name="updateExample" default-entity-name="Example" 
engine="entity-auto" invoke="update" auth="true">
-        <description>Update a Example</description>
+        <description>Update an Example</description>
         <permission-service service-name="exampleGenericPermission" 
main-action="UPDATE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>
         <attribute name="oldStatusId" type="String" mode="OUT" 
optional="false"/>
     </service>
-    <service name="deleteExample" default-entity-name="Example" 
engine="entity-auto" invoke="delete" auth="true">
-        <description>Delete a Example</description>
+    <service name="deleteExample" default-entity-name="Example" engine="groovy"
+            
location="component://example/src/main/groovy/org/apache/ofbiz/example/ExampleAdditionalServices.groovy"
 invoke="deleteExample" auth="true">
+        <description>Delete an Example</description>
         <permission-service service-name="exampleGenericPermission" 
main-action="DELETE"/>
-        <auto-attributes include="pk" mode="IN" optional="false"/>
+        <auto-attributes include="pk" mode="INOUT" optional="false"/>
     </service>
     <service name="createExampleStatus" default-entity-name="ExampleStatus" 
engine="simple"
             
location="component://example/minilang/example/ExampleServices.xml" 
invoke="createExampleStatus" auth="true">
diff --git 
a/example/src/main/groovy/org/apache/ofbiz/example/ExampleAdditionalServices.groovy
 
b/example/src/main/groovy/org/apache/ofbiz/example/ExampleAdditionalServices.groovy
new file mode 100644
index 000000000..1374edde7
--- /dev/null
+++ 
b/example/src/main/groovy/org/apache/ofbiz/example/ExampleAdditionalServices.groovy
@@ -0,0 +1,42 @@
+/*
+ * 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.example
+
+import org.apache.ofbiz.entity.GenericValue
+
+Map deleteExample() {
+    Map result = success()
+
+    String exampleId = parameters.exampleId
+
+    GenericValue example = delegator.findOne('Example', [exampleId: 
exampleId], false)
+
+    if (example) {
+        // Remove related records using the GenericValue helper
+        example.removeRelated('ExampleItem')
+        example.removeRelated('ExampleStatus')
+        example.removeRelated('ExampleFeatureAppl')
+
+        example.remove()
+    }
+
+    result.exampleId = exampleId
+
+    return result
+}

Reply via email to