From 51fa610039ba157afa9fa3436bec998e9d0ac129 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 18 Apr 2013 14:33:45 +0000 Subject: [PATCH] also commented notification added git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@73617 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../server/CommentNotificationsThread.java | 66 +++++++++++++++++++ ...read.java => LikeNotificationsThread.java} | 8 +-- .../user/newsfeed/server/NewsServiceImpl.java | 13 ++-- 3 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/newsfeed/server/CommentNotificationsThread.java rename src/main/java/org/gcube/portlets/user/newsfeed/server/{NotificationsThread.java => LikeNotificationsThread.java} (66%) diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/server/CommentNotificationsThread.java b/src/main/java/org/gcube/portlets/user/newsfeed/server/CommentNotificationsThread.java new file mode 100644 index 0000000..74b3e4c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/newsfeed/server/CommentNotificationsThread.java @@ -0,0 +1,66 @@ +package org.gcube.portlets.user.newsfeed.server; + +import java.util.HashSet; +import java.util.List; + +import org.gcube.applicationsupportlayer.social.NotificationsManager; +import org.gcube.common.core.utils.logging.GCUBEClientLog; +import org.gcube.portal.databook.server.DatabookStore; +import org.gcube.portal.databook.shared.Comment; +import org.gcube.vomanagement.usermanagement.UserManager; +import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager; + +/** + * + * @author Massimiliano Assante ISTI-CNR + * + */ +public class CommentNotificationsThread implements Runnable { + private static GCUBEClientLog _log = new GCUBEClientLog(CommentNotificationsThread.class); + + String commenterUserId; + String commentedFeedId; + private String commentText; + private String feedOwnerId; + private NotificationsManager nm; + private HashSet userIdsToNotify; + + + public CommentNotificationsThread(DatabookStore storeInstance, String commenterUserId, String commentedFeedId, String commentText, NotificationsManager nm, String feedOwnerId) { + super(); + this.nm = nm; + this.commenterUserId = commenterUserId; + this.commentedFeedId = commentedFeedId; + this.commentText = commentText; + this.feedOwnerId = feedOwnerId; + + userIdsToNotify = new HashSet(); + List feedComments = storeInstance.getAllCommentByFeed(commentedFeedId); + for (Comment comment : feedComments) { + if (comment.getUserid().compareTo(commenterUserId) != 0) { + userIdsToNotify.add(comment.getUserid()); + } + } + + //clean + //this.comments = comments; + } + + @Override + public void run() { + String feedOwnerFullName = ""; + UserManager um = new LiferayUserManager(); + try { + feedOwnerFullName = um.getUserByScreenName(feedOwnerId).getFullname(); + } catch (Exception e) { + feedOwnerFullName = feedOwnerId; + } + if (userIdsToNotify != null) { + for (String userId : userIdsToNotify) { + boolean result = nm.notifyCommentReply(userId, commentedFeedId, commentText, feedOwnerFullName); + _log.trace("Sending Notification for also commented to: " + feedOwnerFullName + " result?"+ result); + } + } + + } +} diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/server/NotificationsThread.java b/src/main/java/org/gcube/portlets/user/newsfeed/server/LikeNotificationsThread.java similarity index 66% rename from src/main/java/org/gcube/portlets/user/newsfeed/server/NotificationsThread.java rename to src/main/java/org/gcube/portlets/user/newsfeed/server/LikeNotificationsThread.java index e1e9568..0f0bd0a 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/server/NotificationsThread.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/server/LikeNotificationsThread.java @@ -11,15 +11,15 @@ import org.gcube.portal.databook.shared.Like; * @author Massimiliano Assante ISTI-CNR * */ -public class NotificationsThread implements Runnable { - private static GCUBEClientLog _log = new GCUBEClientLog(NotificationsThread.class); +public class LikeNotificationsThread implements Runnable { + private static GCUBEClientLog _log = new GCUBEClientLog(LikeNotificationsThread.class); private String commentText; private NotificationsManager nm; private ArrayList likes; - public NotificationsThread(String commentText, NotificationsManager nm, ArrayList likes) { + public LikeNotificationsThread(String commentText, NotificationsManager nm, ArrayList likes) { super(); this.commentText = commentText; this.nm = nm; @@ -29,7 +29,7 @@ public class NotificationsThread implements Runnable { @Override public void run() { for (Like fav : likes) { - boolean result = nm.notifyCommentReply(fav.getUserid(), fav.getFeedid(), commentText); + boolean result = nm.notifyCommentOnFavorite(fav.getUserid(), fav.getFeedid(), commentText); _log.trace("Sending Notification for favorited post comment added to: " + fav.getFullName() + " result?"+ result); } diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java index 46c52a9..b22c3ab 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java @@ -94,9 +94,9 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); if (user == null) { _log.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL"); - //user = "test.user"; - user = "massimiliano.assante"; - SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE"); + user = "test.user"; +// user = "massimiliano.assante"; +// SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE"); } else { withinPortal = true; @@ -310,6 +310,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService ArrayList OrganizationFeeds = (ArrayList) store.getRecentFeedsByVRE("/gcube/devsec/devVRE", 5); for (Feed feed : OrganizationFeeds) { feedsMap.put(feed.getKey(), feed); + _log.trace("Reading desc: " + feed.getDescription()); } if (! onlyConnections) { @@ -416,9 +417,13 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService if (! user.getUsername().equals(feedOwnerId) && (!isAppFeed)) { boolean result = nm.notifyOwnCommentReply(feedOwnerId, feedid, escapeHtml(commentText)); _log.trace("Comment Notification to post owner added? " + result); + } else if (!isAppFeed) { + //notify the other users who commented this post + Thread thread = new Thread(new CommentNotificationsThread(store, user.getUsername(), comment.getFeedid(), commentText, nm, feedOwnerId)); + thread.start(); } //if there are other users who liked this post they get notified too, asynchronously with this thread - Thread thread = new Thread(new NotificationsThread(commentText, nm, getAllLikesByFeed(feedid))); + Thread thread = new Thread(new LikeNotificationsThread(commentText, nm, getAllLikesByFeed(feedid))); thread.start(); } return comment;