integrated the getInfo from SyncEngine (it is not implemented in the

library)
This commit is contained in:
Francesco Mangiacrapa 2021-05-11 12:05:50 +02:00
parent 8f191559c3
commit 23de9f1abb
3 changed files with 126 additions and 163 deletions

13
pom.xml
View File

@ -95,13 +95,6 @@
<scope>compile</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.gcube.spatial-data</groupId> -->
<!-- <artifactId>ws-thredds</artifactId> -->
<!-- <version>[0.0.1-SNAPSHOT, 1.0.0-SNAPSHOT)</version> -->
<!-- <scope>compile</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
@ -118,11 +111,13 @@
<!-- LOGGER -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<artifactId>slf4j-log4j12</artifactId>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -14,6 +14,7 @@ import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.oidc.rest.JWTToken;
import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
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;
@ -24,7 +25,6 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/**
* The Class SyncronizeWithThredds.
*
@ -348,8 +348,6 @@ public class SyncronizeWithThredds {
}
}
// NOT UPDATED
/**
* Gets the sync status.
*
@ -375,9 +373,22 @@ public class SyncronizeWithThredds {
* @param userToken the user token
* @throws Exception the exception
*/
public void registerCallbackForId(String folderId, String scope, String userToken) throws Exception {
protected void registerCallbackForId(String folderId, String scope, String userToken) throws Exception {
setContextParameters(scope, userToken);
workspaceThreddsSynchronize.registerCallbackForId(folderId);
}
/**
* Gets the sync status info.
*
* @param itemId the item id
* @return the sync status info
* @throws Exception the exception
*/
public Sync_Status getSyncStatusInfo(String itemId, String scope, String userToken) throws Exception {
setContextParameters(scope, userToken);
return workspaceThreddsSynchronize.getInfo(itemId);
}
}

View File

@ -35,12 +35,11 @@ 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 {
@ -74,14 +73,12 @@ 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.
*
@ -115,7 +112,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
return listCtlgs;
}
/**
* Checks if is item synched.
*
@ -124,9 +120,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @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)
*/
// UPDATED
@Override
public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception {
@ -138,13 +131,12 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
if (theConfig != null) {
logger.info("Folder id: " + folderId + " is synched");
//String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
//ThSyncFolderDescriptor serverFolderSync = getSyncService().checkItemSynched(folderId,wsScope,wsUserToken);
//the status is not set here (into isItemSynched implementation).
Sync_Status theStatus = null;
WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig, theStatus);
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
Sync_Status theStatus = getSyncService().getSyncStatusInfo(folderId,wsScope,wsUserToken);
WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig,
theStatus);
logger.debug("isItemSynched for id: " + folderId + " returning: " + toWsThreddFolder);
return toWsThreddFolder;
}
@ -153,7 +145,8 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
return null;
} catch (ItemNotSynched e) {
logger.info("The folderId: "+folderId +" is not synched, returning null for "+WsThreddsSynchFolderDescriptor.class.getSimpleName());
logger.info("The folderId: " + folderId + " is not synched, returning null for "
+ WsThreddsSynchFolderDescriptor.class.getSimpleName());
return null;
} catch (WorkspaceFolderLocked e) {
@ -166,7 +159,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
}
}
/**
* Do sync folder.
*
@ -175,14 +167,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @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)
*/
// UPDATED
@Override
public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig)
@ -198,10 +182,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
logger.debug("Creating server config " + config);
}
// 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, this.getThreadLocalRequest(), user);
logger.debug("Returning for folderId " + folderId + " the syncStatus: " + status);
@ -213,20 +193,12 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
}
/**
* Do sync folder.
* Do un sync folder.
*
* @param folderId the folder id
* @return the th sync status
* @return the boolean
* @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)
*/
// Updated
@Override
public Boolean doUnSyncFolder(final String folderId) throws Exception {
@ -235,8 +207,8 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
ThSyncFolderDescriptor foldeDesr = getSyncService().isItemSynched(folderId);
return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(),
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(
@ -244,9 +216,9 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
}
}
/**
* 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
@ -281,8 +253,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
}
}
/**
* Gets the list scope with the role Data-Manager for logged user.
*
@ -336,7 +306,8 @@ 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.getGroupName(), fullScope, groupManager, scopeType);
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles,
gCubeGroup.getGroupName(), fullScope, groupManager, scopeType);
if (gcubeScope != null) {
listOfScopes.add(gcubeScope);
}
@ -347,43 +318,47 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
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);
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, theRootVO.getGroupName(),
rootVOFullScope, groupManager, GcubeScopeType.ROOT);
if (gcubeScope != null) {
listOfScopes.add(gcubeScope);
}
}
catch (UserRetrievalFault | UserManagementSystemException
| GroupRetrievalFault e) {
} 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");
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 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
* @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);
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);
@ -397,21 +372,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
return null;
}
// /**
// * Register callback for id.
// *
// * @param folderId the folder id
// * @throws Exception the exception
// */
// private 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.
*
@ -420,9 +380,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @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)
*/
@Override
public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());