minor fixes

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@163124 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2018-02-09 14:39:52 +00:00
parent 611d3ab580
commit f9710ffbb5
2 changed files with 32 additions and 18 deletions

View File

@ -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<String, String> roleForVre = UserUtil.getVreRoleForUser(
SessionUtil.getCurrentUser(getThreadLocalRequest()).getEmail(),
SessionUtil.getCurrentUser(
getThreadLocalRequest()).getEmail(),
scopePerCurrentUrl,
getCatalogue(scopePerCurrentUrl), isViewPerVREEnabled() != null);
getCatalogue(scopePerCurrentUrl),
isViewPerVREEnabled() != null,
getThreadLocalRequest().getSession());
ckan.addListOfVREs(roleForVre);
return ckan;

View File

@ -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<String, String> getVreRoleForUser(String userEMail, String context, DataCatalogue instance, boolean isViewPerVREEnabled){
public static Map<String, String> getVreRoleForUser(String userEMail, String context, DataCatalogue instance, boolean isViewPerVREEnabled,
HttpSession httpSession){
GroupManager groupManager = new LiferayGroupManager();
UserManager userManager = new LiferayUserManager();
@ -70,17 +76,22 @@ public class UserUtil {
// perform further checks
if(!isViewPerVREEnabled){
List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(user.getUserId());
String keyPerScope = context + ADD_USER_TO_OTHER_ORG_KEY;
Boolean alreadyAdded = (Boolean)httpSession.getAttribute(keyPerScope);
if(alreadyAdded == null || !alreadyAdded){
new AddUserToOrganizationThread(
instance,
user,
listOfGroups,
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;