Scarab commit: svn commit: r10205 - branches/release/b21/src/java/org/tigris/scarab/notification

[email protected]
Newsgroups gmane.comp.java.scarab.cvs
Message-ID <[email protected]>
Author: dabbous
Date: 2006-07-10 03:31:36-0700
New Revision: 10205

Added:
   branches/release/b21/src/java/org/tigris/scarab/notification/ScarabOldNotificationManager.java
      - copied, changed from r10202, /branches/release/b21/src/java/org/tigris/scarab/notification/ScarabNotificationManager.java
Modified:
   branches/release/b21/src/java/org/tigris/scarab/notification/ScarabNotificationManager.java

Log:
renamed ScarabNotificationManager to ScarabOldNotificationManager.java
"reimplemented" ScarabNotificationManager.java by fully deriving from 
ScarabNewNotificationManager.java

So now ScarabNewNotificationManager silently replaces the old NM. If
users want/need the old NM this can be customized via properties.


Modified: branches/release/b21/src/java/org/tigris/scarab/notification/ScarabNotificationManager.java
Url: http://scarab.tigris.org/source/browse/scarab/branches/release/b21/src/java/org/tigris/scarab/notification/ScarabNotificationManager.java?view=diff&rev=10205&p1=branches/release/b21/src/java/org/tigris/scarab/notification/ScarabNotificationManager.java&p2=branches/release/b21/src/java/org/tigris/scarab/notification/ScarabNotificationManager.java&r1=10204&r2=10205
==============================================================================
--- branches/release/b21/src/java/org/tigris/scarab/notification/ScarabNotificationManager.java	(original)
+++ branches/release/b21/src/java/org/tigris/scarab/notification/ScarabNotificationManager.java	2006-07-10 03:31:36-0700
@@ -1,267 +1,72 @@
 package org.tigris.scarab.notification;

 

-import java.util.Collection;

-import java.util.HashSet;

-import java.util.Iterator;

-import java.util.Set;

-import java.util.List;

-

-import org.apache.log4j.Logger;

-import org.apache.torque.TorqueException;

-import org.apache.turbine.Turbine;

-import org.tigris.scarab.om.Activity;

-import org.tigris.scarab.om.ActivitySet;

-import org.tigris.scarab.notification.ActivityType;

-import org.tigris.scarab.om.Attachment;

-import org.tigris.scarab.om.AttributePeer;

-import org.tigris.scarab.om.Issue;

-import org.tigris.scarab.om.ScarabUser;

-import org.tigris.scarab.util.Email;

-import org.tigris.scarab.util.EmailContext;

-import org.tigris.scarab.util.Log;

+/* ================================================================

+ * Copyright (c) 2000-2005 CollabNet.  All rights reserved.

+ *

+ * Redistribution and use in source and binary forms, with or without

+ * modification, are permitted provided that the following conditions are

+ * met:

+ *

+ * 1. Redistributions of source code must retain the above copyright

+ * notice, this list of conditions and the following disclaimer.

+ *

+ * 2. Redistributions in binary form must reproduce the above copyright

+ * notice, this list of conditions and the following disclaimer in the

+ * documentation and/or other materials provided with the distribution.

+ *

+ * 3. The end-user documentation included with the redistribution, if

+ * any, must include the following acknowlegement: "This product includes

+ * software developed by CollabNet <http://www.Collab.Net/>."

+ * Alternately, this acknowlegement may appear in the software itself, if

+ * and wherever such third-party acknowlegements normally appear.

+ *

+ * 4. The hosted project names must not be used to endorse or promote

+ * products derived from this software without prior written

+ * permission. For written permission, please contact [email protected].

+ *

+ * 5. Products derived from this software may not use the "Tigris" or

+ * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without

+ * prior written permission of CollabNet.

+ *

+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED

+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF

+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.

+ * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY

+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL

+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE

+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS

+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER

+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR

+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF

+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ *

+ * ====================================================================

+ *

+ * This software consists of voluntary contributions made by many

+ * individuals on behalf of CollabNet.

+ */

 

 /**

- * This class provides the default implementation for the provided notification

- * manager. It just send the notifications by email in the moment they are added.

+ * This class is for backward compatibility. It is only for delegating

+ * functionality to the new scarab notification manager. The preferred

+ * method of utilisation is via configuration. please see

+ * property "scarab.notificationmanager.classname" for further 

+ * information.

+ * <br/>

  * 

  * @author jorgeuriarte

  */

-public class ScarabNotificationManager implements NotificationManager

