r970 - xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify

Jeremi Joslin jeremi at users.forge.objectweb.org
Sun Mar 12 09:35:43 CET 2006


Author: jeremi
Date: 2006-03-12 09:35:42 +0100 (Sun, 12 Mar 2006)
New Revision: 970

Modified:
   xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/EmailNotificationPlugin.java
   xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/EmailNotificationPluginApi.java
   xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/NotificationSender.java
   xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/PageModifications.java
   xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/Utils.java
Log:
Patch made by Robin Fernandes:
* Fixes to the way subscription objects are created. Some properties were of the wrong type or were not correctly linked to their object, resulting in misc strange behaviour.
* Fixed typo which prevented web subscriptions from working
* Added ability to explicitly set/unset a subscription rather than just toggle it. This avoids accidentally subscribing/unsubscribing by hitting the browser's back button.
* The original version would not notify a user if they modified a document after someone else modified it. This version notifies users of the last modification that was not carried out by theirself.
* Use org.apache.commons.mail to send emails instead of XWiki's sendmessage method. I couldn't figure out how to set the email subject with that.

Modified: xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/EmailNotificationPlugin.java
===================================================================
--- xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/EmailNotificationPlugin.java	2006-03-10 02:16:25 UTC (rev 969)
+++ xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/EmailNotificationPlugin.java	2006-03-12 08:35:42 UTC (rev 970)
@@ -23,7 +23,6 @@
 
 import java.text.ParseException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -46,7 +45,6 @@
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.api.Api;
-import com.xpn.xwiki.api.Context;
 import com.xpn.xwiki.api.Document;
 import com.xpn.xwiki.api.XWiki;
 import com.xpn.xwiki.doc.XWikiDocument;
@@ -56,7 +54,6 @@
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.objects.BaseObject;
-import com.xpn.xwiki.objects.DBStringListProperty;
 import com.xpn.xwiki.objects.IntegerProperty;
 import com.xpn.xwiki.objects.ListProperty;
 import com.xpn.xwiki.objects.StringListProperty;
@@ -89,14 +86,13 @@
     public static final String  FIELD_SCHEDULER_NAME                = "schedulerName";
 
     private static final String SUBSCRIPTION_PAGE_NAME              = "EmailSubscriptions";
-    private static final String SUBSCRIPTION_PAGE_WEB               = "Plugins";
+    private static final String SUBSCRIPTION_PAGE_WEB               = "XWiki";
     public static final String  SUBSCRIPTION_CLASS                  = SUBSCRIPTION_PAGE_WEB + "."
                                                                             + SUBSCRIPTION_PAGE_NAME;
 
     private static final String SQL_FULL_PAGE_NAMES                 = "select distinct doc.fullName from XWikiDocument as doc order by doc.web, doc.name";
     private static final String SQL_WEB_NAMES                       = "select distinct doc.web from XWikiDocument as doc order by doc.web";
-    private static final Logger LOG                                 = Logger
-                                                                            .getLogger (EmailNotificationPlugin.class);
+    private static final Logger LOG                                 = Logger.getLogger (EmailNotificationPlugin.class);
 
     private boolean             didAlreadyTryToUpdateClass          = false;
 
@@ -115,7 +111,7 @@
     {
         super.init (context);
         XWikiConfig config = context.getWiki ().getConfig ();
-        this.defaultSchedulerName = config.getProperty (XWIKI_PROPERTY_DEFAULTSCHEDULERNAME, "daily");
+        this.defaultSchedulerName = config.getProperty (XWIKI_PROPERTY_DEFAULTSCHEDULERNAME, "hourly");
 
         initVirtualWikiNames (context);
         initNotificationJobs (context);
@@ -193,7 +189,7 @@
                 notificationSenders.put (cfg.getName (), notifier);
             } catch (Exception e)
             {
-                LOG.error ("error scheduling quartz job " + cfg, e);
+                LOG.error ("error scheduling quartz job " + cfg.getName() + " (" + cfg.getCrontab() + ")", e);
             }
         }
     }
