[kune-commits] r1659 - in trunk/src/main/java/cc/kune: core/server core/server/notifier core/server/scheduler wave/server/kspecific

Vicente J. Ruiz Jurado vjrj_ at ourproject.org
Thu Jan 12 05:14:29 CET 2012


Author: vjrj_
Date: 2012-01-12 05:14:28 +0100 (Thu, 12 Jan 2012)
New Revision: 1659

Added:
   trunk/src/main/java/cc/kune/core/server/notifier/ClearUpdatedWavesHourlyJob.java
Modified:
   trunk/src/main/java/cc/kune/core/server/KuneRackModule.java
   trunk/src/main/java/cc/kune/core/server/PlatformServerModule.java
   trunk/src/main/java/cc/kune/core/server/notifier/NotificationSenderDefault.java
   trunk/src/main/java/cc/kune/core/server/notifier/PendingNotificationHourlyJob.java
   trunk/src/main/java/cc/kune/core/server/notifier/PendingNotificationSender.java
   trunk/src/main/java/cc/kune/core/server/scheduler/CronServerTasksManager.java
   trunk/src/main/java/cc/kune/wave/server/kspecific/WaveEmailNotifier.java
Log:
NEW - # 185: Implement notification levels (hourly and daily) similar to Google Wave 
http://kune.ourproject.org/issues/ticket/185

Modified: trunk/src/main/java/cc/kune/core/server/KuneRackModule.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/KuneRackModule.java	2012-01-12 01:40:41 UTC (rev 1658)
+++ trunk/src/main/java/cc/kune/core/server/KuneRackModule.java	2012-01-12 04:14:28 UTC (rev 1659)
@@ -133,8 +133,6 @@
 
     builder.add(KuneContainerListener.class);
     builder.add(WaveEmailNotifier.class);
-
-    // Cron tasks
     builder.add(CronServerTasksManager.class);
 
     builder.exclude("/http-bind.*");

Modified: trunk/src/main/java/cc/kune/core/server/PlatformServerModule.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/PlatformServerModule.java	2012-01-12 01:40:41 UTC (rev 1658)
+++ trunk/src/main/java/cc/kune/core/server/PlatformServerModule.java	2012-01-12 04:14:28 UTC (rev 1659)
@@ -89,6 +89,7 @@
 import cc.kune.core.server.mapper.Mapper;
 import cc.kune.core.server.notifier.NotificationSender;
 import cc.kune.core.server.notifier.NotificationSenderDefault;
+import cc.kune.core.server.notifier.PendingNotificationSender;
 import cc.kune.core.server.notifier.UsersOnline;
 import cc.kune.core.server.rpc.ContentRPC;
 import cc.kune.core.server.rpc.GroupRPC;
@@ -114,6 +115,7 @@
 import cc.kune.wave.server.ParticipantUtils;
 import cc.kune.wave.server.kspecific.KuneWaveService;
 import cc.kune.wave.server.kspecific.KuneWaveServiceDefault;
+import cc.kune.wave.server.kspecific.WaveEmailNotifier;
 
 import com.google.inject.Singleton;
 import com.google.inject.matcher.Matchers;
@@ -195,8 +197,10 @@
     bind(ParticipantUtils.class);
     bind(UsersOnline.class).to(UserSessionManager.class).in(Singleton.class);
     requestStaticInjection(AccessRightsUtils.class);
+    bind(WaveEmailNotifier.class).in(Singleton.class);
+    bind(PendingNotificationSender.class).in(Singleton.class);
+    bind(NotificationSender.class).to(NotificationSenderDefault.class).in(Singleton.class);
     bind(CronServerTasksManager.class).in(Singleton.class);
