TasksNotifications
import com.xpn.xwiki.*; import com.xpn.xwiki.notify.*; import com.xpn.xwiki.doc.*; import com.xpn.xwiki.api.*; import java.util.*;
public class ITSNotif implements XWikiActionNotificationInterface { def context; def xwiki;
public void setContext(context, xwiki) { this.context = context; this.xwiki = xwiki; }
public void notify(XWikiNotificationRule rule, XWikiDocument doc, String action, XWikiContext context) { if (action.equals("save")&&doc.getObject("TasksCode.IssueClass")) { System.out.println("Notify called for " + doc.getFullName() + " for action " + action); this.context = new com.xpn.xwiki.api.Context(context); this.xwiki = new com.xpn.xwiki.api.XWiki(context.getWiki(), context); sendNotification(new com.xpn.xwiki.api.Document(doc, context), "update"); } }
public String getUserEmail(String user) { def userDoc = xwiki.getDocument(user); userDoc.use("XWiki.XWikiUsers") return userDoc.getValue("email"); }
public String getMessage(String key) { return context.get("msg").get(key); }
public String getMessage(String key, List params) { return context.get("msg").get(key, params); }
public void sendNotification(Document doc, String type) { doc.use("TasksCode.IssueClass") String id = doc.display("id"); String taskTitle = doc.display("title"); String taskStatus = doc.display("status"); String taskAssignee = doc.display("assignee"); String taskReporter = doc.display("reporter"); String taskURL = doc.getExternalURL(); String taskDueDate = doc.display("dueDate"); String taskDesc = doc.getValue("description");
String sender = getMessage("its_notifications_sender"); List list = new ArrayList(); list.add("" + id); list.add(taskTitle); list.add(taskURL); list.add(taskStatus); list.add(taskAssignee); list.add(taskReporter); list.add(taskDueDate); list.add(taskDesc); String title = getMessage("its_notifications_" + type + "_title", list); String content = getMessage("its_notifications_" + type + "_content", list); String assignee = getUserEmail(doc.getValue("assignee")); String reporter = getUserEmail(doc.getValue("reporter")); System.out.println("Ready to send notif email to " + assignee + " and " + reporter + " with title " + title); xwiki.sendMessage(sender, assignee, "To: " + assignee + xwiki.nl + "Subject: " + title + xwiki.nl + xwiki.nl + content); if ((!assignee.equals(reporter))&&(!reporter.equals("tasks@xwiki.com"))) { xwiki.sendMessage(sender, reporter, "To: " + reporter + xwiki.nl + "Subject: " + title + xwiki.nl + xwiki.nl + content); } } }