You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2009/05/14 07:12:24 UTC

svn commit: r774634 - in /ofbiz/trunk/applications/party: data/ script/org/ofbiz/party/communication/ servicedef/ src/org/ofbiz/party/communication/ webapp/partymgr/WEB-INF/

Author: jaz
Date: Thu May 14 05:12:24 2009
New Revision: 774634

URL: http://svn.apache.org/viewvc?rev=774634&view=rev
Log:
refactored "markEventRead" service to allow updating when status is COM_COMPLETE (the default after a messge is sent), also stopped 'admin' users from marking other user's events as read (do a manual status change instead), implemented a little event which marks a communication event as read, and returns a 1px gif image (spacer.gif) to the browser/mail client; include the following in your communication email:

<img src="http://localhost:8080/partymgr/control/ceimages/${communicationEventId}/logo.gif"/>

and when the message is opened, the event will be marked as read (assuming images are loaded); logo.gif can be any name, everything after the communication event ID in pathInfo is ignored


Modified:
    ofbiz/trunk/applications/party/data/PartyTypeData.xml
    ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml
    ofbiz/trunk/applications/party/servicedef/services.xml
    ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java
    ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/controller.xml

Modified: ofbiz/trunk/applications/party/data/PartyTypeData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/data/PartyTypeData.xml?rev=774634&r1=774633&r2=774634&view=diff
==============================================================================
--- ofbiz/trunk/applications/party/data/PartyTypeData.xml (original)
+++ ofbiz/trunk/applications/party/data/PartyTypeData.xml Thu May 14 05:12:24 2009
@@ -311,13 +311,16 @@
     <StatusItem description="Bounced" sequenceId="50" statusCode="BOUNCED" statusId="COM_BOUNCED" statusTypeId="COM_EVENT_STATUS"/>
     <StatusItem description="Cancelled" sequenceId="99" statusCode="CANCELLED" statusId="COM_CANCELLED" statusTypeId="COM_EVENT_STATUS"/>
     <StatusValidChange condition="" statusId="COM_ENTERED" statusIdTo="COM_PENDING" transitionName="Set Pending"/>
+    <StatusValidChange condition="" statusId="COM_ENTERED" statusIdTo="COM_READ" transitionName="Read"/>
     <StatusValidChange condition="" statusId="COM_ENTERED" statusIdTo="COM_COMPLETE" transitionName="Complete"/>
-    <StatusValidChange condition="" statusId="COM_PENDING" statusIdTo="COM_READ" transitionName="Mark Read"/>
+    <StatusValidChange condition="" statusId="COM_PENDING" statusIdTo="COM_READ" transitionName="Read"/>
     <StatusValidChange condition="" statusId="COM_PENDING" statusIdTo="COM_IN_PROGRESS" transitionName="Set In Progress"/>
     <StatusValidChange condition="" statusId="COM_READ" statusIdTo="COM_IN_PROGRESS" transitionName="Set In Progress"/>
     <StatusValidChange condition="" statusId="COM_READ" statusIdTo="COM_COMPLETE" transitionName="Complete"/>
+    <StatusValidChange condition="" statusId="COM_IN_PROGRESS" statusIdTo="COM_READ" transitionName="Read"/>
     <StatusValidChange condition="" statusId="COM_IN_PROGRESS" statusIdTo="COM_COMPLETE" transitionName="Complete"/>
     <StatusValidChange condition="" statusId="COM_IN_PROGRESS" statusIdTo="COM_BOUNCED" transitionName="Bounced"/>
+    <StatusValidChange condition="" statusId="COM_COMPLETE" statusIdTo="COM_READ" transitionName="Read"/>
     <StatusValidChange condition="" statusId="COM_COMPLETE" statusIdTo="COM_RESOLVED" transitionName="Resolve"/>
     <StatusValidChange condition="" statusId="COM_COMPLETE" statusIdTo="COM_REFERRED" transitionName="Refer"/>
     <StatusValidChange condition="" statusId="COM_COMPLETE" statusIdTo="COM_BOUNCED" transitionName="Bounced"/>

Modified: ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml?rev=774634&r1=774633&r2=774634&view=diff
==============================================================================
--- ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml (original)
+++ ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml Thu May 14 05:12:24 2009
@@ -393,34 +393,49 @@
         </if-not-empty>
     </simple-method>
 
