getGroups and getOrganizations now use the newest and fastest ckan-utility-lib's methods which directly query the database

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@141852 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-01-27 10:27:40 +00:00
parent 3427b10f81
commit 7080f55c9e
1 changed files with 28 additions and 23 deletions

View File

@ -5,6 +5,8 @@ import static org.gcube.common.authorization.client.Constants.authorizationServi
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.servlet.http.HttpSession;
@ -160,7 +162,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
return ckan;
}
// retrieve the list of VREs to whom the user belongs
// 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(),
scopePerCurrentUrl,
@ -269,19 +271,17 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
try{
DataCatalogue catalogue = getCatalogue(context);
List<CkanGroup> ckanGroups = catalogue.getGroups();
String apiKey = catalogue.getApiKeyFromUsername(username);
toReturn = new ArrayList<GroupBean>();
// Members/Admin of the group
for (CkanGroup ckanGroup : ckanGroups) {
String role = catalogue.getRoleOfUserInGroup(username, ckanGroup.getName(), apiKey);
if(role == null)
continue;
toReturn.add(new GroupBean(ckanGroup.getTitle(), ckanGroup.getName()));
Map<String, Map<CkanGroup, RolesCkanGroupOrOrg>> mapRoleGroup = catalogue.getUserRoleByGroup(username, apiKey);
Set<Entry<String, Map<CkanGroup, RolesCkanGroupOrOrg>>> set = mapRoleGroup.entrySet();
for (Entry<String, Map<CkanGroup, RolesCkanGroupOrOrg>> entry : set) {
Set<Entry<CkanGroup, RolesCkanGroupOrOrg>> subSet = entry.getValue().entrySet();
for (Entry<CkanGroup, RolesCkanGroupOrOrg> subEntry : subSet) {
toReturn.add(new GroupBean(subEntry.getKey().getTitle(), subEntry.getKey().getName()));
}
}
logger.debug("List of groups to return is " + toReturn);
}catch(Exception e){
@ -430,19 +430,20 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
}else{
logger.debug("Organizations list wasn't into session, retrieving them");
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
List<CkanOrganization> organizations = catalogue.getOrganizationsByUser(username);
String apiKey = catalogue.getApiKeyFromUsername(username);
for (CkanOrganization ckanOrganization : organizations) {
String role = catalogue.getRoleOfUserInOrganization(username, ckanOrganization.getName(), apiKey);
BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName(), RolesCkanGroupOrOrg.valueOf(role.toUpperCase()));
toReturn.add(org);
Map<String, Map<CkanOrganization, RolesCkanGroupOrOrg>> mapRoleGroup = catalogue.getUserRoleByOrganization(username, apiKey);
Set<Entry<String, Map<CkanOrganization, RolesCkanGroupOrOrg>>> set = mapRoleGroup.entrySet();
for (Entry<String, Map<CkanOrganization, RolesCkanGroupOrOrg>> entry : set) {
Set<Entry<CkanOrganization, RolesCkanGroupOrOrg>> subSet = entry.getValue().entrySet();
for (Entry<CkanOrganization, RolesCkanGroupOrOrg> subEntry : subSet) {
BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(subEntry.getKey().getTitle(), "/organization/" + subEntry.getKey().getName(), subEntry.getValue());
toReturn.add(org);
}
}
logger.debug("List of organizations to return for user " + username + " is " + toReturn);
httpSession.setAttribute(keyPerScope, toReturn);
}
}
return toReturn;
}
@ -473,12 +474,16 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
}else{
logger.debug("Groups list wasn't into session, retrieving them");
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
List<CkanGroup> groups = catalogue.getGroupsByUser(username);
String apiKey = catalogue.getApiKeyFromUsername(username);
for (CkanGroup ckanGroup : groups) {
String role = catalogue.getRoleOfUserInGroup(username, ckanGroup.getName(), apiKey);
BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanGroup.getTitle(), "/group/" + ckanGroup.getName(), RolesCkanGroupOrOrg.valueOf(role.toUpperCase()));
toReturn.add(org);
Map<String, Map<CkanGroup, RolesCkanGroupOrOrg>> mapRoleGroup = catalogue.getUserRoleByGroup(username, apiKey);
Set<Entry<String, Map<CkanGroup, RolesCkanGroupOrOrg>>> set = mapRoleGroup.entrySet();
for (Entry<String, Map<CkanGroup, RolesCkanGroupOrOrg>> entry : set) {
Set<Entry<CkanGroup, RolesCkanGroupOrOrg>> subSet = entry.getValue().entrySet();
for (Entry<CkanGroup, RolesCkanGroupOrOrg> subEntry : subSet) {
BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(subEntry.getKey().getTitle(), "/group/" + subEntry.getKey().getName(), subEntry.getValue());
toReturn.add(org);
}
}
logger.debug("List of groups to return for user " + username + " is " + toReturn);
httpSession.setAttribute(keyPerScope, toReturn);