From 5cc52d9e3ca972a47cb1408a5ca302c336d0059e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 17 May 2021 18:17:40 +0200 Subject: [PATCH] the getConfiguration method has been updated by including also the engine.check --- .../wsthreddssync/client/WsThreddsWidget.java | 14 ++++++++--- .../rpc/ThreddsWorkspaceSyncService.java | 15 ++++++++--- .../rpc/ThreddsWorkspaceSyncServiceAsync.java | 10 +++++++- .../binder/MonitorFolderSyncStatusView.java | 1 - .../server/SyncronizeWithThredds.java | 25 +++++++++++++++---- .../ThreddsWorkspaceSyncServiceImpl.java | 21 ++++++++++------ 6 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java index b8a44e8..f2d4f70 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java @@ -176,7 +176,7 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { //at least one THREDDS rights is assigned GWT.log("Performing isItemSynched: "+folder.getFolderId()); - WsThreddsWidget.wsThreddsSyncService.getConfiguration(folder.getFolderId(), new AsyncCallback() { + WsThreddsWidget.wsThreddsSyncService.getConfiguration(folder.getFolderId(), true, new AsyncCallback() { @Override public void onSuccess(WsThreddsSynchFolderDescriptor result) { @@ -196,7 +196,12 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { @Override public void onFailure(Throwable caught) { - box.hide(); + try { + hpLoader.clear(); + hpLoader.setVisible(false); + }catch (Exception e) { + //Silent + } if(caught instanceof WorkspaceFolderLocked){ viewManager.showMonitorSyncToFolder(folder,syncEventsListeners); @@ -204,7 +209,10 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { } viewManager.cancelMonitor(folder); - Window.alert(caught.getMessage()); + Alert alert = new Alert(caught.getMessage(), AlertType.ERROR); + alert.setClose(false); + box.add(alert); + //Window.alert(caught.getMessage()); } }); } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java index 9fed1c5..59d1e16 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java @@ -11,6 +11,7 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; +import org.gcube.usecases.ws.thredds.SyncEngine; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -30,12 +31,16 @@ public interface ThreddsWorkspaceSyncService extends RemoteService { /** * Gets the configuration. * - * @param folderId the folder id - * @return 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 + * @throws Exception the exception */ - WsThreddsSynchFolderDescriptor getConfiguration(String folderId) throws WorkspaceFolderLocked, Exception; + WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus) + throws WorkspaceFolderLocked, Exception; /** * Do sync folder. @@ -91,4 +96,6 @@ public interface ThreddsWorkspaceSyncService extends RemoteService { * @throws Exception the exception */ Map getScopesWithThreddsRolesForLoggedUser() throws Exception; + + } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java index dd61d97..4e6bb34 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java @@ -13,6 +13,7 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescr import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; +// TODO: Auto-generated Javadoc /** * The Interface ThreddsWorkspaceSyncServiceAsync. * @@ -52,10 +53,11 @@ public interface ThreddsWorkspaceSyncServiceAsync { * Gets the configuration. * * @param folderId the folder id + * @param loadStatus the load status * @param callback the callback * @return the configuration */ - void getConfiguration(String folderId, AsyncCallback callback); + void getConfiguration(String folderId, boolean loadStatus, AsyncCallback callback); /** * Do sync folder. @@ -100,5 +102,11 @@ public interface ThreddsWorkspaceSyncServiceAsync { */ void doUnSyncFolder(String folderId, AsyncCallback callback); + /** + * Gets the scopes with thredds roles for logged user. + * + * @param callback the callback + * @return the scopes with thredds roles for logged user + */ void getScopesWithThreddsRolesForLoggedUser(AsyncCallback> callback); } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.java index f80a7f7..3bc422a 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.java @@ -26,7 +26,6 @@ import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Widget; - // TODO: Auto-generated Javadoc /** * The Class ShowThreddsFolderInfoView. diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index 5807a4d..ed07d7d 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -15,11 +15,13 @@ 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.WorkspaceFolderLocked; 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.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize; +import org.gcube.usecases.ws.thredds.SyncEngine; import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; import org.gcube.usecases.ws.thredds.model.ContainerType; import org.gcube.vomanagement.usermanagement.model.GCubeUser; @@ -137,25 +139,38 @@ public class SyncronizeWithThredds { /** * Gets the configuration. * - * @param folderId the folder id - * @param scope the scope - * @param userToken the user token + * @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. Otherwise it callas the + * {@link SyncEngine#getConfig(String)} without sync status + * @param scope the scope + * @param userToken the user token * @return the configuration * @throws ItemNotSynched the item not synched * @throws Exception the exception */ - public ThSyncFolderDescriptor getConfiguration(String folderId, String scope, String userToken) + public ThSyncFolderDescriptor getConfiguration(String folderId, boolean loadStatus, String scope, String userToken) throws ItemNotSynched, Exception { ThSyncFolderDescriptor config = null; try { setContextParameters(scope, userToken); - config = workspaceThreddsSynchronize.getConfiguration(folderId); + + if (loadStatus) { + config = workspaceThreddsSynchronize.checkItemSynched(folderId); + } else { + config = workspaceThreddsSynchronize.getConfiguration(folderId); + } } catch (WorkspaceNotSynchedException e) { logger.debug("WorkspaceNotSynchedException catched. The item with id: " + folderId + " is not synched"); + } catch (WorkspaceFolderLocked e1) { + logger.info("The folder with id: " + folderId + " is locked"); + throw new Exception("The folder with id: "+folderId +" is currently locked. Another sync process is in progress"); } catch (Exception e) { logger.error("Error on reading the configuration for id: " + folderId, e); + throw e; } return config; diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 6bab207..082f5d5 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -20,6 +20,7 @@ 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; @@ -34,7 +35,7 @@ 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. * @@ -112,24 +113,28 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem } /** - * Checks if is item synched. + * Gets the configuration. * - * @param folderId the folder id + * @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 */ - // UPDATED @Override - public WsThreddsSynchFolderDescriptor getConfiguration(String folderId) throws WorkspaceFolderLocked, Exception { + public WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus) + throws WorkspaceFolderLocked, Exception { logger.debug("called isItemSynched for folderId: " + folderId); try { GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - - ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId,wsScope,wsUserToken); + + ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, wsScope, + wsUserToken); if (theConfig != null) { logger.info("Folder id: " + folderId + " is synched"); @@ -205,7 +210,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId,wsScope,wsUserToken); + ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId, false, wsScope, wsUserToken); return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), this.getThreadLocalRequest(), user); } catch (Exception e) {