|
|
|
@ -2,18 +2,26 @@ package org.gcube.portal.socialmail;
|
|
|
|
|
|
|
|
|
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.security.GeneralSecurityException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
import javax.mail.Address;
|
|
|
|
|
import javax.mail.BodyPart;
|
|
|
|
|
import javax.mail.Flags;
|
|
|
|
|
import javax.mail.Folder;
|
|
|
|
|
import javax.mail.Message;
|
|
|
|
|
import javax.mail.MessagingException;
|
|
|
|
|
import javax.mail.Multipart;
|
|
|
|
|
import javax.mail.NoSuchProviderException;
|
|
|
|
|
import javax.mail.Session;
|
|
|
|
|
import javax.mail.Store;
|
|
|
|
|
import javax.mail.internet.InternetAddress;
|
|
|
|
|
import javax.mail.internet.MimeMessage.RecipientType;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
|
@ -26,52 +34,34 @@ import org.gcube.applicationsupportlayer.social.mailing.AppType;
|
|
|
|
|
import org.gcube.applicationsupportlayer.social.mailing.SocialMailingUtil;
|
|
|
|
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
|
|
|
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
|
|
|
|
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
|
import org.gcube.common.authorization.library.provider.UserInfo;
|
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
import org.gcube.portal.databook.server.DatabookStore;
|
|
|
|
|
import org.gcube.portal.databook.shared.Comment;
|
|
|
|
|
import org.gcube.portal.databook.shared.Feed;
|
|
|
|
|
import org.gcube.portal.databook.shared.Like;
|
|
|
|
|
import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
|
|
|
|
|
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
|
|
|
|
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
|
|
|
|
|
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
|
|
|
|
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
|
|
|
|
import org.gcube.common.storagehub.client.proxies.MessageManagerClient;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.IdNotFoundException;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
|
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.shared.Post;
|
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.shared.Like;
|
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.ColumnNameNotFoundException;
|
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PostIDNotFoundException;
|
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PostTypeNotFoundException;
|
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PrivacyLevelTypeNotFoundException;
|
|
|
|
|
import org.gcube.portal.notifications.bean.GenericItemBean;
|
|
|
|
|
import org.gcube.portal.notifications.thread.CommentNotificationsThread;
|
|
|
|
|
import org.gcube.portal.notifications.thread.LikeNotificationsThread;
|
|
|
|
|
import org.gcube.portal.notifications.thread.MessageNotificationsThread;
|
|
|
|
|
import org.gcube.social_networking.social_networking_client_library.MessageClient;
|
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.beans.MessageInbox;
|
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.beans.MessageInputBean;
|
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.beans.Recipient;
|
|
|
|
|
import org.gcube.social_networking.social_networking_client_library.LibClient;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.liferay.portal.kernel.log.Log;
|
|
|
|
|
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
|
|
|
|
import com.sun.mail.util.MailSSLSocketFactory;
|
|
|
|
|
|
|
|
|
|
import jakarta.mail.Address;
|
|
|
|
|
import jakarta.mail.BodyPart;
|
|
|
|
|
import jakarta.mail.Flags;
|
|
|
|
|
import jakarta.mail.Folder;
|
|
|
|
|
import jakarta.mail.Message;
|
|
|
|
|
import jakarta.mail.MessagingException;
|
|
|
|
|
import jakarta.mail.Multipart;
|
|
|
|
|
import jakarta.mail.NoSuchProviderException;
|
|
|
|
|
import jakarta.mail.Session;
|
|
|
|
|
import jakarta.mail.Store;
|
|
|
|
|
import jakarta.mail.internet.InternetAddress;
|
|
|
|
|
import jakarta.mail.internet.MimeMessage.RecipientType;
|
|
|
|
|
import okhttp3.OkHttpClient;
|
|
|
|
|
import okhttp3.Request;
|
|
|
|
|
import okhttp3.ResponseBody;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author Massimiliano Assante, CNR-ISTI
|
|
|
|
@ -80,15 +70,14 @@ import okhttp3.ResponseBody;
|
|
|
|
|
public class PeriodicTask implements Runnable {
|
|
|
|
|
private static final Log _log = LogFactoryUtil.getLog(PeriodicTask.class);
|
|
|
|
|
private static final String APP_ID_NEWSFEED = "org.gcube.portlets.user.newsfeed.server.NewsServiceImpl";
|
|
|
|
|
private static final String SHUB_MESSAGES_ENDPOINT = "workspace/messages/";
|
|
|
|
|
|
|
|
|
|
private DatabookStore socialStore;
|
|
|
|
|
private LibClient libClient;
|
|
|
|
|
private EmailPopAccount popAccount;
|
|
|
|
|
private SocialNetworkingSite site;
|
|
|
|
|
|
|
|
|
|
public PeriodicTask(DatabookStore store, EmailPopAccount popAccount, HttpServletRequest request) {
|
|
|
|
|
public PeriodicTask(LibClient libClient, EmailPopAccount popAccount, HttpServletRequest request) {
|
|
|
|
|
super();
|
|
|
|
|
this.socialStore = store;
|
|
|
|
|
this.libClient = libClient;
|
|
|
|
|
this.popAccount = popAccount;
|
|
|
|
|
this.site = new SocialNetworkingSite(request);
|
|
|
|
|
String serverName = request.getServerName();
|
|
|
|
@ -147,20 +136,6 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String generateAuthorizationToken(String username, String scope) {
|
|
|
|
|
List<String> userRoles = new ArrayList<>();
|
|
|
|
|
userRoles.add(DEFAULT_ROLE);
|
|
|
|
|
String token;
|
|
|
|
|
try {
|
|
|
|
|
token = authorizationService().generateUserToken(new UserInfo(username, userRoles), scope);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return token;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final static String DEFAULT_ROLE = "OrganizationMember";
|
|
|
|
|
|
|
|
|
|
private static void setAuthorizationToken(ASLSession session) throws Exception {
|
|
|
|
@ -229,8 +204,8 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
if (fakeSession != null && subAddressField != null) {
|
|
|
|
|
if (subAddressField.endsWith(AppType.POST.toString()) || subAddressField.endsWith(AppType.POST.toString().toLowerCase())) { //it is a post, a comment on a post or a mention
|
|
|
|
|
_log.debug("Looks like a post, a comment on a post or a mention to me");
|
|
|
|
|
String feedId = extractIdentifier(subAddressField);
|
|
|
|
|
handlePostReply(portalName, feedId, message, fakeSession);
|
|
|
|
|
String postId = extractIdentifier(subAddressField);
|
|
|
|
|
handlePostReply(portalName, postId, message, fakeSession);
|
|
|
|
|
}
|
|
|
|
|
else if (subAddressField.endsWith(AppType.MSG.toString()) || subAddressField.endsWith(AppType.MSG.toString().toLowerCase())) { //it is a message
|
|
|
|
|
_log.debug("Looks like a message reply to me");
|
|
|
|
@ -275,16 +250,6 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
private void handleMessageReply(String portalName, String messageId, Message message, ASLSession fakeSession) {
|
|
|
|
|
|
|
|
|
|
String legacyToken = SecurityTokenProvider.instance.get();
|
|
|
|
|
|
|
|
|
|
_log.info("*****username=" + fakeSession.getUsername());
|
|
|
|
|
_log.info("*****context=" + fakeSession.getScope());
|
|
|
|
|
|
|
|
|
|
legacyToken = generateAuthorizationToken(fakeSession.getUsername(), fakeSession.getScope());
|
|
|
|
|
SecurityTokenProvider.instance.set(legacyToken);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String subject = "";
|
|
|
|
|
String messageText = "";
|
|
|
|
|
try {
|
|
|
|
@ -296,23 +261,34 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
|
|
|
|
|
_log.debug("Found message reply, subject: " + subject + " body: " + messageText);
|
|
|
|
|
String newMessageId = null;
|
|
|
|
|
ArrayList<String> recipientIds = new ArrayList<String>();
|
|
|
|
|
List<String> recipientIds = new ArrayList<>();
|
|
|
|
|
try {
|
|
|
|
|
String username = fakeSession.getUsername();
|
|
|
|
|
String context = fakeSession.getScope();
|
|
|
|
|
ScopeProvider.instance.set(context);
|
|
|
|
|
_log.debug("calling service token on context " + context);
|
|
|
|
|
String scope = fakeSession.getScope();
|
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
|
_log.debug("calling service token on scope " + scope);
|
|
|
|
|
List<String> userRoles = new ArrayList<>();
|
|
|
|
|
userRoles.add(DEFAULT_ROLE);
|
|
|
|
|
fakeSession.setSecurityToken(null);
|
|
|
|
|
String token = authorizationService().generateUserToken(new UserInfo(username, userRoles), context);
|
|
|
|
|
String token = authorizationService().generateUserToken(new UserInfo(username, userRoles), scope);
|
|
|
|
|
SecurityTokenProvider.instance.set(token);
|
|
|
|
|
MessageInbox theMessage = null;
|
|
|
|
|
_log.info("Looking for Message with id "+ messageId);
|
|
|
|
|
String messagesEndpoint = getStorageHubURLFromContext(context)+SHUB_MESSAGES_ENDPOINT;
|
|
|
|
|
theMessage = getMessageWSById(messagesEndpoint, messageId, token);
|
|
|
|
|
_log.info("Got Message = " + theMessage.toString());
|
|
|
|
|
|
|
|
|
|
MessageManagerClient mmClient = AbstractPlugin.messages().build();
|
|
|
|
|
org.gcube.common.storagehub.model.messages.Message theMessage = null;
|
|
|
|
|
try {
|
|
|
|
|
theMessage = mmClient.get(messageId);
|
|
|
|
|
}
|
|
|
|
|
catch (IdNotFoundException e) {
|
|
|
|
|
_log.warn("Message with id "+ messageId + " could not be found, trying by name ...");
|
|
|
|
|
List<org.gcube.common.storagehub.model.messages.Message> messages = mmClient.getReceivedMessages();
|
|
|
|
|
Collections.reverse(messages); //the messages are returned in chronological order, but the messages we look for is one of the newests
|
|
|
|
|
_log.warn("Messages size="+messages.size());
|
|
|
|
|
for(org.gcube.common.storagehub.model.messages.Message msg: messages) {
|
|
|
|
|
if (msg.getName().equals(messageId)) {
|
|
|
|
|
theMessage = msg;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (theMessage != null) {
|
|
|
|
|
String[] addresses = theMessage.getAddresses();
|
|
|
|
|
for (int i = 0; i < addresses.length; i++) {
|
|
|
|
@ -326,20 +302,17 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
recipientIds.remove(fakeSession.getUsername());
|
|
|
|
|
|
|
|
|
|
_log.debug("Message Recipients:");
|
|
|
|
|
ArrayList<Recipient> recipients = new ArrayList<Recipient>();
|
|
|
|
|
for (String rec : recipientIds) {
|
|
|
|
|
recipients.add(new Recipient(rec));
|
|
|
|
|
_log.debug(rec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_log.debug("Constructing reply message");
|
|
|
|
|
messageText += getReplyHeaderMessage(sender, originalSentTime, originalText);
|
|
|
|
|
|
|
|
|
|
_log.debug("Trying to send message with subject: " + subject + " to: " + recipientIds.toString());
|
|
|
|
|
MessageInputBean message2Send = new MessageInputBean(messageText, subject, recipients);
|
|
|
|
|
MessageClient messagesClient = new MessageClient();
|
|
|
|
|
newMessageId = messagesClient.writeMessage(message2Send);
|
|
|
|
|
}
|
|
|
|
|
newMessageId = mmClient.sendMessage(recipientIds, subject, messageText, new ArrayList<String>());
|
|
|
|
|
} else {
|
|
|
|
|
_log.error("Message with id "+ messageId + " could not be found even iterating by name, exiting.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
@ -363,48 +336,6 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* temporary method that get the URL of the Shub based on the context
|
|
|
|
|
* @param context
|
|
|
|
|
* @return the url
|
|
|
|
|
*/
|
|
|
|
|
private String getStorageHubURLFromContext(String context) {
|
|
|
|
|
String toReturn = "";
|
|
|
|
|
if (context.startsWith("/d4science")) {
|
|
|
|
|
toReturn = "https://api.d4science.org/";
|
|
|
|
|
} else if (context.startsWith("/gcube")) {
|
|
|
|
|
toReturn = "https://api.dev.d4science.org/";
|
|
|
|
|
} else {
|
|
|
|
|
toReturn = "https://api.pre.d4science.org/";
|
|
|
|
|
}
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* read a message from shub given the id
|
|
|
|
|
* @param urlString
|
|
|
|
|
* @param token
|
|
|
|
|
* @return
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
private static MessageInbox getMessageWSById(String uri, String messageId, String token) throws IOException {
|
|
|
|
|
String urlString = uri+messageId;
|
|
|
|
|
_log.info("***** getMessageWSById urlString = " + urlString);
|
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder().build();
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(urlString)
|
|
|
|
|
.addHeader("gcube-token", token)
|
|
|
|
|
.build();
|
|
|
|
|
ResponseBody responseBody = client.newCall(request).execute().body();
|
|
|
|
|
String json = responseBody.string();
|
|
|
|
|
_log.info("***** getMessageWSById Response = " + json);
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
MessageInbox theMessage = objectMapper.readValue(json, MessageInbox.class);
|
|
|
|
|
return theMessage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getReplyHeaderMessage(String senderId, Date date, String message) {
|
|
|
|
|
List<String> toPass = new ArrayList<String>();
|
|
|
|
|
toPass.add(senderId);
|
|
|
|
@ -439,21 +370,12 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
/**
|
|
|
|
|
* this method manages the replies coming from post notifications
|
|
|
|
|
* @param portalName
|
|
|
|
|
* @param postId the identifier in the System managing the feeds
|
|
|
|
|
* @param postId the identifier in the System managing the posts
|
|
|
|
|
* @param message the javax mail Message instance
|
|
|
|
|
* @param fakeSession
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
private void handlePostReply(String portalName, String postId, Message message, ASLSession fakeSession) throws Exception {
|
|
|
|
|
String token = AccessTokenProvider.instance.get();
|
|
|
|
|
String legacyToken = SecurityTokenProvider.instance.get();
|
|
|
|
|
|
|
|
|
|
_log.info("*****username=" + fakeSession.getUsername());
|
|
|
|
|
_log.info("*****context=" + fakeSession.getScope());
|
|
|
|
|
|
|
|
|
|
legacyToken = generateAuthorizationToken(fakeSession.getUsername(), fakeSession.getScope());
|
|
|
|
|
SecurityTokenProvider.instance.set(legacyToken);
|
|
|
|
|
|
|
|
|
|
String commentText = extractText(portalName, postId, message);
|
|
|
|
|
_log.info("Extracted id: " + postId + " text=" + commentText);
|
|
|
|
|
String escapedCommentText = org.gcube.portal.socialmail.Utils.escapeHtmlAndTransformUrl(commentText);
|
|
|
|
@ -464,19 +386,13 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
likePost(postId, fakeSession);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
Comment comment = new Comment(UUID.randomUUID().toString(), fakeSession.getUsername(),
|
|
|
|
|
new Date(), postId, escapedCommentText, fakeSession.getUserFullName(), fakeSession.getUserAvatarId());
|
|
|
|
|
|
|
|
|
|
_log.debug("The EscapedCommentText =>" + escapedCommentText);
|
|
|
|
|
boolean commentCommitResult = false;
|
|
|
|
|
try {
|
|
|
|
|
if (socialStore.addComment(comment))
|
|
|
|
|
commentCommitResult = true;
|
|
|
|
|
} catch (FeedIDNotFoundException e) {
|
|
|
|
|
_log.error("Related post not found for this comment " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (libClient.addCommentLib(comment))
|
|
|
|
|
commentCommitResult = true;
|
|
|
|
|
if (commentCommitResult) { //the notifications should start
|
|
|
|
|
notifyUsersInvolved(comment, escapedCommentText, postId, fakeSession);
|
|
|
|
|
}
|
|
|
|
@ -490,46 +406,32 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
* @param fakeSession
|
|
|
|
|
*/
|
|
|
|
|
private void likePost(String postId, ASLSession fakeSession) {
|
|
|
|
|
|
|
|
|
|
String token = AccessTokenProvider.instance.get();
|
|
|
|
|
String legacyToken = SecurityTokenProvider.instance.get();
|
|
|
|
|
|
|
|
|
|
_log.info("*****username=" + fakeSession.getUsername());
|
|
|
|
|
_log.info("*****context=" + fakeSession.getScope());
|
|
|
|
|
|
|
|
|
|
legacyToken = generateAuthorizationToken(fakeSession.getUsername(), fakeSession.getScope());
|
|
|
|
|
SecurityTokenProvider.instance.set(legacyToken);
|
|
|
|
|
|
|
|
|
|
if (postId == null || postId.compareTo("") == 0) {
|
|
|
|
|
_log.warn("Found email with no feedId from " + fakeSession.getUserEmailAddress() + ". Going to trash it");
|
|
|
|
|
_log.warn("Found email with no postId from " + fakeSession.getUserEmailAddress() + ". Going to trash it");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Like like = new Like(UUID.randomUUID().toString(), fakeSession.getUsername(),
|
|
|
|
|
new Date(), postId, fakeSession.getUserFullName(), fakeSession.getUserAvatarId());
|
|
|
|
|
|
|
|
|
|
boolean likeCommitResult = false;
|
|
|
|
|
try {
|
|
|
|
|
if (socialStore.like(like));
|
|
|
|
|
likeCommitResult = true;
|
|
|
|
|
} catch (FeedIDNotFoundException e) {
|
|
|
|
|
_log.error("Related post not found for this like " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (libClient.likeLib(like));
|
|
|
|
|
likeCommitResult = true;
|
|
|
|
|
if (likeCommitResult) { //the notification should be delivered to the post owner
|
|
|
|
|
try {
|
|
|
|
|
Feed post = socialStore.readFeed(postId);
|
|
|
|
|
String feedOwnerId = post.getEntityId();
|
|
|
|
|
boolean isAppFeed = post.isApplicationFeed();
|
|
|
|
|
Post post = libClient.readPostLib(postId);
|
|
|
|
|
String postOwnerId = post.getEntityId();
|
|
|
|
|
boolean isApppost = post.isApplicationPost();
|
|
|
|
|
|
|
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(
|
|
|
|
|
site,
|
|
|
|
|
post.getVreid(),
|
|
|
|
|
fakeSession.getScope(),
|
|
|
|
|
new SocialNetworkingUser(fakeSession.getUsername(), fakeSession.getUserEmailAddress(), fakeSession.getUserFullName(), fakeSession.getUserAvatarId()),
|
|
|
|
|
APP_ID_NEWSFEED
|
|
|
|
|
);
|
|
|
|
|
if (! fakeSession.getUsername().equals(feedOwnerId) && (!isAppFeed)) {
|
|
|
|
|
boolean result = nm.notifyLikedFeed(feedOwnerId, postId, "");
|
|
|
|
|
if (! fakeSession.getUsername().equals(postOwnerId) && (!isApppost)) {
|
|
|
|
|
boolean result = nm.notifyLikedPost(postOwnerId, postId, "");
|
|
|
|
|
_log.trace("Like Notification to post owner added? " + result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -541,48 +443,48 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
/**
|
|
|
|
|
* this method take care of notify all the users that need to be notified when someone comment
|
|
|
|
|
* @param comment
|
|
|
|
|
* @param feedId
|
|
|
|
|
* @param postId
|
|
|
|
|
* @param fakeSession
|
|
|
|
|
* @throws PrivacyLevelTypeNotFoundException
|
|
|
|
|
* @throws FeedTypeNotFoundException
|
|
|
|
|
* @throws FeedIDNotFoundException
|
|
|
|
|
* @throws PostTypeNotFoundException
|
|
|
|
|
* @throws PostIDNotFoundException
|
|
|
|
|
* @throws ColumnNameNotFoundException
|
|
|
|
|
*/
|
|
|
|
|
private void notifyUsersInvolved(Comment comment, String commentText, String feedId, ASLSession fakeSession) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException {
|
|
|
|
|
Feed post = socialStore.readFeed(feedId);
|
|
|
|
|
String feedOwnerId = post.getEntityId();
|
|
|
|
|
boolean isAppFeed = post.isApplicationFeed();
|
|
|
|
|
private void notifyUsersInvolved(Comment comment, String commentText, String postId, ASLSession fakeSession) throws PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, PostIDNotFoundException, ColumnNameNotFoundException {
|
|
|
|
|
Post post = libClient.readPostLib(postId);
|
|
|
|
|
String postOwnerId = post.getEntityId();
|
|
|
|
|
boolean isApppost = post.isApplicationPost();
|
|
|
|
|
|
|
|
|
|
//if the user who commented this post is not the user who posted it notifies the poster user (Feed owner)
|
|
|
|
|
//if the user who commented this post is not the user who posted it notifies the poster user (post owner)
|
|
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(
|
|
|
|
|
site,
|
|
|
|
|
post.getVreid(),
|
|
|
|
|
new SocialNetworkingUser(fakeSession.getUsername(), fakeSession.getUserEmailAddress(), fakeSession.getUserFullName(), fakeSession.getUserAvatarId()),
|
|
|
|
|
APP_ID_NEWSFEED
|
|
|
|
|
);
|
|
|
|
|
if (! fakeSession.getUsername().equals(feedOwnerId) && (!isAppFeed)) {
|
|
|
|
|
boolean result = nm.notifyOwnCommentReply(feedOwnerId, feedId, commentText, comment.getKey());
|
|
|
|
|
if (! fakeSession.getUsername().equals(postOwnerId) && (!isApppost)) {
|
|
|
|
|
boolean result = nm.notifyOwnCommentReply(postOwnerId, postId, commentText, comment.getKey());
|
|
|
|
|
_log.trace("Comment Notification to post owner added? " + result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if there are users who liked this post they get notified, asynchronously with this thread
|
|
|
|
|
ArrayList<Like> likes = getAllLikesByFeed(feedId);
|
|
|
|
|
Thread likesThread = new Thread(new LikeNotificationsThread(commentText, nm, likes, feedOwnerId, comment.getKey()));
|
|
|
|
|
ArrayList<Like> likes = getAllLikesByPost(postId);
|
|
|
|
|
Thread likesThread = new Thread(new LikeNotificationsThread(commentText, nm, likes, postOwnerId, comment.getKey()));
|
|
|
|
|
likesThread.start();
|
|
|
|
|
|
|
|
|
|
UserManager userManager = new LiferayUserManager();
|
|
|
|
|
//notify the other users who commented this post (excluding the ones above)
|
|
|
|
|
Thread commentsNotificationthread = new Thread(new CommentNotificationsThread(socialStore, userManager, fakeSession.getUsername(), comment.getFeedid(), commentText, nm, feedOwnerId, comment.getKey(), likes));
|
|
|
|
|
Thread commentsNotificationthread = new Thread(new CommentNotificationsThread(userManager, fakeSession.getUsername(), comment.getPostid(), commentText, nm, postOwnerId, comment.getKey(), likes));
|
|
|
|
|
commentsNotificationthread.start();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param feedid
|
|
|
|
|
* @param postid
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public ArrayList<Like> getAllLikesByFeed(String feedid) {
|
|
|
|
|
_log.trace("Asking likes for " + feedid);
|
|
|
|
|
ArrayList<Like> toReturn = (ArrayList<Like>) socialStore.getAllLikesByFeed(feedid);
|
|
|
|
|
public ArrayList<Like> getAllLikesByPost(String postid) {
|
|
|
|
|
_log.trace("Asking likes for " + postid);
|
|
|
|
|
ArrayList<Like> toReturn = (ArrayList<Like>) libClient.getAllLikesByPostLib(postid);
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|