From 2cfc589a1321b8b5a38b495251c60f44fed23ce3 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 3 Mar 2021 18:14:53 +0100 Subject: [PATCH 1/3] Starting work on #20847 --- CHANGELOG.md | 4 + pom.xml | 2 +- .../wsthreddssync/client/WsThreddsWidget.java | 4 + .../wsthreddssync/server/GenericUtils.java | 46 +++++++ .../ThreddsWorkspaceSyncServiceImpl.java | 116 ++++++++++++++++-- .../widgets/wsthreddssync/server/WsUtil.java | 89 +++++++++++++- .../shared/GatewayRolesThredds.java | 18 +++ 7 files changed, 267 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/GenericUtils.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GatewayRolesThredds.java diff --git a/CHANGELOG.md b/CHANGELOG.md index d736f2d..0b74765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v1.3.0-SNAPSHOT] - 2021-03-03 + +[#20847] Support the roles of THREDDS Admin and THREDDS Publisher + ## [v1.2.0] - 2020-07-21 [#19676] Migrated to git/jenkins diff --git a/pom.xml b/pom.xml index eeac454..9556869 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portlets.widgets ws-thredds-sync-widget jar - 1.2.0 + 1.3.0-SNAPSHOT ws-thredds-sync-widget gCube ws-thredds-sync-widget is a widget to use and interact with ws-thredds facility in order to syncronize the Workspace folders with Thredds Reporitory folders diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java index 3ce54c1..9347724 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java @@ -50,6 +50,10 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { private WsThreddsWidgetViewManager viewManager = new WsThreddsWidgetViewManager(); private final List syncEventsListeners = new ArrayList(); + + public static final String MISSING_THREDDS_ADMIN_RIGHTS = "It seems you are not authorized to create a configuration with Thredds Catalogue. Request it to the VRE manager or the portal administrator."; + + public static final String MISSING_THREDDS_PUBLISHER_RIGHTS = "It seems you are not authorized to run a syncronization task with Thredds Catalogue. Request it to the VRE manager or the portal administrator."; /** * This is the entry point method. diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/GenericUtils.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/GenericUtils.java new file mode 100644 index 0000000..380b54d --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/GenericUtils.java @@ -0,0 +1,46 @@ +package org.gcube.portlets.widgets.wsthreddssync.server; + +import java.net.MalformedURLException; +import java.net.URL; + +import javax.servlet.http.HttpServletRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The Class GenericUtils. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Mar 3, 2021 + */ +public class GenericUtils { + + public static Logger LOG = LoggerFactory.getLogger(GenericUtils.class); + + /** + * Gets the gateway client hostname. + * + * @param httpServletRequest the http servlet request + * @return the gateway client hostname + */ + public static String getGatewayClientHostname(HttpServletRequest httpServletRequest) { + try { + String clientURL = httpServletRequest.getRequestURL().toString(); + URL gURL = new URL(clientURL); + StringBuilder theURL = new StringBuilder(); +// theURL.append(gURL.getProtocol()); +// theURL.append("://"); + theURL.append(gURL.getHost()); + return theURL.toString(); + } catch (MalformedURLException e) { + LOG.warn("Failed to determine the gateway from the client url: "+httpServletRequest.getRequestURL()); + return null; + } + } + + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 580de0a..ee5255f 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.wsthreddssync.server; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Set; import org.gcube.common.portal.PortalContext; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; @@ -12,7 +13,9 @@ import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; +import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GenericUtils; import org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService; +import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScopeType; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; @@ -156,7 +159,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem */ @Override public List getListOfScopesForLoggedUser() throws Exception{ - logger.debug("getListOfVREsForLoggedUser...: "); + logger.info("getListOfVREsForLoggedUser...: "); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); long userId = user.getUserId(); @@ -176,7 +179,13 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem try { - List listOfGroups = groupManager.listGroupsByUser(userId); + String gatewayHostname = GenericUtils.getGatewayClientHostname(getThreadLocalRequest()); + //list of Scopes filtered for gateway + Set filteredGroupsForGatw = groupManager.listGroupsByUserAndSite(userId, gatewayHostname); + + //List listOfGroups = groupManager.listGroupsByUser(userId); + List listOfGroups = new ArrayList(filteredGroupsForGatw); + logger.info("list of VREs in the gateway "+gatewayHostname+" are "+listOfGroups.size()); for (GCubeGroup gCubeGroup : listOfGroups) { GcubeScopeType scopeType=null; if(groupManager.isVRE(gCubeGroup.getGroupId())){ @@ -189,16 +198,39 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem // } if(scopeType!=null){ - GcubeScope gcubeVRE = new GcubeScope(gCubeGroup.getGroupName(), groupManager.getInfrastructureScope(gCubeGroup.getGroupId()), scopeType); - listOfScopes.add(gcubeVRE); + List roles = WsUtil.getThreddsRoleFor(user, gCubeGroup); + //Adding only the scope where the user has the (GatewayRolesThredds.THREDDS_ADMIN role + /*if(roles!=null && roles.size()>0 && roles.contains(GatewayRolesThredds.THREDDS_ADMIN)) { + GcubeScope gcubeScope = new GcubeScope(gCubeGroup.getGroupName(), groupManager.getInfrastructureScope(gCubeGroup.getGroupId()), scopeType); + listOfScopes.add(gcubeScope); + }*/ + + //Adding only the scope where the user has the THREDDS_ADMIN role + GcubeScope gcubeScope = availableScopeForRole(roles, gCubeGroup, groupManager, scopeType); + if(gcubeScope!=null) { + listOfScopes.add(gcubeScope); + } } - + } + + GCubeGroup theRootVO = groupManager.getRootVO(); + List roles = WsUtil.getThreddsRoleFor(user, theRootVO); + //ADDING THE ROOT SCOPE + /*if(roles!=null && roles.size()>0 && roles.contains(GatewayRolesThredds.THREDDS_ADMIN)) { + GcubeScope gcubeScope = new GcubeScope(theRootVO.getGroupName(), groupManager.getInfrastructureScope(theRootVO.getGroupId()), GcubeScopeType.ROOT); + listOfScopes.add(gcubeScope); + }*/ + + ///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the scope + GcubeScope gcubeScope = availableScopeForRole(roles, theRootVO, groupManager, GcubeScopeType.ROOT); + if(gcubeScope!=null) { + listOfScopes.add(gcubeScope); } //ADDING THE ROOT SCOPE - String infraName = PortalContext.getConfiguration().getInfrastructureName(); + /*String infraName = PortalContext.getConfiguration().getInfrastructureName(); GcubeScope gcubeRoot = new GcubeScope(infraName, "/"+infraName, GcubeScopeType.ROOT); - listOfScopes.add(gcubeRoot); + listOfScopes.add(gcubeRoot)*/ } @@ -207,15 +239,72 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem logger.error("Error occurred server-side getting VRE folders: ", e); throw new Exception("Sorry, an error occurred server-side getting VRE folders, try again later"); } + + if(listOfScopes.isEmpty()) { + throw new Exception("No scope detected with the needed role: "+GatewayRolesThredds.THREDDS_ADMIN.getRoleName()+". Contact the VRE manager or the portal administrator"); + } Collections.sort(listOfScopes); logger.info("Returning list of VREs: "+listOfScopes); return listOfScopes; } + + + /** + * Available scope for role and catalogue, checks if for the input scope: + * - the user has the role {@link GatewayRolesThredds.#THREDDS_ADMIN}alid catalogue configured for thredds + * - the scope has an available thredds catalogue configured (by calling the service) + * + * @param roles the roles + * @param scope the scope + * @param groupManager the group manager + * @param scopeType the scope type + * @return the gcube scope {@link GcubeScope} if the two conditions (see description) are satisfied, null otherwise + * @throws Exception the exception + */ + private GcubeScope availableScopeForRoleAndCatalogue(List roles, GCubeGroup scope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception { + + if(roles!=null && roles.size()>0 && roles.contains(GatewayRolesThredds.THREDDS_ADMIN)) { + try { + List list = getAvailableCataloguesForScope(scope.getGroupName()); + if(list!=null && list.size()>0) { + return new GcubeScope(scope.getGroupName(), groupManager.getInfrastructureScope(scope.getGroupId()), scopeType); + } + }catch (Exception e) { + logger.error("Error on checking available catalogue for scope: "+scope.getGroupName(), e); + } + } + return null; + } + + + /** + * Available scope for role , checks if for the input scope the user has the role of {@link GatewayRolesThredds.#THREDDS_ADMIN} + * + * @param roles the roles + * @param scope the scope + * @param groupManager the group manager + * @param scopeType the scope type + * @return the gcube scope {@link GcubeScope} if the user has the role of {@link GatewayRolesThredds.#THREDDS_ADMIN}, null otherwise + * @throws Exception the exception + */ + private GcubeScope availableScopeForRole(List roles, GCubeGroup scope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception { + + if(roles!=null && roles.size()>0 && roles.contains(GatewayRolesThredds.THREDDS_ADMIN)) { + return new GcubeScope(scope.getGroupName(), groupManager.getInfrastructureScope(scope.getGroupId()), scopeType); + } + return null; + } - - + /** + * Checks if is item synched. + * + * @param folderId the folder id + * @return the ws thredds synch folder descriptor + * @throws WorkspaceFolderLocked the workspace folder locked + * @throws Exception the exception + */ /* (non-Javadoc) * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#isItemSynched(java.lang.String) */ @@ -271,6 +360,14 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem } + /** + * Monitor sync status. + * + * @param folderId the folder id + * @return the th sync status + * @throws ItemNotSynched the item not synched + * @throws Exception the exception + */ /* (non-Javadoc) * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#monitorSyncStatus(java.lang.String) */ @@ -287,7 +384,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem * Do sync folder. * * @param folderId the folder id - * @param clientConfig the th config * @return the th sync status * @throws Exception the exception */ diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java index 2315ec7..26c7479 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java @@ -3,7 +3,15 @@ */ package org.gcube.portlets.widgets.wsthreddssync.server; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; //import org.gcube.common.homelibrary.home.HomeLibrary; //import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; @@ -14,6 +22,17 @@ import org.gcube.common.portal.PortalContext; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; import org.gcube.common.storagehubwrapper.server.tohl.Workspace; +import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.the; +import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds; +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.RoleManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; +import org.gcube.vomanagement.usermanagement.model.GCubeRole; //import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; @@ -21,7 +40,6 @@ import org.slf4j.LoggerFactory; import com.liferay.portal.service.UserLocalServiceUtil; - /** * The Class WsUtil. * @@ -29,7 +47,10 @@ import com.liferay.portal.service.UserLocalServiceUtil; * Nov 25, 2016 */ public class WsUtil { + + + /** The logger. */ private static Logger logger = LoggerFactory.getLogger(WsUtil.class); @@ -96,4 +117,70 @@ public class WsUtil { } } + /** + * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the thredds roles the user has in them. + * retrieve the VREs to whom a given user + * + * @param user the user + * @return the list vre for user + */ + public static Map> getScopesThreddsRolesForUser(GCubeUser user){ + logger.info("called getScopesThreddsRolesForUser user: "+user+", in all contexts"); + + GroupManager groupManager = new LiferayGroupManager(); + Map> mapRoleByGroupSingleVre = new HashMap>(); + //GCubeUser user; + try { + + //Retrieving the list of VOs and VREs + List listOfGroups = groupManager.listGroupsByUser(user.getUserId()); + //adding also the ROOT-VO + listOfGroups.add(groupManager.getRootVO()); + for (GCubeGroup gCubeGroup : listOfGroups) { + List threddsRoles = getThreddsRoleFor(user, gCubeGroup); + if(threddsRoles.size()>0) { + mapRoleByGroupSingleVre.put(gCubeGroup.getGroupName(), threddsRoles); + } + } + + logger.info("For user: "+user+", returning Map (VRE, ThreddsRoles) " + mapRoleByGroupSingleVre); + return mapRoleByGroupSingleVre; + }catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) { + logger.error("An error occurred during geThreddsVreRolesForUser: "+user, e); + return null; + } + } + + + /** + * Gets the thredds role for the user in the vre + * + * @param user the user + * @param vre the vre + * @return the thredds role for + */ + public static List getThreddsRoleFor(GCubeUser user, GCubeGroup vre){ + logger.info("called getThreddsRoleFor user: "+user+", in the scope: "+vre.getGroupName()); + try { + RoleManager roleManager = new LiferayRoleManager(); + List roles = roleManager.listRolesByUserAndGroup(user.getUserId(), vre.getGroupId()); + List threddsRoles = new ArrayList(); + for (GCubeRole gCubeRole : roles) { + if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.THREDDS_ADMIN.getRoleName())){ + threddsRoles.add(GatewayRolesThredds.THREDDS_ADMIN); + } + if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.THREDDS_PUBLISHER.getRoleName())){ + threddsRoles.add(GatewayRolesThredds.THREDDS_PUBLISHER); + } + } + + logger.info("For user: "+user+" in the scope: "+vre.getGroupName()+" returning roles: " + threddsRoles); + return threddsRoles; + }catch (UserRetrievalFault | GroupRetrievalFault e) { + logger.error("An error occurred during getVreRoleForUser: "+user, e); + return null; + } + } + + } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GatewayRolesThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GatewayRolesThredds.java new file mode 100644 index 0000000..2fa7f1c --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GatewayRolesThredds.java @@ -0,0 +1,18 @@ +package org.gcube.portlets.widgets.wsthreddssync.shared; + + public enum GatewayRolesThredds { + + THREDDS_ADMIN("Thredds-Admin"), + THREDDS_PUBLISHER("Thredds-Publisher"); + + private String name; + + private GatewayRolesThredds(String name) { + this.name = name; + } + + public String getRoleName() { + return this.name; + } + +} From e438b0084b9720fc2eec6d80119c742d4f2467b5 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 3 Mar 2021 18:16:56 +0100 Subject: [PATCH 2/3] removed unused imports --- .../wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java | 1 - .../gcube/portlets/widgets/wsthreddssync/server/WsUtil.java | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index ee5255f..51ded4f 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -13,7 +13,6 @@ import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; -import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GenericUtils; import org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService; import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope; diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java index 26c7479..2d5927d 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java @@ -3,15 +3,12 @@ */ package org.gcube.portlets.widgets.wsthreddssync.server; -import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; //import org.gcube.common.homelibrary.home.HomeLibrary; //import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; @@ -22,7 +19,6 @@ import org.gcube.common.portal.PortalContext; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; import org.gcube.common.storagehubwrapper.server.tohl.Workspace; -import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.the; import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.RoleManager; From b0ce8ac5e314a6bc0dc528c382fad76ce465bb59 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 4 Mar 2021 16:24:54 +0100 Subject: [PATCH 3/3] Added management to support the roles of THREDDS Admin and THREDDS Publisher --- .../wsthreddssync/client/WsThreddsWidget.java | 107 ++++++++++++++---- .../rpc/ThreddsWorkspaceSyncService.java | 11 ++ .../rpc/ThreddsWorkspaceSyncServiceAsync.java | 5 + .../view/WsThreddsWidgetViewManager.java | 78 ++++++++----- .../binder/ShowThreddsFolderInfoView.java | 10 ++ .../ThreddsWorkspaceSyncServiceImpl.java | 91 ++++++++++----- .../widgets/wsthreddssync/server/WsUtil.java | 38 ++++--- 7 files changed, 244 insertions(+), 96 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java index 9347724..177da75 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java @@ -2,6 +2,7 @@ package org.gcube.portlets.widgets.wsthreddssync.client; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; @@ -19,17 +20,21 @@ import org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncS import org.gcube.portlets.widgets.wsthreddssync.client.view.LoaderIcon; import org.gcube.portlets.widgets.wsthreddssync.client.view.WsThreddsWidgetViewManager; import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.MonitorFolderSyncStatusView; +import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds; import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; +import com.github.gwtbootstrap.client.ui.Alert; import com.github.gwtbootstrap.client.ui.Modal; +import com.github.gwtbootstrap.client.ui.constants.AlertType; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.HorizontalPanel; // TODO: Auto-generated Javadoc @@ -51,10 +56,12 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { private final List syncEventsListeners = new ArrayList(); - public static final String MISSING_THREDDS_ADMIN_RIGHTS = "It seems you are not authorized to create a configuration with Thredds Catalogue. Request it to the VRE manager or the portal administrator."; + public static final String MISSING_THREDDS_ADMIN_RIGHTS = "It seems you are not authorized to create a configuration towards THREDDS Catalogue. Request it to the VRE manager or the portal administrator."; + + public static final String MISSING_THREDDS_PUBLISHER_RIGHTS = "It seems you are not authorized to run a syncronization task towards THREDDS Catalogue. Request it to the VRE manager or the portal administrator."; + + public static final String MISSING_THREDDS_RIGHTS = "It seems you are not authorized to interact with the facility 'Sync with THREDDS'. Request authorization to the VRE manager or the portal administrator."; - public static final String MISSING_THREDDS_PUBLISHER_RIGHTS = "It seems you are not authorized to run a syncronization task with Thredds Catalogue. Request it to the VRE manager or the portal administrator."; - /** * This is the entry point method. */ @@ -146,38 +153,96 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { final Modal box = new Modal(true); box.setTitle("Checking configurations..."); - LoaderIcon loader = new LoaderIcon("Checking folder configurations..."); - box.add(loader); - - GWT.log("Performing isItemSynched: "+folder.getFolderId()); - WsThreddsWidget.wsThreddsSyncService.isItemSynched(folder.getFolderId(), new AsyncCallback() { + final HorizontalPanel hpLoader = new HorizontalPanel(); + LoaderIcon loader = new LoaderIcon("Checking authorizations and folder configurations..."); + hpLoader.add(loader); + box.add(hpLoader); + + //LAOADING ROLES + WsThreddsWidget.wsThreddsSyncService.getScopesWithThreddsRolesForLoggedUser(new AsyncCallback>() { @Override - public void onSuccess(WsThreddsSynchFolderDescriptor result) { - box.hide(); - //GWT.log("WsThreddsSynchFolderDescriptor result: "+result); - viewManager.showThreddsFolderInfo(folder, result); - + public void onFailure(Throwable caught) { + hpLoader.clear(); + hpLoader.setVisible(false); + Alert alert = new Alert(); + alert.setType(AlertType.INFO); + alert.setText(caught.getMessage()); + box.add(alert); } @Override - public void onFailure(Throwable caught) { - box.hide(); + public void onSuccess(Map result) { + try { + hpLoader.clear(); + hpLoader.setVisible(false); + }catch (Exception e) { + //Silent + } + + if(result!=null) { + + GWT.log("Returned Map(Scope,Role): "+result); + final boolean isThreddsPubliser = result.containsValue(GatewayRolesThredds.THREDDS_PUBLISHER); + final boolean isThreddsAdmin = result.containsValue(GatewayRolesThredds.THREDDS_ADMIN); + + //no rights assigned + if(!isThreddsAdmin && !isThreddsPubliser) { + showMissingRights(box); + return; + } + + //at least one THREDDS rights is assigned + GWT.log("Performing isItemSynched: "+folder.getFolderId()); + WsThreddsWidget.wsThreddsSyncService.isItemSynched(folder.getFolderId(), new AsyncCallback() { + + @Override + public void onSuccess(WsThreddsSynchFolderDescriptor result) { + box.hide(); + //GWT.log("WsThreddsSynchFolderDescriptor result: "+result); + viewManager.showThreddsFolderInfo(folder, result, isThreddsAdmin, isThreddsPubliser); - if(caught instanceof WorkspaceFolderLocked){ - viewManager.showMonitorSyncToFolder(folder,syncEventsListeners); + } + + @Override + public void onFailure(Throwable caught) { + box.hide(); + + if(caught instanceof WorkspaceFolderLocked){ + viewManager.showMonitorSyncToFolder(folder,syncEventsListeners); + return; + } + + viewManager.cancelMonitor(folder); + Window.alert(caught.getMessage()); + } + }); + + + + + }else { + //no rights detected + showMissingRights(box); return; } - - viewManager.cancelMonitor(folder); - // TODO Auto-generated method stub - Window.alert(caught.getMessage()); + } + }); + box.show(); } + + private void showMissingRights(Modal box) { + Alert alert = new Alert(); + alert.setType(AlertType.WARNING); + alert.setText(MISSING_THREDDS_RIGHTS); + alert.setClose(false); + box.add(alert); + } private void performFolderUnSync(final WsFolder folder) { GWT.log("Performing doSyncFolder on: "+folder); diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java index f52e9c5..28a7b99 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java @@ -1,11 +1,13 @@ package org.gcube.portlets.widgets.wsthreddssync.client.rpc; import java.util.List; +import java.util.Map; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; +import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; @@ -79,4 +81,13 @@ public interface ThreddsWorkspaceSyncService extends RemoteService { * @throws Exception the exception */ Boolean doUnSyncFolder(String folderId) throws Exception; + + /** + * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them. + * + * @param user the user + * @return the VREs and Thredds roles for a given user + * @throws Exception + */ + Map getScopesWithThreddsRolesForLoggedUser() throws Exception; } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java index fee13d1..aff801c 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java @@ -1,9 +1,11 @@ package org.gcube.portlets.widgets.wsthreddssync.client.rpc; import java.util.List; +import java.util.Map; import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; +import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; @@ -109,4 +111,7 @@ public interface ThreddsWorkspaceSyncServiceAsync * @param callback the callback */ void doUnSyncFolder(String folderId, AsyncCallback callback); + + + void getScopesWithThreddsRolesForLoggedUser(AsyncCallback> callback); } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java index 9be1b6e..27229d4 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java @@ -1,7 +1,5 @@ package org.gcube.portlets.widgets.wsthreddssync.client.view; - - import java.util.HashMap; import java.util.List; import java.util.Map; @@ -34,8 +32,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.VerticalPanel; - -// TODO: Auto-generated Javadoc /** * The Class WsThreddsWidgetViewManager. * @@ -44,9 +40,11 @@ import com.google.gwt.user.client.ui.VerticalPanel; */ public class WsThreddsWidgetViewManager { + public static final String CREATE_CONFIGURATION = "Create Configuration"; + public static final String THIS_FOLDER_IS_NOT_CONFIGURED_DO_YOU_WANT_CREATE_A_CONFIGURATION = "This Folder is not configured. Do you want create a configuration?"; + private Map mapMonitor = new HashMap(); - /** * Instantiates a new ws thredds widget view manager. */ @@ -332,8 +330,10 @@ public class WsThreddsWidgetViewManager { * * @param folder the folder * @param folderDescriptor the folder descriptor + * @param isThreddsAdmin the is thredds admin + * @param isThreddsPubliser the is thredds publiser */ - public void showThreddsFolderInfo(final WsFolder folder, final WsThreddsSynchFolderDescriptor folderDescriptor){ + public void showThreddsFolderInfo(final WsFolder folder, final WsThreddsSynchFolderDescriptor folderDescriptor, final boolean isThreddsAdmin, final boolean isThreddsPubliser){ GWT.log("ShowThreddsFolderInfo folder: "+folder); //GWT.log("WsThreddsSynchFolderDescriptor is: "+folderDescriptor); @@ -358,10 +358,10 @@ public class WsThreddsWidgetViewManager { } }; - boolean isCreateConfiguration = folderDescriptor==null?true:false; + final boolean isCreateConfiguration = folderDescriptor==null?true:false; - ShowThreddsFolderInfoView folderInfo = new ShowThreddsFolderInfoView(folder.getFolderId(), isCreateConfiguration) { + final ShowThreddsFolderInfoView folderInfo = new ShowThreddsFolderInfoView(folder.getFolderId(), isCreateConfiguration) { @Override public void submitHandler(SUBMIT_ACTION action) { @@ -410,37 +410,59 @@ public class WsThreddsWidgetViewManager { }; folderInfo.updateViewToResult(folder, folderDescriptor); - + if(isCreateConfiguration) { folderInfo.getMainPanel().setVisible(false); - folderInfo.setError(true, "This Folder is not configured. Do you want create a configuration?"); - folderInfo.getPager().getLeft().setText("Create Configuration"); + + if(isThreddsAdmin) { + folderInfo.setError(true, THIS_FOLDER_IS_NOT_CONFIGURED_DO_YOU_WANT_CREATE_A_CONFIGURATION); + folderInfo.getPager().getLeft().setText(CREATE_CONFIGURATION); + }else { + //Create Configuration button + folderInfo.getPager().getLeft().setVisible(false); + folderInfo.setError(true, WsThreddsWidget.MISSING_THREDDS_ADMIN_RIGHTS); + } + }else { //USER CAN PERFORM DO SYNC //MOREOVER, HE/SHE COULD UPDATE THE CONFIGURATION BUT IT IS NOT SUPPORTED SERVER-SIDE + + //hiding create/update configuration folderInfo.getPager().getLeft().setVisible(false); + + if(isThreddsPubliser || isThreddsAdmin) { + + //hiding unsync button if the user is a publisher + if(isThreddsPubliser) + folderInfo.showUnsyncButton(false); + + if(folderDescriptor.getServerFolderDescriptor().isLocked()) { + VerticalPanel v = new VerticalPanel(); + Alert alert = new Alert("Current Folder synchronization is locked by another proccess. Do you want see synchronization status?"); + alert.setClose(true); + alert.setType(AlertType.INFO); + + Button butt = new Button("Show Status"); + butt.addClickHandler(new ClickHandler() { - if(folderDescriptor.getServerFolderDescriptor().isLocked()) { - VerticalPanel v = new VerticalPanel(); - Alert alert = new Alert("Current Folder synchronization is locked by another proccess. Do you want see synchronization status?"); - alert.setClose(true); - alert.setType(AlertType.INFO); - - Button butt = new Button("Show Status"); - butt.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - WsThreddsWidget.eventBus.fireEvent(new ShowMonitorSyncStatusEvent(folder)); - } - }); + @Override + public void onClick(ClickEvent event) { + WsThreddsWidget.eventBus.fireEvent(new ShowMonitorSyncStatusEvent(folder)); + } + }); - v.add(alert); - v.add(butt); - box.add(v); + v.add(alert); + v.add(butt); + box.add(v); + } + }else { + //DoSync button + folderInfo.getPager().getRight().setVisible(false); + folderInfo.setError(true, WsThreddsWidget.MISSING_THREDDS_PUBLISHER_RIGHTS); } } + panelView.addViewAsWidget(folderInfo); box.add(panelView); diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java index 1859e1a..4762035 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java @@ -355,6 +355,16 @@ public abstract class ShowThreddsFolderInfoView extends Composite { public HTMLPanel getMainPanel(){ return form_unit_fields; } + + + /** + * Show unsync. + * + * @param show the show + */ + public void showUnsyncButton(boolean show) { + button_do_unsync.setVisible(show); + } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 51ded4f..9cd73f9 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -2,7 +2,9 @@ package org.gcube.portlets.widgets.wsthreddssync.server; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import org.gcube.common.portal.PortalContext; @@ -73,7 +75,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem return true; } catch (Exception ex) { - logger.trace("Development Mode ON"); + logger.warn("Development Mode ON"); return false; } } @@ -148,6 +150,44 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem return listCtlgs; } + + + /** + * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them. + * + * @param user the user + * @return the VREs and Thredds roles for a given user + * @throws Exception + */ + @Override + public Map getScopesWithThreddsRolesForLoggedUser() throws Exception{ + logger.info("called getScopesWithThreddsRolesForLoggedUser"); + + GCubeUser user = null; + Map mapScopesRoles = null; + + //DEV MODE + if (!isWithinPortal()){ + mapScopesRoles = new HashMap(); +// mapScopesRoles.put( "/gcube/devsec/devVRE", GatewayRolesThredds.THREDDS_PUBLISHER); +// mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER); +// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER); + return mapScopesRoles; + } + + try { + + user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user); + + logger.info("returning Map(scopes,roles): "+mapScopesRoles); + return mapScopesRoles; + }catch (Exception e) { + String errorMsg = "An error occurred on checking user roles. Refresh the page and try again."; + logger.error("An error occurred on checking user roles for user: "+user, e); + throw new Exception(errorMsg); + } + } /** @@ -165,7 +205,8 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem // Instanciate the manager GroupManager groupManager = new LiferayGroupManager(); List listOfScopes = new ArrayList(); - + + //DEV MODE if (!isWithinPortal()){ listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE)); listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE)); @@ -197,15 +238,9 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem // } if(scopeType!=null){ - List roles = WsUtil.getThreddsRoleFor(user, gCubeGroup); - //Adding only the scope where the user has the (GatewayRolesThredds.THREDDS_ADMIN role - /*if(roles!=null && roles.size()>0 && roles.contains(GatewayRolesThredds.THREDDS_ADMIN)) { - GcubeScope gcubeScope = new GcubeScope(gCubeGroup.getGroupName(), groupManager.getInfrastructureScope(gCubeGroup.getGroupId()), scopeType); - listOfScopes.add(gcubeScope); - }*/ - + GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, gCubeGroup); //Adding only the scope where the user has the THREDDS_ADMIN role - GcubeScope gcubeScope = availableScopeForRole(roles, gCubeGroup, groupManager, scopeType); + GcubeScope gcubeScope = availableScopeForRoleAndCatalogue(roles, gCubeGroup, groupManager, scopeType); if(gcubeScope!=null) { listOfScopes.add(gcubeScope); } @@ -213,15 +248,9 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem } GCubeGroup theRootVO = groupManager.getRootVO(); - List roles = WsUtil.getThreddsRoleFor(user, theRootVO); - //ADDING THE ROOT SCOPE - /*if(roles!=null && roles.size()>0 && roles.contains(GatewayRolesThredds.THREDDS_ADMIN)) { - GcubeScope gcubeScope = new GcubeScope(theRootVO.getGroupName(), groupManager.getInfrastructureScope(theRootVO.getGroupId()), GcubeScopeType.ROOT); - listOfScopes.add(gcubeScope); - }*/ - - ///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the scope - GcubeScope gcubeScope = availableScopeForRole(roles, theRootVO, groupManager, GcubeScopeType.ROOT); + GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, theRootVO); + ///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the ROOT-VO + GcubeScope gcubeScope = availableScopeForRoleAndCatalogue(roles, theRootVO, groupManager, GcubeScopeType.ROOT); if(gcubeScope!=null) { listOfScopes.add(gcubeScope); } @@ -244,29 +273,29 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem } Collections.sort(listOfScopes); - logger.info("Returning list of VREs: "+listOfScopes); + logger.info("Returning list of allowed scope/s with: "+GatewayRolesThredds.THREDDS_ADMIN + " role/s: "+listOfScopes); return listOfScopes; } /** * Available scope for role and catalogue, checks if for the input scope: - * - the user has the role {@link GatewayRolesThredds.#THREDDS_ADMIN}alid catalogue configured for thredds - * - the scope has an available thredds catalogue configured (by calling the service) - * - * @param roles the roles + * - the user has the role {@link GatewayRolesThredds.#THREDDS_ADMIN} + * - the scope has an available thredds catalogue configured + * + * @param role the role * @param scope the scope * @param groupManager the group manager * @param scopeType the scope type * @return the gcube scope {@link GcubeScope} if the two conditions (see description) are satisfied, null otherwise * @throws Exception the exception */ - private GcubeScope availableScopeForRoleAndCatalogue(List roles, GCubeGroup scope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception { + private GcubeScope availableScopeForRoleAndCatalogue(GatewayRolesThredds role, GCubeGroup scope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception { - if(roles!=null && roles.size()>0 && roles.contains(GatewayRolesThredds.THREDDS_ADMIN)) { + if(role!=null && role.equals(GatewayRolesThredds.THREDDS_ADMIN)) { try { List list = getAvailableCataloguesForScope(scope.getGroupName()); - if(list!=null && list.size()>0) { + if(list!=null) { return new GcubeScope(scope.getGroupName(), groupManager.getInfrastructureScope(scope.getGroupId()), scopeType); } }catch (Exception e) { @@ -279,17 +308,17 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem /** * Available scope for role , checks if for the input scope the user has the role of {@link GatewayRolesThredds.#THREDDS_ADMIN} - * - * @param roles the roles + * + * @param role the role * @param scope the scope * @param groupManager the group manager * @param scopeType the scope type * @return the gcube scope {@link GcubeScope} if the user has the role of {@link GatewayRolesThredds.#THREDDS_ADMIN}, null otherwise * @throws Exception the exception */ - private GcubeScope availableScopeForRole(List roles, GCubeGroup scope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception { + private GcubeScope availableScopeForRole(GatewayRolesThredds role, GCubeGroup scope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception { - if(roles!=null && roles.size()>0 && roles.contains(GatewayRolesThredds.THREDDS_ADMIN)) { + if(role!=null && role.equals(GatewayRolesThredds.THREDDS_ADMIN)) { return new GcubeScope(scope.getGroupName(), groupManager.getInfrastructureScope(scope.getGroupId()), scopeType); } return null; diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java index 2d5927d..ee9ef4a 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java @@ -114,18 +114,16 @@ public class WsUtil { } /** - * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the thredds roles the user has in them. - * retrieve the VREs to whom a given user + * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them. * * @param user the user - * @return the list vre for user + * @return the VREs and Thredds roles for a given user */ - public static Map> getScopesThreddsRolesForUser(GCubeUser user){ + public static Map getScopesWithThreddsRolesForUser(GCubeUser user){ logger.info("called getScopesThreddsRolesForUser user: "+user+", in all contexts"); GroupManager groupManager = new LiferayGroupManager(); - Map> mapRoleByGroupSingleVre = new HashMap>(); - //GCubeUser user; + Map mapRoleByGroupSingleVre = new HashMap(); try { //Retrieving the list of VOs and VREs @@ -133,9 +131,9 @@ public class WsUtil { //adding also the ROOT-VO listOfGroups.add(groupManager.getRootVO()); for (GCubeGroup gCubeGroup : listOfGroups) { - List threddsRoles = getThreddsRoleFor(user, gCubeGroup); - if(threddsRoles.size()>0) { - mapRoleByGroupSingleVre.put(gCubeGroup.getGroupName(), threddsRoles); + GatewayRolesThredds threddsRole = getThreddsRoleFor(user, gCubeGroup); + if(threddsRole != null) { + mapRoleByGroupSingleVre.put(gCubeGroup.getGroupName(), threddsRole); } } @@ -149,17 +147,17 @@ public class WsUtil { /** - * Gets the thredds role for the user in the vre + * Gets the (highest) thredds role for the user in the scope * * @param user the user - * @param vre the vre + * @param scope the vre * @return the thredds role for */ - public static List getThreddsRoleFor(GCubeUser user, GCubeGroup vre){ - logger.info("called getThreddsRoleFor user: "+user+", in the scope: "+vre.getGroupName()); + public static GatewayRolesThredds getThreddsRoleFor(GCubeUser user, GCubeGroup scope){ + logger.info("called getThreddsRoleFor user: "+user+", in the scope: "+scope.getGroupName()); try { RoleManager roleManager = new LiferayRoleManager(); - List roles = roleManager.listRolesByUserAndGroup(user.getUserId(), vre.getGroupId()); + List roles = roleManager.listRolesByUserAndGroup(user.getUserId(), scope.getGroupId()); List threddsRoles = new ArrayList(); for (GCubeRole gCubeRole : roles) { if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.THREDDS_ADMIN.getRoleName())){ @@ -170,8 +168,16 @@ public class WsUtil { } } - logger.info("For user: "+user+" in the scope: "+vre.getGroupName()+" returning roles: " + threddsRoles); - return threddsRoles; + logger.info("For user: "+user+" in the scope: "+scope.getGroupName()+" read the role/s: " + threddsRoles); + + GatewayRolesThredds toReturn = null; + if (threddsRoles.contains(GatewayRolesThredds.THREDDS_ADMIN)) + toReturn = GatewayRolesThredds.THREDDS_ADMIN; + else if (threddsRoles.contains(GatewayRolesThredds.THREDDS_PUBLISHER)) + toReturn = GatewayRolesThredds.THREDDS_PUBLISHER; + + logger.info("returning role: " + toReturn); + return toReturn; }catch (UserRetrievalFault | GroupRetrievalFault e) { logger.error("An error occurred during getVreRoleForUser: "+user, e); return null;