-    <simple-method method-name="markEventRead" short-description="Marks a Communication Event as Read">
+    <simple-method method-name="markEventRead" short-description="Automatically Marks a Communication Event as Read" login-required="false">
         <if-empty field="parameters.communicationEventId">
             <set from-field="parameters.messageId" field="parameters.communicationEventId"/>
         </if-empty>
         <entity-one entity-name="CommunicationEvent" value-field="event"/>
 
+        <!--  get the 'system' user to run the update service as -->
+        <entity-one entity-name="UserLogin" value-field="system">
+            <field-map field-name="userLoginId" value="system"/>
+        </entity-one>
+                 
         <if>
             <condition>
-                <or>
-                    <if-compare-field field="event.partyIdTo" to-field="userLogin.partyId" operator="equals"/>
-                    <if-has-permission permission="PARTYMGR" action="_CME_UPDATE"/>
-                </or>
+                <and>
+                    <or>
+                        <!--  valid statuses which can go to read -->
+                        <if-compare field="event.statusId" operator="equals" value="COM_ENTERED"/>
+                        <if-compare field="event.statusId" operator="equals" value="COM_PENDING"/>
+                        <if-compare field="event.statusId" operator="equals" value="COM_IN_PROGRESS"/>                        
+                        <if-compare field="event.statusId" operator="equals" value="COM_COMPLETE"/>
+                    </or>
+                    <or> 
+                       <!--  if the user is not logged in, its okay to update, assumption is an external event -->
+                       <if-empty field="userLogin"/> 
+                       <!--  if the user is logged in, make sure they are the owner of the event -->                  
+                       <and>
+                           <not><if-empty field="userLogin"/></not>
+                           <if-compare-field field="event.partyIdTo" to-field="userLogin.partyId" operator="equals"/>
+                           <!--  note: it is not okay for an admin to mark another user's event as read -->
+                       </and>                   
+                    </or>
+                </and>                
             </condition>
-            <then>
-                <if>
-                    <condition>
-                        <or>
-                            <if-compare field="event.statusId" operator="equals" value="COM_ENTERED"/>
-                            <if-compare field="event.statusId" operator="equals" value="COM_PENDING"/>
-                        </or>
-                    </condition>
-                    <then>
-                        <set value="COM_READ" field="event.statusId"/>
-                        <store-value value-field="event"/>
-                    </then>
-                </if>
-            </then>
-        </if>
+            <then>               
+                <set field="updateCtx.communicationEventId" from-field="event.communicationEventId"/>                
+                <set field="updateCtx.statusId" value="COM_READ"/>
+                <set field="updateCtx.userLogin" from-field="userLogin"/>
+                <if-empty field="userLogin">
+                    <set field="updateCtx.userLogin" from-field="system"/>
+                </if-empty>
+                <call-service service-name="updateCommunicationEvent" in-map-name="updateCtx" include-user-login="false"/>
+            </then>            
+        </if>               
     </simple-method>
 
     <simple-method method-name="sendEmailDated"

Modified: ofbiz/trunk/applications/party/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/servicedef/services.xml?rev=774634&r1=774633&r2=774634&view=diff
==============================================================================
--- ofbiz/trunk/applications/party/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/party/servicedef/services.xml Thu May 14 05:12:24 2009
@@ -776,13 +776,13 @@
         <auto-attributes include="nonpk" mode="IN" optional="true" entity-name="CommunicationEventWorkEff"/>
     </service>
     <service name="markCommEventRead" engine="simple"
-            location="component://party/script/org/ofbiz/party/communication/CommunicationEventServices.xml" invoke="markEventRead" auth="true">
-        <description>Marks a communication event as read if in the entered/pending status</description>
+            location="component://party/script/org/ofbiz/party/communication/CommunicationEventServices.xml" invoke="markEventRead" auth="false">
+        <description>Marks a communication event as read</description>
         <attribute name="communicationEventId" type="String" mode="IN" optional="false"/>
     </service>
     <service name="markMessageRead" engine="simple"
