Wiki source code of TasksNotifications
Last modified by XWikiGuest on 2011/11/08 08:53
Hide last authors
author | version | line-number | content |
---|---|---|---|
1.1 | 1 | ||
2 | import com.xpn.xwiki.*; | ||
3 | import com.xpn.xwiki.notify.*; | ||
4 | import com.xpn.xwiki.doc.*; | ||
5 | import com.xpn.xwiki.api.*; | ||
6 | import java.util.*; | ||
7 | |||
8 | |||
9 | public class ITSNotif implements XWikiActionNotificationInterface { | ||
10 | def context; | ||
11 | def xwiki; | ||
12 | |||
13 | public void setContext(context, xwiki) { | ||
14 | this.context = context; | ||
15 | this.xwiki = xwiki; | ||
16 | } | ||
17 | |||
18 | public void notify(XWikiNotificationRule rule, XWikiDocument doc, String action, XWikiContext context) { | ||
19 | if (action.equals("save")&&doc.getObject("TasksCode.IssueClass")) { | ||
20 | System.out.println("Notify called for " + doc.getFullName() + " for action " + action); | ||
21 | this.context = new com.xpn.xwiki.api.Context(context); | ||
22 | this.xwiki = new com.xpn.xwiki.api.XWiki(context.getWiki(), context); | ||
23 | sendNotification(new com.xpn.xwiki.api.Document(doc, context), "update"); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | public String getUserEmail(String user) { | ||
28 | def userDoc = xwiki.getDocument(user); | ||
29 | userDoc.use("XWiki.XWikiUsers") | ||
30 | return userDoc.getValue("email"); | ||
31 | } | ||
32 | |||
33 | public String getMessage(String key) { | ||
34 | return context.get("msg").get(key); | ||
35 | } | ||
36 | |||
37 | public String getMessage(String key, List params) { | ||
38 | return context.get("msg").get(key, params); | ||
39 | } | ||
40 | |||
41 | public void sendNotification(Document doc, String type) { | ||
42 | doc.use("TasksCode.IssueClass") | ||
43 | String id = doc.display("id"); | ||
44 | String taskTitle = doc.display("title"); | ||
45 | String taskStatus = doc.display("status"); | ||
46 | String taskAssignee = doc.display("assignee"); | ||
47 | String taskReporter = doc.display("reporter"); | ||
48 | String taskURL = doc.getExternalURL(); | ||
49 | String taskDueDate = doc.display("dueDate"); | ||
50 | String taskDesc = doc.getValue("description"); | ||
51 | |||
52 | String sender = getMessage("its_notifications_sender"); | ||
53 | List list = new ArrayList(); | ||
54 | list.add("" + id); | ||
55 | list.add(taskTitle); | ||
56 | list.add(taskURL); | ||
57 | list.add(taskStatus); | ||
58 | list.add(taskAssignee); | ||
59 | list.add(taskReporter); | ||
60 | list.add(taskDueDate); | ||
61 | list.add(taskDesc); | ||
62 | String title = getMessage("its_notifications_" + type + "_title", list); | ||
63 | String content = getMessage("its_notifications_" + type + "_content", list); | ||
64 | String assignee = getUserEmail(doc.getValue("assignee")); | ||
65 | String reporter = getUserEmail(doc.getValue("reporter")); | ||
66 | System.out.println("Ready to send notif email to " + assignee + " and " + reporter + " with title " + title); | ||
67 | |||
68 | xwiki.sendMessage(sender, assignee, "To: " + assignee + xwiki.nl + "Subject: " + title + xwiki.nl + xwiki.nl + content); | ||
69 | if ((!assignee.equals(reporter))&&(!reporter.equals("tasks@xwiki.com"))) { | ||
70 | xwiki.sendMessage(sender, reporter, "To: " + reporter + xwiki.nl + "Subject: " + title + xwiki.nl + xwiki.nl + content); | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | |||
75 | |||
76 |