minor fix for vre's teams mentions

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@141947 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-01-31 14:16:51 +00:00
parent a094714ee0
commit e4aa59ec06
2 changed files with 33 additions and 8 deletions

View File

@ -5,9 +5,6 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="gcube-widgets-2.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="share-updates"/>
</wb-module>

View File

@ -10,10 +10,12 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import javax.net.ssl.HttpsURLConnection;
@ -54,6 +56,7 @@ import org.gcube.portlets.user.shareupdates.shared.UserSettings;
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
import org.gcube.social_networking.socialutillibrary.Utils;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.TeamRetrievalFault;
@ -86,12 +89,15 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
private DatabookStore store;
/**
* connect to cassandra at startup
* Connect to cassandra at startup
*/
public void init() {
store = new DBCassandraAstyanaxImpl();
}
/**
* Close connection pool on close
*/
public void destroy() {
store.closeConnection();
}
@ -209,7 +215,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
// check if is needed to notify people in the vre
notifyPeopleGroup(pLevel, vreOrgId, notifyGroup, username, email, fullName, thumbnailAvatarURL, toShare, hashtags, vreScope2Set, escapedFeedText);
notifyPeopleGroup(pLevel, vreOrgId, notifyGroup, username, email, fullName, thumbnailAvatarURL, toShare, hashtags, vreScope2Set, escapedFeedText, mentionedUsers);
//send the notification to the mentioned users
if (mentionedUsers != null && mentionedUsers.size() > 0)
@ -384,7 +390,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
// check if is needed to notify people in the vre
notifyPeopleGroup(pLevel, vreOrgId, notifyGroup, username, email, fullName, thumbnailAvatarURL, toShare, hashtags, vreScope2Set, textToPost);
notifyPeopleGroup(pLevel, vreOrgId, notifyGroup, username, email, fullName, thumbnailAvatarURL, toShare, hashtags, vreScope2Set, textToPost, mentionedUsers);
//send the notification to the mentioned users
if (mentionedUsers != null && mentionedUsers.size() > 0)
@ -416,7 +422,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
private void notifyPeopleGroup(PrivacyLevel pLevel, Long vreOrgId,
boolean notifyGroup, String username, String email,
String fullName, String thumbnailAvatarURL, Feed toShare,
List<String> hashtags, String vreScope2Set, String postText) {
List<String> hashtags, String vreScope2Set, String postText, ArrayList<ItemBean> mentionedUsers) {
//send the notification about this posts to everyone in the group if notifyGroup is true
if (pLevel == PrivacyLevel.SINGLE_VRE && vreOrgId != null && notifyGroup) {
@ -425,7 +431,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
vreScope2Set,
new SocialNetworkingUser(username, email, fullName, thumbnailAvatarURL),
NEWS_FEED_PORTLET_CLASSNAME);
Thread thread = new Thread(new PostNotificationsThread(toShare.getKey(), postText, ""+vreOrgId, nm, hashtags));
Thread thread = new Thread(new PostNotificationsThread(new LiferayUserManager(), toShare.getKey(), postText, ""+vreOrgId, nm, new HashSet<String>(hashtags), getVreGroupsNames(mentionedUsers)));
thread.start();
}
@ -450,6 +456,28 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
}
}
/**
* Extract mentioned VRE's group names
* @return Set<String> of vre groups' names
*/
private static Set<String> getVreGroupsNames(ArrayList<ItemBean> mentionedUsers){
Set<String> toReturn = new HashSet<String>();
RoleManager rManager = new LiferayRoleManager();
for (ItemBean itemBean : mentionedUsers) {
if(itemBean.isItemGroup())
try {
toReturn.add(rManager.getTeam(Long.parseLong(itemBean.getId())).getTeamName());
} catch (NumberFormatException | UserManagementSystemException
| TeamRetrievalFault e) {
_log.warn("Unable to add this team", e);
}
}
return toReturn;
}
/**
* Common method to notify users.
* @param vreScope2Set