Author: hansbak
Date: Fri Apr 24 10:08:55 2009
New Revision: 768245

URL: http://svn.apache.org/viewvc?rev=768245&view=rev
Log:
fix the new notification services using sendMailFromTemplateSetting using body 
parameters

Modified:
    
ofbiz/trunk/applications/order/script/org/ofbiz/order/request/CustRequestServices.xml
    ofbiz/trunk/applications/order/servicedef/secas.xml
    ofbiz/trunk/applications/order/servicedef/services_request.xml
    ofbiz/trunk/framework/common/script/org/ofbiz/common/email/EmailServices.xml
    
ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaSetField.java

Modified: 
ofbiz/trunk/applications/order/script/org/ofbiz/order/request/CustRequestServices.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/script/org/ofbiz/order/request/CustRequestServices.xml?rev=768245&r1=768244&r2=768245&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/script/org/ofbiz/order/request/CustRequestServices.xml
 (original)
+++ 
ofbiz/trunk/applications/order/script/org/ofbiz/order/request/CustRequestServices.xml
 Fri Apr 24 10:08:55 2009
@@ -62,9 +62,8 @@
             <set field="newEntity.custRequestDate" from-field="nowTimestamp"/>
         </if-empty>
 
-        <if-empty field="parameters.statusId">
-            <set value="CRQ_SUBMITTED" field="newEntity.statusId"/>
-        </if-empty>
+        <!-- always start with submitted -->
+        <set value="CRQ_SUBMITTED" field="newEntity.statusId"/>
 
         <if-not-empty field="parameters.custRequestId">
             <set field="newEntity.custRequestId" 
from-field="parameters.custRequestId"/>
@@ -77,12 +76,10 @@
         <field-to-result field="newEntity.custRequestId" 
result-name="custRequestId"/>
 
         <!-- set status fields and history -->
-        <if-empty field="parameters.statusId">
-            <set field="parameters.statusId" value="CRQ_SUBMITTED"/>
-        </if-empty>
         <set field="parameters.custRequestId" 
from-field="newEntity.custRequestId"/>
         <set-service-fields service-name="setCustRequestStatus" 
map="parameters" to-map="setStat"/>
         <call-service service-name="setCustRequestStatus" 
in-map-name="setStat"/>
+        
 
         <!-- create also the item if key fields are provided -->
         <if>
@@ -363,8 +360,9 @@
 
     <simple-method method-name="setCustRequestStatus" 
short-description="change the customer request Status">
         <entity-one entity-name="CustRequest" value-field="custRequest"/>
-        <if-not-empty field="custRequest.statusId">
+        <if-not-empty field="custRequest">
             <field-to-result field="custRequest.statusId" 
result-name="oldStatusId"/>
+            <field-to-result field="custRequest.custRequestId"  
result-name="custRequestId"/>
             <if-compare-field field="custRequest.statusId" 
to-field="parameters.statusId" operator="not-equals">
                 <entity-one entity-name="StatusValidChange" 
value-field="statusChange">
                     <field-map field-name="statusId" 
from-field="custRequest.statusId"/>
@@ -381,7 +379,6 @@
         <set field="custRequest.statusId" from-field="parameters.statusId"/>
         <store-value value-field="custRequest"/>
         <call-simple-method method-name="createCustRequestStatus"/>
-        <field-to-result field="custRequest.fromPartyId" 
result-name="fromPartyId"/><!-- for notification -->
     </simple-method>
 
     <simple-method method-name="createCustRequestFromCommEvent" 
short-description="Create a Customer request from a commEvent(email)">

Modified: ofbiz/trunk/applications/order/servicedef/secas.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/secas.xml?rev=768245&r1=768244&r2=768245&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/secas.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/secas.xml Fri Apr 24 10:08:55 2009
@@ -326,14 +326,14 @@
     <eca service="setCustRequestStatus" event="commit">
         <condition field-name="oldStatusId" operator="not-equals" 
value="CRQ_ACCEPTED"/>
         <condition field-name="statusId" operator="equals" 
value="CRQ_ACCEPTED"/>
-        <set field-name="partyIdTo" value="${fromPartyId}"/>
+        <set field-name="bodyParameters.custRequestId" 
env-name="custRequestId"/>
         <set field-name="emailTemplateSettingId" value="CUST_REQ_ACCEPTED"/>
         <action service="sendMailFromTemplateSetting" mode="sync"/>
     </eca>
     <eca service="setCustRequestStatus" event="commit">
         <condition field-name="oldStatusId" operator="not-equals" 
value="CRQ_COMPLETED"/>
         <condition field-name="statusId" operator="equals" 
