"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main/java/com/openkm/module/common/CommonNotificationModule.java" between
OpenKM-document-management-system-6.3.10.tar.gz and OpenKM-document-management-system-6.3.11.tar.gz

About: OpenKM (Knowledge Management) is a document management system that allows easy management of documents, users, roles and finding your enterprise documents and records. Community version (source code).

CommonNotificationModule.java  (OpenKM-document-management-system-6.3.10):CommonNotificationModule.java  (OpenKM-document-management-system-6.3.11)
skipping to change at line 33 skipping to change at line 33
import com.openkm.core.*; import com.openkm.core.*;
import com.openkm.dao.TwitterAccountDAO; import com.openkm.dao.TwitterAccountDAO;
import com.openkm.dao.bean.TwitterAccount; import com.openkm.dao.bean.TwitterAccount;
import com.openkm.util.MailUtils; import com.openkm.util.MailUtils;
import com.openkm.util.PathUtils; import com.openkm.util.PathUtils;
import com.openkm.util.TemplateUtils; import com.openkm.util.TemplateUtils;
import freemarker.template.Configuration; import freemarker.template.Configuration;
import freemarker.template.Template; import freemarker.template.Template;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
import org.apache.commons.httpclient.HttpException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import twitter4j.Twitter; import twitter4j.Twitter;
import twitter4j.TwitterException; import twitter4j.TwitterException;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.*; import java.util.*;
public class CommonNotificationModule { public class CommonNotificationModule {
private static Logger log = LoggerFactory.getLogger(CommonNotificationMod ule.class); private static final Logger log = LoggerFactory.getLogger(CommonNotificat ionModule.class);
/** /**
* Clean preview cache for this document * Clean preview cache for this document
*/ */
public static void sendNotification(String user, String nodeUuid, String nodePath, String from, List<String> to, String message, public static void sendNotification(String user, String nodeUuid, String nodePath, String from, List<String> to, String message,
boolean attachment) throws TemplateEx boolean attachment) throws TemplateException, MessagingEx
ception, MessagingException, PathNotFoundException, AccessDeniedException, ception, PathNotFoundException, AccessDeniedException,
RepositoryException, DatabaseException, IOException { RepositoryException, DatabaseException, IOException, Lock
log.debug("sendNotification({}, {}, {}, {}, {}, {}, {})", new Obj Exception {
ect[]{user, nodeUuid, nodePath, from, to, message, attachment}); log.debug("sendNotification({}, {}, {}, {}, {}, {}, {})", user, n
ArrayList<CommonNotificationModule.NodeInfo> nodesInfo = new Arra odeUuid, nodePath, from, to, message, attachment);
yList<CommonNotificationModule.NodeInfo>(); ArrayList<CommonNotificationModule.NodeInfo> nodesInfo = new Arra
yList<>();
CommonNotificationModule.NodeInfo nodeInfo = new NodeInfo(); CommonNotificationModule.NodeInfo nodeInfo = new NodeInfo();
nodeInfo.setUuid(nodeUuid); nodeInfo.setUuid(nodeUuid);
nodeInfo.setPath(nodePath); nodeInfo.setPath(nodePath);
nodesInfo.add(nodeInfo); nodesInfo.add(nodeInfo);
sendNotification(user, nodesInfo, from, to, message, attachment); sendNotification(user, nodesInfo, from, to, message, attachment);
} }
public static void sendNotification(String user, ArrayList<CommonNotifica tionModule.NodeInfo> nodesInfo, String from, List<String> to, public static void sendNotification(String user, ArrayList<CommonNotifica tionModule.NodeInfo> nodesInfo, String from, List<String> to,
String message, boolean attachment) t String message, boolean attachment) throws TemplateExcept
hrows TemplateException, MessagingException, PathNotFoundException, AccessDenied ion, MessagingException, PathNotFoundException, AccessDeniedException,
Exception, RepositoryException, DatabaseException, IOException, Lock
RepositoryException, DatabaseException, IOException { Exception {
log.debug("sendNotification({}, {}, {}, {}, {}, {})", new Object[ log.debug("sendNotification({}, {}, {}, {}, {}, {})", user, nodes
]{user, nodesInfo, from, to, message, attachment}); Info, from, to, message, attachment);
StringWriter swSubject = new StringWriter(); StringWriter swSubject = new StringWriter();
StringWriter swBody = new StringWriter(); StringWriter swBody = new StringWriter();
Configuration cfg = TemplateUtils.getConfig(); Configuration cfg = TemplateUtils.getConfig();
List<String> docsPath = new ArrayList<String>(); List<String> docsPath = new ArrayList<>();
Collection<Map<String, String>> col = new ArrayList<Map<String, S Collection<Map<String, String>> col = new ArrayList<>();
tring>>();
for (CommonNotificationModule.NodeInfo ni : nodesInfo) { for (CommonNotificationModule.NodeInfo ni : nodesInfo) {
Map<String, String> docInfo = new HashMap<String, String> (); Map<String, String> docInfo = new HashMap<>();
docInfo.put("url", Config.APPLICATION_URL + "?uuid=" + ni .getUuid()); docInfo.put("url", Config.APPLICATION_URL + "?uuid=" + ni .getUuid());
docInfo.put("path", ni.getPath()); docInfo.put("path", ni.getPath());
docInfo.put("name", PathUtils.getName(ni.getPath())); docInfo.put("name", PathUtils.getName(ni.getPath()));
col.add(docInfo); col.add(docInfo);
// Used to send attachments // Used to send attachments
docsPath.add(ni.getPath()); docsPath.add(ni.getPath());
} }
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<>();
model.put("userId", user); model.put("userId", user);
model.put("notificationMessage", message); model.put("notificationMessage", message);
model.put("documentList", col); model.put("documentList", col);
if (TemplateUtils.templateExists(Config.NOTIFICATION_MESSAGE_SUBJ ECT)) { if (TemplateUtils.templateExists(Config.NOTIFICATION_MESSAGE_SUBJ ECT)) {
Template tpl = cfg.getTemplate(Config.NOTIFICATION_MESSAG E_SUBJECT); Template tpl = cfg.getTemplate(Config.NOTIFICATION_MESSAG E_SUBJECT);
tpl.process(model, swSubject); tpl.process(model, swSubject);
} else { } else {
StringReader sr = new StringReader(Config.NOTIFICATION_ME SSAGE_SUBJECT); StringReader sr = new StringReader(Config.NOTIFICATION_ME SSAGE_SUBJECT);
Template tpl = new Template("NotificationMessageSubject", sr, cfg); Template tpl = new Template("NotificationMessageSubject", sr, cfg);
skipping to change at line 111 skipping to change at line 110
Template tpl = cfg.getTemplate(Config.NOTIFICATION_MESSAG E_BODY); Template tpl = cfg.getTemplate(Config.NOTIFICATION_MESSAG E_BODY);
tpl.process(model, swBody); tpl.process(model, swBody);
} else { } else {
StringReader sr = new StringReader(Config.NOTIFICATION_ME SSAGE_BODY); StringReader sr = new StringReader(Config.NOTIFICATION_ME SSAGE_BODY);
Template tpl = new Template("NotificationMessageBody", sr , cfg); Template tpl = new Template("NotificationMessageBody", sr , cfg);
tpl.process(model, swBody); tpl.process(model, swBody);
sr.close(); sr.close();
} }
if (attachment) { if (attachment) {
MailUtils.sendDocuments((String) from, to, swSubject.toSt ring(), swBody.toString(), docsPath); MailUtils.sendDocuments(from, to, swSubject.toString(), s wBody.toString(), docsPath);
} else { } else {
MailUtils.sendMessage((String) from, to, swSubject.toStri ng(), swBody.toString()); MailUtils.sendMessage(from, to, swSubject.toString(), swB ody.toString());
} }
} }
/** /**
* send mail Proposed Subscription * send mail Proposed Subscription
*/ */
public static void sendProposedSubscription(String user, ArrayList<Common NotificationModule.NodeInfo> nodesInfo, String from, public static void sendProposedSubscription(String user, ArrayList<Common NotificationModule.NodeInfo> nodesInfo, String from,
List<String> to, String comme nt) throws TemplateException, MessagingException, PathNotFoundException, AccessD eniedException, List<String> to, String comment) throws TemplateException , MessagingException, PathNotFoundException, AccessDeniedException,
RepositoryException, DatabaseException, IOException { RepositoryException, DatabaseException, IOException {
log.debug("sendProposedSubscription({}, {}, {}, {}, {})", new Obj ect[]{user, nodesInfo, from, to, comment}); log.debug("sendProposedSubscription({}, {}, {}, {}, {})", user, n odesInfo, from, to, comment);
StringWriter swSubject = new StringWriter(); StringWriter swSubject = new StringWriter();
StringWriter swBody = new StringWriter(); StringWriter swBody = new StringWriter();
Configuration cfg = TemplateUtils.getConfig(); Configuration cfg = TemplateUtils.getConfig();
List<String> docsPath = new ArrayList<String>(); List<String> docsPath = new ArrayList<>();
Collection<Map<String, String>> col = new ArrayList<Map<String, S Collection<Map<String, String>> col = new ArrayList<>();
tring>>();
for (CommonNotificationModule.NodeInfo ni : nodesInfo) { for (CommonNotificationModule.NodeInfo ni : nodesInfo) {
Map<String, String> docInfo = new HashMap<String, String> (); Map<String, String> docInfo = new HashMap<>();
docInfo.put("url", Config.APPLICATION_URL + "?uuid=" + ni .getUuid()); docInfo.put("url", Config.APPLICATION_URL + "?uuid=" + ni .getUuid());
docInfo.put("path", ni.getPath()); docInfo.put("path", ni.getPath());
docInfo.put("name", PathUtils.getName(ni.getPath())); docInfo.put("name", PathUtils.getName(ni.getPath()));
col.add(docInfo); col.add(docInfo);
// Used to send attachments // Used to send attachments
docsPath.add(ni.getPath()); docsPath.add(ni.getPath());
} }
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<>();
model.put("userId", user); model.put("userId", user);
model.put("proposedSubscriptionComment", comment); model.put("proposedSubscriptionComment", comment);
model.put("documentList", col); model.put("documentList", col);
if (TemplateUtils.templateExists(Config.PROPOSED_SUBSCRIPTION_MES SAGE_SUBJECT)) { if (TemplateUtils.templateExists(Config.PROPOSED_SUBSCRIPTION_MES SAGE_SUBJECT)) {
Template tpl = cfg.getTemplate(Config.PROPOSED_SUBSCRIPTI ON_MESSAGE_SUBJECT); Template tpl = cfg.getTemplate(Config.PROPOSED_SUBSCRIPTI ON_MESSAGE_SUBJECT);
tpl.process(model, swSubject); tpl.process(model, swSubject);
} else { } else {
StringReader sr = new StringReader(Config.PROPOSED_SUBSCR IPTION_MESSAGE_SUBJECT); StringReader sr = new StringReader(Config.PROPOSED_SUBSCR IPTION_MESSAGE_SUBJECT);
Template tpl = new Template("ProposedSubscriptionMessageS ubject", sr, cfg); Template tpl = new Template("ProposedSubscriptionMessageS ubject", sr, cfg);
skipping to change at line 166 skipping to change at line 165
if (TemplateUtils.templateExists(Config.PROPOSED_SUBSCRIPTION_MES SAGE_BODY)) { if (TemplateUtils.templateExists(Config.PROPOSED_SUBSCRIPTION_MES SAGE_BODY)) {
Template tpl = cfg.getTemplate(Config.PROPOSED_SUBSCRIPTI ON_MESSAGE_BODY); Template tpl = cfg.getTemplate(Config.PROPOSED_SUBSCRIPTI ON_MESSAGE_BODY);
tpl.process(model, swBody); tpl.process(model, swBody);
} else { } else {
StringReader sr = new StringReader(Config.PROPOSED_SUBSCR IPTION_MESSAGE_BODY); StringReader sr = new StringReader(Config.PROPOSED_SUBSCR IPTION_MESSAGE_BODY);
Template tpl = new Template("ProposedSubscriptionMessageB ody", sr, cfg); Template tpl = new Template("ProposedSubscriptionMessageB ody", sr, cfg);
tpl.process(model, swBody); tpl.process(model, swBody);
sr.close(); sr.close();
} }
MailUtils.sendMessage((String) from, to, swSubject.toString(), sw Body.toString()); MailUtils.sendMessage(from, to, swSubject.toString(), swBody.toSt ring());
} }
/** /**
* Send mail subscription message * Send mail subscription message
*/ */
public static void sendMailSubscription(String user, String nodeUuid, Str ing nodePath, String eventType, String comment, public static void sendMailSubscription(String user, String nodeUuid, Str ing nodePath, String eventType, String comment,
Set<String> mails) throws Templat Set<String> mails) throws TemplateException, MessagingException,
eException, MessagingException, IOException { IOException {
log.debug("sendMailSubscription({}, {}, {}, {}, {}, {})", new Obj log.debug("sendMailSubscription({}, {}, {}, {}, {}, {})", user, n
ect[]{user, nodeUuid, nodePath, eventType, comment, mails}); odeUuid, nodePath, eventType, comment, mails);
if (comment == null) { if (comment == null) {
comment = ""; comment = "";
} }
StringWriter swSubject = new StringWriter(); StringWriter swSubject = new StringWriter();
StringWriter swBody = new StringWriter(); StringWriter swBody = new StringWriter();
Configuration cfg = TemplateUtils.getConfig(); Configuration cfg = TemplateUtils.getConfig();
Map<String, String> model = new HashMap<String, String>(); Map<String, String> model = new HashMap<>();
model.put("documentUrl", Config.APPLICATION_URL + "?uuid=" + node Uuid); model.put("documentUrl", Config.APPLICATION_URL + "?uuid=" + node Uuid);
model.put("documentPath", nodePath); model.put("documentPath", nodePath);
model.put("documentName", PathUtils.getName(nodePath)); model.put("documentName", PathUtils.getName(nodePath));
model.put("userId", user); model.put("userId", user);
model.put("eventType", eventType); model.put("eventType", eventType);
model.put("subscriptionComment", comment); model.put("subscriptionComment", comment);
if (TemplateUtils.templateExists(Config.SUBSCRIPTION_MESSAGE_SUBJ ECT)) { if (TemplateUtils.templateExists(Config.SUBSCRIPTION_MESSAGE_SUBJ ECT)) {
Template tpl = cfg.getTemplate(Config.SUBSCRIPTION_MESSAG E_SUBJECT); Template tpl = cfg.getTemplate(Config.SUBSCRIPTION_MESSAG E_SUBJECT);
tpl.process(model, swSubject); tpl.process(model, swSubject);
skipping to change at line 219 skipping to change at line 218
sr.close(); sr.close();
} }
MailUtils.sendMessage(mails, swSubject.toString(), swBody.toStrin g()); MailUtils.sendMessage(mails, swSubject.toString(), swBody.toStrin g());
} }
/** /**
* Send twitter subscription message * Send twitter subscription message
*/ */
public static void sendTwitterSubscription(String user, String nodePath, String eventType, String comment, Set<String> users) public static void sendTwitterSubscription(String user, String nodePath, String eventType, String comment, Set<String> users)
throws TemplateException, TwitterException, DatabaseExcep throws TemplateException, TwitterException, DatabaseExcep
tion, HttpException, IOException { tion, IOException {
log.debug("sendTwitterSubscription({}, {}, {}, {}, {})", new Obje log.debug("sendTwitterSubscription({}, {}, {}, {}, {})", user, no
ct[]{user, nodePath, eventType, comment, users}); dePath, eventType, comment, users);
Twitter twitter = new Twitter(Config.SUBSCRIPTION_TWITTER_USER, C onfig.SUBSCRIPTION_TWITTER_PASSWORD); Twitter twitter = new Twitter(Config.SUBSCRIPTION_TWITTER_USER, C onfig.SUBSCRIPTION_TWITTER_PASSWORD);
StringWriter swStatus = new StringWriter(); StringWriter swStatus = new StringWriter();
Configuration cfg = TemplateUtils.getConfig(); Configuration cfg = TemplateUtils.getConfig();
Map<String, String> model = new HashMap<String, String>(); Map<String, String> model = new HashMap<>();
model.put("documentUrl", MailUtils.getTinyUrl(Config.APPLICATION_ URL + "?docPath=" + nodePath)); model.put("documentUrl", MailUtils.getTinyUrl(Config.APPLICATION_ URL + "?docPath=" + nodePath));
model.put("documentPath", nodePath); model.put("documentPath", nodePath);
model.put("documentName", PathUtils.getName(nodePath)); model.put("documentName", PathUtils.getName(nodePath));
model.put("userId", user); model.put("userId", user);
model.put("eventType", eventType); model.put("eventType", eventType);
model.put("subscriptionComment", comment); model.put("subscriptionComment", comment);
if (TemplateUtils.templateExists(Config.SUBSCRIPTION_TWITTER_STAT US)) { if (TemplateUtils.templateExists(Config.SUBSCRIPTION_TWITTER_STAT US)) {
Template tpl = cfg.getTemplate(Config.SUBSCRIPTION_TWITTE R_STATUS); Template tpl = cfg.getTemplate(Config.SUBSCRIPTION_TWITTE R_STATUS);
tpl.process(model, swStatus); tpl.process(model, swStatus);
skipping to change at line 249 skipping to change at line 248
tpl.process(model, swStatus); tpl.process(model, swStatus);
sr.close(); sr.close();
} }
for (Iterator<String> itUsers = users.iterator(); itUsers.hasNext (); ) { for (Iterator<String> itUsers = users.iterator(); itUsers.hasNext (); ) {
String itUser = itUsers.next(); String itUser = itUsers.next();
Collection<TwitterAccount> twitterAccounts = TwitterAccou ntDAO.findByUser(itUser, true); Collection<TwitterAccount> twitterAccounts = TwitterAccou ntDAO.findByUser(itUser, true);
for (Iterator<TwitterAccount> itTwitter = twitterAccounts .iterator(); itTwitter.hasNext(); ) { for (Iterator<TwitterAccount> itTwitter = twitterAccounts .iterator(); itTwitter.hasNext(); ) {
TwitterAccount ta = itTwitter.next(); TwitterAccount ta = itTwitter.next();
log.info("Twitter Notify from {} to {} ({}) - {}" log.info("Twitter Notify from {} to {} ({}) - {}"
, new Object[]{twitter.getUserId(), ta.getTwitterUser(), itUser, , twitter.getUserId(), ta.getTwitterUser(), itUser, swStatus);
swStatus.toString()});
twitter.sendDirectMessage(ta.getTwitterUser(), sw Status.toString()); twitter.sendDirectMessage(ta.getTwitterUser(), sw Status.toString());
} }
} }
} }
public static final class NodeInfo implements Serializable { public static final class NodeInfo implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String uuid; private String uuid;
private String path; private String path;
 End of changes. 20 change blocks. 
43 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)