@ -7,11 +7,12 @@ import java.util.List;
import java.util.Map ;
import java.util.Set ;
import javax.servlet.http.HttpServletRequest ;
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 ;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean ;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor ;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus ;
@ -22,7 +23,6 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScopeType ;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration ;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor ;
import org.gcube.usecases.ws.thredds.SyncEngine ;
import org.gcube.vomanagement.usermanagement.GroupManager ;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault ;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException ;
@ -37,11 +37,12 @@ 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 .
*
* @author Francesco Mangiacrapa francesco . mangiacrapa @isti.cnr.it Feb 14 , 2018
* @author Francesco Mangiacrapa francesco . mangiacrapa @isti.cnr.it
* Feb 14 , 2018
* /
@SuppressWarnings ( "serial" )
public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implements ThreddsWorkspaceSyncService {
@ -59,10 +60,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* /
public synchronized SyncronizeWithThredds getSyncService ( ) {
if ( syncThredds = = null )
if ( syncThredds = = null )
syncThredds = new SyncronizeWithThredds ( ) ;
return syncThredds ;
return syncThredds ;
}
@ -75,212 +76,146 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try {
UserLocalServiceUtil . getService ( ) ;
return true ;
} catch ( Exception ex ) {
}
catch ( Exception ex ) {
logger . warn ( "Development Mode ON" ) ;
return false ;
}
}
/ * *
* Gets the available THREDDS catalogues for target scope .
*
* @param targetFullScope the target scope
* @return the available catalogues for scope
* @throws Exception the exception
* /
// UPDATED
@Override
public List < ThCatalogueBean > getAvailableCataloguesForScope ( String targetFullScope ) throws Exception {
if ( targetFullScope = = null )
throw new Exception ( "Invalid scope null" ) ;
List < ThCatalogueBean > listCtlgs = null ;
try {
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
listCtlgs = getSyncService ( ) . getAvailableCatalogues ( this . getThreadLocalRequest ( ) , user , targetFullScope ) ;
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 ) ;
}
return listCtlgs ;
}
/ * *
* Gets the configuration .
*
* @param folderId the folder id
* @param loadStatus the load status . If true it loads the status by calling the
* { @link SyncEngine # check ( String , boolean ) } but it is time
* consuming . No otherwise .
* @return the ws thredds synch folder descriptor
* @throws WorkspaceFolderLocked the workspace folder locked
* @throws Exception the exception
* /
@Override
public WsThreddsSynchFolderDescriptor getConfiguration ( String folderId , boolean loadStatus )
throws WorkspaceFolderLocked , Exception {
logger . debug ( "called isItemSynched for folderId: " + folderId ) ;
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
return getConfiguration ( folderId , loadStatus , this . getThreadLocalRequest ( ) , user ) ;
}
/ * *
* Gets the configuration .
*
* @param folderId the folder id
* @param loadStatus the load status
* @param httpRequest the http request
* @param user the user
* @return the configuration
* @throws Exception the exception
* /
public WsThreddsSynchFolderDescriptor getConfiguration ( String folderId , boolean loadStatus ,
HttpServletRequest httpRequest , GCubeUser user ) throws Exception {
logger . debug ( "called internal getConfiguration for folderId: " + folderId ) ;
try {
ThSyncFolderDescriptor theConfig = getSyncService ( ) . getConfiguration ( folderId , loadStatus , httpRequest ,
user ) ;
if ( theConfig ! = null ) {
logger . info ( "Folder id: " + folderId + " is synched" ) ;
WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter . toWsThreddsFolderConfig ( theConfig ) ;
logger . debug ( "isItemSynched for id: " + folderId + " returning: " + toWsThreddFolder ) ;
return toWsThreddFolder ;
}
logger . info ( "Folder id: " + folderId + " is not synched, returning null descriptor" ) ;
return null ;
} catch ( ItemNotSynched e ) {
logger . info ( "The folderId: " + folderId + " is not synched, returning null for "
+ WsThreddsSynchFolderDescriptor . class . getSimpleName ( ) ) ;
return null ;
} catch ( WorkspaceFolderLocked e ) {
logger . warn ( e . getMessage ( ) + ", sending exception to client..." ) ;
throw new WorkspaceFolderLocked ( e . getFolderId ( ) , e . getMessage ( ) ) ;
} catch ( Exception e ) {
logger . info ( "Error on isItemSynched for folderId: " + folderId , e ) ;
throw new Exception ( e ) ;
}
}
/ * *
* Do sync folder .
*
* @param folderId the folder id
* @param clientConfig the clien t config
* @param folderId the folder id
* @param clientConfig the th config
* @return the th sync status
* @throws Exception the exception
* /
// UPDATED
/ * ( non - Javadoc )
* @see org . gcube . portlets . widgets . wsthreddssync . client . rpc . ThreddsWorkspaceSyncService # doSyncFolder ( java . lang . String , org . gcube . portlets . widgets . wsthreddssync . shared . WsThreddsSynchFolderDescriptor )
* /
@Override
public ThSyncStatus doSyncFolder ( final String folderId , WsThreddsSynchFolderConfiguration clientConfig )
throws Exception {
logger . info ( "Performing doSyncFolder method on id: " + folderId + ", config: " + clientConfig ) ;
public ThSyncStatus doSyncFolder ( final String folderId , WsThreddsSynchFolderConfiguration clientConfig ) throws Exception {
logger . info ( "Performing doSyncFolder method on id: " + folderId + ", config: " + clientConfig ) ;
try {
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
String targetScopeUserToken = null ;
ThSynchFolderConfiguration config = null ;
if ( clientConfig ! = null & & clientConfig . getSelectedScope ( ) ! = null ) {
config = BeanConverter . toThSynchFolderConfiguration ( clientConfig , folderId ,
clientConfig . getSelectedScope ( ) . getScopeName ( ) ) ;
logger . debug ( "Creating server config " + config ) ;
} else {
logger . info ( "The config sent from client is null, Loading it from ws-thredds" ) ;
ThSyncFolderDescriptor descr = getSyncService ( ) . getConfiguration ( folderId , false ,
this . getThreadLocalRequest ( ) , user ) ;
logger . info ( "From ws-thredds loaded the config: " + config ) ;
config = descr . getConfiguration ( ) ;
if ( clientConfig ! = null ) {
targetScopeUserToken = PortalContext . getConfiguration ( ) . getCurrentUserToken ( clientConfig . getSelectedScope ( ) . getScopeName ( ) , user . getUsername ( ) ) ;
config = BeanConverter . toThSynchFolderConfiguration ( clientConfig , folderId , targetScopeUserToken ) ;
logger . debug ( "Creating server config " + config ) ;
}
ThSyncStatus status = getSyncService ( ) . doSyncFolder ( folderId , config , this . getThreadLocalRequest ( ) , user ) ;
logger . debug ( "Returning for folderId " + folderId + " the syncStatus: " + status ) ;
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 . 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. The server encountered the error: "
+ e . getMessage ( ) ,
e ) ;
} catch ( Exception e ) {
logger . error ( "Do sync Folder error: " , e ) ;
throw new Exception ( "Sorry, an error occurred during synchonization phase, try again later" ) ;
}
}
/ * *
* Do un sync folder .
* Gets the available THREDDS catalogues for target scope .
*
* @param folderId the folder id
* @return the boolean
* @param targetFullScope the target scope
* @return the available catalogues for scope
* @throws Exception the exception
* /
// Updated
@Override
public Boolean doUnSyncFolder ( final String folderId ) throws Exception {
logger . info ( "Performing unsync on folder id: " + folderId ) ;
public List < ThCatalogueBean > getAvailableCataloguesForScope ( String targetFullScope ) throws Exception {
if ( targetFullScope = = null )
throw new Exception ( "Invalid scope null" ) ;
String originalScope = null ;
String originalToken = null ;
List < ThCatalogueBean > listCtlgs = null ;
try {
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
ThSyncFolderDescriptor foldeDesr = getSyncService ( ) . getConfiguration ( folderId , false ,
this . getThreadLocalRequest ( ) , user ) ;
return getSyncService ( ) . doUnSync ( folderId , true , foldeDesr . getConfiguration ( ) , this . getThreadLocalRequest ( ) ,
user ) ;
} catch ( Exception e ) {
logger . error ( "Do un sync Folder error: " , e ) ;
throw new Exception (
"Sorry, an error occurred on deleting sync configurations, refresh and try again later" ) ;
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 ) ;
}
}
}
}
return listCtlgs ;
}
/ * *
* Gets the list of Scopes ( Root - VO , VOs and VREs ) for user and the Thredds
* roles that user has in them .
* Gets the list of Scopes ( Root - VO , VOs and VREs ) for user and the Thredds roles that user has in them .
*
* @return the VREs and Thredds roles for a given user
* @throws Exception the exception
* /
@Override
public Map < String , GatewayRolesThredds > getScopesWithThreddsRolesForLoggedUser ( ) throws Exception {
public Map < String , GatewayRolesThredds > getScopesWithThreddsRolesForLoggedUser ( ) throws Exception {
logger . info ( "called getScopesWithThreddsRolesForLoggedUser" ) ;
GCubeUser user = null ;
Map < String , GatewayRolesThredds > mapScopesRoles = null ;
// DEV MODE
if ( ! isWithinPortal ( ) ) {
// DEV MODE
if ( ! isWithinPortal ( ) ) {
mapScopesRoles = new HashMap < String , GatewayRolesThredds > ( ) ;
mapScopesRoles . put ( "/gcube/devsec/devVRE" , GatewayRolesThredds . DATA_EDITOR ) ;
mapScopesRoles . put ( "/gcube/dev Next/NextNext ", GatewayRolesThredds . DATA_ MANAG ER) ;
// mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER);
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER);
return mapScopesRoles ;
}
GCubeUser user = null ;
try {
user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
String gatewayHostname = GenericUtils . getGatewayClientHostname ( this . getThreadLocalRequest ( ) ) ;
mapScopesRoles = WsUtil . getScopesWithThreddsRolesForUser ( user , gatewayHostname ) ;
logger . info ( "returning Map(scopes,roles): " + mapScopesRoles ) ;
mapScopesRoles = WsUtil . getScopesWithThreddsRolesForUser ( user ) ;
logger . info ( "returning Map(scopes,roles): " + mapScopesRoles ) ;
return mapScopesRoles ;
} catch ( Exception e ) {
} 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 ) ;
logger . error ( "An error occurred on checking user roles for user: " + user , e ) ;
throw new Exception ( errorMsg ) ;
}
}
}
/ * *
* Gets the list scope with the role Data - Manager for logged user .
*
@ -288,17 +223,17 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @throws Exception the exception
* /
@Override
public List < GcubeScope > getListOfDataManagerScopesForLoggedUser ( ) throws Exception {
logger . info ( " called getListOfVREsForLoggedUser...: ") ;
public List < GcubeScope > getListOfDataManagerScopesForLoggedUser ( ) throws Exception {
logger . info ( " getListOfVREsForLoggedUser...: ") ;
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
long userId = user . getUserId ( ) ;
// Instan t iate the manager
// Instan c iate the manager
GroupManager groupManager = new LiferayGroupManager ( ) ;
List < GcubeScope > listOfScopes = new ArrayList < GcubeScope > ( ) ;
// DEV MODE
if ( ! isWithinPortal ( ) ) {
// DEV MODE
if ( ! isWithinPortal ( ) ) {
listOfScopes . add ( new GcubeScope ( "devVRE" , "/gcube/devsec/devVRE" , GcubeScopeType . VRE ) ) ;
listOfScopes . add ( new GcubeScope ( "NextNext" , "/gcube/devNext/NextNext" , GcubeScopeType . VRE ) ) ;
listOfScopes . add ( new GcubeScope ( "devNext" , "/gcube/devNext" , GcubeScopeType . VO ) ) ;
@ -311,94 +246,159 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try {
String gatewayHostname = GenericUtils . getGatewayClientHostname ( getThreadLocalRequest ( ) ) ;
// list of Scopes filtered for gateway
// list of Scopes filtered for gateway
Set < GCubeGroup > filteredGroupsForGatw = groupManager . listGroupsByUserAndSite ( userId , gatewayHostname ) ;
// List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(userId);
// 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 ( ) ) ;
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 ( groupId ) ) {
scopeType = GcubeScopeType . VRE ;
} else if ( groupManager . isVO ( groupId ) ) {
scopeType = GcubeScopeType . VO ;
logger . debug ( "For groupId: " + groupId + " got full scope: " + fullScope ) ;
GcubeScopeType scopeType = null ;
if ( groupManager . isVRE ( groupId ) ) {
scopeType = GcubeScopeType . VRE ;
} else if ( groupManager . isVO ( groupId ) ) {
scopeType = GcubeScopeType . VO ;
}
// }else if(groupManager.isRootVO(gCubeGroup.getGroupId())){
// scopeType = GcubeScopeType.ROOT;
// }
if ( scopeType ! = null ) {
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 . getGroupName ( ) , fullScope , groupManager , scopeType ) ;
if ( gcubeScope ! = null ) {
//Adding only the scope where the user has the THREDDS_ADMIN role
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue ( roles , gCubeGroup . getGroupName ( ) , fullScope , groupManager , scopeType ) ;
if ( gcubeScope ! = null ) {
listOfScopes . add ( gcubeScope ) ;
}
}
}
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 . getGroupName ( ) ,
rootVOFullScope , groupManager , GcubeScopeType . ROOT ) ;
if ( gcubeScope ! = null ) {
///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the ROOT-VO
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue ( roles , theRootVO . getGroupName ( ) , rootVOFullScope , groupManager , GcubeScopeType . ROOT ) ;
if ( gcubeScope ! = null ) {
listOfScopes . add ( gcubeScope ) ;
}
} catch ( UserRetrievalFault | UserManagementSystemException | GroupRetrievalFault e ) {
//ADDING THE ROOT SCOPE
/ * String infraName = PortalContext . getConfiguration ( ) . getInfrastructureName ( ) ;
GcubeScope gcubeRoot = new GcubeScope ( infraName , "/" + infraName , GcubeScopeType . ROOT ) ;
listOfScopes . add ( gcubeRoot ) * /
}
catch ( UserRetrievalFault | UserManagementSystemException
| GroupRetrievalFault e ) {
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 . DATA_MANAGER . getRoleName ( )
+ ". Contact the VRE manager or the portal administrator" ) ;
if ( listOfScopes . isEmpty ( ) ) {
throw new Exception ( "No scope detected with the needed role: " + GatewayRolesThredds . DATA_MANAGER . getRoleName ( ) + ". Contact the VRE manager or the portal administrator" ) ;
}
Collections . sort ( listOfScopes ) ;
logger . info ( "Returning list of allowed scope/s with: " + GatewayRolesThredds . DATA_MANAGER + " role/s: "
+ listOfScopes ) ;
logger . info ( "Returning list of allowed scope/s with: " + GatewayRolesThredds . DATA_MANAGER + " role/s: " + listOfScopes ) ;
return listOfScopes ;
}
/ * *
* Checks if for the input scope : - the user has the role
* {@link GatewayRolesThredds . # THREDDS_ADMIN } - the scope has an available
* THREDDS catalogue configured
* 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 scopeName the scope name e . g . devVRE
* @param fullScope the full scope e . g . / gcube / devsec / devVRE
* @param role the role
* @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
* @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 , 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 ( ) ) ) {
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 < ThCatalogueBean > list = getAvailableCataloguesForScope ( fullScope ) ;
if ( list ! = null ) {
if ( list ! = null ) {
return new GcubeScope ( scopeName , fullScope , scopeType ) ;
}
} catch ( Exception e ) {
logger . error ( "Error on checking available catalogue for scope: " + fullScope , e ) ;
} catch ( Exception e ) {
logger . error ( "Error on checking available catalogue for scope: " + fullScope , e ) ;
}
}
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 )
* /
@Override
public WsThreddsSynchFolderDescriptor isItemSynched ( String folderId ) throws WorkspaceFolderLocked , Exception {
logger . debug ( "Performing isItemSynched for foldeId: " + folderId ) ;
try {
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
String wsScope = PortalContext . getConfiguration ( ) . getCurrentScope ( this . getThreadLocalRequest ( ) ) ;
Sync_Status theStatus = getSyncService ( ) . getSynchedStatusFromItemProperty ( folderId , wsScope , user . getUsername ( ) ) ;
if ( theStatus ! = null ) {
logger . info ( "Folder id: " + folderId + " is synched" ) ;
String wsUserToken = PortalContext . getConfiguration ( ) . getCurrentUserToken ( wsScope , user . getUsername ( ) ) ;
ThSyncFolderDescriptor serverFolderSync = getSyncService ( ) . checkItemSynched ( folderId , wsScope , wsUserToken ) ;
WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter . toWsThreddsFolderConfig ( serverFolderSync , theStatus ) ;
logger . debug ( "IsItemSynched for id: " + folderId + " returning: " + toWsThreddFolder ) ;
return toWsThreddFolder ;
}
logger . info ( "Folder id: " + folderId + " is not synched, returning null descriptor" ) ;
return null ;
} catch ( ItemNotSynched e ) {
logger . info ( "The folderId: " + folderId + " is not synched, returning null FolderDescriptor" ) ;
return null ;
} catch ( WorkspaceFolderLocked e ) {
logger . warn ( e . getMessage ( ) + ", sending exception to client..." ) ;
throw new WorkspaceFolderLocked ( e . getFolderId ( ) , e . getMessage ( ) ) ;
} catch ( Exception e ) {
logger . info ( "Error on isItemSynched for folderId: " + folderId , e ) ;
throw new Exception ( e ) ;
}
}
/ * *
* 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 ) ;
}
/ * *
* Monitor sync status .
@ -406,14 +406,47 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @param folderId the folder id
* @return the th sync status
* @throws ItemNotSynched the item not synched
* @throws Exception the exception
* @throws Exception the exception
* /
/ * ( non - Javadoc )
* @see org . gcube . portlets . widgets . wsthreddssync . client . rpc . ThreddsWorkspaceSyncService # monitorSyncStatus ( java . lang . String )
* /
@Override
public ThSyncStatus monitorSyncStatus ( String folderId ) throws ItemNotSynched , Exception {
public ThSyncStatus monitorSyncStatus ( String folderId ) throws ItemNotSynched , Exception {
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
String wsScope = PortalContext . getConfiguration ( ) . getCurrentScope ( this . getThreadLocalRequest ( ) ) ;
String wsUserToken = PortalContext . getConfiguration ( ) . getCurrentUserToken ( wsScope , user . getUsername ( ) ) ;
return getSyncService ( ) . monitorSyncStatus ( folderId , wsScope , wsUserToken ) ;
}
/ * *
* Do sync folder .
*
* @param folderId the folder id
* @return the th sync status
* @throws Exception the exception
* /
/ * ( non - Javadoc )
* @see org . gcube . portlets . widgets . wsthreddssync . client . rpc . ThreddsWorkspaceSyncService # doSyncFolder ( java . lang . String , org . gcube . portlets . widgets . wsthreddssync . shared . WsThreddsSynchFolderDescriptor )
* /
@Override
public Boolean doUnSyncFolder ( final String folderId ) throws Exception {
logger . info ( "Performing unsync on folder id: " + folderId ) ;
// String scope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
// GCubeUser username = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
// String groupName = PortalContext.getConfiguration().getCurrentGroupName(this.getThreadLocalRequest());
// new GcubeVRE(groupName, scope)
try {
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
String wsScope = PortalContext . getConfiguration ( ) . getCurrentScope ( this . getThreadLocalRequest ( ) ) ;
String wsUserToken = PortalContext . getConfiguration ( ) . getCurrentUserToken ( wsScope , user . getUsername ( ) ) ;
return getSyncService ( ) . doUnSync ( folderId , false , wsScope , wsUserToken ) ;
} catch ( Exception e ) {
logger . error ( "Do un sync Folder error: " , e ) ;
throw new Exception ( "Sorry, an error occurred on deleting sync configurations, refresh and try again later" ) ;
}
}
}