value="CRQ_COMPLETED"/>
-        <set field-name="partyIdTo" value="${fromPartyId}"/>
+        <set field-name="bodyParameters.custRequestId" 
env-name="custRequestId"/>
         <set field-name="emailTemplateSettingId" value="CUST_REQ_COMPLETED"/>
         <action service="sendMailFromTemplateSetting" mode="sync"/>
     </eca>

Modified: ofbiz/trunk/applications/order/servicedef/services_request.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_request.xml?rev=768245&r1=768244&r2=768245&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services_request.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services_request.xml Fri Apr 24 
10:08:55 2009
@@ -154,10 +154,9 @@
     <service name="setCustRequestStatus" engine="simple"
             
location="component://order/script/org/ofbiz/order/request/CustRequestServices.xml"
 invoke="setCustRequestStatus" auth="true">
         <description>Set the Customer Request  Status</description>
-        <attribute name="custRequestId" type="String" mode="IN" 
optional="false"/>
+        <attribute name="custRequestId" type="String" mode="INOUT" 
optional="false"/>
         <attribute name="statusId" type="String" mode="IN" optional="false"/>
         <attribute name="oldStatusId" type="String" mode="OUT" 
optional="true"/>
-        <attribute name="fromPartyId" type="String" mode="OUT"/><!-- for 
notification -->
     </service>
     <service name="createCustRequestFromCommEvent" engine="simple" 
default-entity-name="CommunicationEvent"
             
location="component://order/script/org/ofbiz/order/request/CustRequestServices.xml"
 invoke="createCustRequestFromCommEvent" auth="true">

Modified: 
ofbiz/trunk/framework/common/script/org/ofbiz/common/email/EmailServices.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/script/org/ofbiz/common/email/EmailServices.xml?rev=768245&r1=768244&r2=768245&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/common/script/org/ofbiz/common/email/EmailServices.xml 
(original)
+++ 
ofbiz/trunk/framework/common/script/org/ofbiz/common/email/EmailServices.xml 
Fri Apr 24 10:08:55 2009
@@ -22,9 +22,11 @@
         
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/simple-methods.xsd";>
     <simple-method method-name="sendMailFromTemplateSetting" 
short-description="Send Mail from Email Template Setting">
 
-        <if-not-empty field="parameters.partyId">
+        <!-- if partyIdTo provided but no emailAddress, get it from the 
partyContactMech -->
+        <if-not-empty field="parameters.partyIdTo">
             <if-empty field="parameters.sendTo">
                 <set-service-fields service-name="getPartyEmail" 
map="parameters" to-map="getEmail"/>
+                <set field="getMail.partyId" 
from-field="parameters.partyIdTo"/>
                 <call-service service-name="getPartyEmail" 
in-map-name="getEmail">
                     <result-to-field result-name="emailAddress" 
field="parameters.sendTo"/>
                 </call-service>

Modified: 
ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaSetField.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaSetField.java?rev=768245&r1=768244&r2=768245&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaSetField.java 
(original)
+++ 
ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaSetField.java 
Fri Apr 24 10:08:55 2009
@@ -26,6 +26,7 @@
 import org.ofbiz.entity.model.ModelUtil;
 
 import java.util.Map;
+import javolution.util.FastMap;
 
 /**
  * ServiceEcaSetField
@@ -59,12 +60,35 @@
                     Debug.log("Expanded String: " + s, module);
                 }
             }
+            // TODO: rewrite using the ContextAccessor.java see hack below to 
be able to use maps for email notifications
+            // check if target is a map
+            String mapName = null;
+               Map<String, Object> map = null;
+            if (UtilValidate.isNotEmpty(fieldName) && fieldName.indexOf('.') 
!= -1) {
+                       mapName = fieldName.substring(0, 
fieldName.indexOf('.'));
+                       fieldName = fieldName.substring(fieldName.indexOf('.') 
+1);
+                       if (context.containsKey(mapName)) {
+                               map = (Map<String, Object>) 
context.get(mapName);
+                       } else {
+                               map = FastMap.newInstance();
+                       }
+               }
 
             // process the context changes
+            String newValue = null;
             if (UtilValidate.isNotEmpty(value)) {
-                context.put(fieldName, this.format(value, context));
+                newValue = (String) this.format(value, context);
             } else if (UtilValidate.isNotEmpty(envName) && 
context.get(envName) != null) {
-                context.put(fieldName, this.format((String) 
context.get(envName), context));
+                newValue = (String) this.format((String) context.get(envName), 
context);
+            }
+            
+            if (newValue != null) {
+               if (map != null) {
+                       map.put(fieldName, newValue);
+                       context.put(mapName, map);
+               } else {
+                       context.put(fieldName, newValue);
+               }
             }
         }
     }


Reply via email to