-            location="component://party/script/org/ofbiz/party/communication/CommunicationEventServices.xml" invoke="markEventRead" auth="true">
-        <description>Marks a communication event as read if in the entered/pending status</description>
+            location="component://party/script/org/ofbiz/party/communication/CommunicationEventServices.xml" invoke="markEventRead" auth="false">
+        <description>Marks a communication event as read</description>
         <attribute name="messageId" type="String" mode="IN" optional="false"/>
     </service>
     <service name="sendCommEventAsEmail" engine="java"

Modified: ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java?rev=774634&r1=774633&r2=774634&view=diff
==============================================================================
--- ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java (original)
+++ ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java Thu May 14 05:12:24 2009
@@ -19,6 +19,10 @@
 
 package org.ofbiz.party.communication;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.nio.ByteBuffer;
 import java.sql.Timestamp;
 import java.util.Enumeration;
@@ -34,12 +38,17 @@
 import javax.mail.Address;
 import javax.mail.MessagingException;
 import javax.mail.internet.InternetAddress;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import javolution.util.FastList;
 import javolution.util.FastMap;
 
+import org.ofbiz.base.location.FlexibleLocation;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.StringUtil;
 import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
@@ -938,8 +947,7 @@
      * Calls findPartyFromEmailAddress service and returns a List of the results for the array of addresses
      */
     private static List<Map<String, Object>> buildListOfPartyInfoFromEmailAddresses(Address [] addresses, GenericValue userLogin, LocalDispatcher dispatcher) throws GenericServiceException {
-        InternetAddress emailAddress = null;
-        Map map = null;
+        InternetAddress emailAddress = null;        
         Map<String, Object> result = null;
         List<Map<String, Object>> tempResults = FastList.newInstance();
 
@@ -1115,4 +1123,50 @@
         return ServiceUtil.returnSuccess();
         
     }
+    
+    /*
+     * Event which marks a communication event as read, and returns a 1px image to the browser/mail client
+     */
+    public static String markCommunicationAsRead(HttpServletRequest request, HttpServletResponse response) {        
+        String communicationEventId = null;        
+        
+        // pull the communication event from path info, so we can hide the process from the user
+        String pathInfo = request.getPathInfo();
+        String[] pathParsed = pathInfo.split("/", 3);
+        if (pathParsed != null && pathParsed.length > 2) {
+            pathInfo = pathParsed[2];
+        } else {
+            pathInfo = null;
+        }
+        if (pathInfo != null & pathInfo.indexOf("/") > -1) {
+            pathParsed = pathInfo.split("/");
+            communicationEventId = pathParsed[0];            
+        }
+                
+        // update the communication event
+        if (communicationEventId != null) {
+            Debug.logInfo("Marking communicationEventId [" + communicationEventId + "] from path info : " + request.getPathInfo() + " as read.", module);
+            LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
+            try {                
+                dispatcher.runAsync("markCommEventRead", UtilMisc.toMap("communicationEventId", communicationEventId));                
+            } catch (GenericServiceException e) {
+                Debug.logError(e, module);            
+            }
+        }
+        
+        // return the 1px image (spacer.gif)
+        URL imageUrl;
+        try {
+            imageUrl = FlexibleLocation.resolveLocation("component://images/webapp/images/spacer.gif");
+            InputStream imageStream = imageUrl.openStream();
+            UtilHttp.streamContentToBrowser(response, imageStream, 43, "image/gif", null);            
+        } catch (MalformedURLException e) {
+            Debug.logError(e, module);
+        } catch (IOException e) {
+            Debug.logError(e, module);
+        }
+                
+        // return null to not return any view
+        return null;
+    }
 }

Modified: ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/controller.xml?rev=774634&r1=774633&r2=774634&view=diff
==============================================================================
--- ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/controller.xml Thu May 14 05:12:24 2009
@@ -1181,6 +1181,12 @@
         <response name="error" type="view" value="viewprofile"/>
     </request-map>
 
+    <!--  external communication event; mark as read using 1px image request -->
+    <request-map uri="ceimages">
+        <security https="false" auth="false"/>
+        <event type="java" path="org.ofbiz.party.communication.CommunicationEventServices" invoke="markCommunicationAsRead"/>
+        <response name="success" type="none"/>
+    </request-map>
     <!-- end of request mappings -->
 
     <!-- View Mappings -->