@@ -208,6 +204,7 @@
     }
 
     /**
+     * Toggles subscription
      * synchronized to avoid colliding edits of the subscriptions document when
      * two users decide to subscribe at the same time.
      * @todo TODO: check if this synchronization is necessary
@@ -223,12 +220,34 @@
         if (subscObj == null)
         {
             subscObj = createSubscriptionObject (wiki, context);
-            doc.addObject (SUBSCRIPTION_CLASS, subscObj);
+            doc.addObject(SUBSCRIPTION_CLASS, subscObj);
         }
         toggleSubscription (subscObj, type, docToSubscribe);
         saveDocument (wiki, context, doc);
     }
 
+
+	/**
+	 * Sets subscription
+	 * @param enable
+	 * @param type
+	 * @param docToSubscribe
+	 * @param wiki
+	 * @param context
+	 */
+	public synchronized void processSubscription(final boolean enable, final String type,
+			 						final Document docToSubscribe, final XWiki wiki, final XWikiContext context) {
+        XWikiDocument doc = getUserDocument (wiki, context);
+        BaseObject subscObj = getSubscriptionObject (wiki, context);
+        if (subscObj == null)
+        {
+            subscObj = createSubscriptionObject (wiki, context);
+            doc.addObject(SUBSCRIPTION_CLASS, subscObj);
+        }
+        setSubscription (enable, subscObj, type, docToSubscribe);
+        saveDocument (wiki, context, doc);
+	}   
+    
     /**
      * @param type
      * @param doc
@@ -353,11 +372,75 @@
         }
     }
 
+    /**
+     * Like toggleSubscription, except action is defined explicitly by "enable". 
+     * This is to prevent accidentally toggling subscription when 
+     * hitting the back button in the browser.
+     * @param enable : true to subscribe, false to unsubscribe.
+     * @param subscriptionObj
+     * @param type
+     * @param docToSubscribe
+     */
+    protected void setSubscription(boolean enable, final BaseObject subscriptionObj,
+    							   final String type, final Document docToSubscribe) {
+		if (TYPE_WIKI.equals(type)) {
+			IntegerProperty prop = (IntegerProperty) subscriptionObj
+					.getField(FIELD_SUBSCRIBED_WIKI);
+			if (enable) {
+				prop.setValue(new Integer(1));
+				if (LOG.isDebugEnabled())
+					LOG.debug("turned wiki-wide notifications on");				
+			} else {
+				prop.setValue(new Integer(0));
+				if (LOG.isDebugEnabled())
+					LOG.debug("turned wiki-wide notifications off");
+			}
+		} else {
+			String name;
+			ListProperty list;
+			if (TYPE_PAGE.equals(type)) {
+				list = Utils.getListProperty(subscriptionObj,
+						FIELD_SUBSCRIBED_PAGES);
+				name = docToSubscribe.getFullName();
+			} else if (TYPE_WEB.equals(type)) {
+				list = Utils.getListProperty(subscriptionObj,
+						FIELD_SUBSCRIBED_WEBS);
+				name = docToSubscribe.getWeb();
+			} else {
+				LOG.error("invalid subscription type " + type);
+				return;
+			}
+
+			if (LOG.isDebugEnabled()) {
+				LOG.debug("processing " + type + " subscription for " + name);
+			}
+			// can be either full document names or web names, depending on type
+			List subscribedEntities = list.getList();
+			if (LOG.isDebugEnabled()) {
+				LOG.debug(subscribedEntities.size() + " subscribed " + type
+						+ "s");
+			}
+			if (enable) {
+				if (LOG.isDebugEnabled()) {
+					LOG.debug("add subscription");
+				}
+				subscribedEntities.add(name);				
+			} else {
+				if (LOG.isDebugEnabled()) {
+					LOG.debug("remove subscription");
+				}
+				subscribedEntities.remove(name);
+			}
+		}
+	}
+
+    
+    
     protected XWikiDocument getUserDocument (final XWiki wiki, final XWikiContext context)
     {
         try
         {
-            return wiki.getDocument (context.getUser ()).getDocument ();
+            return wiki.getDocument (context.getUser ()).getDocument();
         } catch (XWikiException e)
         {
             LOG.error ("error getting user document for user" + context.getUser (), e);
@@ -408,32 +491,27 @@
         // BaseClass#newObject()
         BaseClass objClass = getSubscriptionClass (wiki, context);
         subscriptionObj = (BaseObject) objClass.newObject ();
-        // TODO: unsure what name to give to objects (name of class which is
-        // equal to name of page class belongs to, of name of user) ?
-        subscriptionObj.setName (SUBSCRIPTION_CLASS);
-        subscriptionObj.setClassName(objClass.getClassName());
-        // subscriptionObj.setName (user);
+        subscriptionObj.setName(user);
+        subscriptionObj.setClassName(objClass.getName());
         subscriptionObj.setStringValue (FIELD_USERNAME, user);
-        ListProperty subscPages = new DBStringListProperty ();
-        subscPages.setName (FIELD_SUBSCRIBED_PAGES);
-        subscPages.setValue (new ArrayList ());
-        subscriptionObj.addField (FIELD_SUBSCRIBED_PAGES, subscPages);
-        ListProperty subscWebs = new DBStringListProperty ();
-        subscWebs.setName (FIELD_SUBSCRIBED_WEBS);
-        subscWebs.setValue (new ArrayList ());
-        subscriptionObj.addField (FIELD_SUBSCRIBED_WEBS, subscWebs);
-        subscriptionObj.setIntValue (FIELD_SUBSCRIBED_WIKI, 0);
-
-        StringListProperty choosenScheduler = new StringListProperty ();
-        choosenScheduler.setName (FIELD_SCHEDULER_NAME);
-        choosenScheduler.setTextValue (defaultSchedulerName);
-        subscriptionObj.addField (FIELD_SCHEDULER_NAME, choosenScheduler);
-
+        
+        ListProperty subscPages = new StringListProperty ();
+        subscPages.setValue(new ArrayList());
+        subscriptionObj.safeput(FIELD_SUBSCRIBED_PAGES, subscPages);
+        
+        ListProperty subscWebs = new StringListProperty ();
+        subscWebs.setValue(new ArrayList ());
+        subscriptionObj.safeput(FIELD_SUBSCRIBED_WEBS, subscWebs);
+        
+        subscriptionObj.setIntValue(FIELD_SUBSCRIBED_WIKI, 0);
+        subscriptionObj.setStringValue(FIELD_SCHEDULER_NAME, defaultSchedulerName);
+        
         return subscriptionObj;
     }
 
     private BaseClass getSubscriptionClass (final XWiki wiki, final XWikiContext context)
     {
+    	if (LOG.isDebugEnabled()) LOG.debug("In getSubscriptionClass");
         XWikiDocument doc;
         boolean needsUpdate = false;
 
@@ -496,8 +574,7 @@
         }
         needsUpdate |= bclass.addBooleanField (FIELD_SUBSCRIBED_WIKI, "All Documents", "yesno");
 
-        String content = doc.getContent ();
-        if ( (content == null) || (content.equals ("")))
+        if (doc.isNew())
         {
             needsUpdate = true;
             doc.setContent ("1 EMail Notification Plugin\n "
@@ -528,7 +605,7 @@
     {
         final Set schedulerNames = notificationSenders.keySet ();
         if (schedulerNames.size () == 0) return "";
-        StringBuffer values = new StringBuffer ();
+        StringBuffer values = new StringBuffer();
         for (Iterator iter = schedulerNames.iterator (); iter.hasNext ();)
         {
             String name = (String) iter.next ();
@@ -557,6 +634,8 @@
     public void notify (final XWikiNotificationRule rule, final XWikiDocument newdoc,
                         final XWikiDocument olddoc, final int event, final XWikiContext context)
     {
+    	if (LOG.isDebugEnabled())
+            LOG.debug(String.format("Detected change type %d to document %s", event, newdoc.getFullName()));
         for (Iterator iter = notificationSenders.values ().iterator (); iter.hasNext ();)
         {
             final NotificationSender sender = (NotificationSender) iter.next ();
@@ -589,10 +668,13 @@
     public void notify (final XWikiNotificationRule rule, final XWikiDocument doc, final String action,
                         final XWikiContext context)
     {
-        if ("upload".equals (action))
+    	if (LOG.isDebugEnabled()) LOG.debug(String.format("Detected action type %s to document %s", action, doc.getFullName()));
+/*        if ("upload".equals (action))
         {
             // TODO: notify on uploads
         }
+*/        
     }
 
+
 }

Modified: xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/EmailNotificationPluginApi.java
===================================================================
--- xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/EmailNotificationPluginApi.java	2006-03-10 02:16:25 UTC (rev 969)
+++ xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/EmailNotificationPluginApi.java	2006-03-12 08:35:42 UTC (rev 970)
@@ -8,7 +8,6 @@
 
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.api.Api;
-import com.xpn.xwiki.api.Context;
 import com.xpn.xwiki.api.Document;
 import com.xpn.xwiki.api.XWiki;
 
@@ -39,8 +38,34 @@
         return plugin.isSubscribed (type, doc, wiki, context);
     }
 
+    /**
+     * Toggle subscription
+     * @param type: "page", "web", or "wiki"
+     * @param doc
+     * @param wiki
+     */
     public void processSubscription (String type, Document doc, XWiki wiki)
     {
         plugin.processSubscription (type, doc, wiki, context);
     }
+  
+    /**
+     * Set/unset subscription
+     * @param enable: "true" to subscribe, "false" to unsubscribe
+     * @param type: "page", "web", or "wiki"
+     * @param doc
+     * @param wiki
+     */    
+    public void processSubscription (String enable, String type, Document doc, XWiki wiki)
+    {
+    	if (enable.equals("true")) {
+    		plugin.processSubscription(true, type, doc, wiki, context);
+    	} else if (enable.equals("false")) { 
+    		plugin.processSubscription(false, type, doc, wiki, context);
+    	} else {
+    		LOG.warn("Unknown value for enable: " + enable);
+    	}
+
+    }
+    
 }

Modified: xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/NotificationSender.java
===================================================================
--- xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/NotificationSender.java	2006-03-10 02:16:25 UTC (rev 969)
+++ xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/NotificationSender.java	2006-03-12 08:35:42 UTC (rev 970)
@@ -43,22 +43,30 @@
 import org.apache.velocity.VelocityContext;
 
 import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.XWikiConfig;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.objects.BaseObject;
 import com.xpn.xwiki.render.XWikiVelocityRenderer;
 
+import org.apache.commons.mail.EmailException;
+import org.apache.commons.mail.SimpleEmail;
+
 /**
  * Sends out notifications.
  * @author <a href="mailto:jk at jkraemer.net">Jens Krämer </a>
  */
 public class NotificationSender
 {
-    private static final Logger     LOG                        = Logger.getLogger (NotificationSender.class);
+
+	private static final Logger     LOG                        = Logger.getLogger (NotificationSender.class);
     final static String             ALL_SUBSCRIPTIONS          = "from BaseObject as obj where obj.className='"
                                                                        + EmailNotificationPlugin.SUBSCRIPTION_CLASS
                                                                        + "'";
+    public static final String  XWIKI_PROPERTY_EMAILSUBJECT    = "xwiki.plugins.emailnotify.emailSubject";
+    private static final String SUBSCRIPTION_DOCUMENTS_QUERY   = ", BaseObject as obj where obj.name=doc.fullName and obj.className='"+EmailNotificationPlugin.SUBSCRIPTION_CLASS+"'";
+    
     private static final Comparator modificationDateComparator = new Comparator () {
                                                                    public int compare (Object o1, Object o2)
                                                                    {
@@ -98,7 +106,7 @@
      * minimum time span in seconds between last modification and sending out a
      * notification, to prevent multiple notifications on minor edits
      */
-    private int                     minModificationAge         = 10;
+    private int                     minModificationAge         = 0;
 
     /** checked in main loop, exit if true */
     private boolean                 exit                       = false;
@@ -114,6 +122,10 @@
     private String                  template;
     private static final String     TEMPLATE_NAME              = "notificationMail.vm";
 
+    private final String            mailSubject;
+    private final String            mailServer;
+//    private final int            	mailServerPort;
+    
     /**
      * Predicate for filtering delayed modifications and such made by the given
      * user
@@ -127,24 +139,16 @@
             this.userName = uName;
         }
 
-        public boolean evaluate (Object arg0)
+        /* Returns true if provided PageModifications set contains
+         * at least 1 valid modification not by userName
+         */
+        public boolean evaluate(Object arg0)
         {
-            // TODO: only checking the last modification is somewhat flawed:
-            // when a page was first modified by user X and then by user Y, user
-            // Y
-            // later won't get notified of X's change because we here check only
-            // his
-            // own modification and then filter out the whole modification set
-            // because
-            // the last change was his own.
-            // we could call that a feature, though, since he was the last one
-            // modifying the
-            // page and should have already seen the changes made by others...
-            PageModification mod = ((PageModifications) arg0).getLastModification ();
-            if (LOG.isDebugEnabled ())
-                LOG.debug ("eval modification: " + mod + "against user name " + userName);
-            final boolean retval = ! (mod.isDontSendNow () || mod.getModifier ().equals (userName));
-            if (LOG.isDebugEnabled ()) LOG.debug ("retval: " + retval);
+        	boolean retval;
+        	PageModifications mods =(PageModifications) arg0;
+        	PageModification mod = mods.getLastModificationNotBy(userName);
+        	retval = (mod!=null);
+        	if (LOG.isDebugEnabled()) LOG.debug ("evaluated modification "+mod+" as "+retval); 
             return retval;
         }
 
@@ -162,6 +166,11 @@
 
         this.sender = xw.getXWikiPreference ("admin_email", context);
         this.template = readTemplate ();
+        
+        XWikiConfig config = context.getWiki().getConfig();
+        this.mailSubject = config.getProperty(XWIKI_PROPERTY_EMAILSUBJECT, "XWiki change notification");
+        this.mailServer  = xwiki.getXWikiPreference("smtp_server", context);
+        //this.mailServerPort = Integer.parseInt(xwiki.getXWikiPreference("smtp_port", context));        
     }
 
     /**
@@ -228,10 +237,15 @@
         final Map oldWikiModifications = wikiModifications;
         initMaps ();
         if (LOG.isDebugEnabled ()) LOG.debug ("have " + oldPageModifications.size () + " modifications...");
-        checkForTooNewModifications (oldPageModifications);
+        
+        if (minModificationAge>0) {
+          checkForTooNewModifications (oldPageModifications);
+        }
+        
         for (Iterator iter = virtualWikiNames.iterator (); iter.hasNext ();)
         {
             final String wikiName = (String) iter.next ();
+            if (LOG.isDebugEnabled()) LOG.debug("Processing " + oldPageModifications.size () + " mods on wiki " + wikiName);            
             final XWikiContext wikiContext = new XWikiContext ();
             wikiContext.setWiki (xwiki);
             wikiContext.put ("vcontext", new VelocityContext ());
@@ -347,6 +361,7 @@
                             .toString ();
                     if (LOG.isDebugEnabled ()) LOG.debug ("web: " + fullWebName);
                     final Set allModifiedPagesInWeb = (Set) oldWebModifications.get (fullWebName);
+                    if (LOG.isDebugEnabled ()) LOG.debug ("modified in web: " + allModifiedPagesInWeb);
                     if (allModifiedPagesInWeb != null)
                     {
                         if (LOG.isDebugEnabled ())
@@ -416,23 +431,27 @@
             LOG.debug ("sending mail with " + modifications.size () + " modified docs to " + userEmail);
         VelocityContext vcontext = new VelocityContext ();
         vcontext.put ("pagemodifications", modifications);
+        vcontext.put ("currentUser", userobj.getName());        
         vcontext.put ("firstname", userobj.getStringValue ("first_name"));
         vcontext.put ("lastname", userobj.getStringValue ("last_name"));
         vcontext.put ("server", context.getWikiServer ());
         vcontext.put ("wikiName", context.getDatabase ());
-        // todo: get hostname + baseurl from somewhere, to allow linking in
-        // mails
-        // context.g
+        
         String content = XWikiVelocityRenderer.evaluate (template, "emailnotify", vcontext);
-        if (LOG.isDebugEnabled ()) LOG.debug ("sending mail \n" + content + " \n to " + userEmail);
-        try
-        {
-            xwiki.sendMessage (this.sender, userEmail, content, context);
-        } catch (XWikiException e1)
-        {
-            LOG.error ("error sending mail ", e1);
-            e1.printStackTrace ();
-        }
+        if (LOG.isDebugEnabled()) LOG.debug ("sending mail \n" + content + " \n to " + userEmail);
+        SimpleEmail email = new SimpleEmail();
+        email.setHostName(mailServer);
+        //email.setSmtpPort(mailServerPort);
+        email.setSubject(mailSubject);
+        try {
+            email.addTo(userEmail);
+            email.setFrom(this.sender);
+            email.setMsg(content);              	
+            email.send();
+        } catch (EmailException e) {
+        	LOG.error("Error sending email: "+e);
+            e.printStackTrace();
+        }        	
     }
 
     /**
@@ -445,25 +464,20 @@
     protected Collection getAllSubscriptions (XWikiContext context)
     {
         List retval = new ArrayList ();
-
-        try
-        {
-            Collection userDocs = xwiki
-                    .getStore ()
-                    .searchDocuments (
-                                      ", BaseObject as obj where obj.name=CONCAT(XWD_WEB,'.',XWD_NAME) and obj.className='XWiki.XWikiUsers'",
-                                      context);
+        try {        
+            Collection userDocs = xwiki.getStore ().searchDocuments(SUBSCRIPTION_DOCUMENTS_QUERY, context);
             for (Iterator iter = userDocs.iterator (); iter.hasNext ();)
             {
+            
                 // XWikiDocument doc = xwiki.getDocument ((String) iter.next (),
                 // context);
                 XWikiDocument doc = (XWikiDocument) iter.next ();
                 if (doc != null)
                 {
                     BaseObject obj = doc.getObject (EmailNotificationPlugin.SUBSCRIPTION_CLASS);
-
                     if (obj != null)
                     {
+                    	if (LOG.isDebugEnabled()) LOG.debug("Subscription object for user " + doc.getFullName() + " : " + obj);
                         String schedulerName = obj
                                 .getStringValue (EmailNotificationPlugin.FIELD_SCHEDULER_NAME);
                         if (name.equals (schedulerName))
@@ -474,7 +488,7 @@
                         } else
                         {
                             if (LOG.isDebugEnabled ())
-                                LOG.debug ("skipping subscription of user " + doc.getName ()
+                                LOG.debug ("This scheduler is : " + name + ". Skipping subscription of user " + doc.getName ()
                                         + " since not our scheduler name: " + schedulerName);
                         }
                     }
@@ -483,11 +497,12 @@
 
         } catch (XWikiException e)
         {
-            LOG.error ("error retrieving subscriptions of wiki " + context.getDatabase ());
+            LOG.error ("error retrieving subscriptions of wiki " + context.getDatabase () + ": " + e);
             e.printStackTrace ();
             retval = new ArrayList ();
         }
         return retval;
+      
     }
 
     /**
@@ -538,7 +553,7 @@
         if (retval == null)
         {
             retval = new HashSet ();
-            wikiModifications.put (wikiAndWebName, retval);
+            webModifications.put (wikiAndWebName, retval);
         }
         return retval;
     }

Modified: xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/PageModifications.java
===================================================================
--- xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/PageModifications.java	2006-03-10 02:16:25 UTC (rev 969)
+++ xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/PageModifications.java	2006-03-12 08:35:42 UTC (rev 970)
@@ -9,6 +9,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.log4j.Logger;
+
 /**
  * Container for all modifications done to a specific page between two
  * notification runs.
@@ -16,11 +18,11 @@
  */
 public class PageModifications
 {
-    private final List modifications = new ArrayList ();
+    private final List modifications = new ArrayList();
     private final PageData pageData;
     
+    private static final Logger LOG = Logger.getLogger (PageModifications.class);   
     
-    
     public PageModifications (PageModification firstModification)
     {
         modifications.add (firstModification);
@@ -45,6 +47,7 @@
         // TODO: walk through modifications and sum up subsequent modifications
         // in a time interval (10 minutes or so)
         // done by the same user
+   	
         return null;
     }
     
@@ -54,6 +57,29 @@
     }
 
     /**
+     * @param user
+     * @return Last modification that was not made by user and that isn't
+     * marked as "don't send now". Returns null if no such modification found.
+     */
+    public PageModification getLastModificationNotBy(String user)
+    {
+    	if (LOG.isDebugEnabled()) LOG.debug("In getLastModificationNotBy " + user );
+    	int modIndex=modifications.size()-1;
+    	PageModification retpm = null;
+    	while (modIndex>=0) {
+    		PageModification pm = (PageModification) modifications.get(modIndex);
+    		if (LOG.isDebugEnabled()) LOG.debug("Checking mod by " + pm.getModifier() + "against " + user );
+    		if (!user.equals(pm.getModifier()) && !pm.isDontSendNow()) {
+    			retpm=pm;
+    			break;
+    		}
+    		modIndex--;
+    	}
+    	if (LOG.isDebugEnabled()) LOG.debug("returning " + retpm );
+    	return retpm;
+    }    
+    
+    /**
      * @return
      */
     public List getModifications ()

Modified: xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/Utils.java
===================================================================
--- xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/Utils.java	2006-03-10 02:16:25 UTC (rev 969)
+++ xwiki-plugins/emailnotification/trunk/src/java/net/jkraemer/xwiki/plugins/emailnotify/Utils.java	2006-03-12 08:35:42 UTC (rev 970)
@@ -14,7 +14,7 @@
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWiki;
 import com.xpn.xwiki.objects.BaseObject;
-import com.xpn.xwiki.objects.DBStringListProperty;
+import com.xpn.xwiki.objects.StringListProperty;
 import com.xpn.xwiki.objects.IntegerProperty;
 import com.xpn.xwiki.objects.ListProperty;
 
@@ -44,10 +44,9 @@
         if (list == null)
         {
             if (LOG.isDebugEnabled ()) LOG.debug ("creating new list property for field " + fieldName);
-            list = new DBStringListProperty ();
-            list.setName (fieldName);
+            list = new StringListProperty();
             list.setValue (new ArrayList ());
-            subscriptionObj.addField (fieldName, list);
+            subscriptionObj.safeput(fieldName, list);
         }
         return list;
     }





More information about the Xwiki-notifications mailing list