[ofbiz-framework] branch trunk updated: Improved: Convert PartyInvitationService.xml from minilang to groovy (OFBIZ-11360)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Improved: Convert PartyInvitationService.xml from minilang to groovy (OFBIZ-11360)

nmalin
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


The following commit(s) were added to refs/heads/trunk by this push:
     new 604a3bf  Improved: Convert PartyInvitationService.xml from minilang to groovy (OFBIZ-11360)
604a3bf is described below

commit 604a3bfa02227c0f834c04b6b6c819bf1b2809bc
Author: Nicolas Malin <[hidden email]>
AuthorDate: Fri Feb 28 16:38:51 2020 +0100

    Improved: Convert PartyInvitationService.xml from minilang to groovy
    (OFBIZ-11360)
   
    Thanks to Marie-Aline Pantais for providing the patch.
---
 .../party/PartyInvitationServices.groovy           |  80 ++++++++++++++
 .../minilang/party/PartyInvitationServices.xml     | 119 ---------------------
 applications/party/servicedef/services.xml         |  68 ++++++------
 3 files changed, 115 insertions(+), 152 deletions(-)

diff --git a/applications/party/groovyScripts/party/PartyInvitationServices.groovy b/applications/party/groovyScripts/party/PartyInvitationServices.groovy
new file mode 100644
index 0000000..7ef1cbd
--- /dev/null
+++ b/applications/party/groovyScripts/party/PartyInvitationServices.groovy
@@ -0,0 +1,80 @@
+/*
+ * 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.party.party.PartyHelper
+
+import org.apache.ofbiz.base.util.UtilDateTime
+import org.apache.ofbiz.entity.GenericValue
+
+// Party Invitation Services
+def createPartyInvitation() {
+    Map result = success()
+    GenericValue newEntity = makeValue("PartyInvitation", parameters)
+    newEntity.partyInvitationId = delegator.getNextSeqId("PartyInvitation")
+    result.partyInvitationId = newEntity.partyInvitationId
+    if (! parameters.toName && parameters.partyId) {
+        newEntity.toName = PartyHelper.getPartyName(delegator, parameters.partyId, false)
+    }
+    if (!newEntity.lastInviteDate) {
+        newEntity.lastInviteDate = UtilDateTime.nowTimestamp()
+    }
+    newEntity.create()
+    return result
+}
+
+def updatePartyInvitation() {
+    GenericValue lookedUpValue = makeValue("PartyInvitation", parameters)
+    if (! parameters.toName && parameters.partyId) {
+        newEntity.toName = PartyHelper.getPartyName(delegator, parameters.partyId, false)
+    }
+    lookedUpValue.store()
+    return success()
+}
+
+def acceptPartyInvitation() {
+    List partyInvitationGroupAssocs = from("PartyInvitationGroupAssoc")
+            .where(partyInvitationId: parameters.partyInvitationId)
+            .queryList()
+    if (partyInvitationGroupAssocs) {
+        Map createPartyRelationshipCtx = [partyIdTo: parameters.partyId,
+                                          partyRelationshipTypeId: "GROUP_ROLLUP"]
+        partyInvitationGroupAssocs.each {
+            createPartyRelationshipCtx.partyIdFrom = it.partyIdTo
+            run service: "createPartyRelationship", with: createPartyRelationshipCtx
+        }
+    }
+
+    List partyInvitationRoleAssocs = from("PartyInvitationRoleAssoc")
+            .where(partyInvitationId: parameters.partyInvitationId)
+            .queryList()
+    if (partyInvitationRoleAssocs) {
+        Map ensurePartyRoleCtx = [partyId: parameters.partyId]
+        partyInvitationRoleAssocs.each {
+            ensurePartyRoleCtx.roleTypeId = it.roleTypeId
+            run service: "ensurePartyRole", with: ensurePartyRoleCtx
+        }
+    }
+
+    Map updatePartyInvitationCtx = [partyInvitationId: parameters.partyInvitationId,
+                                    statusId: "PARTYINV_ACCEPTED"]
+    Map result = run service: "updatePartyInvitation", with: updatePartyInvitationCtx
+    return result
+}
+
diff --git a/applications/party/minilang/party/PartyInvitationServices.xml b/applications/party/minilang/party/PartyInvitationServices.xml
deleted file mode 100644
index c5b7a56..0000000
--- a/applications/party/minilang/party/PartyInvitationServices.xml
+++ /dev/null
@@ -1,119 +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">
-
-    <!-- Party Invitation Services -->
-    <simple-method method-name="createPartyInvitation" short-description="Create a PartyInvitation">
-        <make-value entity-name="PartyInvitation" value-field="newEntity"/>
-        <sequenced-id sequence-name="PartyInvitation" field="newEntity.partyInvitationId"/>
-        <field-to-result field="newEntity.partyInvitationId" result-name="partyInvitationId"/>
-        <if-empty field="parameters.toName">
-        <if-not-empty field="parameters.partyId">
-            <entity-one entity-name="Person" value-field="person" auto-field-map="false">
-                <field-map field-name="partyId" from-field="parameters.partyId"/>
-            </entity-one>
-            <set field="parameters.toName" value="${person.firstName} ${person.middleName} ${person.lastName}"/>
-        </if-not-empty>
-        </if-empty>
-        <now-timestamp field="nowTimestamp"/>
-        <set from-field="nowTimestamp" field="newEntity.lastInviteDate"/>
-        <set-nonpk-fields map="parameters" value-field="newEntity"/>
-        <create-value value-field="newEntity"/>
-    </simple-method>
-    <simple-method method-name="updatePartyInvitation" short-description="Update a PartyInvitation">
-        <entity-one entity-name="PartyInvitation" value-field="lookedUpValue"/>
-        <if-empty field="parameters.toName">
-        <if-not-empty field="parameters.partyId">
-            <entity-one entity-name="Person" value-field="person" auto-field-map="false">
-                <field-map field-name="partyId" from-field="parameters.partyId"/>
-            </entity-one>
-            <set field="parameters.toName" value="${person.firstName} ${person.middleName} ${person.lastName}"/>
-        </if-not-empty>
-        </if-empty>
-        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
-        <store-value value-field="lookedUpValue"/>
-    </simple-method>
-    <simple-method method-name="deletePartyInvitation" short-description="Remove a PartyInvitation">
-        <entity-one entity-name="PartyInvitation" value-field="lookedUpValue"/>
-        <remove-value value-field="lookedUpValue"/>
-    </simple-method>
-    <simple-method method-name="createPartyInvitationGroupAssoc" short-description="Create a PartyInvitationGroupAssoc">
-        <make-value entity-name="PartyInvitationGroupAssoc" value-field="newEntity"/>
-        <set-pk-fields map="parameters" value-field="newEntity"/>
-        <create-value value-field="newEntity"/>
-    </simple-method>
-    <simple-method method-name="deletePartyInvitationGroupAssoc" short-description="Remove a PartyInvitationGroupAssoc">
-        <entity-one entity-name="PartyInvitationGroupAssoc" value-field="lookedUpValue"/>
-        <remove-value value-field="lookedUpValue"/>
-    </simple-method>
-    <simple-method method-name="createPartyInvitationRoleAssoc" short-description="Create a PartyInvitationRoleAssoc">
-        <make-value entity-name="PartyInvitationRoleAssoc" value-field="newEntity"/>
-        <set-pk-fields map="parameters" value-field="newEntity"/>
-        <create-value value-field="newEntity"/>
-    </simple-method>
-    <simple-method method-name="deletePartyInvitationRoleAssoc" short-description="Remove a PartyInvitationRoleAssoc">
-        <entity-one entity-name="PartyInvitationRoleAssoc" value-field="lookedUpValue"/>
-        <remove-value value-field="lookedUpValue"/>
-    </simple-method>
-    <simple-method method-name="acceptPartyInvitation" short-description="Accept Party Invitation">
-        <entity-and entity-name="PartyInvitationGroupAssoc" list="partyInvitationGroupAssocs">
-            <field-map field-name="partyInvitationId" from-field="parameters.partyInvitationId"/>
-        </entity-and>
-        <if-not-empty field="partyInvitationGroupAssocs">
-            <set field="createPartyRelationshipCtx.partyIdTo" from-field="parameters.partyId"/>
-            <set field="createPartyRelationshipCtx.partyRelationshipTypeId" value="GROUP_ROLLUP"/>
-            <iterate list="partyInvitationGroupAssocs" entry="partyInvitationGroupAssoc">
-                <set field="createPartyRelationshipCtx.partyIdFrom" from-field="partyInvitationGroupAssoc.partyIdTo"/>
-                <call-service service-name="createPartyRelationship" in-map-name="createPartyRelationshipCtx"/>
-            </iterate>
-        </if-not-empty>
-        <entity-and entity-name="PartyInvitationRoleAssoc" list="partyInvitationRoleAssocs">
-            <field-map field-name="partyInvitationId" from-field="parameters.partyInvitationId"/>
-        </entity-and>
-        <if-not-empty field="partyInvitationRoleAssocs">
-            <set field="createPartyRoleCtx.partyId" from-field="parameters.partyId"/>
-            <iterate list="partyInvitationRoleAssocs" entry="partyInvitationRoleAssoc">
-                <entity-one entity-name="PartyRole" value-field="partyRole">
-                    <field-map field-name="roleTypeId" from-field="partyInvitationRoleAssoc.roleTypeId"/>
-                </entity-one>
-                <if-empty field="partyRole">
-                    <set field="createPartyRoleCtx.roleTypeId" from-field="partyInvitationRoleAssoc.roleTypeId"/>
-                    <call-service service-name="createPartyRole" in-map-name="createPartyRoleCtx"/>
-                </if-empty>
-            </iterate>
-        </if-not-empty>
-        <set field="updatePartyInvitationCtx.partyInvitationId" from-field="parameters.partyInvitationId"/>
-        <set field="updatePartyInvitationCtx.statusId" value="PARTYINV_ACCEPTED"/>
-        <call-service service-name="updatePartyInvitation" in-map-name="updatePartyInvitationCtx"/>
-    </simple-method>
-    <simple-method method-name="declinePartyInvitation" short-description="Decline Party Invitation">
-        <set field="updatePartyInvitationCtx.partyInvitationId" from-field="parameters.partyInvitationId"/>
-        <set field="updatePartyInvitationCtx.statusId" value="PARTYINV_DECLINED"/>
-        <call-service service-name="updatePartyInvitation" in-map-name="updatePartyInvitationCtx"/>
-    </simple-method>
-    <simple-method method-name="cancelPartyInvitation" short-description="Cancel Party Invitation">
-        <set field="updatePartyInvitationCtx.partyInvitationId" from-field="parameters.partyInvitationId"/>
-        <set field="updatePartyInvitationCtx.statusId" value="PARTYINV_CANCELLED"/>
-        <call-service service-name="updatePartyInvitation" in-map-name="updatePartyInvitationCtx"/>
-    </simple-method>
-
-</simple-methods>
diff --git a/applications/party/servicedef/services.xml b/applications/party/servicedef/services.xml
index 72fd7c6..2e8f2ab 100644
--- a/applications/party/servicedef/services.xml
+++ b/applications/party/servicedef/services.xml
@@ -1040,59 +1040,61 @@ under the License.
     </service>
 
     <!-- Party Invitation Services -->
-    <service name="createPartyInvitation" engine="simple"
-            location="component://party/minilang/party/PartyInvitationServices.xml" invoke="createPartyInvitation">
+    <service name="createPartyInvitation" engine="groovy" default-entity-name="PartyInvitation"
+            location="component://party/groovyScripts/party/PartyInvitationServices.groovy" invoke="createPartyInvitation">
         <description>Create Party Invitation</description>
-        <auto-attributes entity-name="PartyInvitation" include="pk" mode="IN" optional="true"/>
-        <auto-attributes entity-name="PartyInvitation" include="nonpk" mode="IN" optional="true"/>
+        <auto-attributes include="pk" mode="IN" optional="true"/>
+        <auto-attributes include="nonpk" mode="IN" optional="true"/>
         <override name="partyInvitationId" mode="OUT" optional="false"/>
     </service>
-    <service name="updatePartyInvitation" engine="simple"
-            location="component://party/minilang/party/PartyInvitationServices.xml" invoke="updatePartyInvitation">
+    <service name="updatePartyInvitation" engine="groovy" default-entity-name="PartyInvitation"
+            location="component://party/groovyScripts/party/PartyInvitationServices.groovy" invoke="updatePartyInvitation">
         <description>Update Party Invitation</description>
-        <auto-attributes entity-name="PartyInvitation" include="pk" mode="IN" optional="false"/>
-        <auto-attributes entity-name="PartyInvitation" include="nonpk" mode="IN" optional="true"/>
+        <auto-attributes include="pk" mode="IN" optional="false"/>
+        <auto-attributes include="nonpk" mode="IN" optional="true"/>
     </service>
-    <service name="deletePartyInvitation" engine="simple"
-            location="component://party/minilang/party/PartyInvitationServices.xml" invoke="deletePartyInvitation">
+    <service name="deletePartyInvitation" default-entity-name="PartyInvitation"
+             engine="entity-auto" invoke="delete">
         <description>Remove Party Invitation</description>
-        <auto-attributes entity-name="PartyInvitation" include="pk" mode="IN" optional="false"/>
+        <auto-attributes include="pk" mode="IN"/>
     </service>
-    <service name="createPartyInvitationGroupAssoc" engine="simple"
-            location="component://party/minilang/party/PartyInvitationServices.xml" invoke="createPartyInvitationGroupAssoc">
+    <service name="createPartyInvitationGroupAssoc" default-entity-name="PartyInvitationGroupAssoc"
+             engine="entity-auto" invoke="create">
         <description>Create PartyInvitationGroupAssoc</description>
-        <auto-attributes entity-name="PartyInvitationGroupAssoc" include="pk" mode="IN" optional="false"/>
+        <auto-attributes include="pk" mode="IN"/>
     </service>
-    <service name="deletePartyInvitationGroupAssoc" engine="simple"
-            location="component://party/minilang/party/PartyInvitationServices.xml" invoke="deletePartyInvitationGroupAssoc">
+    <service name="deletePartyInvitationGroupAssoc" default-entity-name="PartyInvitationGroupAssoc"
+             engine="entity-auto" invoke="delete">
         <description>Remove PartyInvitationGroupAssoc</description>
-        <auto-attributes entity-name="PartyInvitationGroupAssoc" include="pk" mode="IN" optional="false"/>
+        <auto-attributes include="pk" mode="IN"/>
     </service>
-    <service name="createPartyInvitationRoleAssoc" engine="simple"
-            location="component://party/minilang/party/PartyInvitationServices.xml" invoke="createPartyInvitationRoleAssoc">
+    <service name="createPartyInvitationRoleAssoc" default-entity-name="PartyInvitationRoleAssoc"
+             engine="entity-auto" invoke="create">
         <description>Create PartyInvitationRoleAssoc</description>
-        <auto-attributes entity-name="PartyInvitationRoleAssoc" include="pk" mode="IN" optional="false"/>
+        <auto-attributes include="pk" mode="IN"/>
     </service>
-    <service name="deletePartyInvitationRoleAssoc" engine="simple"
-            location="component://party/minilang/party/PartyInvitationServices.xml" invoke="deletePartyInvitationRoleAssoc">
+    <service name="deletePartyInvitationRoleAssoc" default-entity-name="PartyInvitationRoleAssoc"
+             engine="entity-auto" invoke="delete">
         <description>Remove PartyInvitationRoleAssoc</description>
-        <auto-attributes entity-name="PartyInvitationRoleAssoc" include="pk" mode="IN" optional="false"/>
+        <auto-attributes include="pk" mode="IN"/>
     </service>
-    <service name="acceptPartyInvitation" engine="simple"
-            location="component://party/minilang/party/PartyInvitationServices.xml" invoke="acceptPartyInvitation">
+    <service name="acceptPartyInvitation" engine="groovy"
+            location="component://party/groovyScripts/party/PartyInvitationServices.groovy" invoke="acceptPartyInvitation">
         <permission-service service-name="accAndDecPartyInvitationPermissionCheck"/>
-        <attribute name="partyInvitationId" type="String" mode="IN" optional="false"/>
-        <attribute name="partyId" type="String" mode="IN" optional="false"/>
+        <attribute name="partyInvitationId" type="String" mode="IN"/>
+        <attribute name="partyId" type="String" mode="IN"/>
     </service>
-    <service name="declinePartyInvitation" engine="simple"
-            location="component://party/minilang/party/PartyInvitationServices.xml" invoke="declinePartyInvitation">
+    <service name="declinePartyInvitation" engine="groovy"
+            location="component://party/groovyScripts/party/PartyInvitationServices.groovy" invoke="updatePartyInvitation">
         <permission-service service-name="accAndDecPartyInvitationPermissionCheck"/>
-        <attribute name="partyInvitationId" type="String" mode="IN" optional="false"/>
+        <attribute name="partyInvitationId" type="String" mode="IN"/>
+        <attribute name="statusId" type="String" mode="IN" optional="true" default-value="PARTYINV_DECLINED"/>
     </service>
-    <service name="cancelPartyInvitation" engine="simple"
-            location="component://party/minilang/party/PartyInvitationServices.xml" invoke="cancelPartyInvitation">
+    <service name="cancelPartyInvitation" engine="groovy"
+            location="component://party/groovyScripts/party/PartyInvitationServices.groovy" invoke="updatePartyInvitation">
         <permission-service service-name="cancelPartyInvitationPermissionCheck"/>
-        <attribute name="partyInvitationId" type="String" mode="IN" optional="false"/>
+        <attribute name="partyInvitationId" type="String" mode="IN"/>
+        <attribute name="statusId" type="String" mode="IN" optional="true" default-value="PARTYINV_CANCELLED"/>
     </service>
 
     <!-- Permission checking services-->