From f7948fafceeb7ad0430d4d27bcc150f8711f7987 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Mon, 9 May 2016 10:08:05 +0000 Subject: [PATCH] Fixed servlet code to retrieve user's groups when the portlet is deployed into root context git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/top-topics@128522 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../user/topics/server/TopicServiceImpl.java | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/topics/server/TopicServiceImpl.java b/src/main/java/org/gcube/portlets/user/topics/server/TopicServiceImpl.java index 289c8dc..7498f54 100644 --- a/src/main/java/org/gcube/portlets/user/topics/server/TopicServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/topics/server/TopicServiceImpl.java @@ -2,14 +2,12 @@ package org.gcube.portlets.user.topics.server; import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Map; import org.apache.commons.codec.binary.Base64; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.SessionManager; -import org.gcube.common.scope.impl.ScopeBean; -import org.gcube.common.scope.impl.ScopeBean.Type; -import org.gcube.portal.custom.communitymanager.SiteManagerUtil; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.databook.client.GCubeSocialNetworking; import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; @@ -18,13 +16,15 @@ import org.gcube.portlets.user.topics.client.TopicService; import org.gcube.portlets.user.topics.shared.HashTagAndOccurrence; import org.gcube.portlets.user.topics.shared.HashtagsWrapper; import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; -import com.liferay.portal.model.Organization; -import com.liferay.portal.model.User; /** * @author Massimiliano Assante, ISTI-CNR @@ -71,7 +71,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi //user = "massimiliano.assante"; return user; } - + /** * return the top 10 hashtag with max occurrence */ @@ -79,7 +79,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi public HashtagsWrapper getHashtags() { ArrayList hashtagsChart = new ArrayList<>(); ASLSession session = getASLSession(); - + String userName = session.getUsername(); boolean isInfrastructure = isInfrastructureScope(); try { @@ -96,11 +96,14 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi if (isInfrastructure) { _log.debug("****** retrieving hashtags for user VREs"); - User currUser = SiteManagerUtil.validateUser(userName); GroupManager gm = new LiferayGroupManager(); - for (Organization org : currUser.getOrganizations()) { - if (gm.isVRE(org.getOrganizationId())) { - String vreid = gm.getInfrastructureScope(org.getOrganizationId()); //get the scope + UserManager um = new LiferayUserManager(); + GCubeUser user = um.getUserByUsername(userName); + List groups = gm.listGroupsByUser(user.getUserId()); + for (GCubeGroup group : groups) { + if (gm.isVRE(group.getGroupId())) { + _log.debug("Retrieving hashtags from VRE " + group.getGroupName()); + String vreid = gm.getInfrastructureScope(group.getGroupId()); //get the scope Map map = store.getVREHashtagsWithOccurrence(vreid); for (String hashtag : map.keySet()) { toSort.add(new HashTagAndOccurrence(hashtag, map.get(hashtag))); @@ -118,6 +121,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi } } + _log.debug("Number of topics retrieved is " + toSort.size()); Collections.sort(toSort, Collections.reverseOrder()); int i = 0; for (HashTagAndOccurrence wrapper : toSort) { @@ -148,14 +152,15 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi private boolean isInfrastructureScope() { boolean toReturn = false; try { - ScopeBean scope = new ScopeBean(getASLSession().getScope()); - toReturn = scope.is(Type.INFRASTRUCTURE); + GroupManager manager = new LiferayGroupManager(); + long groupId = manager.getGroupIdFromInfrastructureScope(getASLSession().getScope()); + toReturn = !manager.isVRE(groupId); return toReturn; } - catch (NullPointerException e) { + catch (Exception e) { _log.error("NullPointerException in isInfrastructureScope returning false"); return false; - } + } } }