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 44c052e53 Improvements: Since MiniLang has been deprecated in OFBiz 
for a long time, the related services and test cases have been migrated to 
Groovy. (#150)
44c052e53 is described below

commit 44c052e536facbc7bcb53745e73eea8234ee3946
Author: Ashish Vijaywargiya <[email protected]>
AuthorDate: Tue Feb 10 16:40:59 2026 +0530

    Improvements: Since MiniLang has been deprecated in OFBiz for a long time, 
the related services and test cases have been migrated to Groovy. (#150)
---
 example/minilang/ExamplePermissionServices.xml     | 43 -------------
 example/minilang/example/ExampleServices.xml       | 71 ----------------------
 example/servicedef/services.xml                    | 14 ++---
 .../ofbiz/example/ExampleAdditionalServices.groovy | 34 +++++++++--
 .../ofbiz/example/ExamplePermissionServices.groovy | 40 ++++++++++++
 .../org/apache/ofbiz/example/ExampleTests.groovy   | 23 ++++++-
 example/testdef/data/ExampleTestData.xml           |  9 +++
 example/testdef/tests.xml                          |  8 +--
 8 files changed, 106 insertions(+), 136 deletions(-)

diff --git a/example/minilang/ExamplePermissionServices.xml 
b/example/minilang/ExamplePermissionServices.xml
deleted file mode 100644
index 5c1ff3283..000000000
--- a/example/minilang/ExamplePermissionServices.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-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.
--->
-
-<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="exampleGenericPermission" 
short-description="Main permission logic">
-        <set field="mainAction" from-field="parameters.mainAction"/>
-        <if-empty field="mainAction">
-            <add-error>
-                <fail-property resource="ExampleUiLabels" 
property="ExamplePermissionMainActionAttributeMissing"/>
-            </add-error>
-            <check-errors/>
-        </if-empty>
-        <if-has-permission permission="EXAMPLE" 
action="_${parameters.mainAction}">
-            <set field="hasPermission" type="Boolean" value="true"/>
-            <field-to-result field="hasPermission"/>
-            <else>
-                <property-to-field resource="ExampleUiLabels" 
property="ExamplePermissionError" field="failMessage"/>
-                <set field="hasPermission" type="Boolean" value="false"/>
-                <field-to-result field="hasPermission"/>
-                <field-to-result field="failMessage"/>
-            </else>
-        </if-has-permission>
-    </simple-method>
-</simple-methods>
diff --git a/example/minilang/example/ExampleServices.xml 
b/example/minilang/example/ExampleServices.xml
deleted file mode 100644
index dfc7274a7..000000000
--- a/example/minilang/example/ExampleServices.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-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.
--->
-
-<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";>
-    <!-- ExampleStatus methods -->
-    <simple-method method-name="createExampleStatus" short-description="create 
a ExampleItem">
-        <now-timestamp field="nowTimestamp"/>
-
-        <!-- find the most recent status record and set the statusEndDate -->
-        <entity-and entity-name="ExampleStatus" list="oldExampleStatusList">
-            <field-map field-name="exampleId" 
from-field="parameters.exampleId"/>
-            <order-by field-name="-statusDate"/>
-        </entity-and>
-        <first-from-list list="oldExampleStatusList" entry="oldExampleStatus"/>
-        <if-not-empty field="oldExampleStatus">
-            <set field="oldExampleStatus.statusEndDate" 
from-field="nowTimestamp"/>
-            <store-value value-field="oldExampleStatus"/>
-        </if-not-empty>
-
-        <make-value entity-name="ExampleStatus" value-field="newEntity"/>
-        <set-pk-fields map="parameters" value-field="newEntity"/>
-        <set-nonpk-fields map="parameters" value-field="newEntity"/>
-        <set field="newEntity.statusDate" from-field="nowTimestamp"/>
-        <set field="newEntity.changeByUserLoginId" 
from-field="userLogin.userLoginId"/>
-        <create-value value-field="newEntity"/>
-    </simple-method>
-
-    <!-- Example ServiceTest Service -->
-    <simple-method method-name="testCreateExampleService" 
short-description="test the create example service" login-required="false">
-        <set field="createExampleMap.exampleTypeId" value="CONTRIVED"/>
-        <set field="createExampleMap.exampleName" value="Test Example"/>
-        <set field="createExampleMap.statusId" value="EXST_IN_DESIGN"/>
-
-        <entity-one entity-name="UserLogin" 
value-field="createExampleMap.userLogin" auto-field-map="false">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-
-        <call-service service-name="createExample" 
in-map-name="createExampleMap">
-            <result-to-field result-name="exampleId" field="exampleId"/>
-        </call-service>
-
-        <entity-one entity-name="Example" value-field="example"/>
-
-        <assert>
-            <not><if-empty field="example"/></not>
-            <if-compare-field field="example.exampleTypeId" 
to-field="createExampleMap.exampleTypeId" operator="equals"/>
-            <if-compare-field field="example.exampleName" 
to-field="createExampleMap.exampleName" operator="equals"/>
-            <if-compare-field field="example.statusId" 
to-field="createExampleMap.statusId" operator="equals"/>
-        </assert>
-
-        <check-errors/>
-    </simple-method>
-</simple-methods>
diff --git a/example/servicedef/services.xml b/example/servicedef/services.xml
index 6b165643e..5193d6949 100644
--- a/example/servicedef/services.xml
+++ b/example/servicedef/services.xml
@@ -53,8 +53,8 @@ under the License.
         <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">
+    <service name="createExampleStatus" default-entity-name="ExampleStatus" 
engine="groovy"
+            
location="component://example/src/main/groovy/org/apache/ofbiz/example/ExampleAdditionalServices.groovy"
 invoke="createExampleStatus" auth="true">
         <description>Create a ExampleStatus</description>
         <permission-service service-name="exampleGenericPermission" 
main-action="CREATE"/>
         <auto-attributes include="all" mode="IN" optional="false">
@@ -124,16 +124,12 @@ under the License.
     </service>
 
     <!-- Permission Services -->
-    <service name="exampleGenericPermission" engine="simple"
-             
location="component://example/minilang/ExamplePermissionServices.xml" 
invoke="exampleGenericPermission">
+    <service name="exampleGenericPermission" engine="groovy"
+             
location="component://example/src/main/groovy/org/apache/ofbiz/example/ExamplePermissionServices.groovy"
 invoke="exampleGenericPermission">
         <implements service="permissionInterface"/>
     </service>
 
-    <!-- Example ServiceTest Service -->
-    <service name="testCreateExampleService" engine="simple"
-             
location="component://example/minilang/example/ExampleServices.xml" 
invoke="testCreateExampleService">
-        <implements service="testServiceInterface"/>
-    </service>
+
     <!-- Send push notification service -->
     <service name="sendExamplePushNotifications" engine="java"
                 location="org.apache.ofbiz.example.ExampleServices" 
invoke="sendExamplePushNotifications" 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
index 78ee9917d..a34204e80 100644
--- 
a/example/src/main/groovy/org/apache/ofbiz/example/ExampleAdditionalServices.groovy
+++ 
b/example/src/main/groovy/org/apache/ofbiz/example/ExampleAdditionalServices.groovy
@@ -18,10 +18,9 @@
  */
 package org.apache.ofbiz.example
 
+import org.apache.ofbiz.base.util.UtilDateTime
 import org.apache.ofbiz.entity.GenericValue
 
-import org.apache.ofbiz.entity.util.EntityQuery
-
 Map deleteExample() {
     Map result = success()
 
@@ -50,14 +49,12 @@ Map findExampleById() {
     String exampleId = parameters.exampleId
 
     if (exampleId) {
-        exampleList = EntityQuery.use(delegator)
-                                 .from('Example')
+        exampleList = from('Example')
                                  .select('exampleId', 'exampleTypeId', 
'exampleName')
                                  .where('exampleId', exampleId)
                                  .queryList()
     } else {
-        exampleList = EntityQuery.use(delegator)
-                                 .from('Example')
+        exampleList = from('Example')
                                  .select('exampleId', 'exampleTypeId', 
'exampleName')
                                  .orderBy('exampleId')
                                  .queryList()
@@ -66,3 +63,28 @@ Map findExampleById() {
 
     return result
 }
+
+Map createExampleStatus() {
+    Map result = success()
+    nowTimestamp = UtilDateTime.nowTimestamp()
+
+    // find the most recent status record and set the statusEndDate
+    GenericValue oldExampleStatus = from('ExampleStatus')
+            .where('exampleId', parameters.exampleId)
+            .orderBy('-statusDate')
+            .queryFirst()
+
+    if (oldExampleStatus) {
+        oldExampleStatus.statusEndDate = nowTimestamp
+        oldExampleStatus.store()
+    }
+
+    GenericValue newEntity = makeValue('ExampleStatus')
+    newEntity.setPKFields(parameters)
+    newEntity.setNonPKFields(parameters)
+    newEntity.statusDate = nowTimestamp
+    newEntity.changeByUserLoginId = userLogin.userLoginId
+    newEntity.create()
+
+    return result
+}
diff --git 
a/example/src/main/groovy/org/apache/ofbiz/example/ExamplePermissionServices.groovy
 
b/example/src/main/groovy/org/apache/ofbiz/example/ExamplePermissionServices.groovy
new file mode 100644
index 000000000..aab53000a
--- /dev/null
+++ 
b/example/src/main/groovy/org/apache/ofbiz/example/ExamplePermissionServices.groovy
@@ -0,0 +1,40 @@
+/*
+ * 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.base.util.UtilProperties
+
+Map exampleGenericPermission() {
+    Map result = success()
+    String mainAction = parameters.mainAction
+
+    if (!mainAction) {
+        return error(UtilProperties.getMessage('ExampleUiLabels', 
'ExamplePermissionMainActionAttributeMissing', locale))
+    }
+
+    if (security.hasEntityPermission('EXAMPLE', '_' + mainAction, userLogin) 
|| security.hasEntityPermission('EXAMPLE', '_ADMIN', userLogin)) {
+        result.hasPermission = true
+    } else {
+        String failMessage = UtilProperties.getMessage('ExampleUiLabels', 
'ExamplePermissionError', locale)
+        result.hasPermission = false
+        result.failMessage = failMessage
+    }
+
+    return result
+}
diff --git 
a/example/src/main/groovy/org/apache/ofbiz/example/ExampleTests.groovy 
b/example/src/main/groovy/org/apache/ofbiz/example/ExampleTests.groovy
index 612c1c721..c8d57ae35 100644
--- a/example/src/main/groovy/org/apache/ofbiz/example/ExampleTests.groovy
+++ b/example/src/main/groovy/org/apache/ofbiz/example/ExampleTests.groovy
@@ -24,11 +24,31 @@ import org.apache.ofbiz.service.testtools.OFBizTestCase
 
 class ExampleTests extends OFBizTestCase {
 
-    public ExampleTests(String name) {
+    ExampleTests(String name) {
         super(name)
     }
 
+    void testCreateExample() {
+        GenericValue userLogin = from('UserLogin').where('userLoginId', 
'system').queryOne()
+        Map<String, Object> serviceCtx = [:]
+        serviceCtx.exampleTypeId = 'CONTRIVED'
+        serviceCtx.exampleName = 'Test Example'
+        serviceCtx.statusId = 'EXST_IN_DESIGN'
+        serviceCtx.userLogin = userLogin
+
+        Map<String, Object> serviceResult = 
dispatcher.runSync('createExample', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String exampleId = serviceResult.exampleId
+
+        GenericValue example = from('Example').where('exampleId', 
exampleId).queryOne()
+        assert example != null
+        assert example.exampleTypeId == 'CONTRIVED'
+        assert example.exampleName == 'Test Example'
+        assert example.statusId == 'EXST_IN_DESIGN'
+    }
+
     void testUpdateExample() {
+        GenericValue userLogin = from('UserLogin').where('userLoginId', 
'system').queryOne()
         Map<String, Object> serviceCtx = [:]
         serviceCtx.exampleId = 'TestExampleUpdate'
         serviceCtx.exampleName = 'Updated Test Example Name'
@@ -43,6 +63,7 @@ class ExampleTests extends OFBizTestCase {
     }
 
     void testDeleteExample() {
+        GenericValue userLogin = from('UserLogin').where('userLoginId', 
'system').queryOne()
         Map<String, Object> serviceCtx = [:]
         serviceCtx.exampleId = 'TestExampleDelete'
         serviceCtx.userLogin = userLogin
diff --git a/example/testdef/data/ExampleTestData.xml 
b/example/testdef/data/ExampleTestData.xml
index 36aba3608..25bcefc29 100644
--- a/example/testdef/data/ExampleTestData.xml
+++ b/example/testdef/data/ExampleTestData.xml
@@ -19,6 +19,15 @@ under the License.
 -->
 
 <entity-engine-xml>
+    <SecurityGroup groupId="FULLADMIN" description="Full Admin Group"/>
+    <SecurityPermission description="ALL operations in the Example Management 
Screens." permissionId="EXAMPLE_ADMIN"/>
+    <SecurityGroupPermission fromDate="2001-05-13 12:00:00.0" 
groupId="FULLADMIN" permissionId="EXAMPLE_ADMIN"/>
+    <UserLogin userLoginId="system" enabled="N" isSystem="Y"/>
+    <UserLoginSecurityGroup groupId="FULLADMIN" userLoginId="system" 
fromDate="2001-05-13 12:00:00.0"/>
+
+    <StatusType description="Example" statusTypeId="EXAMPLE_STATUS" 
hasTable="N"/>
+    <StatusItem description="In Design" sequenceId="01" statusCode="IN_DESIGN" 
statusId="EXST_IN_DESIGN" statusTypeId="EXAMPLE_STATUS"/>
+    <ExampleType exampleTypeId="CONTRIVED" description="Contrived Example 
Type"/>
     <Example exampleId="TestExampleUpdate" exampleTypeId="CONTRIVED" 
statusId="EXST_IN_DESIGN" exampleName="Test Example for Update"/>
     <Example exampleId="TestExampleDelete" exampleTypeId="CONTRIVED" 
statusId="EXST_IN_DESIGN" exampleName="Test Example for Delete"/>
 </entity-engine-xml>
diff --git a/example/testdef/tests.xml b/example/testdef/tests.xml
index d61917034..3139e85a1 100644
--- a/example/testdef/tests.xml
+++ b/example/testdef/tests.xml
@@ -25,15 +25,11 @@ under the License.
     <test-case case-name="userLoginEntityXmlAssert">
         <entity-xml action="assert" 
entity-xml-url="component://example/testdef/assertdata/TestUserLoginData.xml"/>
     </test-case>
-    <test-case case-name="testCreateExampleService Through Service Engine">
-        <service-test service-name="testCreateExampleService"/>
-    </test-case>
-    <test-case case-name="testCreateExampleService Direct Simple Method">
-        <simple-method-test 
location="component://example/minilang/example/ExampleServices.xml" 
name="testCreateExampleService"/>
-    </test-case>
+
     <test-case case-name="load-example-test-data">
         <entity-xml action="load" 
entity-xml-url="component://example/testdef/data/ExampleTestData.xml"/>
     </test-case>
+
     <test-case case-name="example-tests-groovy">
         <junit-test-suite class-name="org.apache.ofbiz.example.ExampleTests"/>
     </test-case>

Reply via email to