diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java index a5e1b4d..c3b468e 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java @@ -167,9 +167,12 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem // retrieve the list of VREs to whom the user belongs (actually one vre at most is sent) Map roleForVre = UserUtil.getVreRoleForUser( - SessionUtil.getCurrentUser(getThreadLocalRequest()).getEmail(), - scopePerCurrentUrl, - getCatalogue(scopePerCurrentUrl), isViewPerVREEnabled() != null); + SessionUtil.getCurrentUser( + getThreadLocalRequest()).getEmail(), + scopePerCurrentUrl, + getCatalogue(scopePerCurrentUrl), + isViewPerVREEnabled() != null, + getThreadLocalRequest().getSession()); ckan.addListOfVREs(roleForVre); return ckan; diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/UserUtil.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/UserUtil.java index b614388..e98a587 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/UserUtil.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/UserUtil.java @@ -7,6 +7,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.servlet.http.HttpSession; + import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue; import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server.thread.AddUserToOrganizationThread; @@ -42,14 +44,18 @@ public class UserUtil { //private static Logger logger = LoggerFactory.getLogger(UserUtil.class); private static final Log logger = LogFactoryUtil.getLog(UserUtil.class); + private static final String ADD_USER_TO_OTHER_ORG_KEY = "ADD_USER_TO_OTHER_ORG_KEY"; + /** * Gets the list vre for user and the role the user has in them. * retrieve the groups to whom a given user belongs (given the user EMail) * @param userEMail the user e mail + * @param httpSession * @param pathVre * @return the list vre for user */ - public static Map getVreRoleForUser(String userEMail, String context, DataCatalogue instance, boolean isViewPerVREEnabled){ + public static Map getVreRoleForUser(String userEMail, String context, DataCatalogue instance, boolean isViewPerVREEnabled, + HttpSession httpSession){ GroupManager groupManager = new LiferayGroupManager(); UserManager userManager = new LiferayUserManager(); @@ -58,29 +64,34 @@ public class UserUtil { GCubeUser user; try { user = userManager.getUserByEmail(userEMail); - + // filter according the current context: if it is a VO/VRE, we send all the VRES under the VO. If it is the root vo, we send all user's vres. long groupIdContext = groupManager.getGroupIdFromInfrastructureScope(context); GCubeGroup currentVRE = groupManager.getGroup(groupIdContext); String localRoleInThisVre = RolesCkanGroupOrOrg.convertToCkanCapacity(getLiferayHighestRoleInOrg(roleManager.listRolesByUserAndGroup(user.getUserId(), currentVRE.getGroupId()))); - + // ckan-connector will do it mapRoleByGroupSingleVre.put(currentVRE.getGroupName().toLowerCase(), localRoleInThisVre); - + // perform further checks if(!isViewPerVREEnabled){ - List listOfGroups = groupManager.listGroupsByUser(user.getUserId()); - new AddUserToOrganizationThread( - instance, - user, - listOfGroups, - isViewPerVREEnabled, - groupIdContext, - roleManager, - groupManager, - localRoleInThisVre). - start(); + String keyPerScope = context + ADD_USER_TO_OTHER_ORG_KEY; + Boolean alreadyAdded = (Boolean)httpSession.getAttribute(keyPerScope); + + if(alreadyAdded == null || !alreadyAdded){ + new AddUserToOrganizationThread( + instance, + user, + groupManager.listGroupsByUser(user.getUserId()), + isViewPerVREEnabled, + groupIdContext, + roleManager, + groupManager, + localRoleInThisVre). + start(); + httpSession.setAttribute(keyPerScope, true); + } } logger.debug("Returning Map to the ckan connector : " + mapRoleByGroupSingleVre); return mapRoleByGroupSingleVre;