2018-03-02 17:03:57 +01:00
|
|
|
package org.gcube.portlets.widgets.wsthreddssync.server;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2018-03-14 16:04:08 +01:00
|
|
|
import java.util.Collections;
|
2021-03-04 16:24:54 +01:00
|
|
|
import java.util.HashMap;
|
2018-03-02 17:03:57 +01:00
|
|
|
import java.util.List;
|
2021-03-04 16:24:54 +01:00
|
|
|
import java.util.Map;
|
2021-03-03 18:14:53 +01:00
|
|
|
import java.util.Set;
|
2018-03-02 17:03:57 +01:00
|
|
|
|
2021-05-19 17:29:16 +02:00
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
2018-03-02 17:03:57 +01:00
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
|
2018-03-13 15:09:36 +01:00
|
|
|
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
|
2018-03-08 17:59:33 +01:00
|
|
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
|
2018-03-02 17:03:57 +01:00
|
|
|
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.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService;
|
2021-03-03 18:14:53 +01:00
|
|
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds;
|
2018-03-12 17:43:51 +01:00
|
|
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
|
|
|
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScopeType;
|
2018-03-02 17:03:57 +01:00
|
|
|
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
|
|
|
|
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
|
2021-05-17 18:17:40 +02:00
|
|
|
import org.gcube.usecases.ws.thredds.SyncEngine;
|
2018-03-02 17:03:57 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
2021-03-08 10:55:48 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
|
2018-03-02 17:03:57 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
|
2021-05-17 18:17:40 +02:00
|
|
|
|
2021-05-19 17:29:16 +02:00
|
|
|
// TODO: Auto-generated Javadoc
|
2018-03-02 17:03:57 +01:00
|
|
|
/**
|
|
|
|
* The server side implementation of the RPC service.
|
|
|
|
*
|
2021-05-11 12:05:50 +02:00
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018
|
2018-03-02 17:03:57 +01:00
|
|
|
*/
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implements ThreddsWorkspaceSyncService {
|
2018-03-08 17:59:33 +01:00
|
|
|
|
2018-03-02 17:03:57 +01:00
|
|
|
/** The logger. */
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(ThreddsWorkspaceSyncServiceImpl.class);
|
2018-03-08 17:59:33 +01:00
|
|
|
|
2018-03-02 17:03:57 +01:00
|
|
|
/** The sync thredds. */
|
|
|
|
private SyncronizeWithThredds syncThredds = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the sync service.
|
|
|
|
*
|
|
|
|
* @return the sync service
|
|
|
|
*/
|
|
|
|
public synchronized SyncronizeWithThredds getSyncService() {
|
2018-03-08 17:59:33 +01:00
|
|
|
|
2021-05-11 12:05:50 +02:00
|
|
|
if (syncThredds == null)
|
2018-03-02 17:03:57 +01:00
|
|
|
syncThredds = new SyncronizeWithThredds();
|
2018-03-08 17:59:33 +01:00
|
|
|
|
2021-05-11 12:05:50 +02:00
|
|
|
return syncThredds;
|
2018-03-08 17:59:33 +01:00
|
|
|
|
2018-03-02 17:03:57 +01:00
|
|
|
}
|
2018-03-08 17:59:33 +01:00
|
|
|
|
2018-03-02 17:03:57 +01:00
|
|
|
/**
|
|
|
|
* Checks if is within portal.
|
|
|
|
*
|
|
|
|
* @return true if you're running into the portal, false if in development
|
|
|
|
*/
|
|
|
|
public static boolean isWithinPortal() {
|
|
|
|
try {
|
|
|
|
UserLocalServiceUtil.getService();
|
|
|
|
return true;
|
2021-05-11 12:05:50 +02:00
|
|
|
} catch (Exception ex) {
|
2021-03-04 16:24:54 +01:00
|
|
|
logger.warn("Development Mode ON");
|
2018-03-02 17:03:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-05-11 12:05:50 +02:00
|
|
|
|
2021-05-10 17:01:32 +02:00
|
|
|
/**
|
|
|
|
* Gets the available THREDDS catalogues for target scope.
|
|
|
|
*
|
|
|
|
* @param targetFullScope the target scope
|
|
|
|
* @return the available catalogues for scope
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2021-05-11 12:05:50 +02:00
|
|
|
// UPDATED
|
2021-05-10 17:01:32 +02:00
|
|
|
@Override
|
|
|
|
public List<ThCatalogueBean> getAvailableCataloguesForScope(String targetFullScope) throws Exception {
|
|
|
|
|
2021-05-11 12:05:50 +02:00
|
|
|
if (targetFullScope == null)
|
2021-05-10 17:01:32 +02:00
|
|
|
throw new Exception("Invalid scope null");
|
|
|
|
|
|
|
|
List<ThCatalogueBean> listCtlgs = null;
|
|
|
|
try {
|
2021-05-11 12:05:50 +02:00
|
|
|
|
2021-05-10 17:01:32 +02:00
|
|
|
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
|
|
|
listCtlgs = getSyncService().getAvailableCatalogues(this.getThreadLocalRequest(), user, targetFullScope);
|
2021-05-11 12:05:50 +02:00
|
|
|
|
|
|
|
logger.debug("Retuning " + listCtlgs.size() + " Catalogues for scope: " + targetFullScope);
|
|
|
|
if (logger.isDebugEnabled()) {
|
2021-05-10 17:01:32 +02:00
|
|
|
for (ThCatalogueBean thCatalogueBean : listCtlgs) {
|
|
|
|
logger.debug(thCatalogueBean.toString());
|
|
|
|
}
|
|
|
|
}
|
2021-05-11 12:05:50 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error on checking available Catalogue in the scope: " + targetFullScope, e);
|
2021-05-10 17:01:32 +02:00
|
|
|
}
|
2021-05-11 12:05:50 +02:00
|
|
|
|
2021-05-10 17:01:32 +02:00
|
|
|
return listCtlgs;
|
|
|
|
}
|
2021-05-11 12:05:50 +02:00
|
|
|
|
2021-05-10 18:08:39 +02:00
|
|
|
/**
|
2021-05-17 18:17:40 +02:00
|
|
|
* Gets the configuration.
|
2021-05-10 18:08:39 +02:00
|
|
|
*
|
2021-05-17 18:17:40 +02:00
|
|
|
* @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.
|
2021-05-10 18:08:39 +02:00
|
|
|
* @return the ws thredds synch folder descriptor
|
|
|
|
* @throws WorkspaceFolderLocked the workspace folder locked
|
2021-05-11 12:05:50 +02:00
|
|
|
* @throws Exception the exception
|
2021-05-10 18:08:39 +02:00
|
|
|
*/
|
|
|
|
@Override
|
2021-05-17 18:17:40 +02:00
|
|
|
public WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus)
|
|
|
|
throws WorkspaceFolderLocked, Exception {
|
2021-05-11 12:05:50 +02:00
|
|
|
logger.debug("called isItemSynched for folderId: " + folderId);
|
2021-05-19 17:29:16 +02:00
|
|
|
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);
|
2021-05-10 18:08:39 +02:00
|
|
|
|
|
|
|
try {
|
2021-05-19 17:29:16 +02:00
|
|
|
ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, httpRequest, user);
|
2021-05-10 18:08:39 +02:00
|
|
|
|
2021-05-11 12:05:50 +02:00
|
|
|
if (theConfig != null) {
|
|
|
|
logger.info("Folder id: " + folderId + " is synched");
|
2021-05-13 15:02:53 +02:00
|
|
|
WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig);
|
2021-05-11 12:05:50 +02:00
|
|
|
logger.debug("isItemSynched for id: " + folderId + " returning: " + toWsThreddFolder);
|
2021-05-10 18:08:39 +02:00
|
|
|
return toWsThreddFolder;
|
|
|
|
}
|
|
|
|
|
2021-05-11 12:05:50 +02:00
|
|
|
logger.info("Folder id: " + folderId + " is not synched, returning null descriptor");
|
2021-05-10 18:08:39 +02:00
|
|
|
return null;
|
|
|
|
|
|
|
|
} catch (ItemNotSynched e) {
|
2021-05-11 12:05:50 +02:00
|
|
|
logger.info("The folderId: " + folderId + " is not synched, returning null for "
|
|
|
|
+ WsThreddsSynchFolderDescriptor.class.getSimpleName());
|
2021-05-10 18:08:39 +02:00
|
|
|
return null;
|
|
|
|
|
|
|
|
} catch (WorkspaceFolderLocked e) {
|
2021-05-11 12:05:50 +02:00
|
|
|
logger.warn(e.getMessage() + ", sending exception to client...");
|
2021-05-10 18:08:39 +02:00
|
|
|
throw new WorkspaceFolderLocked(e.getFolderId(), e.getMessage());
|
|
|
|
|
2021-05-11 12:05:50 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.info("Error on isItemSynched for folderId: " + folderId, e);
|
2021-05-10 18:08:39 +02:00
|
|
|
throw new Exception(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 17:03:57 +01:00
|
|
|
/**
|
|
|
|
* Do sync folder.
|
|
|
|
*
|
2021-05-11 12:05:50 +02:00
|
|
|
* @param folderId the folder id
|
2021-05-11 11:09:02 +02:00
|
|
|
* @param clientConfig the client config
|
2018-03-02 17:03:57 +01:00
|
|
|
* @return the th sync status
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2021-05-11 12:05:50 +02:00
|
|
|
// UPDATED
|
2018-03-02 17:03:57 +01:00
|
|
|
@Override
|
2021-05-11 11:09:02 +02:00
|
|
|
public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig)
|
|
|
|
throws Exception {
|
|
|
|
logger.info("Performing doSyncFolder method on id: " + folderId + ", config: " + clientConfig);
|
2018-03-02 17:03:57 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
|
|
|
ThSynchFolderConfiguration config = null;
|
2021-05-10 17:01:32 +02:00
|
|
|
if (clientConfig != null && clientConfig.getSelectedScope() != null) {
|
|
|
|
config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId,
|
|
|
|
clientConfig.getSelectedScope().getScopeName());
|
|
|
|
logger.debug("Creating server config " + config);
|
2021-05-20 17:32:00 +02:00
|
|
|
}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();
|
2018-03-02 17:03:57 +01:00
|
|
|
}
|
2018-03-08 17:59:33 +01:00
|
|
|
|
2021-05-11 11:09:02 +02:00
|
|
|
ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, this.getThreadLocalRequest(), user);
|
|
|
|
logger.debug("Returning for folderId " + folderId + " the syncStatus: " + status);
|
2018-03-08 17:59:33 +01:00
|
|
|
|
2018-03-02 17:03:57 +01:00
|
|
|
return status;
|
2021-05-11 11:09:02 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Do sync Folder error: ", e);
|
2021-05-20 17:32:00 +02:00
|
|
|
throw new Exception("Sorry, an error occurred during synchonization phase. The server encountered the error: "+e.getMessage(), e);
|
2018-03-02 17:03:57 +01:00
|
|
|
}
|
|
|
|
}
|
2021-05-11 12:05:50 +02:00
|
|
|
|
2021-05-11 11:09:02 +02:00
|
|
|
/**
|
2021-05-11 12:05:50 +02:00
|
|
|
* Do un sync folder.
|
2021-05-11 11:09:02 +02:00
|
|
|
*
|
|
|
|
* @param folderId the folder id
|
2021-05-11 12:05:50 +02:00
|
|
|
* @return the boolean
|
2021-05-11 11:09:02 +02:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
// Updated
|
|
|
|
@Override
|
|
|
|
public Boolean doUnSyncFolder(final String folderId) throws Exception {
|
|
|
|
logger.info("Performing unsync on folder id: " + folderId);
|
2018-03-08 17:59:33 +01:00
|
|
|
|
2021-05-11 11:09:02 +02:00
|
|
|
try {
|
|
|
|
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
2021-05-18 12:55:44 +02:00
|
|
|
ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId, false, this.getThreadLocalRequest(), user);
|
2021-05-11 12:05:50 +02:00
|
|
|
return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), this.getThreadLocalRequest(),
|
|
|
|
user);
|
2021-05-11 11:09:02 +02:00
|
|
|
} 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");
|
|
|
|
}
|
|
|
|
}
|
2018-03-08 17:59:33 +01:00
|
|
|
|
2021-03-04 16:24:54 +01:00
|
|
|
/**
|
2021-05-11 12:05:50 +02:00
|
|
|
* Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds
|
|
|
|
* roles that user has in them.
|
2021-03-04 16:24:54 +01:00
|
|
|
*
|
|
|
|
* @return the VREs and Thredds roles for a given user
|
2021-03-08 10:55:48 +01:00
|
|
|
* @throws Exception the exception
|
2021-03-04 16:24:54 +01:00
|
|
|
*/
|
|
|
|
@Override
|
2021-05-11 12:05:50 +02:00
|
|
|
public Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception {
|
2021-03-04 16:24:54 +01:00
|
|
|
logger.info("called getScopesWithThreddsRolesForLoggedUser");
|
2021-05-11 12:05:50 +02:00
|
|
|
|
2021-03-04 16:24:54 +01:00
|
|
|
GCubeUser user = null;
|
|
|
|
Map<String, GatewayRolesThredds> mapScopesRoles = null;
|
2021-05-11 12:05:50 +02:00
|
|
|
|
|
|
|
// DEV MODE
|
|
|
|
if (!isWithinPortal()) {
|
2021-03-04 16:24:54 +01:00
|
|
|
mapScopesRoles = new HashMap<String, GatewayRolesThredds>();
|
2021-03-17 12:43:08 +01:00
|
|
|
mapScopesRoles.put("/gcube/devsec/devVRE", GatewayRolesThredds.DATA_EDITOR);
|
2021-03-04 16:24:54 +01:00
|
|
|
// mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER);
|
|
|
|
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER);
|
|
|
|
return mapScopesRoles;
|
|
|
|
}
|
2021-05-11 12:05:50 +02:00
|
|
|
|
2021-03-04 16:24:54 +01:00
|
|
|
try {
|
|
|
|
|
|
|
|
user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
|
|
|
mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user);
|
2021-05-11 12:05:50 +02:00
|
|
|
|
|
|
|
logger.info("returning Map(scopes,roles): " + mapScopesRoles);
|
2021-03-04 16:24:54 +01:00
|
|
|
return mapScopesRoles;
|
2021-05-11 12:05:50 +02:00
|
|
|
} catch (Exception e) {
|
2021-03-04 16:24:54 +01:00
|
|
|
String errorMsg = "An error occurred on checking user roles. Refresh the page and try again.";
|
2021-05-11 12:05:50 +02:00
|
|
|
logger.error("An error occurred on checking user roles for user: " + user, e);
|
2021-03-04 16:24:54 +01:00
|
|
|
throw new Exception(errorMsg);
|
2021-05-11 12:05:50 +02:00
|
|
|
}
|
2021-03-04 16:24:54 +01:00
|
|
|
}
|
2018-03-08 17:59:33 +01:00
|
|
|
|
2018-03-02 17:03:57 +01:00
|
|
|
/**
|
2021-03-08 10:55:48 +01:00
|
|
|
* Gets the list scope with the role Data-Manager for logged user.
|
2018-03-02 17:03:57 +01:00
|
|
|
*
|
2021-03-08 10:55:48 +01:00
|
|
|
* @return the list of manager scopes for logged user
|
2018-03-02 17:03:57 +01:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
2021-05-11 12:05:50 +02:00
|
|
|
public List<GcubeScope> getListOfDataManagerScopesForLoggedUser() throws Exception {
|
2021-05-11 11:09:02 +02:00
|
|
|
logger.info("called getListOfVREsForLoggedUser...: ");
|
2018-03-02 17:03:57 +01:00
|
|
|
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
|
|
|
long userId = user.getUserId();
|
|
|
|
|
2021-05-11 11:09:02 +02:00
|
|
|
// Instantiate the manager
|
2018-03-02 17:03:57 +01:00
|
|
|
GroupManager groupManager = new LiferayGroupManager();
|
2018-03-14 16:04:08 +01:00
|
|
|
List<GcubeScope> listOfScopes = new ArrayList<GcubeScope>();
|
2021-05-11 12:05:50 +02:00
|
|
|
|
|
|
|
// DEV MODE
|
|
|
|
if (!isWithinPortal()) {
|
2018-03-14 16:04:08 +01:00
|
|
|
listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE));
|
|
|
|
listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE));
|
2018-03-14 16:26:18 +01:00
|
|
|
listOfScopes.add(new GcubeScope("devNext", "/gcube/devNext", GcubeScopeType.VO));
|
|
|
|
listOfScopes.add(new GcubeScope("devsec", "/gcube/devsec", GcubeScopeType.VO));
|
|
|
|
listOfScopes.add(new GcubeScope("gcube", "/gcube", GcubeScopeType.ROOT));
|
|
|
|
Collections.sort(listOfScopes);
|
2018-03-14 16:04:08 +01:00
|
|
|
return listOfScopes;
|
2018-03-02 17:03:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2021-03-03 18:14:53 +01:00
|
|
|
String gatewayHostname = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
|
2021-05-11 12:05:50 +02:00
|
|
|
// list of Scopes filtered for gateway
|
2021-03-03 18:14:53 +01:00
|
|
|
Set<GCubeGroup> filteredGroupsForGatw = groupManager.listGroupsByUserAndSite(userId, gatewayHostname);
|
2021-05-11 12:05:50 +02:00
|
|
|
|
|
|
|
// List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(userId);
|
2021-03-03 18:14:53 +01:00
|
|
|
List<GCubeGroup> listOfGroups = new ArrayList<GCubeGroup>(filteredGroupsForGatw);
|
2021-05-11 12:05:50 +02:00
|
|
|
logger.info("list of VREs in the gateway " + gatewayHostname + " are " + listOfGroups.size());
|
2018-03-02 17:03:57 +01:00
|
|
|
for (GCubeGroup gCubeGroup : listOfGroups) {
|
2021-03-08 12:36:19 +01:00
|
|
|
long groupId = gCubeGroup.getGroupId();
|
|
|
|
String fullScope = groupManager.getInfrastructureScope(groupId);
|
2021-05-11 12:05:50 +02:00
|
|
|
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;
|
2018-03-12 17:43:51 +01:00
|
|
|
}
|
2018-03-14 16:04:08 +01:00
|
|
|
// }else if(groupManager.isRootVO(gCubeGroup.getGroupId())){
|
|
|
|
// scopeType = GcubeScopeType.ROOT;
|
|
|
|
// }
|
2018-03-12 17:43:51 +01:00
|
|
|
|
2021-05-11 12:05:50 +02:00
|
|
|
if (scopeType != null) {
|
2021-03-04 16:24:54 +01:00
|
|
|
GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, gCubeGroup);
|
2021-05-11 12:05:50 +02:00
|
|
|
// Adding only the scope where the user has the THREDDS_ADMIN role
|
|
|
|
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles,
|
|
|
|
gCubeGroup.getGroupName(), fullScope, groupManager, scopeType);
|
|
|
|
if (gcubeScope != null) {
|
2021-03-03 18:14:53 +01:00
|
|
|
listOfScopes.add(gcubeScope);
|
|
|
|
}
|
2018-03-02 17:03:57 +01:00
|
|
|
}
|
2021-03-03 18:14:53 +01:00
|
|
|
}
|
2021-05-11 12:05:50 +02:00
|
|
|
|
2021-03-03 18:14:53 +01:00
|
|
|
GCubeGroup theRootVO = groupManager.getRootVO();
|
2021-03-04 16:24:54 +01:00
|
|
|
GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, theRootVO);
|
2021-03-08 12:36:19 +01:00
|
|
|
String rootVOFullScope = groupManager.getInfrastructureScope(theRootVO.getGroupId());
|
2021-05-11 12:05:50 +02:00
|
|
|
/// 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) {
|
2021-03-03 18:14:53 +01:00
|
|
|
listOfScopes.add(gcubeScope);
|
2018-03-02 17:03:57 +01:00
|
|
|
}
|
|
|
|
|
2021-05-11 12:05:50 +02:00
|
|
|
} catch (UserRetrievalFault | UserManagementSystemException | GroupRetrievalFault e) {
|
2018-03-02 17:03:57 +01:00
|
|
|
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");
|
|
|
|
}
|
2021-05-11 12:05:50 +02:00
|
|
|
|
|
|
|
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");
|
2021-03-03 18:14:53 +01:00
|
|
|
}
|
2018-03-02 17:03:57 +01:00
|
|
|
|
2018-03-14 16:04:08 +01:00
|
|
|
Collections.sort(listOfScopes);
|
2021-05-11 12:05:50 +02:00
|
|
|
logger.info("Returning list of allowed scope/s with: " + GatewayRolesThredds.DATA_MANAGER + " role/s: "
|
|
|
|
+ listOfScopes);
|
2018-03-14 16:04:08 +01:00
|
|
|
return listOfScopes;
|
2018-03-02 17:03:57 +01:00
|
|
|
}
|
2021-05-11 12:05:50 +02:00
|
|
|
|
2021-03-03 18:14:53 +01:00
|
|
|
/**
|
2021-05-11 12:05:50 +02:00
|
|
|
* Checks if for the input scope: - the user has the role
|
|
|
|
* {@link GatewayRolesThredds.#THREDDS_ADMIN} - the scope has an available
|
|
|
|
* THREDDS catalogue configured
|
2021-03-04 16:24:54 +01:00
|
|
|
*
|
2021-05-11 12:05:50 +02:00
|
|
|
* @param role the role
|
|
|
|
* @param scopeName the scope name e.g. devVRE
|
|
|
|
* @param fullScope the full scope e.g. /gcube/devsec/devVRE
|
2021-03-03 18:14:53 +01:00
|
|
|
* @param groupManager the group manager
|
2021-05-11 12:05:50 +02:00
|
|
|
* @param scopeType the scope type
|
|
|
|
* @return the gcube scope {@link GcubeScope} if the two conditions (see
|
|
|
|
* description) are satisfied, null otherwise
|
2021-03-03 18:14:53 +01:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2021-05-11 12:05:50 +02:00
|
|
|
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())) {
|
2021-03-03 18:14:53 +01:00
|
|
|
try {
|
2021-03-08 12:36:19 +01:00
|
|
|
List<ThCatalogueBean> list = getAvailableCataloguesForScope(fullScope);
|
2021-05-11 12:05:50 +02:00
|
|
|
if (list != null) {
|
2021-03-08 12:36:19 +01:00
|
|
|
return new GcubeScope(scopeName, fullScope, scopeType);
|
2021-03-03 18:14:53 +01:00
|
|
|
}
|
2021-05-11 12:05:50 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error on checking available catalogue for scope: " + fullScope, e);
|
2021-03-03 18:14:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2018-03-08 17:59:33 +01:00
|
|
|
|
2021-03-03 18:14:53 +01:00
|
|
|
/**
|
|
|
|
* Monitor sync status.
|
|
|
|
*
|
|
|
|
* @param folderId the folder id
|
|
|
|
* @return the th sync status
|
|
|
|
* @throws ItemNotSynched the item not synched
|
2021-05-11 12:05:50 +02:00
|
|
|
* @throws Exception the exception
|
2018-03-02 17:03:57 +01:00
|
|
|
*/
|
|
|
|
@Override
|
2021-05-11 12:05:50 +02:00
|
|
|
public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception {
|
2018-03-02 17:03:57 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|