You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by nm...@apache.org on 2021/09/15 15:37:15 UTC

[ofbiz-framework] 02/02: Improved: Convert SystemInfoServices.xml mini lang to groovy (OFBIZ-11919)

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

commit 2ebf14eddd0d75ba5630b26c8e451e82703397e9
Author: Nicolas Malin <ni...@nereide.fr>
AuthorDate: Wed Sep 15 17:35:49 2021 +0200

    Improved: Convert SystemInfoServices.xml mini lang to groovy (OFBIZ-11919)
    
    Thanks to Rohit Koushal to submit the patch
---
 .../ofbizsetup/SystemInfoServices.groovy           | 104 ++++++++++++++
 .../commonext/minilang/SystemInfoServices.xml      | 159 ---------------------
 applications/commonext/servicedef/services.xml     |  24 ++--
 3 files changed, 116 insertions(+), 171 deletions(-)

diff --git a/applications/commonext/groovyScripts/ofbizsetup/SystemInfoServices.groovy b/applications/commonext/groovyScripts/ofbizsetup/SystemInfoServices.groovy
new file mode 100644
index 0000000..25071cb
--- /dev/null
+++ b/applications/commonext/groovyScripts/ofbizsetup/SystemInfoServices.groovy
@@ -0,0 +1,104 @@
+/*
+ * 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.
+ */
+
+import org.apache.ofbiz.base.util.UtilDateTime
+import org.apache.ofbiz.entity.GenericValue
+
+def createSystemInfoNote() {
+    parameters.noteParty = parameters.noteParty ?: userLogin.partyId
+    GenericValue noteData = makeValue("NoteData", parameters)
+    noteData.noteDateTime = UtilDateTime.nowTimestamp()
+    noteData.noteName = "SYSTEMNOTE"
+    noteData.setNextSeqId()
+    noteData.create()
+    return success()
+}
+
+def deleteSystemInfoNote() {
+    GenericValue noteData = from("NoteData").where(noteId: parameters.noteId).queryOne()
+    noteData.removeRelated('CustRequestItemNote')
+    noteData.removeRelated('CustRequestNote')
+    noteData.removeRelated('MarketingCampaignNote')
+    noteData.removeRelated('OrderHeaderNote')
+    noteData.removeRelated('PartyNote')
+    noteData.removeRelated('QuoteNote')
+    noteData.removeRelated('WorkEffortNote')
+    noteData.remove()
+    return success()
+}
+
+def deleteAllSystemNotes() {
+    delegator.removeByAnd("NoteData", [noteParty: userLogin.partyId, noteName: "SYSTEMNOTE"])
+    return success()
+}
+
+def getSystemInfoNotes() {
+    List systemInfoNotes = from("NoteData")
+            .where(noteParty: userLogin.partyId,
+                    noteName: "SYSTEMNOTE")
+            .orderBy("-noteDateTime")
+            .queryList()
+    if (systemInfoNotes) {
+        return success(systemInfoNotes: systemInfoNotes)
+    }
+    return success()
+}
+
+def getLastSystemInfoNote() {
+    Map result = success()
+    List systemInfoNotes = from("NoteData")
+            .where(noteParty: userLogin ? userLogin.partyId : "_NA_",
+                    noteName: "SYSTEMNOTE")
+            .orderBy("-noteDateTime")
+            .queryList()
+    if (systemInfoNotes) {
+        result.lastSystemInfoNote1 = systemInfoNotes[0]
+        if (systemInfoNotes.size() == 2) {
+            result.lastSystemInfoNote2 = systemInfoNotes[1]
+        } else if (systemInfoNotes.size() > 2) {
+            result.lastSystemInfoNote2 = systemInfoNotes[1]
+            result.lastSystemInfoNote3 = systemInfoNotes[2]
+        }
+    }
+    return result
+}
+
+def getSystemInfoStatus() {
+    List systemInfoStatus = []
+    List comms = from("CommunicationEventAndRole")
+            .where(partyId: userLogin.partyId,
+                    statusId: "COM_ROLE_COMPLETED")
+            .orderBy("-entryDate")
+            .queryList()
+    if (comms) {
+        systemInfoStatus << [noteInfo: "Open communication events: " + comms.size(), noteDateTime: comms[0].entryDate]
+    }
+
+    List assigns = from("WorkEffortAndPartyAssign")
+            .where(partyId: userLogin.partyId,
+                    statusId: "PAS_ASSIGNED",
+                    workEffortTypeId: "TASK")
+            .orderBy("-fromDate")
+            .filterByDate()
+            .queryList()
+    if (assigns) {
+        systemInfoStatus << [noteInfo: "Assigned and not completed tasks: " + assigns.size(), noteDateTime: assigns[0].fromDate]
+    }
+    return success(systemInfoStatus: systemInfoStatus)
+}
\ No newline at end of file
diff --git a/applications/commonext/minilang/SystemInfoServices.xml b/applications/commonext/minilang/SystemInfoServices.xml
deleted file mode 100644
index d199a7e..0000000
--- a/applications/commonext/minilang/SystemInfoServices.xml
+++ /dev/null
@@ -1,159 +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="createSystemInfoNote" short-description="Create a system to to a specific party">
-        <set field="parameters.partyId" from-field="parameters.partyId" default-value="userLogin.partyId"/>
-        <make-value entity-name="NoteData" value-field="noteData"/>
-        <set-nonpk-fields map="parameters" value-field="noteData"/>
-        <now-timestamp field="noteData.noteDateTime"/>
-        <sequenced-id sequence-name="NoteData" field="noteData.noteId"/>
-        <set field="noteData.noteName" value="SYSTEMNOTE"/>
-        <create-value value-field="noteData"/>
-    </simple-method>
-
-    <simple-method method-name="getPortletAttributeMap" short-description="get the attributes of the SystemInfoNotes portlet for a userlogin">
-        <!-- get the portlet settings: works only if portlet is used only one time and the user only has a single userLogin -->
-        <entity-and entity-name="UserLogin" list="ulList">
-            <field-map field-name="partyId" from-field="partyId"/>
-        </entity-and>
-        <if-not-empty field="ulList">
-            <set field="haveUserLogin" value="true"/>
-            <first-from-list list="ulList" entry="userLogin"/>
-            <set field="paMap.ownerUserLoginId" from-field="userLogin.userLoginId"/>
-            <set field="paMap.portalPortletId" value="SystemInfoNotes"/>
-            <call-service service-name="getPortletAttributes" in-map-name="paMap">
-                <result-to-field result-name="attributeMap" field="attributeMap"/>
-            </call-service>
-        </if-not-empty>
-    </simple-method>
-
-    <simple-method method-name="deleteSystemInfoNote" short-description="Delete SystemInfo Note">
-        <entity-one entity-name="NoteData" value-field="noteData"/>
-        <remove-related relation-name="CustRequestItemNote" value-field="noteData"/>
-        <remove-related relation-name="CustRequestNote" value-field="noteData"/>
-        <remove-related relation-name="MarketingCampaignNote" value-field="noteData"/>
-        <remove-related relation-name="OrderHeaderNote" value-field="noteData"/>
-        <remove-related relation-name="PartyNote" value-field="noteData"/>
-        <remove-related relation-name="QuoteNote" value-field="noteData"/>
-        <remove-related relation-name="WorkEffortNote" value-field="noteData"/>
-        <remove-value value-field="noteData"/>
-    </simple-method>
-
-    <simple-method method-name="deleteAllSystemNotes" short-description="delete all system notes from a particular user">
-        <set field="removeData.noteParty" from-field="parameters.userLogin.partyId"/>
-        <set field="removeData.noteName" value="SYSTEMNOTE"/>
-        <remove-by-and entity-name="NoteData" map="removeData"/>
-    </simple-method>
-
-    <simple-method method-name="getSystemInfoStatus" short-description="">
-        <!-- communication events -->
-        <entity-count entity-name="CommunicationEventRole" count-field="comCount">
-            <condition-list combine="and">
-                <condition-expr field-name="partyId" from-field="userLogin.partyId"/>
-                <condition-expr field-name="statusId" operator="not-equals" value="COM_ROLE_COMPLETED"/>    
-            </condition-list>
-        </entity-count>
-        <entity-condition entity-name="CommunicationEventAndRole" list="comms">
-            <condition-list combine="and">
-                <condition-expr field-name="partyId" from-field="userLogin.partyId"/>
-                <condition-expr field-name="statusId" operator="not-equals" value="COM_ROLE_COMPLETED"/>    
-            </condition-list>
-            <order-by field-name="-entryDate"/>
-        </entity-condition>
-        <if-compare field="comCount" value="0" operator="greater">
-            <set field="status.noteInfo" value="Open communication events: ${comCount}"/>
-            <first-from-list list="comms" entry="comm"/>
-            <set field="status.noteDateTime" from-field="comm.entryDate"/>
-            <field-to-list field="status" list="systemInfoStatus"/>
-            <clear-field field="status"/>
-        </if-compare>
-        <!-- assigned tasks -->
-        <entity-and entity-name="WorkEffortAndPartyAssign" list="assigns" filter-by-date="true">
-            <field-map field-name="partyId" from-field="parameters.userLogin.partyId"/>
-            <field-map field-name="statusId" value="PAS_ASSIGNED"/>
-            <field-map field-name="workEffortTypeId" value="TASK"/>
-            <order-by field-name="-fromDate"/>
-        </entity-and>
-        <entity-count entity-name="WorkEffortAndPartyAssign" count-field="assignCount">
-            <condition-list combine="and">
-                <condition-expr field-name="partyId"  operator="equals" from-field="parameters.userLogin.partyId"/>
-                <condition-expr field-name="statusId" operator="equals" value="PAS_ASSIGNED"/>
-                <condition-expr field-name="workEffortTypeId" operator="equals" value="TASK"/>
-            </condition-list>
-        </entity-count>            
-        <if-compare field="assignCount" value="0" operator="greater">
-            <set field="status.noteInfo" value="Assigned and not completed tasks: ${assignCount}"/>
-            <first-from-list list="assigns" entry="assign"/>
-            <set field="status.noteDateTime" from-field="assign.fromDate"/>
-            <field-to-list field="status" list="systemInfoStatus"/>
-        </if-compare>
-        
-        <!-- return result -->
-        <if-not-empty field="systemInfoStatus">
-            <field-to-result field="systemInfoStatus"/>
-        </if-not-empty>
-        
-    </simple-method>
-    <simple-method method-name="getSystemInfoNotes" short-description="">
-        <entity-and entity-name="NoteData" list="systemInfoNotes">
-            <field-map field-name="noteParty" from-field="parameters.userLogin.partyId"/>
-            <field-map field-name="noteName" value="SYSTEMNOTE"/>
-            <order-by field-name="-noteDateTime"/>
-        </entity-and>
-        <if-not-empty field="systemInfoNotes">
-            <field-to-result field="systemInfoNotes"/>
-        </if-not-empty>
-    </simple-method>
-
-    <simple-method method-name="getLastSystemInfoNote"
-        short-description="Get the last 3 system info notes"
-        login-required="false">
-        <if-not-empty field="parameters.userLogin">
-            <entity-and entity-name="NoteData" list="systemInfoNotes">
-                <field-map field-name="noteParty"
-                    from-field="parameters.userLogin.partyId"/>
-                <field-map field-name="noteName" value="SYSTEMNOTE"/>
-                <order-by field-name="-noteDateTime"/>
-            </entity-and>
-            <else>
-                <entity-and entity-name="NoteData" list="systemInfoNotes">
-                    <field-map field-name="noteParty" value="_NA_"/>
-                    <field-map field-name="noteName" value="SYSTEMNOTE"/>
-                    <order-by field-name="-noteDateTime"/>
-                </entity-and>
-            </else>
-        </if-not-empty>
-        <if-not-empty field="systemInfoNotes">
-            <set field="lastSystemInfoNote1" from-field="systemInfoNotes[0]"/>
-            <field-to-result field="lastSystemInfoNote1"/>
-            <if-not-empty field="systemInfoNotes[2]">
-                <set field="lastSystemInfoNote2" from-field="systemInfoNotes[1]"/>
-                <field-to-result field="lastSystemInfoNote2"/>
-            </if-not-empty>
-            <if-not-empty field="systemInfoNotes[3]">
-                <set field="lastSystemInfoNote3" from-field="systemInfoNotes[2]"/>
-                <field-to-result field="lastSystemInfoNote3"/>
-            </if-not-empty>
-        </if-not-empty>
-    </simple-method>
-</simple-methods>
diff --git a/applications/commonext/servicedef/services.xml b/applications/commonext/servicedef/services.xml
index d71ee4b..804079a 100644
--- a/applications/commonext/servicedef/services.xml
+++ b/applications/commonext/servicedef/services.xml
@@ -24,34 +24,34 @@ under the License.
     <vendor>OFBiz</vendor>
     <version>1.0</version>
 
