From 28ab028a0745a039ec3389e50edecf4771148c10 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Wed, 10 Jul 2013 15:39:14 +0000 Subject: [PATCH] fix for ticket #1911 git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@78905 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 4 +-- .settings/com.google.gdt.eclipse.core.prefs | 4 +-- .settings/org.eclipse.wst.common.component | 3 ++ pom.xml | 2 +- .../server/MentionNotificationsThread.java | 13 +++---- .../server/ShareUpdateServiceImpl.java | 34 ++++++++++++++----- 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/.classpath b/.classpath index b52e78d..1cfebfc 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + @@ -31,5 +31,5 @@ - + diff --git a/.settings/com.google.gdt.eclipse.core.prefs b/.settings/com.google.gdt.eclipse.core.prefs index 3e6b0b7..3947006 100644 --- a/.settings/com.google.gdt.eclipse.core.prefs +++ b/.settings/com.google.gdt.eclipse.core.prefs @@ -1,6 +1,6 @@ -#Sun Jun 02 00:32:02 CEST 2013 +#Wed Jul 10 16:38:29 CEST 2013 eclipse.preferences.version=1 jarsExcludedFromWebInfLib= -lastWarOutDir=/Users/massi/Documents/workspace/share-updates/target/share-updates-0.4.0-SNAPSHOT +lastWarOutDir=/Users/massi/Documents/workspace/share-updates/target/share-updates-0.5.0-SNAPSHOT warSrcDir=src/main/webapp warSrcDirIsOutput=false diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index fe006d9..a7f437d 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -5,6 +5,9 @@ + + uses + diff --git a/pom.xml b/pom.xml index 89cc431..bb6ce0c 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.user share-updates war - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT gCube Share Updates Portlet diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/MentionNotificationsThread.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/MentionNotificationsThread.java index cfede0c..2253df2 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/MentionNotificationsThread.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/MentionNotificationsThread.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import org.gcube.applicationsupportlayer.social.NotificationsManager; import org.gcube.common.core.utils.logging.GCUBEClientLog; +import org.gcube.portlets.user.pickuser.shared.PickingUser; /** * @@ -16,22 +17,22 @@ public class MentionNotificationsThread implements Runnable { private String postText; private String postId; private NotificationsManager nm; - private ArrayList userIds; + private ArrayList users; - public MentionNotificationsThread(String postId, String postText, NotificationsManager nm, ArrayList userIds) { + public MentionNotificationsThread(String postId, String postText, NotificationsManager nm, ArrayList users) { super(); this.postId = postId; this.postText = postText; this.nm = nm; - this.userIds = userIds; + this.users = users; } @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); + for (PickingUser userToNotify : users) { + boolean result = nm.notifyUserTag(userToNotify.getUsername(), postId, postText); + _log.trace("Sending Notification for post mention to: " + userToNotify.getUsername() + " result?"+ result); } } } diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java index 56aebea..cba7313 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java @@ -24,6 +24,7 @@ import org.gcube.applicationsupportlayer.social.NotificationsManager; import org.gcube.common.core.utils.logging.GCUBEClientLog; import org.gcube.portal.custom.communitymanager.OrganizationsUtil; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; +import org.gcube.portal.databook.client.GCubeSocialNetworking; import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; import org.gcube.portal.databook.server.DatabookStore; import org.gcube.portal.databook.shared.ClientFeed; @@ -124,9 +125,18 @@ 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, ArrayList mentionedUserFullNames) { + public ClientFeed share(String postText, FeedType feedType, PrivacyLevel pLevel, + String vreId, String linkTitle, String linkDesc, String url, String urlThumbnail, String host, ArrayList mentionedUserFullNames) { String escapedFeedText = escapeHtml(postText); + + ArrayList mentionedUsers = null; + if (mentionedUserFullNames != null && ! mentionedUserFullNames.isEmpty()) { + mentionedUsers = getSelectedUserIds(mentionedUserFullNames); + escapedFeedText = convertMentionPeopleAnchorHTML(escapedFeedText, mentionedUsers); + } + + ASLSession session = getASLSession(); String username = session.getUsername(); String email = username+"@isti.cnr.it"; @@ -184,10 +194,10 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar toShare.getUriThumbnail(), toShare.getLinkHost()); //send the notification to the mentioned users - ArrayList mentionedUserIds = getSelectedUserIds(mentionedUserFullNames); - if (mentionedUserIds != null && mentionedUserIds.size() > 0) { + + if (mentionedUsers != null && mentionedUsers.size() > 0) { NotificationsManager nm = new ApplicationNotificationsManager(session); - Thread thread = new Thread(new MentionNotificationsThread(toShare.getKey(), escapedFeedText, nm, mentionedUserIds)); + Thread thread = new Thread(new MentionNotificationsThread(toShare.getKey(), escapedFeedText, nm, mentionedUsers)); thread.start(); } @@ -195,7 +205,13 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar } - + private String convertMentionPeopleAnchorHTML(String escapedFeedText, ArrayList taggedPeople) { + for (PickingUser tagged : taggedPeople) { + String taggedHTML = ""+tagged.getFullName()+" "; + escapedFeedText = escapedFeedText.replace(tagged.getFullName(), taggedHTML); + } + return escapedFeedText; + } private UserSettings getUserSettingsFromSession() { return (UserSettings) getASLSession().getAttribute(UserInfo.USER_INFO_ATTR); @@ -617,16 +633,16 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar * * @return the screennames of the addressee (user logins e.g. pino.pini) */ - public ArrayList getSelectedUserIds(ArrayList fullNames) { + public ArrayList getSelectedUserIds(ArrayList fullNames) { if (fullNames == null) - return new ArrayList(); + return new ArrayList(); else { ArrayList allUsers = getPortalUsers(); - ArrayList toReturn = new ArrayList(); + ArrayList toReturn = new ArrayList(); for (String fullName : fullNames) for (PickingUser puser : allUsers) { if (puser.getFullName().compareTo(fullName) == 0) { - toReturn.add(puser.getUsername()); + toReturn.add(puser); break; } }