svn commit: r1847056 - in /ofbiz/ofbiz-framework/trunk/applications/order: groovyScripts/quote/ minilang/test/ servicedef/ webapp/ordermgr/WEB-INF/ widget/ordermgr/

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

svn commit: r1847056 - in /ofbiz/ofbiz-framework/trunk/applications/order: groovyScripts/quote/ minilang/test/ servicedef/ webapp/ordermgr/WEB-INF/ widget/ordermgr/

nmalin
Author: nmalin
Date: Tue Nov 20 20:19:34 2018
New Revision: 1847056

URL: http://svn.apache.org/viewvc?rev=1847056&view=rev
Log:
Improved: Migrate from minilang to entity-auto createQuoteWorkEffort et deleteQuoteWorkEffort.
(OFBIZ-10553)
But createQuoteWorkEffort is not a crud service on entity QuoteWorkEffort because it is linked to a seca to call createWorkeffort before if a workEffortId is not present in context.

<eca service="createQuoteWorkEffort" event="in-validate">
   <condition field-name="workEffortId" operator="is-empty"/>
   <action service="createWorkEffort" mode="sync"/>
</eca>

I converted this service createQuoteWorkEffort has a real Crud service and create an other ensureWorkEffortAndCreateQuoteWorkEffort to simulate the attendee process. Now we have a coherent service naming and not surprise for developer .
To manage the service createQuoteWorkEffort as deprecated, I define it twice

     <service name="createQuoteWorkEffort" default-entity-name="QuoteWorkEffort" engine="entity-auto" invoke="create" auth="true">
        <deprecated use-instead="ensureWorkEffortAndCreateQuoteWorkEffort" since="Upcoming Release">
            use createQuoteWorkEffort to create a workeffort has been deprecated for best pratice naming reason, use ensureWorkEffortAndCreateQuoteWorkEffort instead.
            Now createQuoteWorkEffort work as a crud service on QuoteWorkEffort
        </deprecated>
    </service>
    <service name="createQuoteWorkEffort" default-entity-name="QuoteWorkEffort" engine="entity-auto" invoke="create" auth="true">
        <description>Create a new QuoteWorkEffort</description>
        <required-permissions join-type="AND">
            <check-permission permission="ORDERMGR" action="_CREATE"/>
        </required-permissions>
        <auto-attributes mode="IN" include="pk"/>
     </service>

First to alert on deprecation and second ensure that the definition work fine.
In log we will have an alert on the deprecation and an alert on the duplicated definition during the deprecation time.

Thanks to Antoine Ouvrard, Gil Portenseigne, Leila Mekika and Mathieu Lirzin for their review

Added:
    ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/quote/QuoteServices.groovy   (with props)
Modified:
    ofbiz/ofbiz-framework/trunk/applications/order/minilang/test/QuoteTests.xml
    ofbiz/ofbiz-framework/trunk/applications/order/servicedef/secas.xml
    ofbiz/ofbiz-framework/trunk/applications/order/servicedef/services_quote.xml
    ofbiz/ofbiz-framework/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml
    ofbiz/ofbiz-framework/trunk/applications/order/widget/ordermgr/QuoteWorkEffortForms.xml

Added: ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/quote/QuoteServices.groovy
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/quote/QuoteServices.groovy?rev=1847056&view=auto
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/quote/QuoteServices.groovy (added)
+++ ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/quote/QuoteServices.groovy Tue Nov 20 20:19:34 2018
@@ -0,0 +1,45 @@
+/*
+ * 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.service.ExecutionServiceException
+import org.apache.ofbiz.service.ServiceUtil
+
+/**
+ * Ensures that a workEffort exist and create a QuoteWorkEffort.
+ */
+def ensureWorkEffortAndCreateQuoteWorkEffort() {
+    String workEffortId = parameters.workEffortId
+    if (!workEffortId) {
+        Map serviceResult = run service: 'createWorkEffort', with: parameters
+        if (ServiceUtil.isError(serviceResult)) {
+            return serviceResult
+        }
+        workEffortId = serviceResult.workEffortId
+    }
+    Map createQuoteWorkEffortInMap = [quoteId: parameters.quoteId, workEffortId: workEffortId]
+    Map serviceResult
+    try {
+        serviceResult = run service: 'createQuoteWorkEffort', with: createQuoteWorkEffortInMap
+    } catch (ExecutionServiceException e) {
+        serviceResult = ServiceUtil.returnError(e.toString())
+    }
+    serviceResult.workEffortId = workEffortId
+    return serviceResult
+}

Propchange: ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/quote/QuoteServices.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/quote/QuoteServices.groovy
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/quote/QuoteServices.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/ofbiz-framework/trunk/applications/order/minilang/test/QuoteTests.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/minilang/test/QuoteTests.xml?rev=1847056&r1=1847055&r2=1847056&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/minilang/test/QuoteTests.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/minilang/test/QuoteTests.xml Tue Nov 20 20:19:34 2018
@@ -29,13 +29,12 @@ under the License.
         <set field="serviceCtx.workEffortId" value="9007"/>
 
         <!-- Execute the service -->
-        <call-service service-name="createQuoteWorkEffort" in-map-name="serviceCtx">
+        <call-service service-name="ensureWorkEffortAndCreateQuoteWorkEffort" in-map-name="serviceCtx">
             <results-to-map map-name="serviceResult"/>
         </call-service>
 
         <!-- Confirm the service output parameters -->
         <assert>
-            <if-compare-field field="serviceResult.quoteId" operator="equals" to-field="serviceCtx.quoteId"/>
             <if-compare-field field="serviceResult.workEffortId" operator="equals" to-field="serviceCtx.workEffortId"/>
         </assert>
 
@@ -63,7 +62,7 @@ under the License.
 
         <!-- Execute the service, note break-on-error is false so that the test itself doesn't
              fail and we also need a separate transaction so our lookup below doesn't fail due to the rollback -->
-        <call-service service-name="createQuoteWorkEffort" in-map-name="serviceCtx"
+        <call-service service-name="ensureWorkEffortAndCreateQuoteWorkEffort" in-map-name="serviceCtx"
             break-on-error="false" require-new-transaction="true">
             <results-to-map map-name="serviceResult"/>
         </call-service>
@@ -98,16 +97,11 @@ under the License.
         <set field="serviceCtx.workEffortTypeId" value="ROUTING"/>
         <set field="serviceCtx.quoteId" value="9000"/>
 
-        <call-service service-name="createQuoteWorkEffort" in-map-name="serviceCtx">
+        <call-service service-name="ensureWorkEffortAndCreateQuoteWorkEffort" in-map-name="serviceCtx">
             <results-to-map map-name="serviceResult"/>
         </call-service>
 
-        <assert>
-            <and>
-                <if-compare-field field="serviceResult.quoteId" operator="equals" to-field="serviceCtx.quoteId"/>
-                <not><if-empty field="serviceResult.workEffortId"/></not>
-            </and>
-        </assert>
+        <assert><not><if-empty field="serviceResult.workEffortId"/></not></assert>
         <!-- Confirm that a matching WorkEffort was created -->
         <entity-and entity-name="WorkEffort" list="workEfforts">
             <field-map field-name="workEffortId" from-field="serviceResult.workEffortId"/>

Modified: ofbiz/ofbiz-framework/trunk/applications/order/servicedef/secas.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/servicedef/secas.xml?rev=1847056&r1=1847055&r2=1847056&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/servicedef/secas.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/servicedef/secas.xml Tue Nov 20 20:19:34 2018
@@ -392,11 +392,6 @@ under the License.
         <action service="updateRequirementsToOrdered" mode="sync"/>
     </eca>
 
-    <!-- WorkEffort -->
-    <eca service="createQuoteWorkEffort" event="in-validate">
-        <condition field-name="workEffortId" operator="is-empty"/>
-        <action service="createWorkEffort" mode="sync"/>
-    </eca>
     <!-- Ensure Quote Role -->
     <eca service="createQuoteRole" event="invoke">
         <action service="ensurePartyRole" mode="sync"/>

Modified: ofbiz/ofbiz-framework/trunk/applications/order/servicedef/services_quote.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/servicedef/services_quote.xml?rev=1847056&r1=1847055&r2=1847056&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/servicedef/services_quote.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/servicedef/services_quote.xml Tue Nov 20 20:19:34 2018
@@ -209,20 +209,38 @@ under the License.
         <auto-attributes include="pk" mode="IN" optional="true"/>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>
     </service>
