@ -2,7 +2,10 @@ 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 ;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched ;
@ -13,6 +16,7 @@ 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.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 ;
@ -71,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 ;
}
}
@ -146,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 < String , GatewayRolesThredds > getScopesWithThreddsRolesForLoggedUser ( ) throws Exception {
logger . info ( "called getScopesWithThreddsRolesForLoggedUser" ) ;
GCubeUser user = null ;
Map < String , GatewayRolesThredds > mapScopesRoles = null ;
//DEV MODE
if ( ! isWithinPortal ( ) ) {
mapScopesRoles = new HashMap < String , GatewayRolesThredds > ( ) ;
// 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 ) ;
}
}
/ * *
@ -156,14 +198,15 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* /
@Override
public List < GcubeScope > getListOfScopesForLoggedUser ( ) throws Exception {
logger . debug ( "getListOfVREsForLoggedUser...: " ) ;
logger . info ( "getListOfVREsForLoggedUser...: " ) ;
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
long userId = user . getUserId ( ) ;
// Instanciate the manager
GroupManager groupManager = new LiferayGroupManager ( ) ;
List < GcubeScope > listOfScopes = new ArrayList < GcubeScope > ( ) ;
//DEV MODE
if ( ! isWithinPortal ( ) ) {
listOfScopes . add ( new GcubeScope ( "devVRE" , "/gcube/devsec/devVRE" , GcubeScopeType . VRE ) ) ;
listOfScopes . add ( new GcubeScope ( "NextNext" , "/gcube/devNext/NextNext" , GcubeScopeType . VRE ) ) ;
@ -176,7 +219,13 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try {
List < GCubeGroup > listOfGroups = groupManager . listGroupsByUser ( userId ) ;
String gatewayHostname = GenericUtils . getGatewayClientHostname ( getThreadLocalRequest ( ) ) ;
//list of Scopes filtered for gateway
Set < GCubeGroup > filteredGroupsForGatw = groupManager . listGroupsByUserAndSite ( userId , gatewayHostname ) ;
//List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(userId);
List < GCubeGroup > listOfGroups = new ArrayList < GCubeGroup > ( 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 +238,27 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
// }
if ( scopeType ! = null ) {
GcubeScope gcubeVRE = new GcubeScope ( gCubeGroup . getGroupName ( ) , groupManager . getInfrastructureScope ( gCubeGroup . getGroupId ( ) ) , scopeType ) ;
listOfScopes . add ( gcubeVRE ) ;
GatewayRolesThredds roles = WsUtil . getThreddsRoleFor ( user , gCubeGroup ) ;
//Adding only the scope where the user has the THREDDS_ADMIN role
GcubeScope gcubeScope = availableScopeForRoleAndCatalogue ( roles , gCubeGroup , groupManager , scopeType ) ;
if ( gcubeScope ! = null ) {
listOfScopes . add ( gcubeScope ) ;
}
}
}
GCubeGroup theRootVO = groupManager . getRootVO ( ) ;
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 ) ;
}
//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 +267,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 ) ;
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 }
* - 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 ( GatewayRolesThredds role , GCubeGroup scope , GroupManager groupManager , GcubeScopeType scopeType ) throws Exception {
if ( role ! = null & & role . equals ( GatewayRolesThredds . THREDDS_ADMIN ) ) {
try {
List < ThCatalogueBean > list = getAvailableCataloguesForScope ( scope . getGroupName ( ) ) ;
if ( list ! = null ) {
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 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 ( GatewayRolesThredds role , GCubeGroup scope , GroupManager groupManager , GcubeScopeType scopeType ) throws Exception {
if ( role ! = null & & role . equals ( 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 +388,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 +412,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
* /