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
This commit is contained in:
parent
64de50b635
commit
51fa610039
|
@ -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<String> 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<String>();
|
||||
List<Comment> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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<Like> likes;
|
||||
|
||||
|
||||
public NotificationsThread(String commentText, NotificationsManager nm, ArrayList<Like> likes) {
|
||||
public LikeNotificationsThread(String commentText, NotificationsManager nm, ArrayList<Like> 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);
|
||||
}
|
||||
|
|
@ -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<Feed> OrganizationFeeds = (ArrayList<Feed>) 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;
|
||||
|
|
Loading…
Reference in New Issue