Added filter in order to fetch organizations in which the user can publish

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@129153 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-17 20:43:57 +00:00
parent 7613502aaa
commit 96147b6e65
1 changed files with 24 additions and 3 deletions

View File

@ -3,8 +3,10 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.server;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
@ -17,6 +19,7 @@ import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.ckanutillibrary.CKanUtilsImpl;
import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean;
import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization;
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField;
@ -105,7 +108,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.debug("User in session is " + username);
String token = null;
if(this.getThreadLocalRequest().getSession().getAttribute("") != null)
if(this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY) != null)
token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY);
else{
@ -120,13 +123,31 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
}
/**
* Retrieve the list of organizations in which the user can publish
* Retrieve the list of organizations in which the user can publish (roles ADMIN, EDITOR)
* @param username
* @return the list of organizations
*/
private List<String> getUserOrganizationsList(String username) {
logger.debug("Request for user " + username + " organizations list");
return instance.getOrganizationsNamesByUser(username);
// We need to retrieve orgs in which the user has the roles ADMIN, EDITOR
List<RolesIntoOrganization> rolesToMatch = new ArrayList<RolesIntoOrganization>();
rolesToMatch.add(RolesIntoOrganization.EDITOR);
rolesToMatch.add(RolesIntoOrganization.ADMIN);
List<String> orgsName = new ArrayList<String>();
Map<String, List<RolesIntoOrganization>> orgsAndRoles = instance.getGroupsAndRolesByUser(username, rolesToMatch);
Iterator<Entry<String, List<RolesIntoOrganization>>> iterator = orgsAndRoles.entrySet().iterator();
// get the names
while (iterator.hasNext()) {
Map.Entry<String, java.util.List<RolesIntoOrganization>> entry = (Map.Entry<String, java.util.List<RolesIntoOrganization>>) iterator
.next();
orgsName.add(entry.getKey());
}
return orgsName;
}
/**