-    <service name="createQuoteWorkEffort" default-entity-name="QuoteWorkEffort" engine="simple" auth="true"
-            location="component://order/minilang/quote/QuoteServices.xml" invoke="createQuoteWorkEffort">
-        <description>Creates a new QuoteWorkEffort record and WorkEffort record</description>
-        <auto-attributes mode="IN" include="nonpk" optional="true"/>
-        <auto-attributes mode="INOUT" include="pk" optional="true"/>
-        <auto-attributes mode="IN" include="nonpk" optional="true" entity-name="WorkEffort"/>
-        <auto-attributes mode="INOUT" include="pk" optional="true" entity-name="WorkEffort"/>
-        <override name="quoteId" optional="false"/>
-        <override name="workEffortId" optional="false"/>
+
+    <!--Duplicate the service createQuoteWorkEffort, the first inform the deprecation, the second override and work normally-->
+    <service name="createQuoteWorkEffort" default-entity-name="QuoteWorkEffort" engine="entity-auto" invoke="create" auth="true">
+        <deprecated use-instead="ensureWorkEffortAndCreateQuoteWorkEffort" since="Upcoming Release">
+            use createQuoteWorkEffort to create a workeffort has been deprecated for best pratice naming reason, use ensureWorkEffortAndCreateQuoteWorkEffort instead.
+            Now createQuoteWorkEffort work as a crud service on QuoteWorkEffort
+        </deprecated>
+    </service>
+    <service name="createQuoteWorkEffort" default-entity-name="QuoteWorkEffort" engine="entity-auto" invoke="create" auth="true">
+        <description>Create a new QuoteWorkEffort</description>
+        <required-permissions join-type="AND">
+            <check-permission permission="ORDERMGR" action="_CREATE"/>
+        </required-permissions>
+        <auto-attributes mode="IN" include="pk"/>
     </service>
-    <service name="deleteQuoteWorkEffort" default-entity-name="QuoteWorkEffort" engine="simple" auth="true"
-            location="component://order/minilang/quote/QuoteServices.xml" invoke="deleteQuoteWorkEffort">
-        <description>Creates a new QuoteWorkEffort record</description>
-        <auto-attributes mode="IN" include="pk" optional="false"/>
+    <service name="deleteQuoteWorkEffort" default-entity-name="QuoteWorkEffort" engine="entity-auto" invoke="delete" auth="true">
+        <description>Delete a new QuoteWorkEffort</description>
+        <required-permissions join-type="AND">
+            <check-permission permission="ORDERMGR" action="_DELETE"/>
+        </required-permissions>
+        <auto-attributes mode="IN" include="pk"/>
+    </service>
+    <service name="ensureWorkEffortAndCreateQuoteWorkEffort" default-entity-name="WorkEffort" engine="groovy"
+             location="component://order/groovyScripts/quote/QuoteServices.groovy" invoke="ensureWorkEffortAndCreateQuoteWorkEffort" auth="true">
+        <description>Creates a new QuoteWorkEffort record and WorkEffort if needed</description>
+        <required-permissions join-type="AND">
+            <check-permission permission="ORDERMGR" action="_CREATE"/>
+        </required-permissions>
+        <auto-attributes mode="IN" include="pk" optional="true"/>
+        <auto-attributes mode="OUT" include="pk"/>
+        <auto-attributes mode="IN" include="nonpk" optional="true"/>
+        <attribute name="quoteId" type="String" mode="IN"/>
     </service>
     <service name="createQuoteFromCart" engine="simple" auth="true"
             location="component://order/minilang/quote/QuoteServices.xml" invoke="createQuoteFromCart">

Modified: ofbiz/ofbiz-framework/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml?rev=1847056&r1=1847055&r2=1847056&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml Tue Nov 20 20:19:34 2018
@@ -1617,9 +1617,9 @@ under the License.
         <security https="true" auth="true"/>
         <response name="success" type="view" value="EditQuoteWorkEffort"/>
     </request-map>
-    <request-map uri="createQuoteWorkEffort">
+    <request-map uri="ensureWorkEffortAndCreateQuoteWorkEffort">
         <security https="true" auth="true"/>
-        <event type="service" invoke="createQuoteWorkEffort"/>
+        <event type="service" invoke="ensureWorkEffortAndCreateQuoteWorkEffort"/>
         <response name="success" type="view" value="EditQuoteWorkEffort"/>
         <response name="error" type="view" value="AddQuoteWorkEffort"/>
     </request-map>

Modified: ofbiz/ofbiz-framework/trunk/applications/order/widget/ordermgr/QuoteWorkEffortForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/widget/ordermgr/QuoteWorkEffortForms.xml?rev=1847056&r1=1847055&r2=1847056&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/widget/ordermgr/QuoteWorkEffortForms.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/widget/ordermgr/QuoteWorkEffortForms.xml Tue Nov 20 20:19:34 2018
@@ -47,7 +47,7 @@ under the License.
         </field>
     </form>
 
-    <form name="AddQuoteWorkEffort" extends="EditWorkEffort" extends-resource="component://workeffort/widget/WorkEffortForms.xml" target="/ordermgr/control/createQuoteWorkEffort" target-type="inter-app" title="" type="single"
+    <form name="AddQuoteWorkEffort" extends="EditWorkEffort" extends-resource="component://workeffort/widget/WorkEffortForms.xml" target="/ordermgr/control/ensureWorkEffortAndCreateQuoteWorkEffort" target-type="inter-app" title="" type="single"
         header-row-style="header-row" default-table-style="basic-table">
 
         <field name="quoteId" map-name="parameters"><display/></field>