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 e21d363c7 Improved: Added findExampleById service to retrieve Example
records by ID, If no ID is provided then it will return all the records from
Example entity. This service can be helpful to test REST integration of ofbiz
with other platforms.
e21d363c7 is described below
commit e21d363c77cfa63056e56bffe1ffe136ccbd2be8
Author: Ashish Vijaywargiya <[email protected]>
AuthorDate: Thu Jan 29 19:08:24 2026 +0530
Improved: Added findExampleById service to retrieve Example records by ID,
If no ID is provided then it will return all the records from Example entity.
This service can be helpful to test REST integration of ofbiz with other
platforms.
---
example/api/example.rest.xml | 5 +++++
example/servicedef/services.xml | 6 +++++
.../ofbiz/example/ExampleAdditionalServices.groovy | 26 ++++++++++++++++++++++
3 files changed, 37 insertions(+)
diff --git a/example/api/example.rest.xml b/example/api/example.rest.xml
index 83a808ac7..50f60ae02 100644
--- a/example/api/example.rest.xml
+++ b/example/api/example.rest.xml
@@ -44,5 +44,10 @@ under the License.
consumes="application/json">
<service name="updateExample"/>
</operation>
+
+ <operation verb="get" description="Find Example by ID"
+ consumes="application/json">
+ <service name="findExampleById"/>
+ </operation>
</resource>
</api>
\ No newline at end of file
diff --git a/example/servicedef/services.xml b/example/servicedef/services.xml
index 97f5c0bf4..6b165643e 100644
--- a/example/servicedef/services.xml
+++ b/example/servicedef/services.xml
@@ -47,6 +47,12 @@ under the License.
<permission-service service-name="exampleGenericPermission"
main-action="DELETE"/>
<auto-attributes include="pk" mode="INOUT" optional="false"/>
</service>
+ <service name="findExampleById" default-entity-name="Example"
engine="groovy"
+
location="component://example/src/main/groovy/org/apache/ofbiz/example/ExampleAdditionalServices.groovy"
invoke="findExampleById" auth="true">
+ <description>Find Example by ID</description>
+ <auto-attributes include="pk" mode="IN" optional="true"/>
+ <attribute name="exampleList" mode="OUT" optional="true" type="List"/>
+ </service>
<service name="createExampleStatus" default-entity-name="ExampleStatus"
engine="simple"
location="component://example/minilang/example/ExampleServices.xml"
invoke="createExampleStatus" auth="true">
<description>Create a ExampleStatus</description>
diff --git
a/example/src/main/groovy/org/apache/ofbiz/example/ExampleAdditionalServices.groovy
b/example/src/main/groovy/org/apache/ofbiz/example/ExampleAdditionalServices.groovy
index 1374edde7..78ee9917d 100644
---
a/example/src/main/groovy/org/apache/ofbiz/example/ExampleAdditionalServices.groovy
+++
b/example/src/main/groovy/org/apache/ofbiz/example/ExampleAdditionalServices.groovy
@@ -20,6 +20,8 @@ package org.apache.ofbiz.example
import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.entity.util.EntityQuery
+
Map deleteExample() {
Map result = success()
@@ -40,3 +42,27 @@ Map deleteExample() {
return result
}
+
+Map findExampleById() {
+ Map result = success()
+ List exampleList = []
+
+ String exampleId = parameters.exampleId
+
+ if (exampleId) {
+ exampleList = EntityQuery.use(delegator)
+ .from('Example')
+ .select('exampleId', 'exampleTypeId',
'exampleName')
+ .where('exampleId', exampleId)
+ .queryList()
+ } else {
+ exampleList = EntityQuery.use(delegator)
+ .from('Example')
+ .select('exampleId', 'exampleTypeId',
'exampleName')
+ .orderBy('exampleId')
+ .queryList()
+ }
+ result.exampleList = exampleList
+
+ return result
+}