-    <service name="createSystemInfoNote" engine="simple" default-entity-name="NoteData"
-        location="component://commonext/minilang/SystemInfoServices.xml" invoke="createSystemInfoNote">
+    <service name="createSystemInfoNote" engine="groovy" default-entity-name="NoteData"
+        location="component://commonext/groovyScripts/ofbizsetup/SystemInfoServices.groovy" invoke="createSystemInfoNote">
         <description>Create a system info note</description>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>
     </service>
-    <service name="deleteSystemInfoNote" engine="simple" default-entity-name="NoteData"
-        location="component://commonext/minilang/SystemInfoServices.xml" invoke="deleteSystemInfoNote">
+    <service name="deleteSystemInfoNote" engine="groovy" default-entity-name="NoteData"
+        location="component://commonext/groovyScripts/ofbizsetup/SystemInfoServices.groovy" invoke="deleteSystemInfoNote">
         <description>Delete a system info note</description>
         <auto-attributes include="pk" mode="IN" optional="false"/>
     </service>
-    <service name="deleteAllSystemNotes" engine="simple" auth="true"
-        location="component://commonext/minilang/SystemInfoServices.xml" invoke="deleteAllSystemNotes">
+    <service name="deleteAllSystemNotes" engine="groovy" auth="true"
+        location="component://commonext/groovyScripts/ofbizsetup/SystemInfoServices.groovy" invoke="deleteAllSystemNotes">
         <description>Delete all system notes for the logged on party</description>
     </service>
