added check to retrieve groups already stored by the portlet

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@134318 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-11-17 13:29:58 +00:00
parent cf300cf7e3
commit 9e1c853f33
1 changed files with 21 additions and 12 deletions

View File

@ -579,22 +579,31 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// get http session
HttpSession httpSession = getThreadLocalRequest().getSession();
String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
DataCatalogue catalogue = getCatalogue(scope);
List<CkanGroup> ckanGroups = catalogue.getGroups();
String apiKey = catalogue.getApiKeyFromUsername(username);
// Members/Admin of the group
for (CkanGroup ckanGroup : ckanGroups) {
String role = catalogue.getRoleOfUserInGroup(username, ckanGroup.getName(), apiKey);
// check if they are in session
String keyPerScopeGroups = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scope);
if(role == null)
continue;
if(httpSession.getAttribute(keyPerScopeGroups) != null){
toReturn = (List<GroupBean>)httpSession.getAttribute(keyPerScopeGroups);
logger.info("Found user's groups in session " + toReturn);
}else{
toReturn.add(new GroupBean(ckanGroup.getTitle(), ckanGroup.getName()));
DataCatalogue catalogue = getCatalogue(scope);
List<CkanGroup> ckanGroups = catalogue.getGroups();
String apiKey = catalogue.getApiKeyFromUsername(username);
// 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()));
}
httpSession.setAttribute(keyPerScopeGroups, toReturn);
}
logger.debug("List of groups to return is " + toReturn);
}else{
logger.warn("Dev mode detected");
toReturn = Arrays.asList(new GroupBean("Group title", "aaa"));