+public class ScarabNotificationManager extends ScarabNewNotificationManager

 {

-    public static Logger log = Log.get(ScarabNotificationManager.class

-            .getName());

-

-    private static final Integer NOTIFICATION_MANAGER_ID = new Integer(1);

-    public Integer getManagerId()

-    {

-        return NOTIFICATION_MANAGER_ID;

-    }

-    /**

-     * Receives an activitySet from which to generate notification. Current

-     * implementation does only online email sending, with no aggregation or

-     * filtering.

-     */

-    public void addActivityNotification(ActivityType event,

-            ActivitySet activitySet, Issue issue, ScarabUser fromUser)

-    {

-        this.addActivityNotification(

-                event,

-                activitySet,

-                issue,

-                null,

-                null, fromUser);

-    }

-    

-    /**

-     * Long version of the addActivityNotification method, allowing to pass the sets of

-     * users involved as 'To' or 'CC'.

-     */

-    public void addActivityNotification(ActivityType event, ActivitySet activitySet, Issue issue,

-            Set toUsers, Set ccUsers, ScarabUser fromUser)

-    {

-        if (log.isDebugEnabled())

-            log.debug("addActivityNotification: " + issue.getIdPrefix()

-                    + issue.getIssueId() + "-" + event);

-        

-        Attachment activityAttch = null;

-        Set changes = null;

-        try

-        {

-            activityAttch = activitySet.getAttachment();

-            List activityList = activitySet.getActivityList();

-            changes = new HashSet(activityList.size());

-            for (Iterator itr = activityList.iterator(); itr.hasNext();)

-            {

-                Activity activity = (Activity) itr.next();

-                if (activity.getIssue().equals(issue))

-                {

-                    changes.add(activity);

-                }

-            }

-        }

-        catch (Exception e)

-        {

-            log.error("addActivityNotification: Error accessing activityset: "

-                    + e);

-        }

-        EmailContext ectx = new EmailContext();

-        ectx.setIssue(issue);

-        ectx.put("attachment", activityAttch);

-        ectx.put("uniqueActivityDescriptions", changes);

-

-        String template = configureEmailContext(ectx, event, activitySet, issue);

-

-        try

-        {

-            // FIXME: This should really be 'queued', delaying the sending

-            // untill sendPendingNotifications is called

-            this.sendEmail(changes, activityAttch, ectx, issue, activitySet

-                    .getCreator(), toUsers, ccUsers, template);

-        }

-        catch (Exception e)

-        {

-            log.error("addNotification: " + e);

-        }

-    }

-    

-    /**

-     * Does nothing, because this implementation currently send the

-     * notifications online in the moment they are generated calling

-     * addActivityNotification methods.

-     */

-    public void sendPendingNotifications()

-    {

-        log.debug("sendPendingNotifications(): No implementation required.");

-    }

-

-    /**

-     * Decides what templates to use for email, and set needed values in the

-     * context, depending on the event that originated the notification.

-     * 

-     * @param event

-     *            The NotificationEvent originated

-     * @param ectx

-     *            Returned initialized/updated by reference

-     * @return The name of the email template to be used

-     */

-    private String configureEmailContext(EmailContext ectx, ActivityType event,

-            ActivitySet acttivitySet, Issue issue)

-    {

-        String template = null;

-

-        // Select appropiate template depending on the event

-        if (event == ActivityType.USER_ATTRIBUTE_CHANGED)

-        {

-            template = Turbine.getConfiguration().getString(

-                    "scarab.email.assignissue.template",

-                    "ModifyIssue.vm");

-

-            ectx.setSubjectTemplate("AssignIssueModifyIssueSubject.vm");

-        }

-        else if (event == ActivityType.ISSUE_CREATED)

-        {

-            template = Turbine.getConfiguration().getString(

-                    "scarab.email.reportissue.template",

-                    "NewIssueNotification.vm");

-        }

-        else if (event == ActivityType.ISSUE_MOVED || event == ActivityType.ISSUE_COPIED)

-        {

-            template = Turbine.getConfiguration().getString(

-                    "scarab.email.moveissue.template",

-                    "MoveIssue.vm");

-            ectx.setDefaultTextKey("MovedIssueEmailSubject");

-

-            // placed in the context for the email to be able to access them

-            // from within the email template

-            try

-            {

-                Issue newIssue = ((Activity)acttivitySet.getActivitys().get(0)).getIssue();

-                ectx.put("issue", newIssue);

-                ectx.put("module", newIssue.getModule());

-                ectx.setModule(newIssue.getModule());

-                Attachment reason = acttivitySet.getAttachment();

-                ectx.put("reason", (reason == null)?"[no reason provided]":reason.getData());

-                ectx.put("oldModule", issue.getModule());

-                ectx.put("oldIssueType", issue.getIssueType());

-                ectx.put("oldIssue", issue);

-                if (event == ActivityType.ISSUE_COPIED)

-                    ectx.put("action", "copy");

-                else

-                    ectx.put("action", "move");

-            }

-            catch (TorqueException te)

-            {

-                Log.get(this.getClass().getName()).error(

-                        "configureEmailContext: Can't get the issues from activitySet="

-                                + acttivitySet.getActivitySetId());

-            }

-            

-            if (event == ActivityType.ISSUE_COPIED) 

-                ectx.setDefaultTextKey("CopiedIssueEmailSubject");

-            else

-                ectx.setDefaultTextKey("MovedIssueEmailSubject");

-        }

-        else if (event == ActivityType.ATTACHMENT_CREATED)

-        {

-            template = Turbine.getConfiguration().getString(

-                    "scarab.email.modifyissue.template",

-                    "ModifyIssue.vm");

-        }

-        else

-        {

-            /** Rest of cases will use, by default, ModifyIssue.vm * */

-            template = Turbine.getConfiguration().getString(

-                    "scarab.email.modifyissue.template",

-                    "ModifyIssue.vm");

-            ectx.setDefaultTextKey("DefaultModifyIssueEmailSubject");

-        }

-        return template;

-    }

-

-    /**

-     * Sends email to the users associated with the issue. That is associated

-     * with this activitySet. If no subject and template specified, assume

-     * modify issue action. throws Exception

-     * 

-     * @param activityDesc

-     *            Set containing the different descriptions of this activityset

-     * @param attachment

-     *            Attachment of the activityset (if present)

-     * @param context

-     *            Any contextual information for the message.

-     * @param issue

-     *            The issue

-     * @param creator

-     *            The user originating the notification event

-     * @param toUsers

-     * @param ccUsers

-     * @param template

-     *            The name of the velocity template containing the mail text

-     */

-    private void sendEmail(Set activityDesc, Attachment attachment,

-            EmailContext context, Issue issue, ScarabUser creator,

-            Collection toUsers, Collection ccUsers, String template)

-            throws Exception

-    {

-        // add data to context

-

-        if (toUsers == null)

-        {

-            // Then add users who are assigned to "email-to" attributes

-            toUsers = issue.getAllUsersToEmail(AttributePeer.EMAIL_TO);

-        }

-

-        if (ccUsers == null)

-        {

-            // add users to cc field of email

-            ccUsers = issue.getAllUsersToEmail(AttributePeer.CC_TO);

-        }

-

-        String[] replyToUser = issue.getModule().getSystemEmail();

-

-        if (Turbine.getConfiguration().getString("scarab.email.replyto.sender")

-                .equals("true"))

-        {

-            Email.sendEmail(

-                    context,

-                    issue.getModule(),

-                    creator,

-                    creator,

-                    toUsers,

-                    ccUsers,

-                    template);

-        }

-        else

-        {

-            Email.sendEmail(

-                    context,

-                    issue.getModule(),

-                    creator,

-                    replyToUser,

-                    toUsers,

-                    ccUsers,

-                    template);

-        }

-    }

-

+  /**

+   * Important note:

+   * If you want to utilise the old NotificationManager available

+   * before release b21, please customize your properties as:

+   * 

+   * scarab.notificationmanager.classname=tigris.scarab.notification.ScarabOldNotificationManager

+   * 

+   * We recommend to NOT use the old notification manager implementation.

+   * We only keep it for backward compatibility. The old implementation

+   * may be removed in a later release.

+   */

 }


