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> <scope>compile</scope>
</dependency> </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> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId> <artifactId>authorization-client</artifactId>
@ -118,11 +111,13 @@
<!-- LOGGER --> <!-- LOGGER -->
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-log4j12</artifactId>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -14,6 +14,7 @@ import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.oidc.rest.JWTToken; import org.gcube.oidc.rest.JWTToken;
import org.gcube.portal.oidc.lr62.OIDCUmaUtil; import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; 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.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/** /**
* The Class SyncronizeWithThredds. * The Class SyncronizeWithThredds.
* *
@ -348,8 +348,6 @@ public class SyncronizeWithThredds {
} }
} }
// NOT UPDATED
/** /**
* Gets the sync status. * Gets the sync status.
* *
@ -375,9 +373,22 @@ public class SyncronizeWithThredds {
* @param userToken the user token * @param userToken the user token
* @throws Exception the exception * @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); setContextParameters(scope, userToken);
workspaceThreddsSynchronize.registerCallbackForId(folderId); 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.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
// TODO: Auto-generated Javadoc
/** /**
* The server side implementation of the RPC service. * The server side implementation of the RPC service.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018
* Feb 14, 2018
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implements ThreddsWorkspaceSyncService { public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implements ThreddsWorkspaceSyncService {
@ -58,10 +57,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
*/ */
public synchronized SyncronizeWithThredds getSyncService() { public synchronized SyncronizeWithThredds getSyncService() {
if(syncThredds==null) if (syncThredds == null)
syncThredds = new SyncronizeWithThredds(); syncThredds = new SyncronizeWithThredds();
return syncThredds; return syncThredds;
} }
@ -74,14 +73,12 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try { try {
UserLocalServiceUtil.getService(); UserLocalServiceUtil.getService();
return true; return true;
} } catch (Exception ex) {
catch (Exception ex) {
logger.warn("Development Mode ON"); logger.warn("Development Mode ON");
return false; return false;
} }
} }
/** /**
* Gets the available THREDDS catalogues for target scope. * Gets the available THREDDS catalogues for target scope.
* *
@ -89,101 +86,88 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @return the available catalogues for scope * @return the available catalogues for scope
* @throws Exception the exception * @throws Exception the exception
*/ */
//UPDATED // UPDATED
@Override @Override
public List<ThCatalogueBean> getAvailableCataloguesForScope(String targetFullScope) throws Exception { public List<ThCatalogueBean> getAvailableCataloguesForScope(String targetFullScope) throws Exception {
if(targetFullScope==null) if (targetFullScope == null)
throw new Exception("Invalid scope null"); throw new Exception("Invalid scope null");
List<ThCatalogueBean> listCtlgs = null; List<ThCatalogueBean> listCtlgs = null;
try { try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
listCtlgs = getSyncService().getAvailableCatalogues(this.getThreadLocalRequest(), user, targetFullScope); listCtlgs = getSyncService().getAvailableCatalogues(this.getThreadLocalRequest(), user, targetFullScope);
logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+targetFullScope); logger.debug("Retuning " + listCtlgs.size() + " Catalogues for scope: " + targetFullScope);
if(logger.isDebugEnabled()){ if (logger.isDebugEnabled()) {
for (ThCatalogueBean thCatalogueBean : listCtlgs) { for (ThCatalogueBean thCatalogueBean : listCtlgs) {
logger.debug(thCatalogueBean.toString()); logger.debug(thCatalogueBean.toString());
} }
} }
}catch (Exception e) { } catch (Exception e) {
logger.error("Error on checking available Catalogue in the scope: "+targetFullScope, e); logger.error("Error on checking available Catalogue in the scope: " + targetFullScope, e);
} }
return listCtlgs; return listCtlgs;
} }
/** /**
* Checks if is item synched. * Checks if is item synched.
* *
* @param folderId the folder id * @param folderId the folder id
* @return the ws thredds synch folder descriptor * @return the ws thredds synch folder descriptor
* @throws WorkspaceFolderLocked the workspace folder locked * @throws WorkspaceFolderLocked the workspace folder locked
* @throws Exception the exception * @throws Exception the exception
*/ */
/* (non-Javadoc) // UPDATED
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#isItemSynched(java.lang.String)
*/
//UPDATED
@Override @Override
public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception{ public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception {
logger.debug("called isItemSynched for folderId: "+folderId); logger.debug("called isItemSynched for folderId: " + folderId);
try { try {
ThSyncFolderDescriptor theConfig = getSyncService().isItemSynched(folderId); ThSyncFolderDescriptor theConfig = getSyncService().isItemSynched(folderId);
if(theConfig!=null) { if (theConfig != null) {
logger.info("Folder id: "+folderId+" is synched"); logger.info("Folder id: " + folderId + " is synched");
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
//String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
//ThSyncFolderDescriptor serverFolderSync = getSyncService().checkItemSynched(folderId,wsScope,wsUserToken); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
Sync_Status theStatus = getSyncService().getSyncStatusInfo(folderId,wsScope,wsUserToken);
//the status is not set here (into isItemSynched implementation). WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig,
Sync_Status theStatus = null; theStatus);
WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig, theStatus); logger.debug("isItemSynched for id: " + folderId + " returning: " + toWsThreddFolder);
logger.debug("isItemSynched for id: "+folderId +" returning: "+toWsThreddFolder);
return toWsThreddFolder; return toWsThreddFolder;
} }
logger.info("Folder id: "+folderId+" is not synched, returning null descriptor"); logger.info("Folder id: " + folderId + " is not synched, returning null descriptor");
return null; return null;
} catch (ItemNotSynched e) { } 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; return null;
} catch (WorkspaceFolderLocked e) { } catch (WorkspaceFolderLocked e) {
logger.warn(e.getMessage() +", sending exception to client..."); logger.warn(e.getMessage() + ", sending exception to client...");
throw new WorkspaceFolderLocked(e.getFolderId(), e.getMessage()); throw new WorkspaceFolderLocked(e.getFolderId(), e.getMessage());
}catch (Exception e) { } catch (Exception e) {
logger.info("Error on isItemSynched for folderId: "+folderId, e); logger.info("Error on isItemSynched for folderId: " + folderId, e);
throw new Exception(e); throw new Exception(e);
} }
} }
/** /**
* Do sync folder. * Do sync folder.
* *
* @param folderId the folder id * @param folderId the folder id
* @param clientConfig the client config * @param clientConfig the client config
* @return the th sync status * @return the th sync status
* @throws Exception the exception * @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)
*/
//UPDATED
@Override @Override
public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig)
throws Exception { throws Exception {
@ -198,10 +182,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
logger.debug("Creating server config " + config); 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); ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, this.getThreadLocalRequest(), user);
logger.debug("Returning for folderId " + folderId + " the syncStatus: " + status); logger.debug("Returning for folderId " + folderId + " the syncStatus: " + status);
@ -211,22 +191,14 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
throw new Exception("Sorry, an error occurred during synchonization phase, try again later"); throw new Exception("Sorry, an error occurred during synchonization phase, try again later");
} }
} }
/** /**
* Do sync folder. * Do un sync folder.
* *
* @param folderId the folder id * @param folderId the folder id
* @return the th sync status * @return the boolean
* @throws Exception the exception * @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 // Updated
@Override @Override
public Boolean doUnSyncFolder(final String folderId) throws Exception { public Boolean doUnSyncFolder(final String folderId) throws Exception {
@ -235,8 +207,8 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try { try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
ThSyncFolderDescriptor foldeDesr = getSyncService().isItemSynched(folderId); ThSyncFolderDescriptor foldeDesr = getSyncService().isItemSynched(folderId);
return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), this.getThreadLocalRequest(),
this.getThreadLocalRequest(), user); user);
} catch (Exception e) { } catch (Exception e) {
logger.error("Do un sync Folder error: ", e); logger.error("Do un sync Folder error: ", e);
throw new Exception( throw new Exception(
@ -244,45 +216,43 @@ 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 * @return the VREs and Thredds roles for a given user
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception{ public Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception {
logger.info("called getScopesWithThreddsRolesForLoggedUser"); logger.info("called getScopesWithThreddsRolesForLoggedUser");
GCubeUser user = null; GCubeUser user = null;
Map<String, GatewayRolesThredds> mapScopesRoles = null; Map<String, GatewayRolesThredds> mapScopesRoles = null;
//DEV MODE // DEV MODE
if (!isWithinPortal()){ if (!isWithinPortal()) {
mapScopesRoles = new HashMap<String, GatewayRolesThredds>(); mapScopesRoles = new HashMap<String, GatewayRolesThredds>();
mapScopesRoles.put("/gcube/devsec/devVRE", GatewayRolesThredds.DATA_EDITOR); mapScopesRoles.put("/gcube/devsec/devVRE", GatewayRolesThredds.DATA_EDITOR);
// mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER); // mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER);
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER); // mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER);
return mapScopesRoles; return mapScopesRoles;
} }
try { try {
user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user); mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user);
logger.info("returning Map(scopes,roles): "+mapScopesRoles); logger.info("returning Map(scopes,roles): " + mapScopesRoles);
return mapScopesRoles; return mapScopesRoles;
}catch (Exception e) { } catch (Exception e) {
String errorMsg = "An error occurred on checking user roles. Refresh the page and try again."; 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); throw new Exception(errorMsg);
} }
} }
/** /**
* Gets the list scope with the role Data-Manager for logged user. * Gets the list scope with the role Data-Manager for logged user.
* *
@ -290,7 +260,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public List<GcubeScope> getListOfDataManagerScopesForLoggedUser() throws Exception{ public List<GcubeScope> getListOfDataManagerScopesForLoggedUser() throws Exception {
logger.info("called getListOfVREsForLoggedUser...: "); logger.info("called getListOfVREsForLoggedUser...: ");
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
long userId = user.getUserId(); long userId = user.getUserId();
@ -298,9 +268,9 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
// Instantiate the manager // Instantiate the manager
GroupManager groupManager = new LiferayGroupManager(); GroupManager groupManager = new LiferayGroupManager();
List<GcubeScope> listOfScopes = new ArrayList<GcubeScope>(); List<GcubeScope> listOfScopes = new ArrayList<GcubeScope>();
//DEV MODE // DEV MODE
if (!isWithinPortal()){ if (!isWithinPortal()) {
listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE)); listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE));
listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE)); listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE));
listOfScopes.add(new GcubeScope("devNext", "/gcube/devNext", GcubeScopeType.VO)); listOfScopes.add(new GcubeScope("devNext", "/gcube/devNext", GcubeScopeType.VO));
@ -313,104 +283,94 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try { try {
String gatewayHostname = GenericUtils.getGatewayClientHostname(getThreadLocalRequest()); String gatewayHostname = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
//list of Scopes filtered for gateway // list of Scopes filtered for gateway
Set<GCubeGroup> filteredGroupsForGatw = groupManager.listGroupsByUserAndSite(userId, gatewayHostname); 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); 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) { for (GCubeGroup gCubeGroup : listOfGroups) {
long groupId = gCubeGroup.getGroupId(); long groupId = gCubeGroup.getGroupId();
String fullScope = groupManager.getInfrastructureScope(groupId); String fullScope = groupManager.getInfrastructureScope(groupId);
logger.debug("For groupId: "+groupId+" got full scope: "+fullScope); logger.debug("For groupId: " + groupId + " got full scope: " + fullScope);
GcubeScopeType scopeType=null; GcubeScopeType scopeType = null;
if(groupManager.isVRE(groupId)){ if (groupManager.isVRE(groupId)) {
scopeType = GcubeScopeType.VRE; scopeType = GcubeScopeType.VRE;
}else if(groupManager.isVO(groupId)){ } else if (groupManager.isVO(groupId)) {
scopeType = GcubeScopeType.VO; scopeType = GcubeScopeType.VO;
} }
// }else if(groupManager.isRootVO(gCubeGroup.getGroupId())){ // }else if(groupManager.isRootVO(gCubeGroup.getGroupId())){
// scopeType = GcubeScopeType.ROOT; // scopeType = GcubeScopeType.ROOT;
// } // }
if(scopeType!=null){ if (scopeType != null) {
GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, gCubeGroup); GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, gCubeGroup);
//Adding only the scope where the user has the THREDDS_ADMIN role // 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,
if(gcubeScope!=null) { gCubeGroup.getGroupName(), fullScope, groupManager, scopeType);
if (gcubeScope != null) {
listOfScopes.add(gcubeScope); listOfScopes.add(gcubeScope);
} }
} }
} }
GCubeGroup theRootVO = groupManager.getRootVO(); GCubeGroup theRootVO = groupManager.getRootVO();
GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, theRootVO); GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, theRootVO);
String rootVOFullScope = groupManager.getInfrastructureScope(theRootVO.getGroupId()); String rootVOFullScope = groupManager.getInfrastructureScope(theRootVO.getGroupId());
///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the ROOT-VO /// 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(),
if(gcubeScope!=null) { rootVOFullScope, groupManager, GcubeScopeType.ROOT);
if (gcubeScope != null) {
listOfScopes.add(gcubeScope); listOfScopes.add(gcubeScope);
} }
} } catch (UserRetrievalFault | UserManagementSystemException | GroupRetrievalFault e) {
catch (UserRetrievalFault | UserManagementSystemException
| GroupRetrievalFault e) {
logger.error("Error occurred server-side getting VRE folders: ", 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"); throw new Exception("Sorry, an error occurred server-side getting VRE folders, try again later");
} }
if(listOfScopes.isEmpty()) { 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); 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; return listOfScopes;
} }
/** /**
* Checks if for the input scope: * Checks if for the input scope: - the user has the role
* - the user has the role {@link GatewayRolesThredds.#THREDDS_ADMIN} * {@link GatewayRolesThredds.#THREDDS_ADMIN} - the scope has an available
* - the scope has an available THREDDS catalogue configured * THREDDS catalogue configured
* *
* @param role the role * @param role the role
* @param scopeName the scope name e.g. devVRE * @param scopeName the scope name e.g. devVRE
* @param fullScope the full scope e.g. /gcube/devsec/devVRE * @param fullScope the full scope e.g. /gcube/devsec/devVRE
* @param groupManager the group manager * @param groupManager the group manager
* @param scopeType the scope type * @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 * @throws Exception the exception
*/ */
private GcubeScope checkDataManagerCapacityAndThreddsCatalogue(GatewayRolesThredds role, String scopeName, String fullScope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception { private GcubeScope checkDataManagerCapacityAndThreddsCatalogue(GatewayRolesThredds role, String scopeName,
logger.debug("checking Data-Manager capacity and THREEDS catalogues for role: "+role, "scope name: "+scopeName+", scope: "+fullScope + " scope type: "+scopeType); String fullScope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception {
if(role!=null && role.getRoleName().equalsIgnoreCase(GatewayRolesNames.DATA_MANAGER.getRoleName())){ 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 { try {
List<ThCatalogueBean> list = getAvailableCataloguesForScope(fullScope); List<ThCatalogueBean> list = getAvailableCataloguesForScope(fullScope);
if(list!=null) { if (list != null) {
return new GcubeScope(scopeName, fullScope, scopeType); return new GcubeScope(scopeName, fullScope, scopeType);
} }
}catch (Exception e) { } catch (Exception e) {
logger.error("Error on checking available catalogue for scope: "+fullScope, e); logger.error("Error on checking available catalogue for scope: " + fullScope, e);
} }
} }
return null; 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. * Monitor sync status.
@ -418,13 +378,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @param folderId the folder id * @param folderId the folder id
* @return the th sync status * @return the th sync status
* @throws ItemNotSynched the item not synched * @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 @Override
public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception{ public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());