added notification for user "mentions"
git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@73585 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8530439672
commit
153bf3f40f
6
pom.xml
6
pom.xml
|
@ -65,6 +65,12 @@
|
||||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.applicationsupportlayer</groupId>
|
||||||
|
<artifactId>aslsocial</artifactId>
|
||||||
|
<version>[0.1.0-SNAPSHOT, 1.0.0-SNAPSHOT)</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>gcf</artifactId>
|
<artifactId>gcf</artifactId>
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package org.gcube.portlets.user.shareupdates.server;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
||||||
|
import org.gcube.common.core.utils.logging.GCUBEClientLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Massimiliano Assante ISTI-CNR
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MentionNotificationsThread implements Runnable {
|
||||||
|
private static GCUBEClientLog _log = new GCUBEClientLog(MentionNotificationsThread.class);
|
||||||
|
|
||||||
|
private String postText;
|
||||||
|
private String postId;
|
||||||
|
private NotificationsManager nm;
|
||||||
|
private ArrayList<String> userIds;
|
||||||
|
|
||||||
|
|
||||||
|
public MentionNotificationsThread(String postId, String postText, NotificationsManager nm, ArrayList<String> userIds) {
|
||||||
|
super();
|
||||||
|
this.postId = postId;
|
||||||
|
this.postText = postText;
|
||||||
|
this.nm = nm;
|
||||||
|
this.userIds = userIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (String userIdToNotify : userIds) {
|
||||||
|
boolean result = nm.notifyUserTag(userIdToNotify, postId, postText);
|
||||||
|
_log.trace("Sending Notification for post mention to: " + userIdToNotify + " result?"+ result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,8 @@ import javax.net.ssl.X509TrustManager;
|
||||||
import org.apache.commons.validator.routines.UrlValidator;
|
import org.apache.commons.validator.routines.UrlValidator;
|
||||||
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;
|
||||||
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
||||||
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
||||||
import org.gcube.common.core.utils.logging.GCUBEClientLog;
|
import org.gcube.common.core.utils.logging.GCUBEClientLog;
|
||||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
||||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||||
|
@ -112,8 +114,8 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
_log.warn("USER IS NULL setting test.user and Running OUTSIDE PORTAL");
|
_log.warn("USER IS NULL setting test.user and Running OUTSIDE PORTAL");
|
||||||
user = "test.user";
|
user = "test.user";
|
||||||
// user = "massimiliano.assante";
|
user = "massimiliano.assante";
|
||||||
// SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE");
|
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE");
|
||||||
withinPortal = false;
|
withinPortal = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -122,84 +124,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
||||||
System.out.println("SessionID = " + sessionID);
|
System.out.println("SessionID = " + sessionID);
|
||||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* this method extractPeopleTags from the user post
|
|
||||||
* @param postText text with tagged people: txt .. <input with the actual person profile
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private ArrayList<String> extractPeopleTags(String postText) {
|
|
||||||
ArrayList<String> toReturn = new ArrayList<String>();
|
|
||||||
String toParse = "<html><head></head><body>" + postText + "</body></html>";
|
|
||||||
|
|
||||||
HtmlCleaner cleaner = new HtmlCleaner();
|
|
||||||
// parse the string HTML
|
|
||||||
TagNode pageData = cleaner.clean(toParse);
|
|
||||||
TagNode[] inputElements = pageData.getElementsByName("input", true);
|
|
||||||
if (inputElements != null) {
|
|
||||||
for (int i = 0; i < inputElements.length; i++) {
|
|
||||||
System.out.println("Found input " + inputElements[i].getAttributes().get("value"));
|
|
||||||
toReturn.add(inputElements[i].getAttributes().get("value"));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_log.trace("No person tags in this post");
|
|
||||||
}
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* remove all the html and leave the text
|
|
||||||
* @param html
|
|
||||||
* @return the text inside the html
|
|
||||||
*/
|
|
||||||
private static String html2text(String html) {
|
|
||||||
return Jsoup.parse(html).text().replace(" "," ");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this method is used when posting a feed
|
|
||||||
*
|
|
||||||
* It converts the tagged people <input with the actual person profile link, not trivial
|
|
||||||
*
|
|
||||||
* @param postText is the html you get from the contentDIV smartarea sth like:
|
|
||||||
* text text text <input .... value="Massimiliano Assante" ... type="text"><span> etc etc</span>
|
|
||||||
*
|
|
||||||
* @return a String ready to be posted
|
|
||||||
*/
|
|
||||||
private String transformPost(String postText) {
|
|
||||||
ArrayList<String> taggedPeople = extractPeopleTags(postText);
|
|
||||||
if (taggedPeople == null || taggedPeople.size() == 0) { //there are no tagged people, remove html and go
|
|
||||||
String escapedFeedText = escapeHtml(postText); //here escape html to avoid xss attacks
|
|
||||||
String html = "<html><head></head><body>" + escapedFeedText + "</body></html>";
|
|
||||||
return html2text(html);
|
|
||||||
} else {
|
|
||||||
_log.trace("postText curing: " + postText);
|
|
||||||
// this is needed to reconstruct the place of people tags, selfexplaining i think
|
|
||||||
int i = 0;
|
|
||||||
while (postText.contains("<input")) {
|
|
||||||
//the replacing does not affect html but affects the While guard
|
|
||||||
postText = postText.replaceFirst("<input", "_usr_place_holder_["+i+"]<br");
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
String html = "<html><head></head><body>" + postText + "</body></html>";
|
|
||||||
String postWithPlaceHolders = html2text(html);
|
|
||||||
_log.trace("before cure: " + postWithPlaceHolders);
|
|
||||||
/*
|
|
||||||
* at this point you have the html removed and somthing like "text text text _usr_place_holder_[0] text text text _usr_place_holder_[1]"
|
|
||||||
* you need to replace _usr_place_holder_[i](s) with the people with same index in taggedPeople ArrayList
|
|
||||||
*/
|
|
||||||
String escapedFeedText = escapeHtml(postWithPlaceHolders); //here escape html to avoid xss attacks
|
|
||||||
ArrayList<String> usernames = getSelectedUserIds(taggedPeople);
|
|
||||||
i = 0;
|
|
||||||
for (String tagged : taggedPeople) {
|
|
||||||
String username = (i < usernames.size()) ? usernames.get(i) : "";
|
|
||||||
String taggedHTML = "<a class=\"link\" href=\""+GCubeSocialNetworking.USER_PROFILE_LINK+"?uid="+ username + "\">"+tagged+"</a> ";
|
|
||||||
escapedFeedText = escapedFeedText.replace("_usr_place_holder_["+i+"]", taggedHTML);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
_log.trace("After cure: " + escapedFeedText);
|
|
||||||
return escapedFeedText;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -207,7 +132,8 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
||||||
public ClientFeed share(String postText, FeedType feedType, PrivacyLevel pLevel, String vreId, String linkTitle, String linkDesc, String url, String urlThumbnail, String host) {
|
public ClientFeed share(String postText, FeedType feedType, PrivacyLevel pLevel, String vreId, String linkTitle, String linkDesc, String url, String urlThumbnail, String host) {
|
||||||
|
|
||||||
String escapedFeedText = transformPost(postText);
|
String escapedFeedText = transformPost(postText);
|
||||||
String username = getASLSession().getUsername();
|
ASLSession session = getASLSession();
|
||||||
|
String username = session.getUsername();
|
||||||
String email = username+"@isti.cnr.it";
|
String email = username+"@isti.cnr.it";
|
||||||
String fullName = username+" FULL";
|
String fullName = username+" FULL";
|
||||||
String thumbnailURL = "images/Avatar_default.png";
|
String thumbnailURL = "images/Avatar_default.png";
|
||||||
|
@ -257,13 +183,103 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
||||||
}
|
}
|
||||||
if (!result) return null;
|
if (!result) return null;
|
||||||
|
|
||||||
|
//everything went fine
|
||||||
ClientFeed cf = new ClientFeed(toShare.getKey(), toShare.getType().toString(), username, feedDate, toShare.getUri(),
|
ClientFeed cf = new ClientFeed(toShare.getKey(), toShare.getType().toString(), username, feedDate, toShare.getUri(),
|
||||||
replaceAmpersand(toShare.getDescription()), fullName, email, thumbnailURL, toShare.getLinkTitle(), toShare.getLinkDescription(),
|
replaceAmpersand(toShare.getDescription()), fullName, email, thumbnailURL, toShare.getLinkTitle(), toShare.getLinkDescription(),
|
||||||
toShare.getUriThumbnail(), toShare.getLinkHost());
|
toShare.getUriThumbnail(), toShare.getLinkHost());
|
||||||
|
|
||||||
|
//send the notification to the mentioned users
|
||||||
|
ArrayList<String> mentionedUserIds = getSelectedUserIds(extractPeopleTags(postText));
|
||||||
|
if (mentionedUserIds != null && mentionedUserIds.size() > 0) {
|
||||||
|
NotificationsManager nm = new ApplicationNotificationsManager(session);
|
||||||
|
Thread thread = new Thread(new MentionNotificationsThread(toShare.getKey(), postText, nm, mentionedUserIds));
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
return cf;
|
return cf;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this method is used when posting a feed
|
||||||
|
*
|
||||||
|
* It converts the tagged people <input with the actual person profile link, not trivial
|
||||||
|
*
|
||||||
|
* @param postText is the html you get from the contentDIV smartarea sth like:
|
||||||
|
* text text text <input .... value="Massimiliano Assante" ... type="text"><span> etc etc</span>
|
||||||
|
*
|
||||||
|
* @return a String ready to be posted
|
||||||
|
*/
|
||||||
|
private String transformPost(String postText) {
|
||||||
|
ArrayList<String> taggedPeople = extractPeopleTags(postText);
|
||||||
|
if (taggedPeople == null || taggedPeople.size() == 0) { //there are no tagged people, remove html and go
|
||||||
|
String escapedFeedText = escapeHtml(postText); //here escape html to avoid xss attacks
|
||||||
|
String html = "<html><head></head><body>" + escapedFeedText + "</body></html>";
|
||||||
|
return html2text(html);
|
||||||
|
} else {
|
||||||
|
_log.trace("postText curing: " + postText);
|
||||||
|
// this is needed to reconstruct the place of people tags, selfexplaining i think
|
||||||
|
int i = 0;
|
||||||
|
while (postText.contains("<input")) {
|
||||||
|
//the replacing does not affect html but affects the While guard
|
||||||
|
postText = postText.replaceFirst("<input", "_usr_place_holder_["+i+"]<br");
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
String html = "<html><head></head><body>" + postText + "</body></html>";
|
||||||
|
String postWithPlaceHolders = html2text(html);
|
||||||
|
_log.trace("before cure: " + postWithPlaceHolders);
|
||||||
|
/*
|
||||||
|
* at this point you have the html removed and somthing like "text text text _usr_place_holder_[0] text text text _usr_place_holder_[1]"
|
||||||
|
* you need to replace _usr_place_holder_[i](s) with the people with same index in taggedPeople ArrayList
|
||||||
|
*/
|
||||||
|
String escapedFeedText = escapeHtml(postWithPlaceHolders); //here escape html to avoid xss attacks
|
||||||
|
ArrayList<String> usernames = getSelectedUserIds(taggedPeople);
|
||||||
|
i = 0;
|
||||||
|
for (String tagged : taggedPeople) {
|
||||||
|
String username = (i < usernames.size()) ? usernames.get(i) : "";
|
||||||
|
String taggedHTML = "<a class=\"link\" href=\""+GCubeSocialNetworking.USER_PROFILE_LINK+"?uid="+ username + "\">"+tagged+"</a> ";
|
||||||
|
escapedFeedText = escapedFeedText.replace("_usr_place_holder_["+i+"]", taggedHTML);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
_log.trace("After cure: " + escapedFeedText);
|
||||||
|
return escapedFeedText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this method extractPeopleTags from the user post
|
||||||
|
* @param postText text with tagged people: txt .. <input with the actual person profile
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private ArrayList<String> extractPeopleTags(String postText) {
|
||||||
|
ArrayList<String> toReturn = new ArrayList<String>();
|
||||||
|
String toParse = "<html><head></head><body>" + postText + "</body></html>";
|
||||||
|
|
||||||
|
HtmlCleaner cleaner = new HtmlCleaner();
|
||||||
|
// parse the string HTML
|
||||||
|
TagNode pageData = cleaner.clean(toParse);
|
||||||
|
TagNode[] inputElements = pageData.getElementsByName("input", true);
|
||||||
|
if (inputElements != null) {
|
||||||
|
for (int i = 0; i < inputElements.length; i++) {
|
||||||
|
System.out.println("Found input " + inputElements[i].getAttributes().get("value"));
|
||||||
|
toReturn.add(inputElements[i].getAttributes().get("value"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_log.trace("No person tags in this post");
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* remove all the html and leave the text
|
||||||
|
* @param html
|
||||||
|
* @return the text inside the html
|
||||||
|
*/
|
||||||
|
private static String html2text(String html) {
|
||||||
|
return Jsoup.parse(html).text().replace(" "," ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private UserSettings getUserSettingsFromSession() {
|
private UserSettings getUserSettingsFromSession() {
|
||||||
return (UserSettings) getASLSession().getAttribute(UserInfo.USER_INFO_ATTR);
|
return (UserSettings) getASLSession().getAttribute(UserInfo.USER_INFO_ATTR);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue