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 ee89197..393921b 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 @@ -129,14 +129,14 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem /** * Gets the available THREDDS catalogues for target scope. * - * @param targetScope the target scope + * @param targetFullScope the target scope * @return the available catalogues for scope * @throws Exception the exception */ @Override - public List getAvailableCataloguesForScope(String targetScope) throws Exception { + public List getAvailableCataloguesForScope(String targetFullScope) throws Exception { - if(targetScope==null) + if(targetFullScope==null) throw new Exception("Invalid scope null"); String originalScope = null; @@ -150,19 +150,20 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem originalScope = wsScope; originalToken = wsUserToken; - String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, user.getUsername()); - listCtlgs = getSyncService().getAvailableCataloguesByToken(targetScope, wsUserToken, targetScopeUserToken); + String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetFullScope, user.getUsername()); + listCtlgs = getSyncService().getAvailableCataloguesByToken(targetFullScope, wsUserToken, targetScopeUserToken); - logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+targetScope); + logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+targetFullScope); if(logger.isDebugEnabled()){ for (ThCatalogueBean thCatalogueBean : listCtlgs) { logger.debug(thCatalogueBean.toString()); } } }catch (Exception e) { - logger.error("Error on checking available Catalogue in the scope: "+targetScope, e); + logger.error("Error on checking available Catalogue in the scope: "+targetFullScope, e); }finally { - if(originalScope!=null && originalScope.compareTo(targetScope)!=0) { + + if(originalScope!=null && originalScope.compareTo(targetFullScope)!=0) { logger.info("Resetting the scope: "+originalScope + " was original WS context"); ScopeProvider.instance.set(originalScope); if(originalToken!=null) { @@ -252,10 +253,13 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem List listOfGroups = new ArrayList(filteredGroupsForGatw); logger.info("list of VREs in the gateway "+gatewayHostname+" are "+listOfGroups.size()); for (GCubeGroup gCubeGroup : listOfGroups) { + long groupId = gCubeGroup.getGroupId(); + String fullScope = groupManager.getInfrastructureScope(groupId); + logger.debug("For groupId: "+groupId+" got full scope: "+fullScope); GcubeScopeType scopeType=null; - if(groupManager.isVRE(gCubeGroup.getGroupId())){ + if(groupManager.isVRE(groupId)){ scopeType = GcubeScopeType.VRE; - }else if(groupManager.isVO(gCubeGroup.getGroupId())){ + }else if(groupManager.isVO(groupId)){ scopeType = GcubeScopeType.VO; } // }else if(groupManager.isRootVO(gCubeGroup.getGroupId())){ @@ -265,7 +269,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem if(scopeType!=null){ GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, gCubeGroup); //Adding only the scope where the user has the THREDDS_ADMIN role - GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, gCubeGroup, groupManager, scopeType); + GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, gCubeGroup.getGroupName(), fullScope, groupManager, scopeType); if(gcubeScope!=null) { listOfScopes.add(gcubeScope); } @@ -274,8 +278,9 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem GCubeGroup theRootVO = groupManager.getRootVO(); GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, theRootVO); + String rootVOFullScope = groupManager.getInfrastructureScope(theRootVO.getGroupId()); ///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the ROOT-VO - GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, theRootVO, groupManager, GcubeScopeType.ROOT); + GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, theRootVO.getGroupName(), rootVOFullScope, groupManager, GcubeScopeType.ROOT); if(gcubeScope!=null) { listOfScopes.add(gcubeScope); } @@ -309,22 +314,23 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem * - the scope has an available THREDDS catalogue configured * * @param role the role - * @param scope the scope + * @param scopeName the scope name e.g. devVRE + * @param fullScope the full scope e.g. /gcube/devsec/devVRE * @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 checkDataManagerCapacityAndThreddsCatalogue(GatewayRolesThredds role, GCubeGroup scope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception { - + private GcubeScope checkDataManagerCapacityAndThreddsCatalogue(GatewayRolesThredds role, String scopeName, String fullScope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception { + logger.debug("checking Data-Manager capacity and THREEDS catalogues for role: "+role, "scope name: "+scopeName+", scope: "+fullScope + " scope type: "+scopeType); if(role!=null && role.getRoleName().equalsIgnoreCase(GatewayRolesNames.DATA_MANAGER.getRoleName())){ try { - List list = getAvailableCataloguesForScope(scope.getGroupName()); + List list = getAvailableCataloguesForScope(fullScope); if(list!=null) { - return new GcubeScope(scope.getGroupName(), groupManager.getInfrastructureScope(scope.getGroupId()), scopeType); + return new GcubeScope(scopeName, fullScope, scopeType); } }catch (Exception e) { - logger.error("Error on checking available catalogue for scope: "+scope.getGroupName(), e); + logger.error("Error on checking available catalogue for scope: "+fullScope, e); } } 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 21d995a..64148d8 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 @@ -173,7 +173,7 @@ public class WsUtil { } } - logger.info("For user: "+user+" in the scope: "+scope.getGroupName()+" read the role/s: " + threddsRoles); + logger.info("For user: "+user.getUsername()+" in the scope: "+scope.getGroupName()+" read the role/s: " + threddsRoles); GatewayRolesThredds toReturn = null; if (threddsRoles.contains(GatewayRolesThredds.DATA_MANAGER))