diff --git a/CHANGELOG.md b/CHANGELOG.md index c458be6..7ee7a17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [v1.4.0-SNAPSHOT] - 2021-05-10 + +#### Enhancements + +[#21379] Moved to new ws-synchronized-module-library (based on w-thredds 1.x) and performed UMA tokens "context switches" +[#21444] Moved to maven-portal-bom >= 3.6.2-SNAPSHOT + ## [v1.3.0] - 2021-03-17 [#20847] Support the roles of THREDDS Admin and THREDDS Publisher diff --git a/pom.xml b/pom.xml index 0914765..008063e 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portlets.widgets ws-thredds-sync-widget jar - 1.3.0 + 1.4.0-SNAPSHOT ws-thredds-sync-widget gCube ws-thredds-sync-widget is a widget to use and interact with ws-thredds facility in order to syncronize the Workspace folders with Thredds Reporitory folders @@ -42,7 +42,7 @@ org.gcube.distribution maven-portal-bom - 3.6.0 + 3.6.2-SNAPSHOT pom import @@ -62,19 +62,6 @@ gwt-bootstrap - - - org.gcube.common.portal - portal-manager - provided - - - - com.liferay.portal - portal-service - provided - - org.gcube.dvos @@ -88,34 +75,34 @@ [1.0.0, 2.0.0-SNAPSHOT) - - - - - - - - org.gcube.common - authorization-client - [2.0.0, 3-0-0-SNAPSHOT) + org.gcube.portal + oidc-library-portal + + + + + org.gcube.common.portal + portal-manager + provided - org.gcube.common - storagehub-client-wrapper - [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + com.liferay.portal + portal-service + provided - org.slf4j - slf4j-log4j12 + slf4j-api + provided org.slf4j - slf4j-api + slf4j-log4j12 + provided 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 64c17a8..45bb2a4 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 @@ -37,7 +37,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.HorizontalPanel; -// TODO: Auto-generated Javadoc /** * The Class WsThreddsWidget. * @@ -148,6 +147,7 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { } final Modal box = new Modal(true); + box.setWidth(600); box.setTitle("Checking authorizations and configurations..."); final HorizontalPanel hpLoader = new HorizontalPanel(); LoaderIcon loader = new LoaderIcon("Checking authorizations and folder configurations..."); @@ -176,7 +176,7 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { //at least one THREDDS rights is assigned GWT.log("Performing isItemSynched: "+folder.getFolderId()); - WsThreddsWidget.wsThreddsSyncService.isItemSynched(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()); } }); } @@ -275,21 +283,29 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { * @param config the config */ private void performFolderSync(final WsFolder folder, WsThreddsSynchFolderConfiguration config) { - GWT.log("Performing doSyncFolder on: "+folder); + GWT.log("Performing doSyncFolder on: "+folder+" and config: "+config); final Modal box = new Modal(true); box.setTitle("Starting synchronization..."); box.hide(false); - LoaderIcon loader = new LoaderIcon("Inizializiting synchronization to the folder: "+folder.getFoderName()); + final LoaderIcon loader = new LoaderIcon("Inizializiting synchronization to the folder: "+folder.getFoderName()); box.add(loader); wsThreddsSyncService.doSyncFolder(folder.getFolderId(), config, new AsyncCallback() { @Override public void onFailure(Throwable caught) { - Window.alert(caught.getMessage()); + //Window.alert(caught.getMessage()); viewManager.cancelMonitor(folder); - if(box!=null) - box.hide(); + if(box!=null) { + try { + box.remove(loader); + }catch (Exception e) { + + } + Alert alertError = new Alert(caught.getMessage(), AlertType.ERROR); + alertError.setClose(false); + box.add(alertError); + } } 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 4c20452..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,11 +11,13 @@ 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; +// TODO: Auto-generated Javadoc /** * The Interface ThreddsWorkspaceSyncService. * @@ -25,15 +27,20 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @RemoteServiceRelativePath("wsthreddssync") public interface ThreddsWorkspaceSyncService extends RemoteService { + /** - * 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 + * @throws Exception the exception */ - WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception; + WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus) + throws WorkspaceFolderLocked, Exception; /** * Do sync folder. @@ -85,9 +92,10 @@ public interface ThreddsWorkspaceSyncService extends RemoteService { /** * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them. * - * @param user the user * @return the VREs and Thredds roles for a given user - * @throws Exception + * @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 0372091..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,68 +13,61 @@ 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. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Mar 8, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 8, 2018 */ -public interface ThreddsWorkspaceSyncServiceAsync -{ - - /** - * Utility class to get the RPC Async interface from client-side code. - * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Mar 8, 2018 - */ - public static final class Util - { - private static ThreddsWorkspaceSyncServiceAsync instance; - - /** - * Gets the single instance of Util. - * - * @return single instance of Util - */ - public static final ThreddsWorkspaceSyncServiceAsync getInstance() - { - if ( instance == null ) - { - instance = (ThreddsWorkspaceSyncServiceAsync) GWT.create( ThreddsWorkspaceSyncService.class ); - } - return instance; - } - - /** - * Instantiates a new util. - */ - private Util() - { - // Utility class should not be instantiated - } - } - +public interface ThreddsWorkspaceSyncServiceAsync { /** - * Checks if is item synched. + * Utility class to get the RPC Async interface from client-side code. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 8, 2018 + */ + public static final class Util { + private static ThreddsWorkspaceSyncServiceAsync instance; + + /** + * Gets the single instance of Util. + * + * @return single instance of Util + */ + public static final ThreddsWorkspaceSyncServiceAsync getInstance() { + if (instance == null) { + instance = (ThreddsWorkspaceSyncServiceAsync) GWT.create(ThreddsWorkspaceSyncService.class); + } + return instance; + } + + /** + * Instantiates a new util. + */ + private Util() { + // Utility class should not be instantiated + } + } + + /** + * Gets the configuration. * * @param folderId the folder id + * @param loadStatus the load status * @param callback the callback + * @return the configuration */ - void isItemSynched(String folderId, AsyncCallback callback); - + void getConfiguration(String folderId, boolean loadStatus, AsyncCallback callback); /** * Do sync folder. * - * @param folderId the folder id + * @param folderId the folder id * @param clientConfig the client config - * @param callback the callback + * @param callback the callback */ - void doSyncFolder(String folderId, WsThreddsSynchFolderConfiguration clientConfig, AsyncCallback callback); - + void doSyncFolder(String folderId, WsThreddsSynchFolderConfiguration clientConfig, + AsyncCallback callback); /** * Monitor sync status. @@ -84,8 +77,6 @@ public interface ThreddsWorkspaceSyncServiceAsync */ void monitorSyncStatus(String folderId, AsyncCallback callback); - - /** * Gets the list of scopes for logged user. * @@ -97,13 +88,12 @@ public interface ThreddsWorkspaceSyncServiceAsync /** * Gets the available catalogues for scope. * - * @param scope the scope + * @param scope the scope * @param callback the callback * @return the available catalogues for scope */ void getAvailableCataloguesForScope(String scope, AsyncCallback> callback); - /** * Do un sync folder. * @@ -112,6 +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/WsThreddsWidgetViewManager.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java index ca695b4..512b97f 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java @@ -340,7 +340,8 @@ public class WsThreddsWidgetViewManager { //GWT.log("WsThreddsSynchFolderDescriptor is: "+folderDescriptor); final Modal box = new Modal(true); - //box.setWidth(WIDHT_DIALOG+"px"); + box.getElement().addClassName("modal-sync-widget-config"); + box.setWidth(600); box.setTitle("Thredds Sync Information for: "+FormatUtil.getFolderTitle(folder.getFoderName(), 20)); final AbstractViewDialogBox panelView = new AbstractViewDialogBox() { @@ -358,7 +359,6 @@ public class WsThreddsWidgetViewManager { final boolean isCreateConfiguration = folderDescriptor==null?true:false; - //is the user a THREDDS_ADMIN (so DATA_MANAGER) in at least one scope? boolean isThreddsAdmin = false; 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/client/view/binder/ShowThreddsFolderInfoView.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java index 0fd0728..50acb61 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java @@ -1,6 +1,5 @@ package org.gcube.portlets.widgets.wsthreddssync.client.view.binder; - import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,48 +30,41 @@ import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Widget; - /** * The Class ShowThreddsFolderInfoView. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 15, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 15, 2018 */ public abstract class ShowThreddsFolderInfoView extends Composite { - /** The ui binder. */ - private static ShowThreddsFolderInfoViewUiBinder uiBinder = - GWT.create(ShowThreddsFolderInfoViewUiBinder.class); + private static ShowThreddsFolderInfoViewUiBinder uiBinder = GWT.create(ShowThreddsFolderInfoViewUiBinder.class); /** * The Interface ShowThreddsFolderInfoViewUiBinder. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 15, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 15, 2018 */ - interface ShowThreddsFolderInfoViewUiBinder - extends UiBinder { + interface ShowThreddsFolderInfoViewUiBinder extends UiBinder { } - @UiField TextBox field_folder_status; @UiField ListBox field_select_scope; - @UiField TextBox field_catalogue_name; - @UiField TextBox field_remote_path; @UiField TextBox field_folder_path; +// @UiField +// TextBox field_sync_updated; @UiField TextBox field_folder_locked; @@ -80,16 +72,13 @@ public abstract class ShowThreddsFolderInfoView extends Composite { @UiField Button button_do_unsync; - - /*@UiField - TextBox field_last_sync; - */ - + /* + * @UiField TextBox field_last_sync; + */ @UiField ControlGroup cg_catalogue_name; - @UiField ControlGroup cg_remote_path; @@ -107,15 +96,14 @@ public abstract class ShowThreddsFolderInfoView extends Composite { private boolean isCreateConfiguration; - - /** * The Enum SUBMIT_ACTION. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Mar 12, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 12, 2018 */ - public static enum SUBMIT_ACTION {CREATE_UPDATE_CONFIGURATION, DO_UNSYNC, DO_SYNC}; + public static enum SUBMIT_ACTION { + CREATE_UPDATE_CONFIGURATION, DO_UNSYNC, DO_SYNC + }; /** * Submit handler. @@ -128,25 +116,22 @@ public abstract class ShowThreddsFolderInfoView extends Composite { * Sets the error. * * @param visible the visible - * @param error the error + * @param error the error */ public abstract void setError(boolean visible, String error); - /** - * Because this class has a default constructor, it can - * be used as a binder template. In other words, it can be used in other - * *.ui.xml files as follows: - * - * Hello! - * - * Note that depending on the widget that is used, it may be necessary to - * implement HasHTML instead of HasText. + * Because this class has a default constructor, it can be used as a binder + * template. In other words, it can be used in other *.ui.xml files as follows: + * + * Hello! Note that + * depending on the widget that is used, it may be necessary to implement + * HasHTML instead of HasText. * - * @param folderId the folder id + * @param folderId the folder id * @param isCreateConfiguration the is create configuration - * @param mapScopeThreddsRoles the map scope thredds roles + * @param mapScopeThreddsRoles the map scope thredds roles */ public ShowThreddsFolderInfoView(String folderId, boolean isCreateConfiguration) { this.folderId = folderId; @@ -168,33 +153,34 @@ public abstract class ShowThreddsFolderInfoView extends Composite { @Override public void onClick(ClickEvent event) { setError(false, ""); - //boolean isValid = validateSubmit(); - //if(isValid) + // boolean isValid = validateSubmit(); + // if(isValid) submitHandler(SUBMIT_ACTION.DO_SYNC); } }); - if(isCreateConfiguration) { - WsThreddsWidget.wsThreddsSyncService.getListOfDataManagerScopesForLoggedUser(new AsyncCallback>() { + if (isCreateConfiguration) { + WsThreddsWidget.wsThreddsSyncService + .getListOfDataManagerScopesForLoggedUser(new AsyncCallback>() { - @Override - public void onSuccess(List result) { + @Override + public void onSuccess(List result) { - for (GcubeScope gcubeScope : result) { - String toValue = FormatUtil.toScopeValue(gcubeScope); - mapScopes.put(gcubeScope.getScopeName(), gcubeScope); - field_select_scope.addItem(toValue, gcubeScope.getScopeName()); + for (GcubeScope gcubeScope : result) { + String toValue = FormatUtil.toScopeValue(gcubeScope); + mapScopes.put(gcubeScope.getScopeName(), gcubeScope); + field_select_scope.addItem(toValue, gcubeScope.getScopeName()); - } - } + } + } - @Override - public void onFailure(Throwable caught) { - // TODO Auto-generated method stub + @Override + public void onFailure(Throwable caught) { + // TODO Auto-generated method stub - } - }); + } + }); } } @@ -202,23 +188,19 @@ public abstract class ShowThreddsFolderInfoView extends Composite { /** * Update view to result. * - * @param folder the folder + * @param folder the folder * @param syncFolderDesc the sync folder desc */ public void updateViewToResult(final WsFolder folder, WsThreddsSynchFolderDescriptor syncFolderDesc) { this.field_select_scope.clear(); - if(syncFolderDesc==null) { + if (syncFolderDesc == null) { pager.getRight().setVisible(false); return; } - if(syncFolderDesc.getSyncStatus()!=null) { - this.field_folder_status.setValue(syncFolderDesc.getSyncStatus().toString()); - } - - if(syncFolderDesc.getSelectedScope()!=null) { + if (syncFolderDesc.getSelectedScope() != null) { String toValue = FormatUtil.toScopeValue(syncFolderDesc.getSelectedScope()); this.field_select_scope.addItem(toValue, syncFolderDesc.getSelectedScope().getScopeName()); this.field_select_scope.setValue(0, syncFolderDesc.getSelectedScope().getScopeName()); @@ -226,35 +208,38 @@ public abstract class ShowThreddsFolderInfoView extends Composite { } ThSyncFolderDescriptor sfd = syncFolderDesc.getServerFolderDescriptor(); - if(sfd!=null) { + if (sfd != null) { this.field_folder_path.setValue(sfd.getFolderPath()); this.field_folder_path.setTitle(sfd.getFolderPath()); - this.field_folder_locked.setValue(sfd.isLocked()+""); + this.field_folder_locked.setValue(sfd.isLocked() + ""); + + if (sfd.getElementInfo() != null) { + this.field_folder_status.setValue(sfd.getElementInfo().getSyncStatus().toString()); + } ThSynchFolderConfiguration config = sfd.getConfiguration(); - if(config!=null) { + if (config != null) { + this.field_catalogue_name.setValue(config.getToCreateCatalogName()); this.field_catalogue_name.setTitle(config.getToCreateCatalogName()); this.field_remote_path.setValue(config.getRemotePath()); this.field_remote_path.setTitle(config.getRemotePath()); + } - ThProcessDescriptor lpd = sfd.getLocalProcessDescriptor(); - if(lpd!=null) { - //this.field_last_sync.setValue(DateTimeFormat.getFormat(DATE_FORMAT_YYYY_MM_DD_HH_MM_SS).format(new Date(lpd.getLaunchTime()))); + if (lpd != null) { + // this.field_last_sync.setValue(DateTimeFormat.getFormat(DATE_FORMAT_YYYY_MM_DD_HH_MM_SS).format(new + // Date(lpd.getLaunchTime()))); ThSynchFolderConfiguration sc = lpd.getSynchConfiguration(); - if(sc!=null) { - - //this.field_select_vre.setValue(sc.get, value); - + if (sc != null) { + // this.field_select_vre.setValue(sc.get, value); } } } - button_do_unsync.setVisible(true); button_do_unsync.addClickHandler(new ClickHandler() { @@ -276,8 +261,6 @@ public abstract class ShowThreddsFolderInfoView extends Composite { return isCreateConfiguration; } - - /** * Validate submit. * @@ -287,13 +270,13 @@ public abstract class ShowThreddsFolderInfoView extends Composite { cg_catalogue_name.setType(ControlGroupType.NONE); cg_remote_path.setType(ControlGroupType.NONE); - if(field_catalogue_name.getValue()==null || field_catalogue_name.getValue().isEmpty()){ + if (field_catalogue_name.getValue() == null || field_catalogue_name.getValue().isEmpty()) { cg_catalogue_name.setType(ControlGroupType.ERROR); setError(true, "Unit Title field is required"); return false; } - if(field_remote_path.getValue()==null || field_remote_path.getValue().isEmpty()){ + if (field_remote_path.getValue() == null || field_remote_path.getValue().isEmpty()) { cg_remote_path.setType(ControlGroupType.ERROR); setError(true, "Folder Name field is required"); return false; @@ -302,7 +285,6 @@ public abstract class ShowThreddsFolderInfoView extends Composite { return true; } - /** * Gets the remote path. * @@ -317,24 +299,21 @@ public abstract class ShowThreddsFolderInfoView extends Composite { * * @return the catalogue name */ - public String getCatalogueName(){ + public String getCatalogueName() { return field_catalogue_name.getValue(); } - - /** * Gets the selected scope. * * @return the selected scope */ - public GcubeScope getSelectedScope(){ - //String item = field_select_scope.getSelectedItemText(); + public GcubeScope getSelectedScope() { + // String item = field_select_scope.getSelectedItemText(); String scope = field_select_scope.getSelectedValue(); return mapScopes.get(scope); } - /** * Gets the pager. * @@ -349,11 +328,10 @@ public abstract class ShowThreddsFolderInfoView extends Composite { * * @return the main panel */ - public HTMLPanel getMainPanel(){ + public HTMLPanel getMainPanel() { return form_unit_fields; } - - + /** * Show unsync. * @@ -363,6 +341,4 @@ public abstract class ShowThreddsFolderInfoView extends Composite { button_do_unsync.setVisible(show); } - - } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.ui.xml b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.ui.xml index f511cd0..f4f6f9d 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.ui.xml @@ -1,6 +1,7 @@ + xmlns:g="urn:import:com.google.gwt.user.client.ui" + xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"> .noBorder { border: 0px; @@ -13,36 +14,46 @@ Sync Status - + Folder Path - + Locked - + + + + + + + + + + Catalogue Name - + Published in the Scope - + @@ -50,22 +61,24 @@ Remote Path - + - - - - - - - + + + + + + + + - Delete Synchronize + Delete Synchronize diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/public/WsThreddsWidget.css b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/public/WsThreddsWidget.css index bd03bab..429a381 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/public/WsThreddsWidget.css +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/public/WsThreddsWidget.css @@ -23,8 +23,18 @@ width: 750px !important; } -.myLittleMarginLeft{ - +.myLittleMarginLeft { margin-left: 25px !important; +} + +.modal-sync-widget-config { +} + +.modal-sync-widget-config .modal-body { + max-height: 600px; +} + +.modal-sync-widget-config form input, form select { + width: 300px; } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java index 5fa7a67..9700a16 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java @@ -1,9 +1,5 @@ package org.gcube.portlets.widgets.wsthreddssync.server; -import static org.gcube.common.authorization.client.Constants.authorizationService; - -import org.gcube.common.authorization.library.AuthorizationEntry; -import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope; @@ -14,6 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +// TODO: Auto-generated Javadoc /** * The Class BeanConverter. * @@ -33,28 +30,26 @@ public class BeanConverter { * @param theStatus the the status * @return the ws thredds synch folder descriptor */ - public static WsThreddsSynchFolderDescriptor toWsThreddsFolderConfig(ThSyncFolderDescriptor t, - Sync_Status theStatus) { + public static WsThreddsSynchFolderDescriptor toWsThreddsFolderConfig(ThSyncFolderDescriptor t) { - if (t == null) + if (t == null || t.getConfiguration()==null) return null; WsThreddsSynchFolderDescriptor ws = new WsThreddsSynchFolderDescriptor(); ws.setServerFolderDescriptor(t); - ws.setSyncStatus(theStatus); // FROM TARGET TOKEN TO SCOPE // t.getConfiguration().getTargetToken() + + String targetContext = t.getConfiguration().getTargetContext(); - if (t.getConfiguration().getTargetToken() != null) { + if (targetContext != null) { try { - AuthorizationEntry entry = authorizationService().get(t.getConfiguration().getTargetToken()); - String scope = entry.getContext(); - GcubeScope selectedScope = new GcubeScope(toScopeTitle(scope), scope, toGcubeScope(scope)); + GcubeScope selectedScope = new GcubeScope(toScopeTitle(targetContext), targetContext, toGcubeScope(targetContext)); ws.setSelectedScope(selectedScope); - logger.debug("Resolved SCOPE: " + selectedScope + " from token"); + logger.debug("Got target SCOPE: " + selectedScope + " from configuration"); } catch (Exception e) { - logger.error("I cannot resolve the scope for the token: "+t.getConfiguration().getTargetToken()); + logger.error("I cannot read the scope for: "+targetContext); } } @@ -104,16 +99,17 @@ public class BeanConverter { } } + /** * To th synch folder configuration. * - * @param t the t - * @param rootFolderId the root folder id - * @param targetScopeUserToken the target scope user token + * @param t the t + * @param rootFolderId the root folder id + * @param targetContext the target context * @return the th synch folder configuration */ public static ThSynchFolderConfiguration toThSynchFolderConfiguration(WsThreddsSynchFolderConfiguration t, - String rootFolderId, String targetScopeUserToken) { + String rootFolderId, String targetContext) { if (t == null) return null; @@ -121,7 +117,7 @@ public class BeanConverter { ThSynchFolderConfiguration ts = new ThSynchFolderConfiguration(); ts.setFilter(t.getFilter()); ts.setRemotePath(t.getRemotePath()); - ts.setTargetToken(targetScopeUserToken); + ts.setTargetContext(targetContext); ts.setToCreateCatalogName(t.getCatalogName()); ts.setRootFolderId(rootFolderId); return ts; 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 c6bd2be..590f738 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 @@ -4,240 +4,453 @@ package org.gcube.portlets.widgets.wsthreddssync.server; import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.authorization.library.provider.UmaJWTProvider; +import org.gcube.common.portal.PortalContext; 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.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; 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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + /** * The Class SyncronizeWithThredds. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 7, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 7, 2018 + * updated May, 2021 */ public class SyncronizeWithThredds { - /** The logger. */ private Logger logger = LoggerFactory.getLogger(SyncronizeWithThredds.class); /** The workspace thredds synchronize. */ - private WorkspaceThreddsSynchronize workspaceThreddsSynchronize; + private WorkspaceThreddsSynchronize workspaceThreddsSynchronizeLib; /** The Constant sdf. */ - //private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); - + // private static final SimpleDateFormat sdf = new + // SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); /** * Instantiates a new publish on thredds. * * @param wsScopeUserToken the ws scope user token - * @param username the username - * @param httpSession the http session + * @param username the username + * @param httpSession the http session */ public SyncronizeWithThredds() { - this.workspaceThreddsSynchronize = WorkspaceThreddsSynchronize.getInstance(); + this.workspaceThreddsSynchronizeLib = WorkspaceThreddsSynchronize.getInstance(); } - /** * Sets the context parameters. * - * @param scope the scope + * @param scope the scope * @param userToken the user token */ private void setContextParameters(String scope, String userToken) { - logger.debug("Setting context parameters with scope: "+scope +", user token: "+userToken.substring(0,10)+"-MASKED-TOKEN"); + logger.debug("Setting context parameters with scope: " + scope + ", user token: " + userToken.substring(0, 10) + + "-MASKED-TOKEN"); ScopeProvider.instance.set(scope); SecurityTokenProvider.instance.set(userToken); } - /** - * Do sync folder. + * Change context for UMA. * - * @param folderId the folder id - * @param thConfig the th config - * @param scope the scope - * @param userToken the user token - * @return the th sync status - * @throws Exception the exception + * @param httpRequest the http request + * @param user the user + * @param targetScope the target scope + * @return the string representing the previous UMA Token read from + * {@link UmaJWTProvider#get()} */ - public synchronized ThSyncStatus doSyncFolder(final String folderId, ThSynchFolderConfiguration thConfig, String scope, String userToken) throws Exception{ - logger.debug("Perfoming doSynFolder on folderId: "+folderId); - boolean firstSync = false; - + private String changeContextForUMA(HttpServletRequest httpRequest, GCubeUser user, String targetScope) { + logger.debug("Setting UMA context with target scope: " + targetScope + ", user: " + user.getUsername()); + String previousUMAToken = null; try { - setContextParameters(scope, userToken); - ThSyncFolderDescriptor folder = workspaceThreddsSynchronize.checkItemSynched(folderId); - }catch (ItemNotSynched e) { - firstSync = true; - // TODO: handle exception - }catch (Exception e) { - logger.error("Error on check item sync: ",e); - throw new Exception("Sorry an error occurred during folder publishing, refresh and try again"); - } - - try{ - - if(firstSync) { - if(thConfig==null) { - throw new Exception("A valid folder configuration must be provided to perform the synchronization"); - } - - logger.info("First sync setting synchronized folder configuration: "+thConfig); - workspaceThreddsSynchronize.setSynchronizedFolder(thConfig, folderId); + previousUMAToken = UmaJWTProvider.instance.get(); + JWTToken umaToken = OIDCUmaUtil.getUMAToken(httpRequest, user.getUsername(), targetScope); + setContextForUMA(umaToken.getRaw()); + } catch (Exception e) { + logger.warn("Error on set context for UMA: ", e); + if (previousUMAToken != null) { + logger.info("Setting previous UMA Token: " + previousUMAToken.substring(0, 10) + "-MASKED-TOKEN"); + setContextForUMA(previousUMAToken); } - - logger.info("Calling do sync on folder id: "+folderId); - return workspaceThreddsSynchronize.doSync(folderId); - //SessionUtil.setTransferPublishingOnThredds(httpSession, status); - }catch (Exception e) { - logger.error("Error on do sync: ",e); - throw new Exception(e.getMessage() +", refresh and try again"); - } + + return previousUMAToken; } - - - /** - * Gets the synched status from item property. + * Reset context for UMA. * - * @param folderId the folder id - * @param scope the scope - * @param username the username - * @return the synched status from item property - * @throws Exception the exception + * @param umaToken the uma token + * @return the string */ - public Sync_Status getSynchedStatusFromItemProperty(String folderId, String scope, String username) throws Exception{ + private void setContextForUMA(String umaToken) { + logger.info("called set context for UMA"); - try { - try { - ScopeProvider.instance.set(scope); - return workspaceThreddsSynchronize.getSynchedStatusFromItemProperty(folderId, username); - }catch (ItemNotSynched e) { - logger.info("The folder id: "+folderId +" is not synched returning null as "+Sync_Status.class.getSimpleName()); - return null; - } - - }catch (Exception e) { - logger.error("Error on getSynchedStatusFromItemProperty for id: "+folderId, e); - throw new Exception("Sorry, an error occurred during read sync status from HL properties, try again later"); + if (umaToken == null || umaToken.isEmpty()) { + logger.info("Uma Token is null or empty, skipping operation"); + return; } - } + logger.info("Going to set UMA Token: " + umaToken.substring(0, 10) + "-MASKED-TOKEN"); + UmaJWTProvider.instance.set(umaToken); + logger.debug("UmaJWTProvider instance set performed to : " + umaToken.substring(0, 10) + "-MASKED-TOKEN"); + + } /** * Checks if is item synched. * - * @param folderId the folder id - * @param scope the scope - * @param username the username + * @param folderId the folder id + * @param scope the scope + * @param userToken the user token + * @param itemProperties the item properties + * @param itemType the item type * @return true, if is item synched * @throws ItemNotSynched the item not synched - * @throws Exception the exception + * @throws Exception the exception */ - public boolean isItemSynched(String folderId, String scope, String username) throws ItemNotSynched, Exception{ + public boolean isItemSynched(String folderId, String scope, String userToken, Map itemProperties, + ContainerType itemType) throws ItemNotSynched, Exception { - Sync_Status value = getSynchedStatusFromItemProperty(folderId, scope, username); - - if(value!=null) - return true; - - return false; + setContextParameters(scope, userToken); + return workspaceThreddsSynchronizeLib.isItemSynched(folderId, itemProperties, itemType); } + /** + * Gets 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. Otherwise it calls the + * {@link SyncEngine#getConfig(String)} without sync status + * @param httpRequest the http request + * @param user the user + * @return the configuration + * @throws ItemNotSynched the item not synched + * @throws Exception the exception + */ + public ThSyncFolderDescriptor getConfiguration(String folderId, boolean loadStatus, HttpServletRequest httpRequest, GCubeUser user) + throws ItemNotSynched, Exception { + + ThSyncFolderDescriptor config = null; + String wsScope = PortalContext.getConfiguration().getCurrentScope(httpRequest); + String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); + String originalScope = wsScope; + String originalToken = wsUserToken; + String previousUmaToken = null; + String targetScope = null; + try { + + setContextParameters(wsScope, wsUserToken); + + if (loadStatus) { + + config = workspaceThreddsSynchronizeLib.getConfiguration(folderId); + // context switch for UMA token + targetScope = config.getConfiguration().getTargetContext(); + previousUmaToken = changeContextForUMA(httpRequest, user, targetScope); + + // context switch for gcube-token and scope + // getting token into target scope + String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, + user.getUsername()); + setContextParameters(targetScope, targetScopeUserToken); + + config = workspaceThreddsSynchronizeLib.checkItemSynched(folderId); + } else { + config = workspaceThreddsSynchronizeLib.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; + } finally { + + if(previousUmaToken!=null) { + // resetting UMA token in the WS scope + setContextForUMA(previousUmaToken); + } + + if (originalScope != null && targetScope!=null && originalScope.compareTo(targetScope) != 0) { + logger.info("Resetting the scope: " + originalScope + " which was original WS context"); + ScopeProvider.instance.set(originalScope); + if (originalToken != null) { + logger.info("Resetting the user token: " + originalToken.substring(0, 10) + + "-MASKED-TOKEN which was original WS context"); + SecurityTokenProvider.instance.set(originalToken); + } + } + } + + return config; + } /** - * Check item synched. + * Gets the available catalogues. * - * @param folderId the folder id - * @param scope the scope - * @param userToken the user token - * @return the th sync folder descriptor - * @throws ItemNotSynched the item not synched - * @throws WorkspaceFolderLocked the workspace folder locked + * @param httpRequest the http request + * @param user the user + * @param targetScope the target scope + * @return the available catalogues * @throws Exception the exception */ - public ThSyncFolderDescriptor checkItemSynched(String folderId, String scope, String userToken) throws ItemNotSynched, WorkspaceFolderLocked, Exception{ - setContextParameters(scope, userToken); - return workspaceThreddsSynchronize.checkItemSynched(folderId); + public List getAvailableCatalogues(HttpServletRequest httpRequest, GCubeUser user, + String targetScope) throws Exception { + String originalScope = null; + String originalToken = null; + String previousUmaToken = null; + List listCatalogues = null; + try { + // context switch for Uma token + previousUmaToken = changeContextForUMA(httpRequest, user, targetScope); + + // context switch for gcube-token and scope + PortalContext pConfig = PortalContext.getConfiguration(); + String wsScope = pConfig.getCurrentScope(httpRequest); + String wsUserToken = pConfig.getCurrentUserToken(wsScope, user.getUsername()); + // Thread Local contexts + originalScope = wsScope; + originalToken = wsUserToken; + // getting token into target scope + String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, + user.getUsername()); + setContextParameters(targetScope, targetScopeUserToken); + + // calling the engine + listCatalogues = workspaceThreddsSynchronizeLib.getAvailableCatalogues(); + } catch (Exception e) { + logger.error("Error on getting available Catalogues in the scope: " + targetScope, e); + + } finally { + + // resetting UMA token in the WS scope + setContextForUMA(previousUmaToken); + + if (originalScope != null && originalScope.compareTo(targetScope) != 0) { + logger.info("Resetting the scope: " + originalScope + " which was original WS context"); + ScopeProvider.instance.set(originalScope); + if (originalToken != null) { + logger.info("Resetting the user token: " + originalToken.substring(0, 10) + + "-MASKED-TOKEN which was original WS context"); + SecurityTokenProvider.instance.set(originalToken); + } + } + } + return listCatalogues; + } + + /** + * Do sync folder. + * + * @param folderId the folder id + * @param thConfig the th config + * @param httpRequest the http request + * @param user the user + * @return the th sync status + * @throws Exception the exception + */ + public synchronized ThSyncStatus doSyncFolder(final String folderId, ThSynchFolderConfiguration thConfig, + HttpServletRequest httpRequest, GCubeUser user) throws Exception { + logger.debug("called doSynFolder for folderId: " + folderId); + + boolean firstSync = false; + String originalScope = null; + String originalToken = null; + String previousUmaToken = null; + + if (thConfig == null) { + throw new Exception("A valid folder configuration must be provided to perform the synchronization"); + } + + String targetScope = thConfig.getTargetContext(); + if (targetScope == null || targetScope.isEmpty()) { + throw new Exception("Error, the target scope is not valid!"); + } + + logger.info("going to doSynFolder for folderId: " + folderId + ", target scope is: " + targetScope); + + try { + // context switch for Uma token + previousUmaToken = changeContextForUMA(httpRequest, user, targetScope); + + // context switch for gcube-token and scope + PortalContext pConfig = PortalContext.getConfiguration(); + String wsScope = pConfig.getCurrentScope(httpRequest); + String wsUserToken = pConfig.getCurrentUserToken(wsScope, user.getUsername()); + // Thread Local contexts + originalScope = wsScope; + originalToken = wsUserToken; + // getting token into target scope + String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, + user.getUsername()); + setContextParameters(targetScope, targetScopeUserToken); + + ThSyncFolderDescriptor folder = workspaceThreddsSynchronizeLib.checkItemSynched(folderId); + + } catch (ItemNotSynched e) { + firstSync = true; + } catch (Exception e) { + logger.error("Error on check item sync: ", e); + throw e; + } + + try { + + if (firstSync) { + logger.info("First sync setting the synchronized folder configuration: " + thConfig); + workspaceThreddsSynchronizeLib.setSynchronizedFolder(thConfig, folderId); + } + + logger.info("Calling do sync on folder id: " + folderId); + return workspaceThreddsSynchronizeLib.doSync(folderId); + + } catch (Exception e) { + logger.error("Error on doSyncFolder for folderId: "+folderId, e); + throw e; + + } finally { + + // resetting UMA token in the WS scope + setContextForUMA(previousUmaToken); + + if (originalScope != null && originalScope.compareTo(targetScope) != 0) { + logger.info("Resetting the scope: " + originalScope + " which was original WS context"); + ScopeProvider.instance.set(originalScope); + if (originalToken != null) { + logger.info("Resetting the user token: " + originalToken.substring(0, 10) + + "-MASKED-TOKEN which was original WS context"); + SecurityTokenProvider.instance.set(originalToken); + } + } + } + } + + /** + * Do un sync. + * + * @param folderId the folder id + * @param deleteRemoteContent the delete remote content + * @param thConfig the th config + * @param httpRequest the http request + * @param user the user + * @return the boolean + * @throws Exception the exception + */ + public Boolean doUnSync(String folderId, boolean deleteRemoteContent, ThSynchFolderConfiguration thConfig, + HttpServletRequest httpRequest, GCubeUser user) throws Exception { + logger.debug("called doUnSync for folderId: " + folderId); + + String originalScope = null; + String originalToken = null; + String previousUmaToken = null; + + if (thConfig == null) { + throw new Exception("A valid folder configuration must be provided to perform the synchronization"); + } + + String targetScope = thConfig.getTargetContext(); + if (targetScope == null || targetScope.isEmpty()) { + throw new Exception("Error, the target scope is not valid!"); + } + + logger.info("going to doSynFolder for folderId: " + folderId + ", target scope is: " + targetScope); + + try { + // context switch for Uma token + previousUmaToken = changeContextForUMA(httpRequest, user, targetScope); + + // context switch for gcube-token and scope + PortalContext pConfig = PortalContext.getConfiguration(); + String wsScope = pConfig.getCurrentScope(httpRequest); + String wsUserToken = pConfig.getCurrentUserToken(wsScope, user.getUsername()); + // Thread Local contexts + originalScope = wsScope; + originalToken = wsUserToken; + // getting token into target scope + String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, + user.getUsername()); + setContextParameters(targetScope, targetScopeUserToken); + + return workspaceThreddsSynchronizeLib.doUnSync(folderId, deleteRemoteContent); + + } catch (ItemNotSynched e) { + throw new Exception("The item with id: " + folderId + " is not synched"); + } catch (Exception e) { + logger.error("Error on check item sync: ", e); + throw new Exception("Sorry an error occurred during folder publishing, refresh and try again"); + + } finally { + + // resetting UMA token in the WS scope + setContextForUMA(previousUmaToken); + + if (originalScope != null && originalScope.compareTo(targetScope) != 0) { + logger.info("Resetting the scope: " + originalScope + " which was original WS context"); + ScopeProvider.instance.set(originalScope); + if (originalToken != null) { + logger.info("Resetting the user token: " + originalToken.substring(0, 10) + + "-MASKED-TOKEN which was original WS context"); + SecurityTokenProvider.instance.set(originalToken); + } + } + } } /** * Gets the sync status. * - * @param itemId the item id - * @param scope the scope + * @param itemId the item id + * @param scope the scope * @param userToken the user token * @return the sync status * @throws ItemNotSynched the item not synched - * @throws Exception the exception + * @throws Exception the exception */ - public ThSyncStatus monitorSyncStatus(String itemId, String scope, String userToken) throws ItemNotSynched, Exception{ + public ThSyncStatus monitorSyncStatus(String itemId, String scope, String userToken) + throws ItemNotSynched, Exception { setContextParameters(scope, userToken); - return workspaceThreddsSynchronize.monitorSyncStatus(itemId); + return workspaceThreddsSynchronizeLib.monitorSyncStatus(itemId); } - - - /** - * Do un sync. - * - * @param folderId the folder id - * @param deleteRemoteContent the delete remote content - * @param scope the scope - * @param userToken the user token - * @return the boolean - * @throws Exception the exception - */ - public Boolean doUnSync(String folderId, boolean deleteRemoteContent, String scope, String userToken) throws Exception { - - setContextParameters(scope, userToken); - return workspaceThreddsSynchronize.doUnSync(folderId, deleteRemoteContent); - } - - - /** * Register callback for id. * - * @param folderId the folder id - * @param scope the scope + * @param folderId the folder id + * @param scope the scope * @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 available catalogues by token. - * - * @param scope the scope - * @param userToken the user token - * @param targetToken the target token - * @return the available catalogues by token - * @throws Exception the exception - */ - public List getAvailableCataloguesByToken(String scope, String userToken, String targetToken) throws Exception { - setContextParameters(scope, userToken); - return workspaceThreddsSynchronize.getAvailableCataloguesByToken(targetToken); + workspaceThreddsSynchronizeLib.registerCallbackForId(folderId); } } 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 373e869..7e3bfb7 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 @@ -7,12 +7,11 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import javax.servlet.http.HttpServletRequest; + import org.gcube.common.portal.PortalContext; -import org.gcube.common.scope.api.ScopeProvider; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; -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; @@ -23,6 +22,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; @@ -38,11 +38,11 @@ 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 { @@ -60,10 +60,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem */ public synchronized SyncronizeWithThredds getSyncService() { - if(syncThredds==null) + if (syncThredds == null) syncThredds = new SyncronizeWithThredds(); - return syncThredds; + return syncThredds; } @@ -76,56 +76,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; } } - - - /** - * Do sync folder. - * - * @param folderId the folder id - * @param clientConfig the th config - * @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) - */ - @Override - public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) throws Exception{ - logger.info("Performing doSyncFolder method on id: "+folderId +", config: "+clientConfig); - - try { - GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - String targetScopeUserToken = null; - ThSynchFolderConfiguration config = null; - if(clientConfig!=null) { - targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(clientConfig.getSelectedScope().getScopeName(), user.getUsername()); - config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId, targetScopeUserToken); - 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, wsScope, wsUserToken); - logger.debug("Returning for folderId "+folderId+" the syncStatus: "+status); - - return status; - }catch (Exception e) { - logger.error("Do sync Folder error: ",e); - throw new Exception("Sorry, an error occurred during synchonization phase, try again later"); - } - } - - - /** * Gets the available THREDDS catalogues for target scope. * @@ -133,89 +89,192 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem * @return the available catalogues for scope * @throws Exception the exception */ + // UPDATED @Override public List getAvailableCataloguesForScope(String targetFullScope) throws Exception { - if(targetFullScope==null) + if (targetFullScope == null) throw new Exception("Invalid scope null"); - String originalScope = null; - String originalToken = null; List listCtlgs = null; try { + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); - String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - //Thread Local contexts - originalScope = wsScope; - originalToken = wsUserToken; - - String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetFullScope, user.getUsername()); - listCtlgs = getSyncService().getAvailableCataloguesByToken(targetFullScope, wsUserToken, targetScopeUserToken); - - logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+targetFullScope); - if(logger.isDebugEnabled()){ + listCtlgs = getSyncService().getAvailableCatalogues(this.getThreadLocalRequest(), user, targetFullScope); + + logger.debug("Retuning " + listCtlgs.size() + " Catalogues for scope: " + targetFullScope); + if (logger.isDebugEnabled()) { for (ThCatalogueBean thCatalogueBean : listCtlgs) { logger.debug(thCatalogueBean.toString()); } } - }catch (Exception e) { - logger.error("Error on checking available Catalogue in the scope: "+targetFullScope, e); - }finally { - - if(originalScope!=null && originalScope.compareTo(targetFullScope)!=0) { - logger.info("Resetting the scope: "+originalScope + " which was original WS context"); - ScopeProvider.instance.set(originalScope); - if(originalToken!=null) { - logger.info("Resetting the user token: "+originalToken.substring(0,10)+"-MASKED-TOKEN which was original WS context"); - SecurityTokenProvider.instance.set(originalToken); - } - - } + } catch (Exception e) { + logger.error("Error on checking available Catalogue in the scope: " + targetFullScope, e); } return listCtlgs; } - - + /** - * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them. + * Gets 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 + */ + @Override + public WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus) + throws WorkspaceFolderLocked, Exception { + logger.debug("called isItemSynched for folderId: " + folderId); + 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); + + try { + ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, httpRequest, user); + + if (theConfig != null) { + logger.info("Folder id: " + folderId + " is synched"); + WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig); + logger.debug("isItemSynched for id: " + folderId + " returning: " + toWsThreddFolder); + return toWsThreddFolder; + } + + logger.info("Folder id: " + folderId + " is not synched, returning null descriptor"); + return null; + + } catch (ItemNotSynched e) { + logger.info("The folderId: " + folderId + " is not synched, returning null for " + + WsThreddsSynchFolderDescriptor.class.getSimpleName()); + return null; + + } catch (WorkspaceFolderLocked e) { + logger.warn(e.getMessage() + ", sending exception to client..."); + throw new WorkspaceFolderLocked(e.getFolderId(), e.getMessage()); + + } catch (Exception e) { + logger.info("Error on isItemSynched for folderId: " + folderId, e); + throw new Exception(e); + } + } + + /** + * Do sync folder. + * + * @param folderId the folder id + * @param clientConfig the client config + * @return the th sync status + * @throws Exception the exception + */ + // UPDATED + @Override + public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) + throws Exception { + logger.info("Performing doSyncFolder method on id: " + folderId + ", config: " + clientConfig); + + try { + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + ThSynchFolderConfiguration config = null; + if (clientConfig != null && clientConfig.getSelectedScope() != null) { + config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId, + clientConfig.getSelectedScope().getScopeName()); + logger.debug("Creating server config " + config); + }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(); + } + + ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, this.getThreadLocalRequest(), user); + logger.debug("Returning for folderId " + folderId + " the syncStatus: " + status); + + return status; + } catch (Exception e) { + logger.error("Do sync Folder error: ", e); + throw new Exception("Sorry, an error occurred during synchonization phase. The server encountered the error: "+e.getMessage(), e); + } + } + + /** + * Do un sync folder. + * + * @param folderId the folder id + * @return the boolean + * @throws Exception the exception + */ + // Updated + @Override + public Boolean doUnSyncFolder(final String folderId) throws Exception { + logger.info("Performing unsync on folder id: " + folderId); + + try { + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId, false, 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( + "Sorry, an error occurred on deleting sync configurations, refresh and try again later"); + } + } + + /** + * 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 */ @Override - public Map getScopesWithThreddsRolesForLoggedUser() throws Exception{ + public Map getScopesWithThreddsRolesForLoggedUser() throws Exception { logger.info("called getScopesWithThreddsRolesForLoggedUser"); - + GCubeUser user = null; Map mapScopesRoles = null; - - //DEV MODE - if (!isWithinPortal()){ + + // DEV MODE + if (!isWithinPortal()) { mapScopesRoles = new HashMap(); mapScopesRoles.put("/gcube/devsec/devVRE", GatewayRolesThredds.DATA_EDITOR); // mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER); // mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER); return mapScopesRoles; } - + try { user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user); - - logger.info("returning Map(scopes,roles): "+mapScopesRoles); + + logger.info("returning Map(scopes,roles): " + mapScopesRoles); return mapScopesRoles; - }catch (Exception e) { + } catch (Exception e) { 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); - } + } } - - /** * Gets the list scope with the role Data-Manager for logged user. * @@ -223,17 +282,17 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem * @throws Exception the exception */ @Override - public List getListOfDataManagerScopesForLoggedUser() throws Exception{ - logger.info("getListOfVREsForLoggedUser...: "); + public List getListOfDataManagerScopesForLoggedUser() throws Exception { + logger.info("called getListOfVREsForLoggedUser...: "); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); long userId = user.getUserId(); - // Instanciate the manager + // Instantiate the manager GroupManager groupManager = new LiferayGroupManager(); List listOfScopes = new ArrayList(); - - //DEV MODE - if (!isWithinPortal()){ + + // DEV MODE + if (!isWithinPortal()) { listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE)); listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE)); listOfScopes.add(new GcubeScope("devNext", "/gcube/devNext", GcubeScopeType.VO)); @@ -246,159 +305,94 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem try { String gatewayHostname = GenericUtils.getGatewayClientHostname(getThreadLocalRequest()); - //list of Scopes filtered for gateway + // list of Scopes filtered for gateway Set filteredGroupsForGatw = groupManager.listGroupsByUserAndSite(userId, gatewayHostname); - - //List listOfGroups = groupManager.listGroupsByUser(userId); + + // List listOfGroups = groupManager.listGroupsByUser(userId); List listOfGroups = new ArrayList(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) { long groupId = gCubeGroup.getGroupId(); String fullScope = groupManager.getInfrastructureScope(groupId); - 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; + 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; } // }else if(groupManager.isRootVO(gCubeGroup.getGroupId())){ // scopeType = GcubeScopeType.ROOT; // } - if(scopeType!=null){ + 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); - if(gcubeScope!=null) { + // Adding only the scope where the user has the THREDDS_ADMIN role + GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, + gCubeGroup.getGroupName(), fullScope, groupManager, scopeType); + if (gcubeScope != null) { listOfScopes.add(gcubeScope); } } } - + GCubeGroup theRootVO = groupManager.getRootVO(); 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); - if(gcubeScope!=null) { + /// 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) { listOfScopes.add(gcubeScope); } - //ADDING THE ROOT SCOPE - /*String infraName = PortalContext.getConfiguration().getInfrastructureName(); - GcubeScope gcubeRoot = new GcubeScope(infraName, "/"+infraName, GcubeScopeType.ROOT); - listOfScopes.add(gcubeRoot)*/ - - - } - 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"); + + 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"); } 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 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 + * @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 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())){ + 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 list = getAvailableCataloguesForScope(fullScope); - if(list!=null) { + if (list != null) { return new GcubeScope(scopeName, fullScope, scopeType); } - }catch (Exception e) { - logger.error("Error on checking available catalogue for scope: "+fullScope, e); + } catch (Exception e) { + logger.error("Error on checking available catalogue for scope: " + fullScope, e); } } 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) - */ - @Override - public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception{ - - logger.debug("Performing isItemSynched for foldeId: "+folderId); - - try { - - GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); - Sync_Status theStatus = getSyncService().getSynchedStatusFromItemProperty(folderId, wsScope, user.getUsername()); - - if(theStatus!=null) { - logger.info("Folder id: "+folderId+" is synched"); - String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - ThSyncFolderDescriptor serverFolderSync = getSyncService().checkItemSynched(folderId,wsScope,wsUserToken); - WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(serverFolderSync, theStatus); - logger.debug("IsItemSynched for id: "+folderId +" returning: "+toWsThreddFolder); - return toWsThreddFolder; - } - - logger.info("Folder id: "+folderId+" is not synched, returning null descriptor"); - return null; - - } catch (ItemNotSynched e) { - logger.info("The folderId: "+folderId +" is not synched, returning null FolderDescriptor"); - return null; - - } catch (WorkspaceFolderLocked e) { - logger.warn(e.getMessage() +", sending exception to client..."); - throw new WorkspaceFolderLocked(e.getFolderId(), e.getMessage()); - - }catch (Exception e) { - logger.info("Error on isItemSynched for folderId: "+folderId, e); - throw new Exception(e); - } - } - - - /** - * Register callback for id. - * - * @param folderId the folder id - * @throws Exception the exception - */ - public 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. @@ -406,47 +400,14 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem * @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) + * @throws Exception the exception */ @Override - public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception{ + public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception { 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); } - - /** - * Do sync folder. - * - * @param folderId the folder id - * @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) - */ - @Override - public Boolean doUnSyncFolder(final String folderId) throws Exception{ - logger.info("Performing unsync on folder id: "+folderId); - -// String scope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); -// GCubeUser username = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); -// String groupName = PortalContext.getConfiguration().getCurrentGroupName(this.getThreadLocalRequest()); -// new GcubeVRE(groupName, scope) - try { - GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); - String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - return getSyncService().doUnSync(folderId, false, wsScope, wsUserToken); - }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"); - } - } - } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java index b722156..51ec50d 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java @@ -10,15 +10,7 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; -//import org.gcube.common.homelibrary.home.HomeLibrary; -//import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; -//import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; -//import org.gcube.common.homelibrary.home.workspace.Workspace; -//import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; import org.gcube.common.portal.PortalContext; -import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; -import org.gcube.common.storagehubwrapper.server.tohl.Workspace; import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.RoleManager; @@ -39,17 +31,13 @@ import com.liferay.portal.service.UserLocalServiceUtil; /** * The Class WsUtil. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Nov 25, 2016 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Nov 25, 2016 */ public class WsUtil { - - /** The logger. */ private static Logger logger = LoggerFactory.getLogger(WsUtil.class); - /** * Checks if is within portal. * @@ -59,14 +47,12 @@ public class WsUtil { try { UserLocalServiceUtil.getService(); return true; - } - catch (Exception ex) { + } catch (Exception ex) { logger.trace("Development Mode ON"); return false; } } - /** * Checks if is session expired. * @@ -76,119 +62,86 @@ public class WsUtil { */ public static boolean isSessionExpired(HttpServletRequest httpServletRequest) throws Exception { logger.trace("workspace session validating..."); - return PortalContext.getConfiguration().getCurrentUser(httpServletRequest)==null; + return PortalContext.getConfiguration().getCurrentUser(httpServletRequest) == null; } /** - * Gets the workspace from storage hub. - * - * @param httpServletRequest the http servlet request - * @return the workspace from storage hub - * @throws Exception the exception - */ - public Workspace getWorkspaceFromStorageHub(HttpServletRequest httpServletRequest) throws Exception { - logger.trace("Get Workspace"); -// String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest); - - GCubeUser user = null; - - try { - String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest); - user = PortalContext.getConfiguration().getCurrentUser(httpServletRequest); - if (user == null || user.getUsername().isEmpty()) - throw new Exception("Session expired"); - - ScopeProvider.instance.set(scope); - logger.trace("Scope provider instancied at: "+scope); - - logger.debug("Getting " + StorageHubWrapper.class.getSimpleName() + " for user: " + user.getUsername() - + " by using the scope: " + scope); - - String token = PortalContext.getConfiguration().getCurrentUserToken(scope, user.getUsername()); - StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true); - return shWrapper.getWorkspace(); - } catch (Exception e) { - logger.error("Error on getting the Workspace via SHUB wrapper", e); - throw new Exception("Error on gettig the Workspace for userId: " + user); - } - } - - /** - * 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. * * @param user the user * @return the VREs and Thredds roles for a given user */ - public static Map getScopesWithThreddsRolesForUser(GCubeUser user){ - logger.info("called getScopesThreddsRolesForUser user: "+user+", in all contexts"); - + public static Map getScopesWithThreddsRolesForUser(GCubeUser user) { + logger.info("called getScopesThreddsRolesForUser user: " + user + ", in all contexts"); + GroupManager groupManager = new LiferayGroupManager(); Map mapRoleByGroupSingleVre = new HashMap(); try { - - //Retrieving the list of VOs and VREs + + // Retrieving the list of VOs and VREs List listOfGroups = groupManager.listGroupsByUser(user.getUserId()); - //adding also the ROOT-VO + // adding also the ROOT-VO listOfGroups.add(groupManager.getRootVO()); for (GCubeGroup gCubeGroup : listOfGroups) { GatewayRolesThredds threddsRole = getThreddsRoleFor(user, gCubeGroup); - if(threddsRole != null) { + if (threddsRole != null) { String toFullScope = groupManager.getInfrastructureScope(gCubeGroup.getGroupId()); mapRoleByGroupSingleVre.put(toFullScope, threddsRole); } } - - logger.info("For user: "+user+", returning Map (VRE, ThreddsRoles) " + mapRoleByGroupSingleVre); + + logger.info("For user: " + user + ", returning Map (VRE, ThreddsRoles) " + mapRoleByGroupSingleVre); return mapRoleByGroupSingleVre; - }catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) { - logger.error("An error occurred during geThreddsVreRolesForUser: "+user, e); + } catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) { + logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e); return null; - } + } } - /** * Gets the (highest) thredds role for the user in the scope * - * @param user the user + * @param user the user * @param scope the vre * @return the thredds role for */ - public static GatewayRolesThredds getThreddsRoleFor(GCubeUser user, GCubeGroup scope){ - if(user==null || scope==null) { - logger.warn("called getThreddsRoleFor with invalid parameter user: "+user+", in the scope: "+scope, ", returning null"); + public static GatewayRolesThredds getThreddsRoleFor(GCubeUser user, GCubeGroup scope) { + if (user == null || scope == null) { + logger.warn("called getThreddsRoleFor with invalid parameter user: " + user + ", in the scope: " + scope, + ", returning null"); return null; } - - logger.info("called getThreddsRoleFor user: "+user.getUsername()+", in the scope: "+scope.getGroupName()); + + logger.info("called getThreddsRoleFor user: " + user.getUsername() + ", in the scope: " + scope.getGroupName()); try { RoleManager roleManager = new LiferayRoleManager(); List roles = roleManager.listRolesByUserAndGroup(user.getUserId(), scope.getGroupId()); List threddsRoles = new ArrayList(); for (GCubeRole gCubeRole : roles) { - if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_MANAGER.getRoleName())){ + if (gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_MANAGER.getRoleName())) { threddsRoles.add(GatewayRolesThredds.DATA_MANAGER); } - if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_EDITOR.getRoleName())){ + if (gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_EDITOR.getRoleName())) { threddsRoles.add(GatewayRolesThredds.DATA_EDITOR); } } - - logger.info("For user: "+user.getUsername()+" in the scope: "+scope.getGroupName()+" read the role/s: " + threddsRoles); - + + logger.info("For user: " + user.getUsername() + " in the scope: " + scope.getGroupName() + + " read the role/s: " + threddsRoles); + GatewayRolesThredds toReturn = null; if (threddsRoles.contains(GatewayRolesThredds.DATA_MANAGER)) toReturn = GatewayRolesThredds.DATA_MANAGER; else if (threddsRoles.contains(GatewayRolesThredds.DATA_EDITOR)) toReturn = GatewayRolesThredds.DATA_EDITOR; - + logger.info("returning highest role: " + toReturn); return toReturn; - }catch (UserRetrievalFault | GroupRetrievalFault e) { - logger.error("An error occurred during getVreRoleForUser: "+user, e); + } catch (UserRetrievalFault | GroupRetrievalFault e) { + logger.error("An error occurred during getVreRoleForUser: " + user, e); return null; } } - } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderConfiguration.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderConfiguration.java index f0d997d..9a43a7a 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderConfiguration.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderConfiguration.java @@ -4,16 +4,12 @@ import java.io.Serializable; import org.gcube.portal.wssynclibrary.shared.thredds.Status; - -// TODO: Auto-generated Javadoc /** * The Class WsThreddsSynchFolderConfiguration. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 16, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 16, 2018 */ -public class WsThreddsSynchFolderConfiguration implements Serializable{ - +public class WsThreddsSynchFolderConfiguration implements Serializable { /** * @@ -31,28 +27,27 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ /** The to create catalog name. */ private String catalogName; - private Status status; //just for serialization + private Status status; // just for serialization private String rootFolderId; - /** * Instantiates a new ws thredds synch folder configuration. */ public WsThreddsSynchFolderConfiguration() { - // TODO Auto-generated constructor stub - } + } /** * Instantiates a new ws thredds synch folder configuration. * - * @param remotePath the remote path - * @param theVRE the the vre - * @param filter the filter + * @param remotePath the remote path + * @param theVRE the the vre + * @param filter the filter * @param catalogName the catalog name */ - public WsThreddsSynchFolderConfiguration(String remotePath, GcubeScope theVRE, String filter, String catalogName, String rootFolderId) { + public WsThreddsSynchFolderConfiguration(String remotePath, GcubeScope theVRE, String filter, String catalogName, + String rootFolderId) { super(); this.remotePath = remotePath; this.selectedScope = theVRE; @@ -61,7 +56,6 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ this.rootFolderId = rootFolderId; } - /** * @param rootFolderId the rootFolderId to set */ @@ -70,7 +64,6 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ this.rootFolderId = rootFolderId; } - /** * @return the rootFolderId */ @@ -79,7 +72,6 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ return rootFolderId; } - /** * Gets the remote path. * @@ -98,7 +90,6 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ this.remotePath = remotePath; } - /** * @return the selectedScope */ @@ -107,17 +98,6 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ return selectedScope; } - - /** - * @return the status - */ - public Status getStatus() { - - return status; - } - - - /** * @param selectedScope the selectedScope to set */ @@ -126,17 +106,6 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ this.selectedScope = selectedScope; } - - - /** - * @param status the status to set - */ - public void setStatus(Status status) { - - this.status = status; - } - - /** * Gets the filter. * @@ -173,8 +142,9 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ this.catalogName = catalogName; } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#toString() */ @Override @@ -197,5 +167,4 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ return builder.toString(); } - } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java index 906401a..6f0b605 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java @@ -2,16 +2,14 @@ package org.gcube.portlets.widgets.wsthreddssync.shared; import java.io.Serializable; -import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; - -// TODO: Auto-generated Javadoc /** * The Class WsThreddsSynchFolderDescriptor. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 20, 2018 + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 13, 2021 */ public class WsThreddsSynchFolderDescriptor implements Serializable { @@ -24,33 +22,24 @@ public class WsThreddsSynchFolderDescriptor implements Serializable { private ThSyncFolderDescriptor serverFolderDescriptor; - private Sync_Status syncStatus; - /** * Instantiates a new ws thredds synch folder configuration. */ public WsThreddsSynchFolderDescriptor() { - // TODO Auto-generated constructor stub } - /** * Instantiates a new ws thredds synch folder descriptor. * - * @param selectedScope the selected scope + * @param selectedScope the selected scope * @param serverFolderDescriptor the server folder descriptor - * @param syncStatus the sync status */ - public WsThreddsSynchFolderDescriptor(GcubeScope selectedScope, ThSyncFolderDescriptor serverFolderDescriptor, - Sync_Status syncStatus) { + public WsThreddsSynchFolderDescriptor(GcubeScope selectedScope, ThSyncFolderDescriptor serverFolderDescriptor) { super(); this.selectedScope = selectedScope; this.serverFolderDescriptor = serverFolderDescriptor; - this.syncStatus = syncStatus; } - - /** * Gets the selected scope. * @@ -61,26 +50,6 @@ public class WsThreddsSynchFolderDescriptor implements Serializable { return selectedScope; } - /** - * Sets the sync status. - * - * @param syncStatus - * the new sync status - */ - public void setSyncStatus(Sync_Status syncStatus) { - this.syncStatus = syncStatus; - } - - /** - * Gets the sync status. - * - * @return the sync status - */ - public Sync_Status getSyncStatus() { - return syncStatus; - } - - /** * Sets the selected scope. * @@ -102,28 +71,21 @@ public class WsThreddsSynchFolderDescriptor implements Serializable { /** * Sets the server folder descriptor. * - * @param serverFolderDescriptor - * the new server folder descriptor + * @param serverFolderDescriptor the new server folder descriptor */ public void setServerFolderDescriptor(ThSyncFolderDescriptor serverFolderDescriptor) { this.serverFolderDescriptor = serverFolderDescriptor; } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("WsThreddsSynchFolderDescriptor [selectedVRE="); + builder.append("WsThreddsSynchFolderDescriptor [selectedScope="); builder.append(selectedScope); builder.append(", serverFolderDescriptor="); builder.append(serverFolderDescriptor); - builder.append(", syncStatus="); - builder.append(syncStatus); builder.append("]"); return builder.toString(); } - } diff --git a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java index e05ba39..ab508d9 100644 --- a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java +++ b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java @@ -1,17 +1,8 @@ package org.gcube.portlets.widgets.wsthreddssync; -import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize; import org.gcube.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds; -import org.gcube.usecases.ws.thredds.SyncEngine; -import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor; -import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus; -import org.gcube.usecases.ws.thredds.faults.WorkspaceLockedException; -import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; -import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack; -import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration; -// TODO: Auto-generated Javadoc /** * The Class TestWsThreddsEngine. * diff --git a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java index a23e663..51e2257 100644 --- a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java +++ b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java @@ -1,14 +1,5 @@ package org.gcube.portlets.widgets.wsthreddssync; -import java.util.Map; - -import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; -import org.gcube.common.storagehubwrapper.server.tohl.Workspace; -import org.gcube.common.storagehubwrapper.shared.tohl.Properties; -import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder; -import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; - public class TestWsThreddsQuery { final static String folderId = "61ea6d91-4b09-43ec-91c4-b2fdb9b8c538"; @@ -16,21 +7,20 @@ public class TestWsThreddsQuery { static String username = "francesco.mangiacrapa"; // NextNeext Francesco's Token static String token = "TOKEN"; - public static final String WS_SYNCH_SYNCH_STATUS = "WS-SYNCH.SYNCH-STATUS"; + /* public static void main(String[] args) { isItemSynched(); - + } + - public static void isItemSynched(){ - + public static void isItemSynched() { + try { ScopeProvider.instance.set(scope); - - StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true); - Workspace workspace = shWrapper.getWorkspace(); + Map metadata = workspace.getMetadata(folderId); if (metadata == null || metadata.isEmpty()) { @@ -40,12 +30,13 @@ public class TestWsThreddsQuery { String wsSyncStatus = (String) metadata.get(WS_SYNCH_SYNCH_STATUS); System.out.println("Current: " + WS_SYNCH_SYNCH_STATUS + " has value: " + wsSyncStatus); - //System.out.println("isSynched: " + isSynched); + // System.out.println("isSynched: " + isSynched); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } - + } + */ } diff --git a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java index c1a69eb..fc7fcd1 100644 --- a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java +++ b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java @@ -5,18 +5,8 @@ package org.gcube.portlets.widgets.wsthreddssync; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; -import org.gcube.common.storagehubwrapper.server.tohl.Workspace; -import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; -import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; -import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException; -import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException; import org.gcube.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds; -import org.gcube.usecases.ws.thredds.Constants; @@ -30,7 +20,7 @@ public class UnSyncThreddsFolders { public static String DEFAULT_SCOPE = "/gcube"; //DEV public static String TEST_USER = "francesco.mangiacrapa"; - public static String TEST_USER_TOKEN = "0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548"; //token user: Francesco Mangiacrapa - /gcube (root) + public static String TEST_USER_TOKEN = "TOKEN"; private static List lstUnSynchedItem = new ArrayList(); private static List lstUnSynchedFailedItem = new ArrayList(); @@ -44,21 +34,6 @@ public class UnSyncThreddsFolders { public static SyncronizeWithThredds syncService = new SyncronizeWithThredds(); - /** - * Gets the workspace. - * - * @return the workspace - * @throws InternalErrorException the internal error exception - * @throws HomeNotFoundException the home not found exception - * @throws WorkspaceFolderNotFoundException the workspace folder not found exception - */ - public static Workspace getWorkspace() throws Exception{ - - ScopeProvider.instance.set(scope); - StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true); - return shWrapper.getWorkspace(); - } - /** * The main method. @@ -68,9 +43,9 @@ public class UnSyncThreddsFolders { * @throws InternalErrorException the internal error exception * @throws HomeNotFoundException the home not found exception */ + /* public static void main(String[] args) throws Exception { - Workspace ws = getWorkspace(); unsycFirstLevel(ws, ws.getRoot().getId(), false); System.out.println("UnSync completed"); @@ -96,14 +71,6 @@ public class UnSyncThreddsFolders { - /** - * Unsyc first level. - * - * @param ws the ws - * @param itemId the item id - * @param depthUnsync the depth unsync - * @throws Exception - */ public static void unsycFirstLevel(Workspace ws, String itemId, boolean depthUnsync) throws Exception{ WorkspaceItem item; @@ -135,24 +102,19 @@ public class UnSyncThreddsFolders { } - /** - * Unsyn folder. - * - * @param workspaceItem the workspace item - */ public static void unsynFolder(WorkspaceItem workspaceItem) { if(workspaceItem==null) return; try{ - boolean synched = syncService.isItemSynched(workspaceItem.getId(), DEFAULT_SCOPE, TEST_USER); + ScopeProvider.instance.set(DEFAULT_SCOPE); + SecurityTokenProvider.instance.set(TEST_USER_TOKEN); + ThSyncFolderDescriptor synched = syncService.isItemSynched(workspaceItem.getId()); System.out.println("Is the workspace item: "+workspaceItem.getId() + " synched? "+synched +", Is folder? "+workspaceItem.isFolder()); - if(synched && workspaceItem.isFolder()){ + if(synched != null){ //Boolean unsynched = syncService.doUnSync(workspaceItem.getId(), false, DEFAULT_SCOPE, TEST_USER_TOKEN); - ScopeProvider.instance.set(DEFAULT_SCOPE); - SecurityTokenProvider.instance.set(TEST_USER_TOKEN); Workspace ws = getWorkspace(); cleanItem(workspaceItem, ws); totalAttempts++; @@ -184,6 +146,7 @@ public class UnSyncThreddsFolders { // } // } } + */ }