-    <service name="getSystemInfoNotes" engine="simple" auth="true"
-        location="component://commonext/minilang/SystemInfoServices.xml" invoke="getSystemInfoNotes">
+    <service name="getSystemInfoNotes" engine="groovy" auth="true"
+        location="component://commonext/groovyScripts/ofbizsetup/SystemInfoServices.groovy" invoke="getSystemInfoNotes">
         <description>Get system notes for the logged on party</description>
         <attribute name="systemInfoNotes" type="List" mode="OUT" optional="true"/>
     </service>
-    <service name="getLastSystemInfoNote" engine="simple" auth="false"
-        location="component://commonext/minilang/SystemInfoServices.xml" invoke="getLastSystemInfoNote">
+    <service name="getLastSystemInfoNote" engine="groovy" auth="false"
+        location="component://commonext/groovyScripts/ofbizsetup/SystemInfoServices.groovy" invoke="getLastSystemInfoNote">
         <description>Get last system note for the logged on party</description>
         <attribute name="lastSystemInfoNote1" type="GenericValue" mode="OUT" optional="true"/>
         <attribute name="lastSystemInfoNote2" type="GenericValue" mode="OUT" optional="true"/>
         <attribute name="lastSystemInfoNote3" type="GenericValue" mode="OUT" optional="true"/>
     </service>
-    <service name="getSystemInfoStatus" engine="simple" auth="true"
-        location="component://commonext/minilang/SystemInfoServices.xml" invoke="getSystemInfoStatus">
+    <service name="getSystemInfoStatus" engine="groovy" auth="true"
+        location="component://commonext/groovyScripts/ofbizsetup/SystemInfoServices.groovy" invoke="getSystemInfoStatus">
         <description>Get system status for the logged on party</description>
         <attribute name="systemInfoStatus" type="List" mode="OUT" optional="true"/>
     </service>