diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 295fdab..bd011ee 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -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 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 rolesToMatch = new ArrayList(); + rolesToMatch.add(RolesIntoOrganization.EDITOR); + rolesToMatch.add(RolesIntoOrganization.ADMIN); + + List orgsName = new ArrayList(); + Map> orgsAndRoles = instance.getGroupsAndRolesByUser(username, rolesToMatch); + Iterator>> iterator = orgsAndRoles.entrySet().iterator(); + + // get the names + while (iterator.hasNext()) { + Map.Entry> entry = (Map.Entry>) iterator + .next(); + orgsName.add(entry.getKey()); + } + + return orgsName; } /**