-    bind(NotificationSender.class).to(NotificationSenderDefault.class).in(Singleton.class);
     bindInterceptor(Matchers.any(), Matchers.annotatedWith(Authenticated.class),
         outermostCall(new AuthenticatedMethodInterceptor()));
     bindInterceptor(Matchers.any(), Matchers.annotatedWith(Authorizated.class),

Added: trunk/src/main/java/cc/kune/core/server/notifier/ClearUpdatedWavesHourlyJob.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/notifier/ClearUpdatedWavesHourlyJob.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/notifier/ClearUpdatedWavesHourlyJob.java	2012-01-12 04:14:28 UTC (rev 1659)
@@ -0,0 +1,33 @@
+package cc.kune.core.server.notifier;
+
+import java.text.ParseException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.quartz.SchedulerException;
+
+import cc.kune.wave.server.kspecific.WaveEmailNotifier;
+
+import com.google.inject.Inject;
+
+public class ClearUpdatedWavesHourlyJob implements Job {
+
+  public static final Log LOG = LogFactory.getLog(ClearUpdatedWavesHourlyJob.class);
+
+  private final WaveEmailNotifier waveNotifier;
+
+  @Inject
+  public ClearUpdatedWavesHourlyJob(final WaveEmailNotifier waveNotifier) throws ParseException,
+      SchedulerException {
+    this.waveNotifier = waveNotifier;
+  }
+
+  @Override
+  public void execute(final JobExecutionContext context) throws JobExecutionException {
+    waveNotifier.clearUpdatedWaves();
+  }
+
+}

Modified: trunk/src/main/java/cc/kune/core/server/notifier/NotificationSenderDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/notifier/NotificationSenderDefault.java	2012-01-12 01:40:41 UTC (rev 1658)
+++ trunk/src/main/java/cc/kune/core/server/notifier/NotificationSenderDefault.java	2012-01-12 04:14:28 UTC (rev 1659)
@@ -49,34 +49,42 @@
         "] ").toString();
   }
 
