@ -2,7 +2,6 @@ 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 ;
@ -100,31 +99,62 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
public ThSyncStatus doSyncFolder ( final String folderId , WsThreddsSynchFolderConfiguration clientConfig ) throws Exception {
logger . info ( "Performing doSyncFolder method on id: " + folderId + ", config: " + clientConfig ) ;
String originalScope = null ;
String originalToken = null ;
try {
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
PortalContext portalContext = PortalContext . getConfiguration ( ) ;
final GCubeUser user = portalContext . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
final String wsScope = portalContext . getCurrentScope ( this . getThreadLocalRequest ( ) ) ;
final String wsUserToken = portalContext . getCurrentUserToken ( wsScope , user . getUsername ( ) ) ;
//Thread Local contexts
originalScope = wsScope ;
originalToken = wsUserToken ;
String targetScopeUserToken = null ;
ThSynchFolderConfiguration config = null ;
if ( clientConfig ! = null ) {
targetScopeUserToken = PortalContext . getConfiguration ( ) . getCurrentUserToken ( clientConfig . getSelectedScope ( ) . getScopeName ( ) , user . getUsername ( ) ) ;
targetScopeUserToken = portalContext . getCurrentUserToken ( clientConfig . getSelectedScope ( ) . getScopeName ( ) , user . getUsername ( ) ) ;
config = BeanConverter . toThSynchFolderConfiguration ( clientConfig , folderId , targetScopeUserToken ) ;
logger . debug ( "Creating server config " + config ) ;
}
/ * Commented because Feature # 20979
logger . info ( "Calling doSyncFolder on folderId: " + folderId + ", config: " + config ) ;
String wsScope = PortalContext . getConfiguration ( ) . getCurrentScope ( this . getThreadLocalRequest ( ) ) ;
String wsUserToken = PortalContext . getConfiguration ( ) . getCurrentUserToken ( wsScope , user . getUsername ( ) ) ;
ThSyncStatus status = getSyncService ( ) . doSyncFolder ( folderId , config , wsScope , wsUserToken ) ;
* /
logger . info ( "Calling doSyncFolder on folderId: " + folderId + ", config: " + config ) ;
logger . info ( "Changing the context to target scope: " + clientConfig . getSelectedScope ( ) . getScopeName ( ) + ", target token: " + targetScopeUserToken . substring ( 0 , 10 ) + "-MASKED-TOKEN" ) ;
String targetScope = clientConfig . getSelectedScope ( ) . getScopeName ( ) ;
ThSyncStatus status = getSyncService ( ) . doSyncFolder ( folderId , config , targetScope , targetScopeUserToken ) ;
logger . debug ( "Returning for folderId " + folderId + " the syncStatus: " + status ) ;
return status ;
} catch ( Exception e ) {
logger . error ( "Do sync Folder error: " , e ) ;
throw new Exception ( "Sorry, an error occurred during synchonization phase, try again later" ) ;
} finally {
String currentScope = PortalContext . getConfiguration ( ) . getCurrentScope ( this . getThreadLocalRequest ( ) ) ;
if ( originalScope ! = null & & originalScope . compareTo ( currentScope ) ! = 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 ) ;
}
}
}
}
}
/ * *
* Gets the available THREDDS catalogues for target scope .
@ -143,14 +173,16 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
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 ( ) ) ;
PortalContext portalContext = PortalContext . getConfiguration ( ) ;
final GCubeUser user = portalContext . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
final String wsScope = portalContext . getCurrentScope ( this . getThreadLocalRequest ( ) ) ;
final String wsUserToken = portalContext . getCurrentUserToken ( wsScope , user . getUsername ( ) ) ;
//Thread Local contexts
originalScope = wsScope ;
originalToken = wsUserToken ;
String targetScopeUserToken = PortalContext. getConfiguration ( ) . getCurrentUserToken ( targetFullScope , user . getUsername ( ) ) ;
String targetScopeUserToken = portalContext . getCurrentUserToken ( targetFullScope , user . getUsername ( ) ) ;
listCtlgs = getSyncService ( ) . getAvailableCataloguesByToken ( targetFullScope , wsUserToken , targetScopeUserToken ) ;
logger . debug ( "Retuning " + listCtlgs . size ( ) + " Catalogues for scope: " + targetFullScope ) ;
@ -193,10 +225,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
//DEV MODE
if ( ! isWithinPortal ( ) ) {
mapScopesRoles = new HashMap < String , GatewayRolesThredds > ( ) ;
mapScopesRoles . put ( "/gcube/devNext/NextNext" , GatewayRolesThredds . DATA_MANAGER ) ;
// mapScopesRoles = new HashMap<String, GatewayRolesThredds>();
//mapScopesRoles.put("/gcube/devsec/devVRE", GatewayRolesThredds.DATA_EDITOR);
// mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER);
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds. THREDDS_PUBLISHE R);
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds. DATA_EDITO R);
return mapScopesRoles ;
}
@ -267,9 +299,9 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
// }
if ( scopeType ! = null ) {
GatewayRolesThredds roles = WsUtil . getThreddsRoleFor ( user , gCubeGroup ) ;
GatewayRolesThredds gatewayRole = WsUtil . getThreddsRoleFor ( user , gCubeGroup ) ;
//Adding only the scope where the user has the THREDDS_ADMIN role
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue ( roles , gCubeGroup . getGroupName ( ) , fullScope , groupManager , scopeType ) ;
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue ( gatewayRole , gCubeGroup . getGroupName ( ) , fullScope , groupManager , scopeType ) ;
if ( gcubeScope ! = null ) {
listOfScopes . add ( gcubeScope ) ;
}
@ -386,18 +418,18 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
}
/ * *
* Register callback for id .
*
* @param folderId the folder id
* @throws Exception the exception
* /
public void registerCallbackForId ( String folderId ) throws Exception {
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
String wsScope = PortalContext . getConfiguration ( ) . getCurrentScope ( this . getThreadLocalRequest ( ) ) ;
String wsUserToken = PortalContext . getConfiguration ( ) . getCurrentUserToken ( wsScope , user . getUsername ( ) ) ;
getSyncService ( ) . registerCallbackForId ( folderId , wsScope , wsUserToken ) ;
}
// /**
// * Register callback for id.
// *
// * @param folderId the folder id
// * @throws Exception the exception
// */
// public void registerCallbackForId(String folderId) throws Exception{
// GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
// String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
// String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
// getSyncService().registerCallbackForId(folderId, wsScope, wsUserToken);
// }
/ * *