|
|
@ -19,6 +19,7 @@ import javax.mail.Session;
|
|
|
|
import javax.mail.Store;
|
|
|
|
import javax.mail.Store;
|
|
|
|
import javax.mail.internet.InternetAddress;
|
|
|
|
import javax.mail.internet.InternetAddress;
|
|
|
|
import javax.mail.internet.MimeMessage.RecipientType;
|
|
|
|
import javax.mail.internet.MimeMessage.RecipientType;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
|
|
import org.gcube.application.framework.core.session.ASLSession;
|
|
|
|
import org.gcube.application.framework.core.session.ASLSession;
|
|
|
|
import org.gcube.application.framework.core.session.SessionManager;
|
|
|
|
import org.gcube.application.framework.core.session.SessionManager;
|
|
|
@ -26,7 +27,8 @@ import org.gcube.application.framework.core.util.GenderType;
|
|
|
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
|
|
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
|
|
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
|
|
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
|
|
|
import org.gcube.applicationsupportlayer.social.mailing.AppType;
|
|
|
|
import org.gcube.applicationsupportlayer.social.mailing.AppType;
|
|
|
|
import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin;
|
|
|
|
import org.gcube.applicationsupportlayer.social.mailing.SocialMailingUtil;
|
|
|
|
|
|
|
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
|
|
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
|
|
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
|
|
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
|
|
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
|
|
@ -37,7 +39,6 @@ import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNot
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.sharing.WorkspaceMessage;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.sharing.WorkspaceMessage;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.sharing.WorkspaceMessageManager;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.sharing.WorkspaceMessageManager;
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
|
|
|
|
|
|
|
import org.gcube.portal.databook.server.DatabookStore;
|
|
|
|
import org.gcube.portal.databook.server.DatabookStore;
|
|
|
|
import org.gcube.portal.databook.shared.Comment;
|
|
|
|
import org.gcube.portal.databook.shared.Comment;
|
|
|
|
import org.gcube.portal.databook.shared.Feed;
|
|
|
|
import org.gcube.portal.databook.shared.Feed;
|
|
|
@ -50,13 +51,12 @@ import org.gcube.portal.notifications.bean.GenericItemBean;
|
|
|
|
import org.gcube.portal.notifications.thread.CommentNotificationsThread;
|
|
|
|
import org.gcube.portal.notifications.thread.CommentNotificationsThread;
|
|
|
|
import org.gcube.portal.notifications.thread.LikeNotificationsThread;
|
|
|
|
import org.gcube.portal.notifications.thread.LikeNotificationsThread;
|
|
|
|
import org.gcube.portal.notifications.thread.MessageNotificationsThread;
|
|
|
|
import org.gcube.portal.notifications.thread.MessageNotificationsThread;
|
|
|
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
|
|
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
|
|
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
import com.liferay.portal.kernel.exception.PortalException;
|
|
|
|
|
|
|
|
import com.liferay.portal.kernel.exception.SystemException;
|
|
|
|
|
|
|
|
import com.liferay.portal.model.User;
|
|
|
|
|
|
|
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
|
|
|
|
import com.sun.mail.util.MailSSLSocketFactory;
|
|
|
|
import com.sun.mail.util.MailSSLSocketFactory;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -68,24 +68,24 @@ public class PeriodicTask implements Runnable {
|
|
|
|
private static final Logger _log = LoggerFactory.getLogger(PeriodicTask.class);
|
|
|
|
private static final Logger _log = LoggerFactory.getLogger(PeriodicTask.class);
|
|
|
|
|
|
|
|
|
|
|
|
private DatabookStore socialStore;
|
|
|
|
private DatabookStore socialStore;
|
|
|
|
private String host;
|
|
|
|
private EmailPopAccount popAccount;
|
|
|
|
private String mailserver_username;
|
|
|
|
private SocialNetworkingSite site;
|
|
|
|
private String password;
|
|
|
|
|
|
|
|
private String portalName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PeriodicTask(DatabookStore store, String portalName, String host, String mailserver_username, String password) {
|
|
|
|
public PeriodicTask(DatabookStore store, EmailPopAccount popAccount, HttpServletRequest request) {
|
|
|
|
super();
|
|
|
|
super();
|
|
|
|
this.socialStore = store;
|
|
|
|
this.socialStore = store;
|
|
|
|
this.portalName = portalName;
|
|
|
|
this.popAccount = popAccount;
|
|
|
|
this.host = host;
|
|
|
|
this.site = new SocialNetworkingSite(request);
|
|
|
|
this.mailserver_username = mailserver_username;
|
|
|
|
String serverName = request.getServerName();
|
|
|
|
this.password = password;
|
|
|
|
//needed because the servlet is called via http
|
|
|
|
|
|
|
|
this.site.setSiteURL("https://"+serverName);
|
|
|
|
|
|
|
|
_log.debug("PeriodicTask instanciated, request serverName=" + serverName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
check(portalName, host, mailserver_username, password);
|
|
|
|
check(popAccount.getPortalName(), popAccount.getPop3Server(), popAccount.getPop3user(), popAccount.getPop3password());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -95,19 +95,17 @@ public class PeriodicTask implements Runnable {
|
|
|
|
String sessionID = UUID.randomUUID().toString();
|
|
|
|
String sessionID = UUID.randomUUID().toString();
|
|
|
|
PortalContext context = PortalContext.getConfiguration();
|
|
|
|
PortalContext context = PortalContext.getConfiguration();
|
|
|
|
String scope = "/" + context.getInfrastructureName();
|
|
|
|
String scope = "/" + context.getInfrastructureName();
|
|
|
|
|
|
|
|
|
|
|
|
String username = "";
|
|
|
|
String username = "";
|
|
|
|
long companyId;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
companyId = OrganizationsUtil.getCompany().getCompanyId();
|
|
|
|
UserManager um = new LiferayUserManager();
|
|
|
|
User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, emailAddress);
|
|
|
|
GCubeUser user = um.getUserByEmail(emailAddress);
|
|
|
|
username = user.getScreenName();
|
|
|
|
username = user.getUsername();
|
|
|
|
SessionManager.getInstance().getASLSession(sessionID, username).setScope(scope);
|
|
|
|
SessionManager.getInstance().getASLSession(sessionID, username).setScope(scope);
|
|
|
|
|
|
|
|
|
|
|
|
//add the social information needed by apps
|
|
|
|
//add the social information needed by apps
|
|
|
|
String fullName = user.getFirstName() + " " + user.getLastName();
|
|
|
|
String fullName = user.getFirstName() + " " + user.getLastName();
|
|
|
|
String email = user.getEmailAddress();
|
|
|
|
String email = user.getEmail();
|
|
|
|
String thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId();
|
|
|
|
String thumbnailURL = user.getUserAvatarURL();
|
|
|
|
boolean isMale = user.isMale();
|
|
|
|
boolean isMale = user.isMale();
|
|
|
|
|
|
|
|
|
|
|
|
SessionManager.getInstance().getASLSession(sessionID, username).setUserFullName(fullName);
|
|
|
|
SessionManager.getInstance().getASLSession(sessionID, username).setUserFullName(fullName);
|
|
|
@ -117,7 +115,7 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
|
|
|
|
|
|
|
_log.debug("Created fakesession for user " + username + " email="+emailAddress);
|
|
|
|
_log.debug("Created fakesession for user " + username + " email="+emailAddress);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (PortalException | SystemException e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
_log.error("Exception while trying to get the user from email address: " + e.getMessage());
|
|
|
|
_log.error("Exception while trying to get the user from email address: " + e.getMessage());
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -264,10 +262,11 @@ public class PeriodicTask implements Runnable {
|
|
|
|
_log.debug("Message with subject: " + subject, " hase been sent, returned id: " + newMessageId);
|
|
|
|
_log.debug("Message with subject: " + subject, " hase been sent, returned id: " + newMessageId);
|
|
|
|
|
|
|
|
|
|
|
|
if (newMessageId != null) {
|
|
|
|
if (newMessageId != null) {
|
|
|
|
_log.debug("Sending message notifications ... ");
|
|
|
|
_log.debug("Sending message notifications ... site server URL= " + site.getSiteURL());
|
|
|
|
List<GenericItemBean> recipients = getUsersbyUserId(recipientIds);
|
|
|
|
List<GenericItemBean> recipients = getUsersbyUserId(recipientIds);
|
|
|
|
|
|
|
|
|
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(
|
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(
|
|
|
|
|
|
|
|
site,
|
|
|
|
fakeSession.getScope(),
|
|
|
|
fakeSession.getScope(),
|
|
|
|
new SocialNetworkingUser(fakeSession.getUsername(), fakeSession.getUserEmailAddress(), fakeSession.getUserFullName(), fakeSession.getUserAvatarId())
|
|
|
|
new SocialNetworkingUser(fakeSession.getUsername(), fakeSession.getUserEmailAddress(), fakeSession.getUserFullName(), fakeSession.getUserAvatarId())
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -298,11 +297,11 @@ public class PeriodicTask implements Runnable {
|
|
|
|
private List<GenericItemBean> getUsersbyUserId(List<String> recipientIds) {
|
|
|
|
private List<GenericItemBean> getUsersbyUserId(List<String> recipientIds) {
|
|
|
|
List<GenericItemBean> recipients = new ArrayList<GenericItemBean>();
|
|
|
|
List<GenericItemBean> recipients = new ArrayList<GenericItemBean>();
|
|
|
|
for (String userid : recipientIds) {
|
|
|
|
for (String userid : recipientIds) {
|
|
|
|
com.liferay.portal.model.User user;
|
|
|
|
GCubeUser user;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), userid);
|
|
|
|
user = new LiferayUserManager().getUserByUsername(userid);
|
|
|
|
recipients.add(new GenericItemBean(""+user.getUserId(), user.getScreenName(), user.getFullName(), ""));
|
|
|
|
recipients.add(new GenericItemBean(""+user.getUserId(), user.getUsername(), user.getFullname(), ""));
|
|
|
|
} catch (PortalException | SystemException e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -320,7 +319,7 @@ public class PeriodicTask implements Runnable {
|
|
|
|
private void handlePostReply(String portalName, String feedId, Message message, ASLSession fakeSession) throws Exception {
|
|
|
|
private void handlePostReply(String portalName, String feedId, Message message, ASLSession fakeSession) throws Exception {
|
|
|
|
String commentText = extractText(portalName, feedId, message);
|
|
|
|
String commentText = extractText(portalName, feedId, message);
|
|
|
|
_log.info("Extracted id: " + feedId + " text=" + commentText);
|
|
|
|
_log.info("Extracted id: " + feedId + " text=" + commentText);
|
|
|
|
String escapedCommentText = Utils.escapeHtmlAndTransformUrl(commentText);
|
|
|
|
String escapedCommentText = org.gcube.portal.socialmail.Utils.escapeHtmlAndTransformUrl(commentText);
|
|
|
|
String subject = message.getSubject();
|
|
|
|
String subject = message.getSubject();
|
|
|
|
|
|
|
|
|
|
|
|
if (escapedCommentText.trim().compareTo("") == 0) {//it is a favorite/subscription
|
|
|
|
if (escapedCommentText.trim().compareTo("") == 0) {//it is a favorite/subscription
|
|
|
@ -377,6 +376,7 @@ public class PeriodicTask implements Runnable {
|
|
|
|
boolean isAppFeed = feed.isApplicationFeed();
|
|
|
|
boolean isAppFeed = feed.isApplicationFeed();
|
|
|
|
|
|
|
|
|
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(
|
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(
|
|
|
|
|
|
|
|
site,
|
|
|
|
fakeSession.getScope(),
|
|
|
|
fakeSession.getScope(),
|
|
|
|
new SocialNetworkingUser(fakeSession.getUsername(), fakeSession.getUserEmailAddress(), fakeSession.getUserFullName(), fakeSession.getUserAvatarId())
|
|
|
|
new SocialNetworkingUser(fakeSession.getUsername(), fakeSession.getUserEmailAddress(), fakeSession.getUserFullName(), fakeSession.getUserAvatarId())
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -407,6 +407,7 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
|
|
|
|
|
|
|
//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 (Feed owner)
|
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(
|
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(
|
|
|
|
|
|
|
|
site,
|
|
|
|
fakeSession.getScope(),
|
|
|
|
fakeSession.getScope(),
|
|
|
|
new SocialNetworkingUser(fakeSession.getUsername(), fakeSession.getUserEmailAddress(), fakeSession.getUserFullName(), fakeSession.getUserAvatarId())
|
|
|
|
new SocialNetworkingUser(fakeSession.getUsername(), fakeSession.getUserEmailAddress(), fakeSession.getUserFullName(), fakeSession.getUserAvatarId())
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -473,7 +474,7 @@ public class PeriodicTask implements Runnable {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
messageContent = message.getContent();
|
|
|
|
messageContent = message.getContent();
|
|
|
|
String toParse = null;
|
|
|
|
String toParse = null;
|
|
|
|
final String SEPARATOR = EmailPlugin.WRITE_ABOVE_TO_REPLY.substring(0, 23);
|
|
|
|
final String SEPARATOR = SocialMailingUtil.WRITE_ABOVE_TO_REPLY.substring(0, 23);
|
|
|
|
// Check if content is pure text/html or in parts
|
|
|
|
// Check if content is pure text/html or in parts
|
|
|
|
if (messageContent instanceof Multipart) {
|
|
|
|
if (messageContent instanceof Multipart) {
|
|
|
|
_log.debug("Checking if isValidReply, found Multipart Message, getting text part ... looking for separator " + SEPARATOR);
|
|
|
|
_log.debug("Checking if isValidReply, found Multipart Message, getting text part ... looking for separator " + SEPARATOR);
|
|
|
@ -512,7 +513,7 @@ public class PeriodicTask implements Runnable {
|
|
|
|
private static String extractText(String portalName, String subjectId, Message message) throws Exception {
|
|
|
|
private static String extractText(String portalName, String subjectId, Message message) throws Exception {
|
|
|
|
Object messageContent = message.getContent();
|
|
|
|
Object messageContent = message.getContent();
|
|
|
|
String toParse = null;
|
|
|
|
String toParse = null;
|
|
|
|
final String SEPARATOR = EmailPlugin.WRITE_ABOVE_TO_REPLY.substring(0, 23);
|
|
|
|
final String SEPARATOR = SocialMailingUtil.WRITE_ABOVE_TO_REPLY.substring(0, 23);
|
|
|
|
// Check if content is pure text/html or in parts
|
|
|
|
// Check if content is pure text/html or in parts
|
|
|
|
if (messageContent instanceof Multipart) {
|
|
|
|
if (messageContent instanceof Multipart) {
|
|
|
|
_log.debug("Found Multipart Message, getting text part ... looking for separator " + SEPARATOR);
|
|
|
|
_log.debug("Found Multipart Message, getting text part ... looking for separator " + SEPARATOR);
|
|
|
|