+  private boolean noOnline(final String username) {
+    final boolean logged = usersOnline.isLogged(username);
+    LOG.debug(String.format("User '' is online for notifications? %s", username, logged));
+    return !logged;
+  }
+
   @Override
   public void send(final PendingNotification notification, final EmailNotificationFrequency withFrequency) {
+    final FormatedString subject = notification.getSubject();
+    final FormatedString body = notification.getBody();
+    final NotificationType notifyType = notification.getNotifyType();
+    final boolean forceSend = notification.isForceSend();
+    final boolean isHtml = notification.isHtml();
+
+    subject.setTemplate(subjectPrefix + subject.getTemplate());
+    if (subject.shouldBeTranslated()) {
+      // Translate per recipient language
+      // final String subjectTranslation = i18n.tWithNT(user.getLanguage(),
+      // subject.getTemplate(), "");
+      // if (subjectTranslation != null) {
+      // Right now commented because we are only testing
+      // subject.setTemplate(subjectTranslation);
+      // }
+    }
+    if (body.shouldBeTranslated()) {
+      // final String bodyTranslation = i18n.tWithNT(user.getLanguage(),
+      // body.getTemplate(), "");
+      // if (bodyTranslation != null) {
+      // Right now commented because we are only testing
+      // body.setTemplate(bodyTranslation);
+      // }
+    }
+
     for (final User user : notification.getDestProvider().getDest()) {
       final String username = user.getShortName();
-      final FormatedString subject = notification.getSubject();
-      final FormatedString body = notification.getBody();
-      final NotificationType notifyType = notification.getNotifyType();
-      final boolean forceSend = notification.isForceSend();
-      final boolean isHtml = notification.isHtml();
 
-      subject.setTemplate(subjectPrefix + subject.getTemplate());
-      if (subject.shouldBeTranslated()) {
-        // Translate per recipient language
-        // final String subjectTranslation = i18n.tWithNT(user.getLanguage(),
-        // subject.getTemplate(), "");
-        // if (subjectTranslation != null) {
-        // Right now commented because we are only testing
-        // subject.setTemplate(subjectTranslation);
-        // }
-      }
-      if (body.shouldBeTranslated()) {
-        // final String bodyTranslation = i18n.tWithNT(user.getLanguage(),
-        // body.getTemplate(), "");
-        // if (bodyTranslation != null) {
-        // Right now commented because we are only testing
-        // body.setTemplate(bodyTranslation);
-        // }
-      }
       switch (notifyType) {
       case chat:
         // FIXME seems that html is not sending correctly... check server specs
@@ -84,7 +92,7 @@
             String.format("<b>%s</b>%s", subject.getString(), body.getString()));
         break;
       case email:
-        if (forceSend || (!usersOnline.isLogged(username) && withFrequency == user.getEmailNotifFreq())) {
+        if (forceSend || (noOnline(username) && withFrequency == user.getEmailNotifFreq())) {
           // we'll send this notification if is mandatory or this user is not
           // only and has this freq configured
           mailService.send(subject, FormatedString.build(emailTemplate.replace("%s", body.getString())),

Modified: trunk/src/main/java/cc/kune/core/server/notifier/PendingNotificationHourlyJob.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/notifier/PendingNotificationHourlyJob.java	2012-01-12 01:40:41 UTC (rev 1658)
+++ trunk/src/main/java/cc/kune/core/server/notifier/PendingNotificationHourlyJob.java	2012-01-12 04:14:28 UTC (rev 1659)
@@ -18,20 +18,16 @@
   public static final Log LOG = LogFactory.getLog(PendingNotificationHourlyJob.class);
   private final PendingNotificationSender pendingManager;
 
-  private final WaveEmailNotifier waveNotifier;
-
   @Inject
   public PendingNotificationHourlyJob(final PendingNotificationSender pendingManager,
       final WaveEmailNotifier waveNotifier) throws ParseException, SchedulerException {
     this.pendingManager = pendingManager;
-    this.waveNotifier = waveNotifier;
   }
 
   @Override
   public void execute(final JobExecutionContext context) throws JobExecutionException {
     LOG.info(String.format("Hourly notifications cron job start, %s", pendingManager));
     pendingManager.sendHourlyNotifications();
-    waveNotifier.clearUpdatedWaves();
     LOG.info(String.format("Hourly notifications cron job end, %s", pendingManager));
   }
 

Modified: trunk/src/main/java/cc/kune/core/server/notifier/PendingNotificationSender.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/notifier/PendingNotificationSender.java	2012-01-12 01:40:41 UTC (rev 1658)
+++ trunk/src/main/java/cc/kune/core/server/notifier/PendingNotificationSender.java	2012-01-12 04:14:28 UTC (rev 1659)
@@ -123,7 +123,7 @@
    * Send daily notifications.
    */
   public void sendDailyNotifications() {
-    send(dailyPendNotif, NO_NEXT, EmailNotificationFrequency.immediately);
+    send(dailyPendNotif, NO_NEXT, EmailNotificationFrequency.daily);
   }
 
   /**
@@ -137,7 +137,7 @@
    * Send immediate notifications.
    */
   public void sendImmediateNotifications() {
-    send(immediatePendNotif, hourlyPendNotif, EmailNotificationFrequency.daily);
+    send(immediatePendNotif, hourlyPendNotif, EmailNotificationFrequency.immediately);
   }
 
   @Override

Modified: trunk/src/main/java/cc/kune/core/server/scheduler/CronServerTasksManager.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/scheduler/CronServerTasksManager.java	2012-01-12 01:40:41 UTC (rev 1658)
+++ trunk/src/main/java/cc/kune/core/server/scheduler/CronServerTasksManager.java	2012-01-12 04:14:28 UTC (rev 1659)
@@ -16,6 +16,7 @@
 import org.quartz.SchedulerException;
 import org.quartz.impl.StdSchedulerFactory;
 
+import cc.kune.core.server.notifier.ClearUpdatedWavesHourlyJob;
 import cc.kune.core.server.notifier.PendingNotificationDailyJob;
 import cc.kune.core.server.notifier.PendingNotificationHourlyJob;
 import cc.kune.core.server.notifier.PendingNotificationImmediateJob;
@@ -53,16 +54,17 @@
   public void start() {
     LOG.info("Starting cron manager");
     try {
-
       sched.start();
       scheduleJob(PendingNotificationImmediateJob.class, "0 */2 * * * ?", "pendinnotifimmediate");
       scheduleJob(PendingNotificationHourlyJob.class, "0 0 * * * ?", "pendingnotifhourly");
+      scheduleJob(ClearUpdatedWavesHourlyJob.class, "0 0 * * * ?", "clearupdatedwaveshourly");
       scheduleJob(PendingNotificationDailyJob.class, "0 5 0 * * ?", "pendingnotifdaily");
     } catch (final SchedulerException e) {
       logError(e);
     } catch (final ParseException e) {
       logError(e);
     }
+    LOG.info("Cron manager started");
   }
 
   @Override

Modified: trunk/src/main/java/cc/kune/wave/server/kspecific/WaveEmailNotifier.java
===================================================================
--- trunk/src/main/java/cc/kune/wave/server/kspecific/WaveEmailNotifier.java	2012-01-12 01:40:41 UTC (rev 1658)
+++ trunk/src/main/java/cc/kune/wave/server/kspecific/WaveEmailNotifier.java	2012-01-12 04:14:28 UTC (rev 1659)
@@ -24,7 +24,6 @@
 import org.waveprotocol.wave.model.waveref.WaveRef;
 
 import cc.kune.core.client.state.SiteTokens;
-import cc.kune.core.server.LogThis;
 import cc.kune.core.server.mail.FormatedString;
 import cc.kune.core.server.notifier.NotificationType;
 import cc.kune.core.server.notifier.PendingNotification;
@@ -41,20 +40,40 @@
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
- at LogThis
 @Singleton
 public class WaveEmailNotifier implements ContainerListener {
   public static final Log LOG = LogFactory.getLog(WaveEmailNotifier.class);
-  private HashSet<WaveId> updatedWavesInLastHour;
 
+  private final KuneBasicProperties basicProperties;
+  private final PendingNotificationSender notificator;
+  private final ParticipantUtils partUtils;
+  private final HashSet<WaveId> updatedWavesInLastHour;
+  private final UserFinder userFinder;
+  private final WaveBus waveBus;
+  private final KuneWaveService waveService;
+
   @Inject
   public WaveEmailNotifier(final WaveBus waveBus, final PendingNotificationSender notificator,
       final KuneBasicProperties basicProperties, final ParticipantUtils partUtils,
       final KuneWaveService waveService, final UserFinder userFinder) {
+    this.waveBus = waveBus;
+    this.notificator = notificator;
+    this.basicProperties = basicProperties;
+    this.partUtils = partUtils;
+    this.waveService = waveService;
+    this.userFinder = userFinder;
+    updatedWavesInLastHour = new HashSet<WaveId>();
+    LOG.info("WaveEmailNotifier created");
+  }
 
+  public void clearUpdatedWaves() {
+    updatedWavesInLastHour.clear();
+  }
+
+  @Override
+  public void start() {
     final String siteCommonName = basicProperties.getSiteCommonName();
     final String siteUrl = basicProperties.getSiteUrl();
-    updatedWavesInLastHour = new HashSet<WaveId>();
     waveBus.subscribe(new Subscriber() {
 
       private void addPendingNotif(final ParticipantId participant, final FormatedString subject,
@@ -136,17 +155,10 @@
         }
       }
     });
+    LOG.info("WaveEmailNotifier started");
   }
 
-  public void clearUpdatedWaves() {
-    updatedWavesInLastHour.clear();
-  }
-
   @Override
-  public void start() {
-  }
-
-  @Override
   public void stop() {
   }
 




More information about the kune-commits mailing list