001: // ================================================================
002: // Copyright (c) 2000-2005 CollabNet. All rights reserved.
003: //
004: // Redistribution and use in source and binary forms, with or without
005: // modification, are permitted provided that the following conditions are
006: // met:
007: //
008: // 1. Redistributions of source code must retain the above copyright
009: // notice, this list of conditions and the following disclaimer.
010: //
011: // 2. Redistributions in binary form must reproduce the above copyright
012: // notice, this list of conditions and the following disclaimer in the
013: // documentation and/or other materials provided with the distribution.
014: //
015: // 3. The end-user documentation included with the redistribution, if
016: // any, must include the following acknowlegement: "This product includes
017: // software developed by Collab.Net <http://www.Collab.Net/>."
018: // Alternately, this acknowlegement may appear in the software itself, if
019: // and wherever such third-party acknowlegements normally appear.
020: //
021: // 4. The hosted project names must not be used to endorse or promote
022: // products derived from this software without prior written
023: // permission. For written permission, please contact info@collab.net.
024: //
025: // 5. Products derived from this software may not use the "Tigris" or
026: // "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
027: // prior written permission of Collab.Net.
028: //
029: // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
030: // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
031: // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
032: // IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
033: // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
034: // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
035: // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
036: // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
037: // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
038: // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
039: // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
040: //
041: // ====================================================================
042: //
043: // This software consists of voluntary contributions made by many
044: // individuals on behalf of Collab.Net.
045:
046: package org.tigris.scarab.om;
047:
048: import org.apache.torque.Torque;
049: import org.apache.torque.TorqueException;
050: import org.apache.torque.om.ObjectKey;
051: import org.apache.torque.om.Persistent;
052: import org.tigris.scarab.notification.ActivityType;
053: import org.tigris.scarab.notification.NotificationManagerFactory;
054: import org.tigris.scarab.tools.localization.L10NKeySet;
055: import org.tigris.scarab.util.ScarabException;
056: import org.tigris.scarab.util.build.l10nchecker.L10nKey;
057:
058: /**
059: * This class manages NotificationFilter objects.
060: * The skeleton for this class was autogenerated by Torque * You should add additional methods to this class to meet the
061: * application requirements. This class will only be generated as
062: * long as it does not already exist in the output directory.
063: */
064: public class NotificationFilterManager extends
065: BaseNotificationFilterManager {
066: /**
067: * Creates a new <code>NotificationFilterManager</code> instance.
068: *
069: * @exception TorqueException if an error occurs
070: */
071: public NotificationFilterManager() throws TorqueException {
072: super ();
073: }
074:
075: public static NotificationFilter getNotificationFilter(
076: NotificationStatus notif) throws ScarabException {
077: NotificationFilter filter = null;
078: try {
079: Long issueId = notif.getIssueId();
080: Issue issue = IssueManager.getInstance(issueId);
081: Integer moduleId = issue.getModuleId();
082: Integer userId = notif.getReceiverId();
083: ActivityType activityType = notif.getActivityType();
084: filter = getNotificationFilter(moduleId, userId,
085: activityType.getCode());
086: } catch (TorqueException te) {
087: throw new ScarabException(
088: L10NKeySet.ExceptionTorqueGeneric, te);
089: }
090: return filter;
091: }
092:
093: public static NotificationFilter getNotificationFilter(
094: Integer moduleId, Integer userId, String activityType)
095: throws ScarabException {
096: NotificationFilter filter = null;
097:
098: try {
099: filter = NotificationFilter.createDefaultFilter(moduleId,
100: userId, NotificationManagerFactory.getInstance()
101: .getManagerId(), ActivityType
102: .getActivityType(activityType));
103: } catch (TorqueException te) {
104: throw new ScarabException(
105: L10NKeySet.ExceptionTorqueGeneric, te);
106: }
107:
108: ObjectKey pk = filter.getPrimaryKey();
109: NotificationFilter result;
110: try {
111: result = NotificationFilterManager.getInstance(pk);
112: if (result == null) {
113: result = filter;
114: }
115: } catch (Exception e) {
116: result = filter;
117: }
118:
119: return result;
120: }
121:
122: /**
123: * determines whether user has enabled notifications for given activityType
124: * in given module.
125: * @param user
126: * @param act
127: * @return
128: * @throws ScarabException
129: */
130: public static boolean isNotificationEnabledFor(Integer moduleId,
131: Integer userId, boolean isSelf, String activityType)
132: throws ScarabException {
133: NotificationFilter filter = getNotificationFilter(moduleId,
134: userId, activityType);
135: boolean result;
136: if (isSelf) {
137: result = filter.getSendSelf();
138: } else {
139: result = filter.getFilterState();
140: }
141: return result;
142: }
143:
144: }
|