Compare commits

..

3 Commits

Author SHA1 Message Date
Francesco Mangiacrapa 2239c3f357 merged with trunk 2021-03-11 17:23:10 +01:00
Francesco Mangiacrapa 44027d88f8 added class 2021-03-11 17:19:54 +01:00
Francesco Mangiacrapa a241ad0a56 merged with trunk 2021-03-11 17:16:40 +01:00
20 changed files with 870 additions and 921 deletions

View File

@ -3,33 +3,10 @@
All notable changes to this project will be documented in this file. 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). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.3.0-SNAPSHOT] - 2021-03-03
## [v1.5.0] - 2021-07-20
#### Enhancements
[#21346] Moved to AccessTokenProvider for UMA tokens "context switches"
[#21576] Adding filtering for gateway to get scopes with THREDDS role for users
Moved to maven-portal-bom 3.6.3
Including new version of ws-thredds
## [v1.4.1-SNAPSHOT] - 2021-07-20
Moved to maven-portal-bom 3.6.3
Just to include new version of ws-thredds
## [v1.4.0] - 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
## [v1.3.0] - 2021-03-17
[#20847] Support the roles of THREDDS Admin and THREDDS Publisher [#20847] Support the roles of THREDDS Admin and THREDDS Publisher
## [v1.2.0] - 2020-07-21 ## [v1.2.0] - 2020-07-21
[#19676] Migrated to git/jenkins [#19676] Migrated to git/jenkins

65
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ws-thredds-sync-widget</artifactId> <artifactId>ws-thredds-sync-widget</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.5.0</version> <version>1.3.0-SNAPSHOT</version>
<name>ws-thredds-sync-widget</name> <name>ws-thredds-sync-widget</name>
<description> <description>
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 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 @@
<dependency> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId> <artifactId>maven-portal-bom</artifactId>
<version>3.6.3</version> <version>3.6.0</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
@ -62,29 +62,6 @@
<artifactId>gwt-bootstrap</artifactId> <artifactId>gwt-bootstrap</artifactId>
</dependency> </dependency>
<!-- User Management Core -->
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>ws-synchronized-module-library</artifactId>
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>oidc-library-portal</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>oidc-library</artifactId>
</dependency>
<!-- PORTAL MANAGER --> <!-- PORTAL MANAGER -->
<dependency> <dependency>
<groupId>org.gcube.common.portal</groupId> <groupId>org.gcube.common.portal</groupId>
@ -98,15 +75,47 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- User Management Core -->
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>ws-synchronized-module-library</artifactId>
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.gcube.spatial-data</groupId> -->
<!-- <artifactId>ws-thredds</artifactId> -->
<!-- <version>[0.0.1-SNAPSHOT, 1.0.0-SNAPSHOT)</version> -->
<!-- <scope>compile</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<version>[2.0.0, 3-0-0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-wrapper</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<!-- LOGGER --> <!-- LOGGER -->
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-log4j12</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-api</artifactId>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -59,4 +59,4 @@ public class WsThreddsSyncConstants {
} }
} }

View File

@ -37,6 +37,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.HorizontalPanel;
// TODO: Auto-generated Javadoc
/** /**
* The Class WsThreddsWidget. * The Class WsThreddsWidget.
* *
@ -147,7 +148,6 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
} }
final Modal box = new Modal(true); final Modal box = new Modal(true);
box.setWidth(600);
box.setTitle("Checking authorizations and configurations..."); box.setTitle("Checking authorizations and configurations...");
final HorizontalPanel hpLoader = new HorizontalPanel(); final HorizontalPanel hpLoader = new HorizontalPanel();
LoaderIcon loader = new LoaderIcon("Checking authorizations and folder configurations..."); 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 //at least one THREDDS rights is assigned
GWT.log("Performing isItemSynched: "+folder.getFolderId()); GWT.log("Performing isItemSynched: "+folder.getFolderId());
WsThreddsWidget.wsThreddsSyncService.getConfiguration(folder.getFolderId(), true, new AsyncCallback<WsThreddsSynchFolderDescriptor>() { WsThreddsWidget.wsThreddsSyncService.isItemSynched(folder.getFolderId(), new AsyncCallback<WsThreddsSynchFolderDescriptor>() {
@Override @Override
public void onSuccess(WsThreddsSynchFolderDescriptor result) { public void onSuccess(WsThreddsSynchFolderDescriptor result) {
@ -196,12 +196,7 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
try { box.hide();
hpLoader.clear();
hpLoader.setVisible(false);
}catch (Exception e) {
//Silent
}
if(caught instanceof WorkspaceFolderLocked){ if(caught instanceof WorkspaceFolderLocked){
viewManager.showMonitorSyncToFolder(folder,syncEventsListeners); viewManager.showMonitorSyncToFolder(folder,syncEventsListeners);
@ -209,10 +204,7 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
} }
viewManager.cancelMonitor(folder); viewManager.cancelMonitor(folder);
Alert alert = new Alert(caught.getMessage(), AlertType.ERROR); Window.alert(caught.getMessage());
alert.setClose(false);
box.add(alert);
//Window.alert(caught.getMessage());
} }
}); });
} }
@ -283,29 +275,21 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
* @param config the config * @param config the config
*/ */
private void performFolderSync(final WsFolder folder, WsThreddsSynchFolderConfiguration config) { private void performFolderSync(final WsFolder folder, WsThreddsSynchFolderConfiguration config) {
GWT.log("Performing doSyncFolder on: "+folder+" and config: "+config); GWT.log("Performing doSyncFolder on: "+folder);
final Modal box = new Modal(true); final Modal box = new Modal(true);
box.setTitle("Starting synchronization..."); box.setTitle("Starting synchronization...");
box.hide(false); box.hide(false);
final LoaderIcon loader = new LoaderIcon("Inizializiting synchronization to the folder: "+folder.getFoderName()); LoaderIcon loader = new LoaderIcon("Inizializiting synchronization to the folder: "+folder.getFoderName());
box.add(loader); box.add(loader);
wsThreddsSyncService.doSyncFolder(folder.getFolderId(), config, new AsyncCallback<ThSyncStatus>() { wsThreddsSyncService.doSyncFolder(folder.getFolderId(), config, new AsyncCallback<ThSyncStatus>() {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
//Window.alert(caught.getMessage()); Window.alert(caught.getMessage());
viewManager.cancelMonitor(folder); viewManager.cancelMonitor(folder);
if(box!=null) { if(box!=null)
try { box.hide();
box.remove(loader);
}catch (Exception e) {
}
Alert alertError = new Alert(caught.getMessage(), AlertType.ERROR);
alertError.setClose(false);
box.add(alertError);
}
} }

View File

@ -11,13 +11,11 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds;
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; 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.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
// TODO: Auto-generated Javadoc
/** /**
* The Interface ThreddsWorkspaceSyncService. * The Interface ThreddsWorkspaceSyncService.
* *
@ -27,20 +25,15 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("wsthreddssync") @RemoteServiceRelativePath("wsthreddssync")
public interface ThreddsWorkspaceSyncService extends RemoteService { public interface ThreddsWorkspaceSyncService extends RemoteService {
/** /**
* Gets the configuration. * Checks if is item synched.
* *
* @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 * @return the ws thredds synch folder descriptor
* @throws WorkspaceFolderLocked the workspace folder locked * @throws WorkspaceFolderLocked the workspace folder locked
* @throws Exception the exception * @throws Exception the exception
*/ */
WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus) WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception;
throws WorkspaceFolderLocked, Exception;
/** /**
* Do sync folder. * Do sync folder.
@ -92,10 +85,9 @@ 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. * 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 * @return the VREs and Thredds roles for a given user
* @throws Exception the exception * @throws Exception
*/ */
Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception; Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception;
} }

View File

@ -13,61 +13,68 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescr
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
// TODO: Auto-generated Javadoc
/** /**
* The Interface ThreddsWorkspaceSyncServiceAsync. * 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 { 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
}
}
/** /**
* Utility class to get the RPC Async interface from client-side code. * Checks if is item synched.
*
* @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 folderId the folder id
* @param loadStatus the load status
* @param callback the callback * @param callback the callback
* @return the configuration
*/ */
void getConfiguration(String folderId, boolean loadStatus, AsyncCallback<WsThreddsSynchFolderDescriptor> callback); void isItemSynched(String folderId, AsyncCallback<WsThreddsSynchFolderDescriptor> callback);
/** /**
* Do sync folder. * Do sync folder.
* *
* @param folderId the folder id * @param folderId the folder id
* @param clientConfig the client config * @param clientConfig the client config
* @param callback the callback * @param callback the callback
*/ */
void doSyncFolder(String folderId, WsThreddsSynchFolderConfiguration clientConfig, void doSyncFolder(String folderId, WsThreddsSynchFolderConfiguration clientConfig, AsyncCallback<ThSyncStatus> callback);
AsyncCallback<ThSyncStatus> callback);
/** /**
* Monitor sync status. * Monitor sync status.
@ -77,6 +84,8 @@ public interface ThreddsWorkspaceSyncServiceAsync {
*/ */
void monitorSyncStatus(String folderId, AsyncCallback<ThSyncStatus> callback); void monitorSyncStatus(String folderId, AsyncCallback<ThSyncStatus> callback);
/** /**
* Gets the list of scopes for logged user. * Gets the list of scopes for logged user.
* *
@ -88,12 +97,13 @@ public interface ThreddsWorkspaceSyncServiceAsync {
/** /**
* Gets the available catalogues for scope. * Gets the available catalogues for scope.
* *
* @param scope the scope * @param scope the scope
* @param callback the callback * @param callback the callback
* @return the available catalogues for scope * @return the available catalogues for scope
*/ */
void getAvailableCataloguesForScope(String scope, AsyncCallback<List<ThCatalogueBean>> callback); void getAvailableCataloguesForScope(String scope, AsyncCallback<List<ThCatalogueBean>> callback);
/** /**
* Do un sync folder. * Do un sync folder.
* *
@ -102,11 +112,6 @@ public interface ThreddsWorkspaceSyncServiceAsync {
*/ */
void doUnSyncFolder(String folderId, AsyncCallback<Boolean> callback); void doUnSyncFolder(String folderId, AsyncCallback<Boolean> 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<Map<String, GatewayRolesThredds>> callback); void getScopesWithThreddsRolesForLoggedUser(AsyncCallback<Map<String, GatewayRolesThredds>> callback);
} }

View File

@ -340,8 +340,7 @@ public class WsThreddsWidgetViewManager {
//GWT.log("WsThreddsSynchFolderDescriptor is: "+folderDescriptor); //GWT.log("WsThreddsSynchFolderDescriptor is: "+folderDescriptor);
final Modal box = new Modal(true); final Modal box = new Modal(true);
box.getElement().addClassName("modal-sync-widget-config"); //box.setWidth(WIDHT_DIALOG+"px");
box.setWidth(600);
box.setTitle("Thredds Sync Information for: "+FormatUtil.getFolderTitle(folder.getFoderName(), 20)); box.setTitle("Thredds Sync Information for: "+FormatUtil.getFolderTitle(folder.getFoderName(), 20));
final AbstractViewDialogBox panelView = new AbstractViewDialogBox() { final AbstractViewDialogBox panelView = new AbstractViewDialogBox() {
@ -359,6 +358,7 @@ public class WsThreddsWidgetViewManager {
final boolean isCreateConfiguration = folderDescriptor==null?true:false; final boolean isCreateConfiguration = folderDescriptor==null?true:false;
//is the user a THREDDS_ADMIN (so DATA_MANAGER) in at least one scope? //is the user a THREDDS_ADMIN (so DATA_MANAGER) in at least one scope?
boolean isThreddsAdmin = false; boolean isThreddsAdmin = false;

View File

@ -26,6 +26,7 @@ import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
// TODO: Auto-generated Javadoc // TODO: Auto-generated Javadoc
/** /**
* The Class ShowThreddsFolderInfoView. * The Class ShowThreddsFolderInfoView.

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.widgets.wsthreddssync.client.view.binder; package org.gcube.portlets.widgets.wsthreddssync.client.view.binder;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -30,41 +31,48 @@ import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
/** /**
* The Class ShowThreddsFolderInfoView. * 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 { public abstract class ShowThreddsFolderInfoView extends Composite {
/** The ui binder. */ /** The ui binder. */
private static ShowThreddsFolderInfoViewUiBinder uiBinder = GWT.create(ShowThreddsFolderInfoViewUiBinder.class); private static ShowThreddsFolderInfoViewUiBinder uiBinder =
GWT.create(ShowThreddsFolderInfoViewUiBinder.class);
/** /**
* The Interface ShowThreddsFolderInfoViewUiBinder. * 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<Widget, ShowThreddsFolderInfoView> { interface ShowThreddsFolderInfoViewUiBinder
extends UiBinder<Widget, ShowThreddsFolderInfoView> {
} }
@UiField @UiField
TextBox field_folder_status; TextBox field_folder_status;
@UiField @UiField
ListBox field_select_scope; ListBox field_select_scope;
@UiField @UiField
TextBox field_catalogue_name; TextBox field_catalogue_name;
@UiField @UiField
TextBox field_remote_path; TextBox field_remote_path;
@UiField @UiField
TextBox field_folder_path; TextBox field_folder_path;
// @UiField
// TextBox field_sync_updated;
@UiField @UiField
TextBox field_folder_locked; TextBox field_folder_locked;
@ -72,13 +80,16 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
@UiField @UiField
Button button_do_unsync; Button button_do_unsync;
/*
* @UiField TextBox field_last_sync; /*@UiField
*/ TextBox field_last_sync;
*/
@UiField @UiField
ControlGroup cg_catalogue_name; ControlGroup cg_catalogue_name;
@UiField @UiField
ControlGroup cg_remote_path; ControlGroup cg_remote_path;
@ -96,14 +107,15 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
private boolean isCreateConfiguration; private boolean isCreateConfiguration;
/** /**
* The Enum SUBMIT_ACTION. * 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 { public static enum SUBMIT_ACTION {CREATE_UPDATE_CONFIGURATION, DO_UNSYNC, DO_SYNC};
CREATE_UPDATE_CONFIGURATION, DO_UNSYNC, DO_SYNC
};
/** /**
* Submit handler. * Submit handler.
@ -116,22 +128,25 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
* Sets the error. * Sets the error.
* *
* @param visible the visible * @param visible the visible
* @param error the error * @param error the error
*/ */
public abstract void setError(boolean visible, String error); public abstract void setError(boolean visible, String error);
/** /**
* Because this class has a default constructor, it can be used as a binder * Because this class has a default constructor, it can
* template. In other words, it can be used in other *.ui.xml files as follows: * be used as a binder template. In other words, it can be used in other
* <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g= * *.ui.xml files as follows:
* "urn:import:**user's package**"> * <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
* <g:**UserClassName**>Hello!</g:**UserClassName> </ui:UiBinder> Note that * xmlns:g="urn:import:**user's package**">
* depending on the widget that is used, it may be necessary to implement * <g:**UserClassName**>Hello!</g:**UserClassName>
* HasHTML instead of HasText. * </ui:UiBinder>
* 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 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) { public ShowThreddsFolderInfoView(String folderId, boolean isCreateConfiguration) {
this.folderId = folderId; this.folderId = folderId;
@ -153,34 +168,33 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
setError(false, ""); setError(false, "");
// boolean isValid = validateSubmit(); //boolean isValid = validateSubmit();
// if(isValid) //if(isValid)
submitHandler(SUBMIT_ACTION.DO_SYNC); submitHandler(SUBMIT_ACTION.DO_SYNC);
} }
}); });
if (isCreateConfiguration) { if(isCreateConfiguration) {
WsThreddsWidget.wsThreddsSyncService WsThreddsWidget.wsThreddsSyncService.getListOfDataManagerScopesForLoggedUser(new AsyncCallback<List<GcubeScope>>() {
.getListOfDataManagerScopesForLoggedUser(new AsyncCallback<List<GcubeScope>>() {
@Override @Override
public void onSuccess(List<GcubeScope> result) { public void onSuccess(List<GcubeScope> result) {
for (GcubeScope gcubeScope : result) { for (GcubeScope gcubeScope : result) {
String toValue = FormatUtil.toScopeValue(gcubeScope); String toValue = FormatUtil.toScopeValue(gcubeScope);
mapScopes.put(gcubeScope.getScopeName(), gcubeScope); mapScopes.put(gcubeScope.getScopeName(), gcubeScope);
field_select_scope.addItem(toValue, gcubeScope.getScopeName()); field_select_scope.addItem(toValue, gcubeScope.getScopeName());
} }
} }
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
}); });
} }
} }
@ -188,19 +202,23 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
/** /**
* Update view to result. * Update view to result.
* *
* @param folder the folder * @param folder the folder
* @param syncFolderDesc the sync folder desc * @param syncFolderDesc the sync folder desc
*/ */
public void updateViewToResult(final WsFolder folder, WsThreddsSynchFolderDescriptor syncFolderDesc) { public void updateViewToResult(final WsFolder folder, WsThreddsSynchFolderDescriptor syncFolderDesc) {
this.field_select_scope.clear(); this.field_select_scope.clear();
if (syncFolderDesc == null) { if(syncFolderDesc==null) {
pager.getRight().setVisible(false); pager.getRight().setVisible(false);
return; return;
} }
if (syncFolderDesc.getSelectedScope() != null) { if(syncFolderDesc.getSyncStatus()!=null) {
this.field_folder_status.setValue(syncFolderDesc.getSyncStatus().toString());
}
if(syncFolderDesc.getSelectedScope()!=null) {
String toValue = FormatUtil.toScopeValue(syncFolderDesc.getSelectedScope()); String toValue = FormatUtil.toScopeValue(syncFolderDesc.getSelectedScope());
this.field_select_scope.addItem(toValue, syncFolderDesc.getSelectedScope().getScopeName()); this.field_select_scope.addItem(toValue, syncFolderDesc.getSelectedScope().getScopeName());
this.field_select_scope.setValue(0, syncFolderDesc.getSelectedScope().getScopeName()); this.field_select_scope.setValue(0, syncFolderDesc.getSelectedScope().getScopeName());
@ -208,38 +226,35 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
} }
ThSyncFolderDescriptor sfd = syncFolderDesc.getServerFolderDescriptor(); ThSyncFolderDescriptor sfd = syncFolderDesc.getServerFolderDescriptor();
if (sfd != null) { if(sfd!=null) {
this.field_folder_path.setValue(sfd.getFolderPath()); this.field_folder_path.setValue(sfd.getFolderPath());
this.field_folder_path.setTitle(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(); ThSynchFolderConfiguration config = sfd.getConfiguration();
if (config != null) { if(config!=null) {
this.field_catalogue_name.setValue(config.getToCreateCatalogName()); this.field_catalogue_name.setValue(config.getToCreateCatalogName());
this.field_catalogue_name.setTitle(config.getToCreateCatalogName()); this.field_catalogue_name.setTitle(config.getToCreateCatalogName());
this.field_remote_path.setValue(config.getRemotePath()); this.field_remote_path.setValue(config.getRemotePath());
this.field_remote_path.setTitle(config.getRemotePath()); this.field_remote_path.setTitle(config.getRemotePath());
} }
ThProcessDescriptor lpd = sfd.getLocalProcessDescriptor(); ThProcessDescriptor lpd = sfd.getLocalProcessDescriptor();
if (lpd != null) { if(lpd!=null) {
// this.field_last_sync.setValue(DateTimeFormat.getFormat(DATE_FORMAT_YYYY_MM_DD_HH_MM_SS).format(new //this.field_last_sync.setValue(DateTimeFormat.getFormat(DATE_FORMAT_YYYY_MM_DD_HH_MM_SS).format(new Date(lpd.getLaunchTime())));
// Date(lpd.getLaunchTime())));
ThSynchFolderConfiguration sc = lpd.getSynchConfiguration(); ThSynchFolderConfiguration sc = lpd.getSynchConfiguration();
if (sc != null) { if(sc!=null) {
// this.field_select_vre.setValue(sc.get, value);
//this.field_select_vre.setValue(sc.get, value);
} }
} }
} }
button_do_unsync.setVisible(true); button_do_unsync.setVisible(true);
button_do_unsync.addClickHandler(new ClickHandler() { button_do_unsync.addClickHandler(new ClickHandler() {
@ -261,6 +276,8 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
return isCreateConfiguration; return isCreateConfiguration;
} }
/** /**
* Validate submit. * Validate submit.
* *
@ -270,13 +287,13 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
cg_catalogue_name.setType(ControlGroupType.NONE); cg_catalogue_name.setType(ControlGroupType.NONE);
cg_remote_path.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); cg_catalogue_name.setType(ControlGroupType.ERROR);
setError(true, "Unit Title field is required"); setError(true, "Unit Title field is required");
return false; 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); cg_remote_path.setType(ControlGroupType.ERROR);
setError(true, "Folder Name field is required"); setError(true, "Folder Name field is required");
return false; return false;
@ -285,6 +302,7 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
return true; return true;
} }
/** /**
* Gets the remote path. * Gets the remote path.
* *
@ -299,21 +317,24 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
* *
* @return the catalogue name * @return the catalogue name
*/ */
public String getCatalogueName() { public String getCatalogueName(){
return field_catalogue_name.getValue(); return field_catalogue_name.getValue();
} }
/** /**
* Gets the selected scope. * Gets the selected scope.
* *
* @return the selected scope * @return the selected scope
*/ */
public GcubeScope getSelectedScope() { public GcubeScope getSelectedScope(){
// String item = field_select_scope.getSelectedItemText(); //String item = field_select_scope.getSelectedItemText();
String scope = field_select_scope.getSelectedValue(); String scope = field_select_scope.getSelectedValue();
return mapScopes.get(scope); return mapScopes.get(scope);
} }
/** /**
* Gets the pager. * Gets the pager.
* *
@ -328,10 +349,11 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
* *
* @return the main panel * @return the main panel
*/ */
public HTMLPanel getMainPanel() { public HTMLPanel getMainPanel(){
return form_unit_fields; return form_unit_fields;
} }
/** /**
* Show unsync. * Show unsync.
* *
@ -341,4 +363,6 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
button_do_unsync.setVisible(show); button_do_unsync.setVisible(show);
} }
} }

View File

@ -1,7 +1,6 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style> <ui:style>
.noBorder { .noBorder {
border: 0px; border: 0px;
@ -14,46 +13,36 @@
<b:ControlGroup ui:field="cg_folder_status"> <b:ControlGroup ui:field="cg_folder_status">
<b:ControlLabel for="cl_folder_status">Sync Status</b:ControlLabel> <b:ControlLabel for="cl_folder_status">Sync Status</b:ControlLabel>
<b:Controls> <b:Controls>
<b:TextBox b:id="field_folder_status" <b:TextBox b:id="field_folder_status" ui:field="field_folder_status"
ui:field="field_folder_status" readOnly="true"></b:TextBox> readOnly="true"></b:TextBox>
</b:Controls> </b:Controls>
</b:ControlGroup> </b:ControlGroup>
<b:ControlGroup ui:field="cg_folder_path"> <b:ControlGroup ui:field="cg_folder_path">
<b:ControlLabel for="cl_folder_path">Folder Path</b:ControlLabel> <b:ControlLabel for="cl_folder_path">Folder Path</b:ControlLabel>
<b:Controls> <b:Controls>
<b:TextBox b:id="field_catalogue_name" <b:TextBox b:id="field_catalogue_name" ui:field="field_folder_path"
ui:field="field_folder_path" readOnly="true"></b:TextBox> readOnly="true"></b:TextBox>
</b:Controls> </b:Controls>
</b:ControlGroup> </b:ControlGroup>
<b:ControlGroup ui:field="cg_folder_locked"> <b:ControlGroup ui:field="cg_folder_locked">
<b:ControlLabel for="cl_folder_locked">Locked</b:ControlLabel> <b:ControlLabel for="cl_folder_locked">Locked</b:ControlLabel>
<b:Controls> <b:Controls>
<b:TextBox b:id="field_folder_locked" <b:TextBox b:id="field_folder_locked" ui:field="field_folder_locked"
ui:field="field_folder_locked" readOnly="true"></b:TextBox> readOnly="true"></b:TextBox>
</b:Controls> </b:Controls>
</b:ControlGroup> </b:ControlGroup>
<!-- <b:ControlGroup ui:field="cg_latest_sync_updated"> -->
<!-- <b:ControlLabel for="cl_latest_sync_updated">Sync Updated</b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextBox b:id="field_sync_updated" -->
<!-- ui:field="field_sync_updated" readOnly="true"></b:TextBox> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<b:ControlGroup ui:field="cg_catalogue_name"> <b:ControlGroup ui:field="cg_catalogue_name">
<b:ControlLabel for="cl_catalogue_name">Catalogue Name</b:ControlLabel> <b:ControlLabel for="cl_catalogue_name">Catalogue Name</b:ControlLabel>
<b:Controls> <b:Controls>
<b:TextBox b:id="field_catalogue_name" <b:TextBox b:id="field_catalogue_name" ui:field="field_catalogue_name"
ui:field="field_catalogue_name" readOnly="true"></b:TextBox> readOnly="true"></b:TextBox>
</b:Controls> </b:Controls>
</b:ControlGroup> </b:ControlGroup>
<b:ControlGroup ui:field="cg_unit_description"> <b:ControlGroup ui:field="cg_unit_description">
<b:ControlLabel for="cl_course_description">Published in the Scope</b:ControlLabel> <b:ControlLabel for="cl_course_description">Published in the Scope</b:ControlLabel>
<b:Controls> <b:Controls>
<b:ListBox b:id="field_select_scope" <b:ListBox b:id="field_select_scope" ui:field="field_select_scope">
ui:field="field_select_scope">
</b:ListBox> </b:ListBox>
</b:Controls> </b:Controls>
</b:ControlGroup> </b:ControlGroup>
@ -61,24 +50,22 @@
<b:ControlGroup ui:field="cg_remote_path"> <b:ControlGroup ui:field="cg_remote_path">
<b:ControlLabel for="cl_remote_path">Remote Path</b:ControlLabel> <b:ControlLabel for="cl_remote_path">Remote Path</b:ControlLabel>
<b:Controls> <b:Controls>
<b:TextBox b:id="field_remote_path" <b:TextBox b:id="field_remote_path" ui:field="field_remote_path"
ui:field="field_remote_path" readOnly="true"></b:TextBox> readOnly="true"></b:TextBox>
</b:Controls> </b:Controls>
</b:ControlGroup> </b:ControlGroup>
<!-- <b:ControlGroup ui:field="cg_last_sync"> -->
<!-- <b:ControlGroup ui:field="cg_last_sync"> --> <!-- <b:ControlLabel for="cl_last_sync">Last Sync Time</b:ControlLabel> -->
<!-- <b:ControlLabel for="cl_last_sync">Last Sync Time</b:ControlLabel> --> <!-- <b:Controls> -->
<!-- <b:Controls> --> <!-- <b:TextBox b:id="field_last_sync" ui:field="field_last_sync" -->
<!-- <b:TextBox b:id="field_last_sync" ui:field="field_last_sync" --> <!-- readOnly="true"></b:TextBox> -->
<!-- readOnly="true"></b:TextBox> --> <!-- </b:Controls> -->
<!-- </b:Controls> --> <!-- </b:ControlGroup> -->
<!-- </b:ControlGroup> -->
</b:Fieldset> </b:Fieldset>
</b:Form> </b:Form>
</g:HTMLPanel> </g:HTMLPanel>
<b:Button type="LINK" ui:field="button_do_unsync" <b:Button type="LINK" ui:field="button_do_unsync" visible="false">Delete Synchronize</b:Button>
visible="false">Delete Synchronize</b:Button>
<b:Pager left="Update Configuration" right="Do Synchronize" <b:Pager left="Update Configuration" right="Do Synchronize"
aligned="true" ui:field="pager" /> aligned="true" ui:field="pager" />
</g:HTMLPanel> </g:HTMLPanel>

View File

@ -23,18 +23,8 @@
width: 750px !important; width: 750px !important;
} }
.myLittleMarginLeft { .myLittleMarginLeft{
margin-left: 25px !important;
} 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;
} }

View File

@ -1,5 +1,9 @@
package org.gcube.portlets.widgets.wsthreddssync.server; 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.ThSyncFolderDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration;
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
@ -10,7 +14,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/** /**
* The Class BeanConverter. * The Class BeanConverter.
* *
@ -30,26 +33,28 @@ public class BeanConverter {
* @param theStatus the the status * @param theStatus the the status
* @return the ws thredds synch folder descriptor * @return the ws thredds synch folder descriptor
*/ */
public static WsThreddsSynchFolderDescriptor toWsThreddsFolderConfig(ThSyncFolderDescriptor t) { public static WsThreddsSynchFolderDescriptor toWsThreddsFolderConfig(ThSyncFolderDescriptor t,
Sync_Status theStatus) {
if (t == null || t.getConfiguration()==null) if (t == null)
return null; return null;
WsThreddsSynchFolderDescriptor ws = new WsThreddsSynchFolderDescriptor(); WsThreddsSynchFolderDescriptor ws = new WsThreddsSynchFolderDescriptor();
ws.setServerFolderDescriptor(t); ws.setServerFolderDescriptor(t);
ws.setSyncStatus(theStatus);
// FROM TARGET TOKEN TO SCOPE // FROM TARGET TOKEN TO SCOPE
// t.getConfiguration().getTargetToken() // t.getConfiguration().getTargetToken()
String targetContext = t.getConfiguration().getTargetContext();
if (targetContext != null) { if (t.getConfiguration().getTargetToken() != null) {
try { try {
GcubeScope selectedScope = new GcubeScope(toScopeTitle(targetContext), targetContext, toGcubeScope(targetContext)); AuthorizationEntry entry = authorizationService().get(t.getConfiguration().getTargetToken());
String scope = entry.getContext();
GcubeScope selectedScope = new GcubeScope(toScopeTitle(scope), scope, toGcubeScope(scope));
ws.setSelectedScope(selectedScope); ws.setSelectedScope(selectedScope);
logger.debug("Got target SCOPE: " + selectedScope + " from configuration"); logger.debug("Resolved SCOPE: " + selectedScope + " from token");
} catch (Exception e) { } catch (Exception e) {
logger.error("I cannot read the scope for: "+targetContext); // TODO: handle exception
} }
} }
@ -99,17 +104,16 @@ public class BeanConverter {
} }
} }
/** /**
* To th synch folder configuration. * To th synch folder configuration.
* *
* @param t the t * @param t the t
* @param rootFolderId the root folder id * @param rootFolderId the root folder id
* @param targetContext the target context * @param targetScopeUserToken the target scope user token
* @return the th synch folder configuration * @return the th synch folder configuration
*/ */
public static ThSynchFolderConfiguration toThSynchFolderConfiguration(WsThreddsSynchFolderConfiguration t, public static ThSynchFolderConfiguration toThSynchFolderConfiguration(WsThreddsSynchFolderConfiguration t,
String rootFolderId, String targetContext) { String rootFolderId, String targetScopeUserToken) {
if (t == null) if (t == null)
return null; return null;
@ -117,7 +121,7 @@ public class BeanConverter {
ThSynchFolderConfiguration ts = new ThSynchFolderConfiguration(); ThSynchFolderConfiguration ts = new ThSynchFolderConfiguration();
ts.setFilter(t.getFilter()); ts.setFilter(t.getFilter());
ts.setRemotePath(t.getRemotePath()); ts.setRemotePath(t.getRemotePath());
ts.setTargetContext(targetContext); ts.setTargetToken(targetScopeUserToken);
ts.setToCreateCatalogName(t.getCatalogName()); ts.setToCreateCatalogName(t.getCatalogName());
ts.setRootFolderId(rootFolderId); ts.setRootFolderId(rootFolderId);
return ts; return ts;

View File

@ -4,451 +4,239 @@
package org.gcube.portlets.widgets.wsthreddssync.server; package org.gcube.portlets.widgets.wsthreddssync.server;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.oidc.rest.JWTToken;
import org.gcube.portal.oidc.lr62.JWTTokenUtil;
import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; 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.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration;
import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class SyncronizeWithThredds. * The Class SyncronizeWithThredds.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 7, 2018 * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* updated May, 2021 * Feb 7, 2018
*/ */
public class SyncronizeWithThredds { public class SyncronizeWithThredds {
/** The logger. */ /** The logger. */
private Logger logger = LoggerFactory.getLogger(SyncronizeWithThredds.class); private Logger logger = LoggerFactory.getLogger(SyncronizeWithThredds.class);
/** The workspace thredds synchronize. */ /** The workspace thredds synchronize. */
private WorkspaceThreddsSynchronize workspaceThreddsSynchronizeLib; private WorkspaceThreddsSynchronize workspaceThreddsSynchronize;
/** The Constant sdf. */ /** The Constant sdf. */
// private static final SimpleDateFormat sdf = new //private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
// SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
/** /**
* Instantiates a new publish on thredds. * Instantiates a new publish on thredds.
* *
* @param wsScopeUserToken the ws scope user token * @param wsScopeUserToken the ws scope user token
* @param username the username * @param username the username
* @param httpSession the http session * @param httpSession the http session
*/ */
public SyncronizeWithThredds() { public SyncronizeWithThredds() {
this.workspaceThreddsSynchronizeLib = WorkspaceThreddsSynchronize.getInstance(); this.workspaceThreddsSynchronize = WorkspaceThreddsSynchronize.getInstance();
} }
/** /**
* Sets the context parameters. * Sets the context parameters.
* *
* @param scope the scope * @param scope the scope
* @param userToken the user token * @param userToken the user token
*/ */
private void setContextParameters(String scope, String userToken) { private void setContextParameters(String scope, String userToken) {
logger.debug("Setting context parameters with scope: " + scope + ", user token: " + userToken.substring(0, 10) logger.debug("Setting context parameters with scope: "+scope +", user token: "+userToken.substring(0,10)+"-MASKED-TOKEN");
+ "-MASKED-TOKEN");
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(userToken); SecurityTokenProvider.instance.set(userToken);
} }
/**
* Change context for UMA.
*
* @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()}
*/
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 {
previousUMAToken = AccessTokenProvider.instance.get();
JWTToken umaToken = OIDCUmaUtil.getUMAToken(httpRequest, user.getUsername(), targetScope);
if (umaToken == null) {
logger.info("Uma Token is null or empty, skipping operation and returning null");
return null;
}
String subAccessToken = umaToken.getAccessTokenString().substring(0, 10);
logger.info("Going to set UMA Token: " + subAccessToken + "-MASKED-TOKEN");
// UmaJWTProvider.instance.set(umaToken);
AccessTokenProvider.instance.set(JWTTokenUtil.getAccessTokenString(umaToken));
logger.debug("UmaJWTProvider instance set performed to : " + subAccessToken + "-MASKED-TOKEN");
} 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");
AccessTokenProvider.instance.set(previousUMAToken);
}
}
return previousUMAToken;
}
/**
* Checks if is item synched.
*
* @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
*/
public boolean isItemSynched(String folderId, String scope, String userToken, Map<String, Object> itemProperties,
ContainerType itemType) throws ItemNotSynched, Exception {
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
AccessTokenProvider.instance.set(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;
}
/**
* Gets the available catalogues.
*
* @param httpRequest the http request
* @param user the user
* @param targetScope the target scope
* @return the available catalogues
* @throws Exception the exception
*/
public List<ThCatalogueBean> getAvailableCatalogues(HttpServletRequest httpRequest, GCubeUser user,
String targetScope) throws Exception {
String originalScope = null;
String originalToken = null;
String previousUmaToken = null;
List<ThCatalogueBean> 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 {
if (previousUmaToken != null) {
// resetting UMA token in the WS scope
AccessTokenProvider.instance.set(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. * Do sync folder.
* *
* @param folderId the folder id * @param folderId the folder id
* @param thConfig the th config * @param thConfig the th config
* @param httpRequest the http request * @param scope the scope
* @param user the user * @param userToken the user token
* @return the th sync status * @return the th sync status
* @throws Exception the exception * @throws Exception the exception
*/ */
public synchronized ThSyncStatus doSyncFolder(final String folderId, ThSynchFolderConfiguration thConfig, public synchronized ThSyncStatus doSyncFolder(final String folderId, ThSynchFolderConfiguration thConfig, String scope, String userToken) throws Exception{
HttpServletRequest httpRequest, GCubeUser user) throws Exception { logger.debug("Perfoming doSynFolder on folderId: "+folderId);
logger.debug("called doSynFolder for folderId: " + folderId);
boolean firstSync = false; 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 { try {
// context switch for Uma token setContextParameters(scope, userToken);
previousUmaToken = changeContextForUMA(httpRequest, user, targetScope); ThSyncFolderDescriptor folder = workspaceThreddsSynchronize.checkItemSynched(folderId);
}catch (ItemNotSynched e) {
// 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; firstSync = true;
} catch (Exception e) { // TODO: handle exception
logger.error("Error on check item sync: ", e); }catch (Exception e) {
throw e; logger.error("Error on check item sync: ",e);
throw new Exception("Sorry an error occurred during folder publishing, refresh and try again");
} }
try { try{
if (firstSync) { if(firstSync) {
logger.info("First sync setting the synchronized folder configuration: " + thConfig); if(thConfig==null)
workspaceThreddsSynchronizeLib.setSynchronizedFolder(thConfig, folderId); throw new Exception("A valid folder configuration must be provided to perforom synchronization");
logger.info("First sync setting synchronized folder configuration: "+thConfig);
workspaceThreddsSynchronize.setSynchronizedFolder(thConfig, folderId);
} }
logger.info("Calling do sync on folder id: " + folderId); logger.info("Calling do sync on folder id: "+folderId);
return workspaceThreddsSynchronizeLib.doSync(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");
} catch (Exception e) {
logger.error("Error on doSyncFolder for folderId: " + folderId, e);
throw e;
} finally {
if (previousUmaToken != null) {
// resetting UMA token in the WS scope
AccessTokenProvider.instance.set(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. * Gets the synched status from item property.
* *
* @param folderId the folder id * @param folderId the folder id
* @param deleteRemoteContent the delete remote content * @param scope the scope
* @param thConfig the th config * @param username the username
* @param httpRequest the http request * @return the synched status from item property
* @param user the user
* @return the boolean
* @throws Exception the exception * @throws Exception the exception
*/ */
public Boolean doUnSync(String folderId, boolean deleteRemoteContent, ThSynchFolderConfiguration thConfig, public Sync_Status getSynchedStatusFromItemProperty(String folderId, String scope, String username) throws Exception{
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 { try {
// context switch for Uma token try {
previousUmaToken = changeContextForUMA(httpRequest, user, targetScope); ScopeProvider.instance.set(scope);
return workspaceThreddsSynchronize.getSynchedStatusFromItemProperty(folderId, username);
// context switch for gcube-token and scope }catch (ItemNotSynched e) {
PortalContext pConfig = PortalContext.getConfiguration(); logger.info("The folder id: "+folderId +" is not synched returning null as "+Sync_Status.class.getSimpleName());
String wsScope = pConfig.getCurrentScope(httpRequest); return null;
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 {
if (previousUmaToken != null) {
// resetting UMA token in the WS scope
AccessTokenProvider.instance.set(previousUmaToken);
} }
if (originalScope != null && originalScope.compareTo(targetScope) != 0) { }catch (Exception e) {
logger.info("Resetting the scope: " + originalScope + " which was original WS context"); logger.error("Error on getSynchedStatusFromItemProperty for id: "+folderId, e);
ScopeProvider.instance.set(originalScope); throw new Exception("Sorry, an error occurred during read sync status from HL properties, try again later");
if (originalToken != null) {
logger.info("Resetting the user token: " + originalToken.substring(0, 10)
+ "-MASKED-TOKEN which was original WS context");
SecurityTokenProvider.instance.set(originalToken);
}
}
} }
} }
/**
* Checks if is item synched.
*
* @param folderId the folder id
* @param scope the scope
* @param username the username
* @return true, if is item synched
* @throws ItemNotSynched the item not synched
* @throws Exception the exception
*/
public boolean isItemSynched(String folderId, String scope, String username) throws ItemNotSynched, Exception{
Sync_Status value = getSynchedStatusFromItemProperty(folderId, scope, username);
if(value!=null)
return true;
return false;
}
/**
* Check item synched.
*
* @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
* @throws Exception the exception
*/
public ThSyncFolderDescriptor checkItemSynched(String folderId, String scope, String userToken) throws ItemNotSynched, WorkspaceFolderLocked, Exception{
setContextParameters(scope, userToken);
return workspaceThreddsSynchronize.checkItemSynched(folderId);
}
/** /**
* Gets the sync status. * Gets the sync status.
* *
* @param itemId the item id * @param itemId the item id
* @param scope the scope * @param scope the scope
* @param userToken the user token * @param userToken the user token
* @return the sync status * @return the sync status
* @throws ItemNotSynched the item not synched * @throws ItemNotSynched the item not synched
* @throws Exception the exception * @throws Exception the exception
*/ */
public ThSyncStatus monitorSyncStatus(String itemId, String scope, String userToken) public ThSyncStatus monitorSyncStatus(String itemId, String scope, String userToken) throws ItemNotSynched, Exception{
throws ItemNotSynched, Exception {
setContextParameters(scope, userToken); setContextParameters(scope, userToken);
return workspaceThreddsSynchronizeLib.monitorSyncStatus(itemId); return workspaceThreddsSynchronize.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. * Register callback for id.
* *
* @param folderId the folder id * @param folderId the folder id
* @param scope the scope * @param scope the scope
* @param userToken the user token * @param userToken the user token
* @throws Exception the exception * @throws Exception the exception
*/ */
protected void registerCallbackForId(String folderId, String scope, String userToken) throws Exception { public void registerCallbackForId(String folderId, String scope, String userToken) throws Exception {
setContextParameters(scope, userToken); setContextParameters(scope, userToken);
workspaceThreddsSynchronizeLib.registerCallbackForId(folderId); 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<ThCatalogueBean> getAvailableCataloguesByToken(String scope, String userToken, String targetToken) throws Exception {
setContextParameters(scope, userToken);
return workspaceThreddsSynchronize.getAvailableCataloguesByToken(targetToken);
} }
} }

View File

@ -7,11 +7,12 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.servlet.http.HttpServletRequest; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext; 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.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; 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.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
@ -22,7 +23,6 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScopeType; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScopeType;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; 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.GroupManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
@ -37,11 +37,12 @@ import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
// TODO: Auto-generated Javadoc
/** /**
* The server side implementation of the RPC service. * The server side implementation of the RPC service.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018 * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 14, 2018
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implements ThreddsWorkspaceSyncService { public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implements ThreddsWorkspaceSyncService {
@ -59,10 +60,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
*/ */
public synchronized SyncronizeWithThredds getSyncService() { public synchronized SyncronizeWithThredds getSyncService() {
if (syncThredds == null) if(syncThredds==null)
syncThredds = new SyncronizeWithThredds(); syncThredds = new SyncronizeWithThredds();
return syncThredds; return syncThredds;
} }
@ -75,12 +76,56 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try { try {
UserLocalServiceUtil.getService(); UserLocalServiceUtil.getService();
return true; return true;
} catch (Exception ex) { }
catch (Exception ex) {
logger.warn("Development Mode ON"); logger.warn("Development Mode ON");
return false; return false;
} }
} }
/**
* 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. * Gets the available THREDDS catalogues for target scope.
* *
@ -88,199 +133,89 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @return the available catalogues for scope * @return the available catalogues for scope
* @throws Exception the exception * @throws Exception the exception
*/ */
// UPDATED
@Override @Override
public List<ThCatalogueBean> getAvailableCataloguesForScope(String targetFullScope) throws Exception { public List<ThCatalogueBean> getAvailableCataloguesForScope(String targetFullScope) throws Exception {
if (targetFullScope == null) if(targetFullScope==null)
throw new Exception("Invalid scope null"); throw new Exception("Invalid scope null");
String originalScope = null;
String originalToken = null;
List<ThCatalogueBean> listCtlgs = null; List<ThCatalogueBean> listCtlgs = null;
try { try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
listCtlgs = getSyncService().getAvailableCatalogues(this.getThreadLocalRequest(), user, targetFullScope); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
logger.debug("Retuning " + listCtlgs.size() + " Catalogues for scope: " + targetFullScope); //Thread Local contexts
if (logger.isDebugEnabled()) { 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()){
for (ThCatalogueBean thCatalogueBean : listCtlgs) { for (ThCatalogueBean thCatalogueBean : listCtlgs) {
logger.debug(thCatalogueBean.toString()); logger.debug(thCatalogueBean.toString());
} }
} }
} catch (Exception e) { }catch (Exception e) {
logger.error("Error on checking available Catalogue in the scope: " + targetFullScope, e); logger.error("Error on checking available Catalogue in the scope: "+targetFullScope, e);
}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);
}
}
} }
return listCtlgs; return listCtlgs;
} }
/** /**
* Gets the configuration. * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them.
*
* @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 * @return the VREs and Thredds roles for a given user
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception { public Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception{
logger.info("called getScopesWithThreddsRolesForLoggedUser"); logger.info("called getScopesWithThreddsRolesForLoggedUser");
GCubeUser user = null;
Map<String, GatewayRolesThredds> mapScopesRoles = null; Map<String, GatewayRolesThredds> mapScopesRoles = null;
// DEV MODE //DEV MODE
if (!isWithinPortal()) { if (!isWithinPortal()){
mapScopesRoles = new HashMap<String, GatewayRolesThredds>(); mapScopesRoles = new HashMap<String, GatewayRolesThredds>();
mapScopesRoles.put("/gcube/devsec/devVRE", GatewayRolesThredds.DATA_EDITOR); mapScopesRoles.put("/gcube/devNext/NextNext", GatewayRolesThredds.DATA_MANAGER);
// mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER); // mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER);
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER); // mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER);
return mapScopesRoles; return mapScopesRoles;
} }
GCubeUser user = null;
try { try {
user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String gatewayHostname = GenericUtils.getGatewayClientHostname(this.getThreadLocalRequest()); mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user);
mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user, gatewayHostname);
logger.info("returning Map(scopes,roles): "+mapScopesRoles);
logger.info("returning Map(scopes,roles): " + mapScopesRoles);
return mapScopesRoles; return mapScopesRoles;
} catch (Exception e) { }catch (Exception e) {
String errorMsg = "An error occurred on checking user roles. Refresh the page and try again."; String errorMsg = "An error occurred on checking user roles. Refresh the page and try again.";
logger.error("An error occurred on checking user roles for user: " + user, e); logger.error("An error occurred on checking user roles for user: "+user, e);
throw new Exception(errorMsg); throw new Exception(errorMsg);
} }
} }
/** /**
* Gets the list scope with the role Data-Manager for logged user. * Gets the list scope with the role Data-Manager for logged user.
* *
@ -288,17 +223,17 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public List<GcubeScope> getListOfDataManagerScopesForLoggedUser() throws Exception { public List<GcubeScope> getListOfDataManagerScopesForLoggedUser() throws Exception{
logger.info("called getListOfVREsForLoggedUser...: "); logger.info("getListOfVREsForLoggedUser...: ");
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
long userId = user.getUserId(); long userId = user.getUserId();
// Instantiate the manager // Instanciate the manager
GroupManager groupManager = new LiferayGroupManager(); GroupManager groupManager = new LiferayGroupManager();
List<GcubeScope> listOfScopes = new ArrayList<GcubeScope>(); List<GcubeScope> listOfScopes = new ArrayList<GcubeScope>();
// DEV MODE //DEV MODE
if (!isWithinPortal()) { if (!isWithinPortal()){
listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE)); listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE));
listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE)); listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE));
listOfScopes.add(new GcubeScope("devNext", "/gcube/devNext", GcubeScopeType.VO)); listOfScopes.add(new GcubeScope("devNext", "/gcube/devNext", GcubeScopeType.VO));
@ -311,94 +246,159 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try { try {
String gatewayHostname = GenericUtils.getGatewayClientHostname(getThreadLocalRequest()); String gatewayHostname = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
// list of Scopes filtered for gateway //list of Scopes filtered for gateway
Set<GCubeGroup> filteredGroupsForGatw = groupManager.listGroupsByUserAndSite(userId, gatewayHostname); Set<GCubeGroup> filteredGroupsForGatw = groupManager.listGroupsByUserAndSite(userId, gatewayHostname);
// List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(userId); //List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(userId);
List<GCubeGroup> listOfGroups = new ArrayList<GCubeGroup>(filteredGroupsForGatw); List<GCubeGroup> listOfGroups = new ArrayList<GCubeGroup>(filteredGroupsForGatw);
logger.info("list of VREs in the gateway " + gatewayHostname + " are " + listOfGroups.size()); logger.info("list of VREs in the gateway "+gatewayHostname+" are "+listOfGroups.size());
for (GCubeGroup gCubeGroup : listOfGroups) { for (GCubeGroup gCubeGroup : listOfGroups) {
long groupId = gCubeGroup.getGroupId(); long groupId = gCubeGroup.getGroupId();
String fullScope = groupManager.getInfrastructureScope(groupId); String fullScope = groupManager.getInfrastructureScope(groupId);
logger.debug("For groupId: " + groupId + " got full scope: " + fullScope); logger.debug("For groupId: "+groupId+" got full scope: "+fullScope);
GcubeScopeType scopeType = null; GcubeScopeType scopeType=null;
if (groupManager.isVRE(groupId)) { if(groupManager.isVRE(groupId)){
scopeType = GcubeScopeType.VRE; scopeType = GcubeScopeType.VRE;
} else if (groupManager.isVO(groupId)) { }else if(groupManager.isVO(groupId)){
scopeType = GcubeScopeType.VO; scopeType = GcubeScopeType.VO;
} }
// }else if(groupManager.isRootVO(gCubeGroup.getGroupId())){ // }else if(groupManager.isRootVO(gCubeGroup.getGroupId())){
// scopeType = GcubeScopeType.ROOT; // scopeType = GcubeScopeType.ROOT;
// } // }
if (scopeType != null) { if(scopeType!=null){
GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, gCubeGroup); GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, gCubeGroup);
// Adding only the scope where the user has the THREDDS_ADMIN role //Adding only the scope where the user has the THREDDS_ADMIN role
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, gCubeGroup.getGroupName(), fullScope, groupManager, scopeType);
gCubeGroup.getGroupName(), fullScope, groupManager, scopeType); if(gcubeScope!=null) {
if (gcubeScope != null) {
listOfScopes.add(gcubeScope); listOfScopes.add(gcubeScope);
} }
} }
} }
GCubeGroup theRootVO = groupManager.getRootVO(); GCubeGroup theRootVO = groupManager.getRootVO();
GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, theRootVO); GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, theRootVO);
String rootVOFullScope = groupManager.getInfrastructureScope(theRootVO.getGroupId()); String rootVOFullScope = groupManager.getInfrastructureScope(theRootVO.getGroupId());
/// ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the ROOT-VO ///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the ROOT-VO
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, theRootVO.getGroupName(), GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, theRootVO.getGroupName(), rootVOFullScope, groupManager, GcubeScopeType.ROOT);
rootVOFullScope, groupManager, GcubeScopeType.ROOT); if(gcubeScope!=null) {
if (gcubeScope != null) {
listOfScopes.add(gcubeScope); listOfScopes.add(gcubeScope);
} }
} catch (UserRetrievalFault | UserManagementSystemException | GroupRetrievalFault e) { //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) {
logger.error("Error occurred server-side getting VRE folders: ", e); logger.error("Error occurred server-side getting VRE folders: ", e);
throw new Exception("Sorry, an error occurred server-side getting VRE folders, try again later"); throw new Exception("Sorry, an error occurred server-side getting VRE folders, try again later");
} }
if (listOfScopes.isEmpty()) { if(listOfScopes.isEmpty()) {
throw new Exception( throw new Exception("No scope detected with the needed role: "+GatewayRolesThredds.DATA_MANAGER.getRoleName()+". Contact the VRE manager or the portal administrator");
"No scope detected with the needed role: " + GatewayRolesThredds.DATA_MANAGER.getRoleName()
+ ". Contact the VRE manager or the portal administrator");
} }
Collections.sort(listOfScopes); Collections.sort(listOfScopes);
logger.info("Returning list of allowed scope/s with: " + GatewayRolesThredds.DATA_MANAGER + " role/s: " logger.info("Returning list of allowed scope/s with: "+GatewayRolesThredds.DATA_MANAGER + " role/s: "+listOfScopes);
+ listOfScopes);
return listOfScopes; return listOfScopes;
} }
/** /**
* Checks if for the input scope: - the user has the role * Checks if for the input scope:
* {@link GatewayRolesThredds.#THREDDS_ADMIN} - the scope has an available * - the user has the role {@link GatewayRolesThredds.#THREDDS_ADMIN}
* THREDDS catalogue configured * - the scope has an available THREDDS catalogue configured
* *
* @param role the role * @param role the role
* @param scopeName the scope name e.g. devVRE * @param scopeName the scope name e.g. devVRE
* @param fullScope the full scope e.g. /gcube/devsec/devVRE * @param fullScope the full scope e.g. /gcube/devsec/devVRE
* @param groupManager the group manager * @param groupManager the group manager
* @param scopeType the scope type * @param scopeType the scope type
* @return the gcube scope {@link GcubeScope} if the two conditions (see * @return the gcube scope {@link GcubeScope} if the two conditions (see description) are satisfied, null otherwise
* description) are satisfied, null otherwise
* @throws Exception the exception * @throws Exception the exception
*/ */
private GcubeScope checkDataManagerCapacityAndThreddsCatalogue(GatewayRolesThredds role, String scopeName, private GcubeScope checkDataManagerCapacityAndThreddsCatalogue(GatewayRolesThredds role, String scopeName, String fullScope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception {
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);
logger.debug("checking Data-Manager capacity and THREEDS catalogues for role: " + role, if(role!=null && role.getRoleName().equalsIgnoreCase(GatewayRolesNames.DATA_MANAGER.getRoleName())){
"scope name: " + scopeName + ", scope: " + fullScope + " scope type: " + scopeType);
if (role != null && role.getRoleName().equalsIgnoreCase(GatewayRolesNames.DATA_MANAGER.getRoleName())) {
try { try {
List<ThCatalogueBean> list = getAvailableCataloguesForScope(fullScope); List<ThCatalogueBean> list = getAvailableCataloguesForScope(fullScope);
if (list != null) { if(list!=null) {
return new GcubeScope(scopeName, fullScope, scopeType); return new GcubeScope(scopeName, fullScope, scopeType);
} }
} catch (Exception e) { }catch (Exception e) {
logger.error("Error on checking available catalogue for scope: " + fullScope, e); logger.error("Error on checking available catalogue for scope: "+fullScope, e);
} }
} }
return null; return null;
} }
/**
* 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. * Monitor sync status.
@ -406,14 +406,47 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @param folderId the folder id * @param folderId the folder id
* @return the th sync status * @return the th sync status
* @throws ItemNotSynched the item not synched * @throws ItemNotSynched the item not synched
* @throws Exception the exception * @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#monitorSyncStatus(java.lang.String)
*/ */
@Override @Override
public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception { public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception{
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
return getSyncService().monitorSyncStatus(folderId, wsScope, wsUserToken); 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");
}
}
} }

View File

@ -7,18 +7,24 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest; 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.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.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds;
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager; import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.VirtualGroupNotExistingException;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
@ -33,13 +39,17 @@ import com.liferay.portal.service.UserLocalServiceUtil;
/** /**
* The Class WsUtil. * 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 { public class WsUtil {
/** The logger. */ /** The logger. */
private static Logger logger = LoggerFactory.getLogger(WsUtil.class); private static Logger logger = LoggerFactory.getLogger(WsUtil.class);
/** /**
* Checks if is within portal. * Checks if is within portal.
* *
@ -49,12 +59,14 @@ public class WsUtil {
try { try {
UserLocalServiceUtil.getService(); UserLocalServiceUtil.getService();
return true; return true;
} catch (Exception ex) { }
catch (Exception ex) {
logger.trace("Development Mode ON"); logger.trace("Development Mode ON");
return false; return false;
} }
} }
/** /**
* Checks if is session expired. * Checks if is session expired.
* *
@ -64,99 +76,118 @@ public class WsUtil {
*/ */
public static boolean isSessionExpired(HttpServletRequest httpServletRequest) throws Exception { public static boolean isSessionExpired(HttpServletRequest httpServletRequest) throws Exception {
logger.trace("workspace session validating..."); logger.trace("workspace session validating...");
return PortalContext.getConfiguration().getCurrentUser(httpServletRequest) == null; return PortalContext.getConfiguration().getCurrentUser(httpServletRequest)==null;
} }
/** /**
* Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds * Gets the workspace from storage hub.
* roles that user has in them. *
* @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.
* *
* @param user the user * @param user the user
* @param gatewayHostname the gateway hostname
* @return the VREs and Thredds roles for a given user * @return the VREs and Thredds roles for a given user
*/ */
public static Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForUser(GCubeUser user, String gatewayHostname) { public static Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForUser(GCubeUser user){
logger.info("called getScopesThreddsRolesForUser user: " + user + ", in the gateway Contexts/VREs"); logger.info("called getScopesThreddsRolesForUser user: "+user+", in all contexts");
GroupManager groupManager = new LiferayGroupManager(); GroupManager groupManager = new LiferayGroupManager();
Map<String, GatewayRolesThredds> mapRoleByGroupSingleVre = new HashMap<String, GatewayRolesThredds>(); Map<String, GatewayRolesThredds> mapRoleByGroupSingleVre = new HashMap<String, GatewayRolesThredds>();
try { try {
long userId = user.getUserId(); //Retrieving the list of VOs and VREs
// list of Scopes filtered for gateway List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(user.getUserId());
Set<GCubeGroup> filteredGroupsForGatw = groupManager.listGroupsByUserAndSite(userId, gatewayHostname); //adding also the ROOT-VO
List<GCubeGroup> listOfGroups = new ArrayList<GCubeGroup>(filteredGroupsForGatw);
logger.info("list of VREs for user "+user.getUsername()+" in the gateway " + gatewayHostname + " are: " + listOfGroups.size());
if(logger.isDebugEnabled()) {
for (GCubeGroup gCubeGroup : listOfGroups) {
logger.info("the user "+user.getUsername()+" is registered in the VRE "+gCubeGroup.getGroupName());
}
}
// adding also the ROOT-VO
listOfGroups.add(groupManager.getRootVO()); listOfGroups.add(groupManager.getRootVO());
for (GCubeGroup gCubeGroup : listOfGroups) { for (GCubeGroup gCubeGroup : listOfGroups) {
GatewayRolesThredds threddsRole = getThreddsRoleFor(user, gCubeGroup); GatewayRolesThredds threddsRole = getThreddsRoleFor(user, gCubeGroup);
if (threddsRole != null) { if(threddsRole != null) {
String toFullScope = groupManager.getInfrastructureScope(gCubeGroup.getGroupId()); mapRoleByGroupSingleVre.put(gCubeGroup.getGroupName(), threddsRole);
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; return mapRoleByGroupSingleVre;
} catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) { }catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e); logger.error("An error occurred during geThreddsVreRolesForUser: "+user, e);
return null; return null;
} catch (VirtualGroupNotExistingException e) { }
logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e);
return null;
}
} }
/** /**
* Gets the (highest) thredds role for the user in the scope * Gets the (highest) thredds role for the user in the scope
* *
* @param user the user * @param user the user
* @param scope the vre * @param scope the vre
* @return the thredds role for * @return the thredds role for
*/ */
public static GatewayRolesThredds getThreddsRoleFor(GCubeUser user, GCubeGroup scope) { public static GatewayRolesThredds getThreddsRoleFor(GCubeUser user, GCubeGroup scope){
if (user == null || scope == null) { if(user==null || scope==null) {
logger.warn("called getThreddsRoleFor with invalid parameter user: " + user + ", in the scope: " + scope, logger.warn("called getThreddsRoleFor with invalid parameter user: "+user+", in the scope: "+scope, ", returning null");
", returning null");
return 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 { try {
RoleManager roleManager = new LiferayRoleManager(); RoleManager roleManager = new LiferayRoleManager();
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(user.getUserId(), scope.getGroupId()); List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(user.getUserId(), scope.getGroupId());
List<GatewayRolesThredds> threddsRoles = new ArrayList<GatewayRolesThredds>(); List<GatewayRolesThredds> threddsRoles = new ArrayList<GatewayRolesThredds>();
for (GCubeRole gCubeRole : roles) { 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); 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); threddsRoles.add(GatewayRolesThredds.DATA_EDITOR);
} }
} }
logger.info("For user: " + user.getUsername() + " in the scope: " + scope.getGroupName() logger.info("For user: "+user.getUsername()+" in the scope: "+scope.getGroupName()+" read the role/s: " + threddsRoles);
+ " read the role/s: " + threddsRoles);
GatewayRolesThredds toReturn = null; GatewayRolesThredds toReturn = null;
if (threddsRoles.contains(GatewayRolesThredds.DATA_MANAGER)) if (threddsRoles.contains(GatewayRolesThredds.DATA_MANAGER))
toReturn = GatewayRolesThredds.DATA_MANAGER; toReturn = GatewayRolesThredds.DATA_MANAGER;
else if (threddsRoles.contains(GatewayRolesThredds.DATA_EDITOR)) else if (threddsRoles.contains(GatewayRolesThredds.DATA_EDITOR))
toReturn = GatewayRolesThredds.DATA_EDITOR; toReturn = GatewayRolesThredds.DATA_EDITOR;
logger.info("returning highest role: " + toReturn); logger.info("returning highest role: " + toReturn);
return toReturn; return toReturn;
} catch (UserRetrievalFault | GroupRetrievalFault e) { }catch (UserRetrievalFault | GroupRetrievalFault e) {
logger.error("An error occurred during getVreRoleForUser: " + user, e); logger.error("An error occurred during getVreRoleForUser: "+user, e);
return null; return null;
} }
} }
} }

View File

@ -4,12 +4,16 @@ import java.io.Serializable;
import org.gcube.portal.wssynclibrary.shared.thredds.Status; import org.gcube.portal.wssynclibrary.shared.thredds.Status;
// TODO: Auto-generated Javadoc
/** /**
* The Class WsThreddsSynchFolderConfiguration. * 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{
/** /**
* *
@ -27,27 +31,28 @@ public class WsThreddsSynchFolderConfiguration implements Serializable {
/** The to create catalog name. */ /** The to create catalog name. */
private String catalogName; private String catalogName;
private Status status; // just for serialization private Status status; //just for serialization
private String rootFolderId; private String rootFolderId;
/** /**
* Instantiates a new ws thredds synch folder configuration. * Instantiates a new ws thredds synch folder configuration.
*/ */
public WsThreddsSynchFolderConfiguration() { public WsThreddsSynchFolderConfiguration() {
// TODO Auto-generated constructor stub
} }
/** /**
* Instantiates a new ws thredds synch folder configuration. * Instantiates a new ws thredds synch folder configuration.
* *
* @param remotePath the remote path * @param remotePath the remote path
* @param theVRE the the vre * @param theVRE the the vre
* @param filter the filter * @param filter the filter
* @param catalogName the catalog name * @param catalogName the catalog name
*/ */
public WsThreddsSynchFolderConfiguration(String remotePath, GcubeScope theVRE, String filter, String catalogName, public WsThreddsSynchFolderConfiguration(String remotePath, GcubeScope theVRE, String filter, String catalogName, String rootFolderId) {
String rootFolderId) {
super(); super();
this.remotePath = remotePath; this.remotePath = remotePath;
this.selectedScope = theVRE; this.selectedScope = theVRE;
@ -56,6 +61,7 @@ public class WsThreddsSynchFolderConfiguration implements Serializable {
this.rootFolderId = rootFolderId; this.rootFolderId = rootFolderId;
} }
/** /**
* @param rootFolderId the rootFolderId to set * @param rootFolderId the rootFolderId to set
*/ */
@ -64,6 +70,7 @@ public class WsThreddsSynchFolderConfiguration implements Serializable {
this.rootFolderId = rootFolderId; this.rootFolderId = rootFolderId;
} }
/** /**
* @return the rootFolderId * @return the rootFolderId
*/ */
@ -72,6 +79,7 @@ public class WsThreddsSynchFolderConfiguration implements Serializable {
return rootFolderId; return rootFolderId;
} }
/** /**
* Gets the remote path. * Gets the remote path.
* *
@ -90,6 +98,7 @@ public class WsThreddsSynchFolderConfiguration implements Serializable {
this.remotePath = remotePath; this.remotePath = remotePath;
} }
/** /**
* @return the selectedScope * @return the selectedScope
*/ */
@ -98,6 +107,17 @@ public class WsThreddsSynchFolderConfiguration implements Serializable {
return selectedScope; return selectedScope;
} }
/**
* @return the status
*/
public Status getStatus() {
return status;
}
/** /**
* @param selectedScope the selectedScope to set * @param selectedScope the selectedScope to set
*/ */
@ -106,6 +126,17 @@ public class WsThreddsSynchFolderConfiguration implements Serializable {
this.selectedScope = selectedScope; this.selectedScope = selectedScope;
} }
/**
* @param status the status to set
*/
public void setStatus(Status status) {
this.status = status;
}
/** /**
* Gets the filter. * Gets the filter.
* *
@ -142,9 +173,8 @@ public class WsThreddsSynchFolderConfiguration implements Serializable {
this.catalogName = catalogName; this.catalogName = catalogName;
} }
/*
* (non-Javadoc) /* (non-Javadoc)
*
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@Override @Override
@ -167,4 +197,5 @@ public class WsThreddsSynchFolderConfiguration implements Serializable {
return builder.toString(); return builder.toString();
} }
} }

View File

@ -2,14 +2,16 @@ package org.gcube.portlets.widgets.wsthreddssync.shared;
import java.io.Serializable; import java.io.Serializable;
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
// TODO: Auto-generated Javadoc
/** /**
* The Class WsThreddsSynchFolderDescriptor. * The Class WsThreddsSynchFolderDescriptor.
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* * Feb 20, 2018
* May 13, 2021
*/ */
public class WsThreddsSynchFolderDescriptor implements Serializable { public class WsThreddsSynchFolderDescriptor implements Serializable {
@ -22,24 +24,33 @@ public class WsThreddsSynchFolderDescriptor implements Serializable {
private ThSyncFolderDescriptor serverFolderDescriptor; private ThSyncFolderDescriptor serverFolderDescriptor;
private Sync_Status syncStatus;
/** /**
* Instantiates a new ws thredds synch folder configuration. * Instantiates a new ws thredds synch folder configuration.
*/ */
public WsThreddsSynchFolderDescriptor() { public WsThreddsSynchFolderDescriptor() {
// TODO Auto-generated constructor stub
} }
/** /**
* Instantiates a new ws thredds synch folder descriptor. * 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 serverFolderDescriptor the server folder descriptor
* @param syncStatus the sync status
*/ */
public WsThreddsSynchFolderDescriptor(GcubeScope selectedScope, ThSyncFolderDescriptor serverFolderDescriptor) { public WsThreddsSynchFolderDescriptor(GcubeScope selectedScope, ThSyncFolderDescriptor serverFolderDescriptor,
Sync_Status syncStatus) {
super(); super();
this.selectedScope = selectedScope; this.selectedScope = selectedScope;
this.serverFolderDescriptor = serverFolderDescriptor; this.serverFolderDescriptor = serverFolderDescriptor;
this.syncStatus = syncStatus;
} }
/** /**
* Gets the selected scope. * Gets the selected scope.
* *
@ -50,6 +61,26 @@ public class WsThreddsSynchFolderDescriptor implements Serializable {
return selectedScope; 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. * Sets the selected scope.
* *
@ -71,21 +102,28 @@ public class WsThreddsSynchFolderDescriptor implements Serializable {
/** /**
* Sets the server folder descriptor. * Sets the server folder descriptor.
* *
* @param serverFolderDescriptor the new server folder descriptor * @param serverFolderDescriptor
* the new server folder descriptor
*/ */
public void setServerFolderDescriptor(ThSyncFolderDescriptor serverFolderDescriptor) { public void setServerFolderDescriptor(ThSyncFolderDescriptor serverFolderDescriptor) {
this.serverFolderDescriptor = serverFolderDescriptor; this.serverFolderDescriptor = serverFolderDescriptor;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("WsThreddsSynchFolderDescriptor [selectedScope="); builder.append("WsThreddsSynchFolderDescriptor [selectedVRE=");
builder.append(selectedScope); builder.append(selectedScope);
builder.append(", serverFolderDescriptor="); builder.append(", serverFolderDescriptor=");
builder.append(serverFolderDescriptor); builder.append(serverFolderDescriptor);
builder.append(", syncStatus=");
builder.append(syncStatus);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }

View File

@ -1,8 +1,17 @@
package org.gcube.portlets.widgets.wsthreddssync; package org.gcube.portlets.widgets.wsthreddssync;
import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize;
import org.gcube.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds; 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. * The Class TestWsThreddsEngine.
* *

View File

@ -1,5 +1,14 @@
package org.gcube.portlets.widgets.wsthreddssync; 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 { public class TestWsThreddsQuery {
final static String folderId = "61ea6d91-4b09-43ec-91c4-b2fdb9b8c538"; final static String folderId = "61ea6d91-4b09-43ec-91c4-b2fdb9b8c538";
@ -7,20 +16,21 @@ public class TestWsThreddsQuery {
static String username = "francesco.mangiacrapa"; static String username = "francesco.mangiacrapa";
// NextNeext Francesco's Token // NextNeext Francesco's Token
static String token = "TOKEN"; static String token = "TOKEN";
public static final String WS_SYNCH_SYNCH_STATUS = "WS-SYNCH.SYNCH-STATUS";
/*
public static void main(String[] args) { public static void main(String[] args) {
isItemSynched(); isItemSynched();
}
public static void isItemSynched() { }
public static void isItemSynched(){
try { try {
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true);
Workspace workspace = shWrapper.getWorkspace();
Map<String, Object> metadata = workspace.getMetadata(folderId); Map<String, Object> metadata = workspace.getMetadata(folderId);
if (metadata == null || metadata.isEmpty()) { if (metadata == null || metadata.isEmpty()) {
@ -30,13 +40,12 @@ public class TestWsThreddsQuery {
String wsSyncStatus = (String) metadata.get(WS_SYNCH_SYNCH_STATUS); String wsSyncStatus = (String) metadata.get(WS_SYNCH_SYNCH_STATUS);
System.out.println("Current: " + WS_SYNCH_SYNCH_STATUS + " has value: " + wsSyncStatus); System.out.println("Current: " + WS_SYNCH_SYNCH_STATUS + " has value: " + wsSyncStatus);
// System.out.println("isSynched: " + isSynched); //System.out.println("isSynched: " + isSynched);
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
*/
} }

View File

@ -5,8 +5,18 @@ package org.gcube.portlets.widgets.wsthreddssync;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds;
import org.gcube.usecases.ws.thredds.Constants;
@ -20,7 +30,7 @@ public class UnSyncThreddsFolders {
public static String DEFAULT_SCOPE = "/gcube"; //DEV public static String DEFAULT_SCOPE = "/gcube"; //DEV
public static String TEST_USER = "francesco.mangiacrapa"; public static String TEST_USER = "francesco.mangiacrapa";
public static String TEST_USER_TOKEN = "TOKEN"; public static String TEST_USER_TOKEN = "0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548"; //token user: Francesco Mangiacrapa - /gcube (root)
private static List<String> lstUnSynchedItem = new ArrayList<String>(); private static List<String> lstUnSynchedItem = new ArrayList<String>();
private static List<String> lstUnSynchedFailedItem = new ArrayList<String>(); private static List<String> lstUnSynchedFailedItem = new ArrayList<String>();
@ -34,6 +44,21 @@ public class UnSyncThreddsFolders {
public static SyncronizeWithThredds syncService = new SyncronizeWithThredds(); 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. * The main method.
@ -43,9 +68,9 @@ public class UnSyncThreddsFolders {
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
* @throws HomeNotFoundException the home not found exception * @throws HomeNotFoundException the home not found exception
*/ */
/*
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Workspace ws = getWorkspace();
unsycFirstLevel(ws, ws.getRoot().getId(), false); unsycFirstLevel(ws, ws.getRoot().getId(), false);
System.out.println("UnSync completed"); System.out.println("UnSync completed");
@ -71,6 +96,14 @@ 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{ public static void unsycFirstLevel(Workspace ws, String itemId, boolean depthUnsync) throws Exception{
WorkspaceItem item; WorkspaceItem item;
@ -102,19 +135,24 @@ public class UnSyncThreddsFolders {
} }
/**
* Unsyn folder.
*
* @param workspaceItem the workspace item
*/
public static void unsynFolder(WorkspaceItem workspaceItem) { public static void unsynFolder(WorkspaceItem workspaceItem) {
if(workspaceItem==null) if(workspaceItem==null)
return; return;
try{ try{
ScopeProvider.instance.set(DEFAULT_SCOPE); boolean synched = syncService.isItemSynched(workspaceItem.getId(), DEFAULT_SCOPE, TEST_USER);
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()); System.out.println("Is the workspace item: "+workspaceItem.getId() + " synched? "+synched +", Is folder? "+workspaceItem.isFolder());
if(synched != null){ if(synched && workspaceItem.isFolder()){
//Boolean unsynched = syncService.doUnSync(workspaceItem.getId(), false, DEFAULT_SCOPE, TEST_USER_TOKEN); //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(); Workspace ws = getWorkspace();
cleanItem(workspaceItem, ws); cleanItem(workspaceItem, ws);
totalAttempts++; totalAttempts++;
@ -146,7 +184,6 @@ public class UnSyncThreddsFolders {
// } // }
// } // }
} }
*/
} }