@ -7,7 +7,9 @@ import java.util.List;
import java.util.Map ;
import java.util.Set ;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider ;
import org.gcube.common.portal.PortalContext ;
import org.gcube.common.scope.api.ScopeProvider ;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched ;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked ;
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status ;
@ -35,7 +37,7 @@ import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet ;
import com.liferay.portal.service.UserLocalServiceUtil ;
// TODO: Auto-generated Javadoc
/ * *
* The server side implementation of the RPC service .
*
@ -123,29 +125,52 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
}
/ * *
* Gets the available catalogues for scope .
* Gets the available THREDDS catalogues for target scope .
*
* @param scope the scope
* @param targetFullScope the target scope
* @return the available catalogues for scope
* @throws Exception the exception
* /
@Override
public List < ThCatalogueBean > getAvailableCataloguesForScope ( String s cope) throws Exception {
public List < ThCatalogueBean > getAvailableCataloguesForScope ( String targetFullS cope) throws Exception {
if ( s cope= = null )
if ( targetFullS cope= = null )
throw new Exception ( "Invalid scope null" ) ;
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
String wsScope = PortalContext . getConfiguration ( ) . getCurrentScope ( this . getThreadLocalRequest ( ) ) ;
String wsUserToken = PortalContext . getConfiguration ( ) . getCurrentUserToken ( wsScope , user . getUsername ( ) ) ;
String targetScopeUserToken = PortalContext . getConfiguration ( ) . getCurrentUserToken ( scope , user . getUsername ( ) ) ;
List < ThCatalogueBean > listCtlgs = getSyncService ( ) . getAvailableCataloguesByToken ( scope , wsUserToken , targetScopeUserToken ) ;
logger . debug ( "Retuning " + listCtlgs . size ( ) + " Catalogues for scope: " + scope ) ;
if ( logger . isDebugEnabled ( ) ) {
for ( ThCatalogueBean thCatalogueBean : listCtlgs ) {
logger . debug ( thCatalogueBean . toString ( ) ) ;
String originalScope = null ;
String originalToken = null ;
List < ThCatalogueBean > listCtlgs = null ;
try {
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
String wsScope = PortalContext . getConfiguration ( ) . getCurrentScope ( this . getThreadLocalRequest ( ) ) ;
String wsUserToken = PortalContext . getConfiguration ( ) . getCurrentUserToken ( wsScope , user . getUsername ( ) ) ;
//Thread Local contexts
originalScope = wsScope ;
originalToken = wsUserToken ;
String targetScopeUserToken = PortalContext . getConfiguration ( ) . getCurrentUserToken ( targetFullScope , user . getUsername ( ) ) ;
listCtlgs = getSyncService ( ) . getAvailableCataloguesByToken ( targetFullScope , wsUserToken , targetScopeUserToken ) ;
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: " + targetFullScope , e ) ;
} finally {
if ( originalScope ! = null & & originalScope . compareTo ( targetFullScope ) ! = 0 ) {
logger . info ( "Resetting the scope: " + originalScope + " which was original WS context" ) ;
ScopeProvider . instance . set ( originalScope ) ;
if ( originalToken ! = null ) {
logger . info ( "Resetting the user token: " + originalToken . substring ( 0 , 10 ) + "-MASKED-TOKEN which was original WS context" ) ;
SecurityTokenProvider . instance . set ( originalToken ) ;
}
}
}
@ -169,7 +194,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
//DEV MODE
if ( ! isWithinPortal ( ) ) {
mapScopesRoles = new HashMap < String , GatewayRolesThredds > ( ) ;
// mapScopesRoles.put( "/gcube/devsec/devVRE", GatewayRolesThredds.THREDDS_PUBLISHER);
mapScopesRoles . put ( "/gcube/devNext/NextNext" , GatewayRolesThredds . DATA_MANAGER ) ;
// mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER);
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER);
return mapScopesRoles ;
@ -228,10 +253,13 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
List < GCubeGroup > listOfGroups = new ArrayList < GCubeGroup > ( 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 ( g roupId) ) {
scopeType = GcubeScopeType . VRE ;
} else if ( groupManager . isVO ( g CubeGroup. getG roupId( ) ) ) {
} else if ( groupManager . isVO ( g roupId) ) {
scopeType = GcubeScopeType . VO ;
}
// }else if(groupManager.isRootVO(gCubeGroup.getGroupId())){
@ -241,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 ) ;
}
@ -250,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 ) ;
}
@ -285,47 +314,29 @@ 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 s cope, GroupManager groupManager , GcubeScopeType scopeType ) throws Exception {
private GcubeScope checkDataManagerCapacityAndThreddsCatalogue ( GatewayRolesThredds role , String scopeName , String fullS cope, 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 < ThCatalogueBean > list = getAvailableCataloguesForScope ( scope. getGroupName ( ) ) ;
List < ThCatalogueBean > list = getAvailableCataloguesForScope ( fullScope ) ;
if ( list ! = null ) {
return new GcubeScope ( scope . getGroupName ( ) , groupManager . getInfrastructureScope ( scope . getGroupId ( ) ) , scopeType ) ;
return new GcubeScope ( scope Name, 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 ;
}
/ * *
* 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 . DATA_MANAGER ) ) {
return new GcubeScope ( scope . getGroupName ( ) , groupManager . getInfrastructureScope ( scope . getGroupId ( ) ) , scopeType ) ;
}
return null ;
}
/ * *
* Checks if is item synched .
*