Source Code Cross Referenced for ScarabOldNotificationManager.java in  » Issue-Tracking » scarab-0.21 » org » tigris » scarab » notification » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Issue Tracking » scarab 0.21 » org.tigris.scarab.notification 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.tigris.scarab.notification;
002:
003:        import java.util.Collection;
004:        import java.util.HashSet;
005:        import java.util.Iterator;
006:        import java.util.Set;
007:        import java.util.List;
008:
009:        import org.apache.log4j.Logger;
010:        import org.apache.torque.TorqueException;
011:        import org.apache.turbine.Turbine;
012:        import org.tigris.scarab.om.Activity;
013:        import org.tigris.scarab.om.ActivitySet;
014:        import org.tigris.scarab.notification.ActivityType;
015:        import org.tigris.scarab.om.Attachment;
016:        import org.tigris.scarab.om.AttributePeer;
017:        import org.tigris.scarab.om.Issue;
018:        import org.tigris.scarab.om.ScarabUser;
019:        import org.tigris.scarab.util.Email;
020:        import org.tigris.scarab.util.EmailContext;
021:        import org.tigris.scarab.util.Log;
022:
023:        /**
024:         * This class provides the default implementation for the provided notification
025:         * manager. It just send the notifications by email in the moment they are added.
026:         * 
027:         * @author jorgeuriarte
028:         */
029:        public class ScarabOldNotificationManager implements 
030:                NotificationManager {
031:            public static Logger log = Log
032:                    .get(ScarabOldNotificationManager.class.getName());
033:
034:            private static final Integer NOTIFICATION_MANAGER_ID = new Integer(
035:                    1);
036:
037:            public Integer getManagerId() {
038:                return NOTIFICATION_MANAGER_ID;
039:            }
040:
041:            /**
042:             * Receives an activitySet from which to generate notification. Current
043:             * implementation does only online email sending, with no aggregation or
044:             * filtering.
045:             */
046:            public void addActivityNotification(ActivityType event,
047:                    ActivitySet activitySet, Issue issue, ScarabUser fromUser) {
048:                this .addActivityNotification(event, activitySet, issue, null,
049:                        null, fromUser);
050:            }
051:
052:            /**
053:             * Long version of the addActivityNotification method, allowing to pass the sets of
054:             * users involved as 'To' or 'CC'.
055:             */
056:            public void addActivityNotification(ActivityType event,
057:                    ActivitySet activitySet, Issue issue, Set toUsers,
058:                    Set ccUsers, ScarabUser fromUser) {
059:                if (log.isDebugEnabled())
060:                    log.debug("addActivityNotification: " + issue.getIdPrefix()
061:                            + issue.getIssueId() + "-" + event);
062:
063:                Attachment activityAttch = null;
064:                Set changes = null;
065:                try {
066:                    activityAttch = activitySet.getAttachment();
067:                    List activityList = activitySet.getActivityList();
068:                    changes = new HashSet(activityList.size());
069:                    for (Iterator itr = activityList.iterator(); itr.hasNext();) {
070:                        Activity activity = (Activity) itr.next();
071:                        if (activity.getIssue().equals(issue)) {
072:                            changes.add(activity);
073:                        }
074:                    }
075:                } catch (Exception e) {
076:                    log
077:                            .error("addActivityNotification: Error accessing activityset: "
078:                                    + e);
079:                }
080:                EmailContext ectx = new EmailContext();
081:                ectx.setIssue(issue);
082:                ectx.put("attachment", activityAttch);
083:                ectx.put("uniqueActivityDescriptions", changes);
084:
085:                String template = configureEmailContext(ectx, event,
086:                        activitySet, issue);
087:
088:                try {
089:                    // FIXME: This should really be 'queued', delaying the sending
090:                    // untill sendPendingNotifications is called
091:                    this .sendEmail(changes, activityAttch, ectx, issue,
092:                            activitySet.getCreator(), toUsers, ccUsers,
093:                            template);
094:                } catch (Exception e) {
095:                    log.error("addNotification: " + e);
096:                }
097:            }
098:
099:            /**
100:             * Does nothing, because this implementation currently send the
101:             * notifications online in the moment they are generated calling
102:             * addActivityNotification methods.
103:             */
104:            public void sendPendingNotifications() {
105:                log
106:                        .debug("sendPendingNotifications(): No implementation required.");
107:            }
108:
109:            /**
110:             * Decides what templates to use for email, and set needed values in the
111:             * context, depending on the event that originated the notification.
112:             * 
113:             * @param event
114:             *            The NotificationEvent originated
115:             * @param ectx
116:             *            Returned initialized/updated by reference
117:             * @return The name of the email template to be used
118:             */
119:            private String configureEmailContext(EmailContext ectx,
120:                    ActivityType event, ActivitySet acttivitySet, Issue issue) {
121:                String template = null;
122:
123:                // Select appropiate template depending on the event
124:                if (event == ActivityType.USER_ATTRIBUTE_CHANGED) {
125:                    template = Turbine.getConfiguration().getString(
126:                            "scarab.email.assignissue.template",
127:                            "ModifyIssue.vm");
128:
129:                    ectx.setSubjectTemplate("AssignIssueModifyIssueSubject.vm");
130:                } else if (event == ActivityType.ISSUE_CREATED) {
131:                    template = Turbine.getConfiguration().getString(
132:                            "scarab.email.reportissue.template",
133:                            "NewIssueNotification.vm");
134:                } else if (event == ActivityType.ISSUE_MOVED
135:                        || event == ActivityType.ISSUE_COPIED) {
136:                    template = Turbine.getConfiguration().getString(
137:                            "scarab.email.moveissue.template", "MoveIssue.vm");
138:                    ectx.setDefaultTextKey("MovedIssueEmailSubject");
139:
140:                    // placed in the context for the email to be able to access them
141:                    // from within the email template
142:                    try {
143:                        Issue newIssue = ((Activity) acttivitySet
144:                                .getActivitys().get(0)).getIssue();
145:                        ectx.put("issue", newIssue);
146:                        ectx.put("module", newIssue.getModule());
147:                        ectx.setModule(newIssue.getModule());
148:                        Attachment reason = acttivitySet.getAttachment();
149:                        ectx.put("reason",
150:                                (reason == null) ? "[no reason provided]"
151:                                        : reason.getData());
152:                        ectx.put("oldModule", issue.getModule());
153:                        ectx.put("oldIssueType", issue.getIssueType());
154:                        ectx.put("oldIssue", issue);
155:                        if (event == ActivityType.ISSUE_COPIED)
156:                            ectx.put("action", "copy");
157:                        else
158:                            ectx.put("action", "move");
159:                    } catch (TorqueException te) {
160:                        Log.get(this .getClass().getName()).error(
161:                                "configureEmailContext: Can't get the issues from activitySet="
162:                                        + acttivitySet.getActivitySetId());
163:                    }
164:
165:                    if (event == ActivityType.ISSUE_COPIED)
166:                        ectx.setDefaultTextKey("CopiedIssueEmailSubject");
167:                    else
168:                        ectx.setDefaultTextKey("MovedIssueEmailSubject");
169:                } else if (event == ActivityType.ATTACHMENT_CREATED) {
170:                    template = Turbine.getConfiguration().getString(
171:                            "scarab.email.modifyissue.template",
172:                            "ModifyIssue.vm");
173:                } else {
174:                    /** Rest of cases will use, by default, ModifyIssue.vm * */
175:                    template = Turbine.getConfiguration().getString(
176:                            "scarab.email.modifyissue.template",
177:                            "ModifyIssue.vm");
178:                    ectx.setDefaultTextKey("DefaultModifyIssueEmailSubject");
179:                }
180:                return template;
181:            }
182:
183:            /**
184:             * Sends email to the users associated with the issue. That is associated
185:             * with this activitySet. If no subject and template specified, assume
186:             * modify issue action. throws Exception
187:             * 
188:             * @param activityDesc
189:             *            Set containing the different descriptions of this activityset
190:             * @param attachment
191:             *            Attachment of the activityset (if present)
192:             * @param context
193:             *            Any contextual information for the message.
194:             * @param issue
195:             *            The issue
196:             * @param creator
197:             *            The user originating the notification event
198:             * @param toUsers
199:             * @param ccUsers
200:             * @param template
201:             *            The name of the velocity template containing the mail text
202:             */
203:            private void sendEmail(Set activityDesc, Attachment attachment,
204:                    EmailContext context, Issue issue, ScarabUser creator,
205:                    Collection toUsers, Collection ccUsers, String template)
206:                    throws Exception {
207:                // add data to context
208:
209:                if (toUsers == null) {
210:                    // Then add users who are assigned to "email-to" attributes
211:                    toUsers = issue.getAllUsersToEmail(AttributePeer.EMAIL_TO);
212:                }
213:
214:                if (ccUsers == null) {
215:                    // add users to cc field of email
216:                    ccUsers = issue.getAllUsersToEmail(AttributePeer.CC_TO);
217:                }
218:
219:                String[] replyToUser = issue.getModule().getSystemEmail();
220:
221:                if (Turbine.getConfiguration().getString(
222:                        "scarab.email.replyto.sender").equals("true")) {
223:                    Email.sendEmail(context, issue.getModule(), creator,
224:                            creator, toUsers, ccUsers, template);
225:                } else {
226:                    Email.sendEmail(context, issue.getModule(), creator,
227:                            replyToUser, toUsers, ccUsers, template);
228:                }
229:            }
230:
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.