Copied: branches/release/b21/src/java/org/tigris/scarab/notification/ScarabOldNotificationManager.java (from r10202, /branches/release/b21/src/java/org/tigris/scarab/notification/ScarabNotificationManager.java)
Url: http://scarab.tigris.org/source/browse/scarab/branches/release/b21/src/java/org/tigris/scarab/notification/ScarabOldNotificationManager.java?view=diff&rev=10205&p1=/branches/release/b21/src/java/org/tigris/scarab/notification/ScarabNotificationManager.java&p2=branches/release/b21/src/java/org/tigris/scarab/notification/ScarabOldNotificationManager.java&r1=10202&r2=10205
==============================================================================
--- /branches/release/b21/src/java/org/tigris/scarab/notification/ScarabNotificationManager.java	(original)
+++ branches/release/b21/src/java/org/tigris/scarab/notification/ScarabOldNotificationManager.java	2006-07-10 03:31:36-0700
@@ -26,9 +26,9 @@
  * 

  * @author jorgeuriarte

  */

-public class ScarabNotificationManager implements NotificationManager

+public class ScarabOldNotificationManager implements NotificationManager

 {

-    public static Logger log = Log.get(ScarabNotificationManager.class

+    public static Logger log = Log.get(ScarabOldNotificationManager.class

             .getName());

 

     private static final Integer NOTIFICATION_MANAGER_ID = new Integer(1);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.