@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.wsthreddssync.server;
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.List ;
import java.util.Set ;
import org.gcube.common.portal.PortalContext ;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched ;
@ -12,7 +13,9 @@ import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
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.ckandatapublisherwidget.server.utils.GenericUtils ;
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 ;
@ -156,7 +159,7 @@ 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 ( ) ;
@ -176,7 +179,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 +198,39 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
// }
if ( scopeType ! = null ) {
GcubeScope gcubeVRE = new GcubeScope ( gCubeGroup . getGroupName ( ) , groupManager . getInfrastructureScope ( gCubeGroup . getGroupId ( ) ) , scopeType ) ;
listOfScopes . add ( gcubeVRE ) ;
List < GatewayRolesThredds > roles = WsUtil . getThreddsRoleFor ( user , gCubeGroup ) ;
//Adding only the scope where the user has the (GatewayRolesThredds.THREDDS_ADMIN role
/ * if ( roles ! = null & & roles . size ( ) > 0 & & roles . contains ( GatewayRolesThredds . THREDDS_ADMIN ) ) {
GcubeScope gcubeScope = new GcubeScope ( gCubeGroup . getGroupName ( ) , groupManager . getInfrastructureScope ( gCubeGroup . getGroupId ( ) ) , scopeType ) ;
listOfScopes . add ( gcubeScope ) ;
} * /
//Adding only the scope where the user has the THREDDS_ADMIN role
GcubeScope gcubeScope = availableScopeForRole ( roles , gCubeGroup , groupManager , scopeType ) ;
if ( gcubeScope ! = null ) {
listOfScopes . add ( gcubeScope ) ;
}
}
}
GCubeGroup theRootVO = groupManager . getRootVO ( ) ;
List < GatewayRolesThredds > roles = WsUtil . getThreddsRoleFor ( user , theRootVO ) ;
//ADDING THE ROOT SCOPE
/ * if ( roles ! = null & & roles . size ( ) > 0 & & roles . contains ( GatewayRolesThredds . THREDDS_ADMIN ) ) {
GcubeScope gcubeScope = new GcubeScope ( theRootVO . getGroupName ( ) , groupManager . getInfrastructureScope ( theRootVO . getGroupId ( ) ) , GcubeScopeType . ROOT ) ;
listOfScopes . add ( gcubeScope ) ;
} * /
///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the scope
GcubeScope gcubeScope = availableScopeForRole ( 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 +239,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 ) ;
return listOfScopes ;
}
/ * *
* Available scope for role and catalogue , checks if for the input scope :
* - the user has the role { @link GatewayRolesThredds . # THREDDS_ADMIN } alid catalogue configured for thredds
* - the scope has an available thredds catalogue configured ( by calling the service )
*
* @param roles the roles
* @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 ( List < GatewayRolesThredds > roles , GCubeGroup scope , GroupManager groupManager , GcubeScopeType scopeType ) throws Exception {
if ( roles ! = null & & roles . size ( ) > 0 & & roles . contains ( GatewayRolesThredds . THREDDS_ADMIN ) ) {
try {
List < ThCatalogueBean > list = getAvailableCataloguesForScope ( scope . getGroupName ( ) ) ;
if ( list ! = null & & list . size ( ) > 0 ) {
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 roles the roles
* @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 ( List < GatewayRolesThredds > roles , GCubeGroup scope , GroupManager groupManager , GcubeScopeType scopeType ) throws Exception {
if ( roles ! = null & & roles . size ( ) > 0 & & roles . contains ( 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 +360,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 +384,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
* /