Compare commits

..

3 Commits

@ -3,33 +3,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.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
## [v1.3.0-SNAPSHOT] - 2021-03-03
[#20847] Support the roles of THREDDS Admin and THREDDS Publisher
## [v1.2.0] - 2020-07-21
[#19676] Migrated to git/jenkins

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ws-thredds-sync-widget</artifactId>
<packaging>jar</packaging>
<version>1.5.0</version>
<version>1.3.0-SNAPSHOT</version>
<name>ws-thredds-sync-widget</name>
<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
@ -42,7 +42,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.3</version>
<version>3.6.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -62,6 +62,19 @@
<artifactId>gwt-bootstrap</artifactId>
</dependency>
<!-- PORTAL MANAGER -->
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<scope>provided</scope>
</dependency>
<!-- User Management Core -->
<dependency>
<groupId>org.gcube.dvos</groupId>
@ -75,38 +88,34 @@
<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.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>oidc-library</artifactId>
<artifactId>authorization-client</artifactId>
<version>[2.0.0, 3-0-0-SNAPSHOT)</version>
</dependency>
<!-- PORTAL MANAGER -->
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-wrapper</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<scope>provided</scope>
</dependency>
<!-- LOGGER -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>

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

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

@ -13,61 +13,68 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescr
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
// TODO: Auto-generated Javadoc
/**
* The Interface ThreddsWorkspaceSyncServiceAsync.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 8, 2018
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 8, 2018
*/
public interface ThreddsWorkspaceSyncServiceAsync {
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.
*
* @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.
* Checks if is item synched.
*
* @param folderId the folder id
* @param loadStatus the load status
* @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.
*
* @param folderId the folder id
* @param folderId the folder id
* @param clientConfig the client config
* @param callback the callback
* @param callback the callback
*/
void doSyncFolder(String folderId, WsThreddsSynchFolderConfiguration clientConfig,
AsyncCallback<ThSyncStatus> callback);
void doSyncFolder(String folderId, WsThreddsSynchFolderConfiguration clientConfig, AsyncCallback<ThSyncStatus> callback);
/**
* Monitor sync status.
@ -77,6 +84,8 @@ public interface ThreddsWorkspaceSyncServiceAsync {
*/
void monitorSyncStatus(String folderId, AsyncCallback<ThSyncStatus> callback);
/**
* Gets the list of scopes for logged user.
*
@ -88,12 +97,13 @@ public interface ThreddsWorkspaceSyncServiceAsync {
/**
* Gets the available catalogues for scope.
*
* @param scope the scope
* @param scope the scope
* @param callback the callback
* @return the available catalogues for scope
*/
void getAvailableCataloguesForScope(String scope, AsyncCallback<List<ThCatalogueBean>> callback);
/**
* Do un sync folder.
*
@ -102,11 +112,6 @@ public interface ThreddsWorkspaceSyncServiceAsync {
*/
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);
}

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

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

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

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

@ -23,18 +23,8 @@
width: 750px !important;
}
.myLittleMarginLeft {
.myLittleMarginLeft{
margin-left: 25px !important;
}
.modal-sync-widget-config {
}
.modal-sync-widget-config .modal-body {
max-height: 600px;
}
.modal-sync-widget-config form input, form select {
width: 300px;
}

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

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

@ -7,11 +7,12 @@ import java.util.List;
import java.util.Map;
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.scope.api.ScopeProvider;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
@ -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.WsThreddsSynchFolderConfiguration;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
import org.gcube.usecases.ws.thredds.SyncEngine;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
@ -37,11 +37,12 @@ import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.service.UserLocalServiceUtil;
// TODO: Auto-generated Javadoc
/**
* The server side implementation of the RPC service.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 14, 2018
*/
@SuppressWarnings("serial")
public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implements ThreddsWorkspaceSyncService {
@ -59,10 +60,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
*/
public synchronized SyncronizeWithThredds getSyncService() {
if (syncThredds == null)
if(syncThredds==null)
syncThredds = new SyncronizeWithThredds();
return syncThredds;
return syncThredds;
}
@ -75,212 +76,146 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try {
UserLocalServiceUtil.getService();
return true;
} catch (Exception ex) {
}
catch (Exception ex) {
logger.warn("Development Mode ON");
return false;
}
}
/**
* Gets the available THREDDS catalogues for target scope.
*
* @param targetFullScope the target scope
* @return the available catalogues for scope
* @throws Exception the exception
*/
// UPDATED
@Override
public List<ThCatalogueBean> getAvailableCataloguesForScope(String targetFullScope) throws Exception {
if (targetFullScope == null)
throw new Exception("Invalid scope null");
List<ThCatalogueBean> listCtlgs = null;
try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
listCtlgs = getSyncService().getAvailableCatalogues(this.getThreadLocalRequest(), user, targetFullScope);
logger.debug("Retuning " + listCtlgs.size() + " Catalogues for scope: " + targetFullScope);
if (logger.isDebugEnabled()) {
for (ThCatalogueBean thCatalogueBean : listCtlgs) {
logger.debug(thCatalogueBean.toString());
}
}
} catch (Exception e) {
logger.error("Error on checking available Catalogue in the scope: " + targetFullScope, e);
}
return listCtlgs;
}
/**
* Gets the configuration.
*
* @param folderId the folder id
* @param loadStatus the load status. If true it loads the status by calling the
* {@link SyncEngine#check(String, boolean)} but it is time
* consuming. No otherwise.
* @return the ws thredds synch folder descriptor
* @throws WorkspaceFolderLocked the workspace folder locked
* @throws Exception the exception
*/
@Override
public WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus)
throws WorkspaceFolderLocked, Exception {
logger.debug("called isItemSynched for folderId: " + folderId);
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
return getConfiguration(folderId, loadStatus, this.getThreadLocalRequest(), user);
}
/**
* Gets the configuration.
*
* @param folderId the folder id
* @param loadStatus the load status
* @param httpRequest the http request
* @param user the user
* @return the configuration
* @throws Exception the exception
*/
public WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus,
HttpServletRequest httpRequest, GCubeUser user) throws Exception {
logger.debug("called internal getConfiguration for folderId: " + folderId);
try {
ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, httpRequest,
user);
if (theConfig != null) {
logger.info("Folder id: " + folderId + " is synched");
WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig);
logger.debug("isItemSynched for id: " + folderId + " returning: " + toWsThreddFolder);
return toWsThreddFolder;
}
logger.info("Folder id: " + folderId + " is not synched, returning null descriptor");
return null;
} catch (ItemNotSynched e) {
logger.info("The folderId: " + folderId + " is not synched, returning null for "
+ WsThreddsSynchFolderDescriptor.class.getSimpleName());
return null;
} catch (WorkspaceFolderLocked e) {
logger.warn(e.getMessage() + ", sending exception to client...");
throw new WorkspaceFolderLocked(e.getFolderId(), e.getMessage());
} catch (Exception e) {
logger.info("Error on isItemSynched for folderId: " + folderId, e);
throw new Exception(e);
}
}
/**
* Do sync folder.
*
* @param folderId the folder id
* @param clientConfig the client config
* @param folderId the folder id
* @param clientConfig the th config
* @return the th sync status
* @throws Exception the exception
*/
// UPDATED
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#doSyncFolder(java.lang.String, org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor)
*/
@Override
public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig)
throws Exception {
logger.info("Performing doSyncFolder method on id: " + folderId + ", config: " + clientConfig);
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 && 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();
if(clientConfig!=null) {
targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(clientConfig.getSelectedScope().getScopeName(), user.getUsername());
config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId, targetScopeUserToken);
logger.debug("Creating server config "+config);
}
ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, this.getThreadLocalRequest(), user);
logger.debug("Returning for folderId " + folderId + " the syncStatus: " + status);
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. The server encountered the error: "
+ e.getMessage(),
e);
}catch (Exception e) {
logger.error("Do sync Folder error: ",e);
throw new Exception("Sorry, an error occurred during synchonization phase, try again later");
}
}
/**
* Do un sync folder.
* Gets the available THREDDS catalogues for target scope.
*
* @param folderId the folder id
* @return the boolean
* @param targetFullScope the target scope
* @return the available catalogues for scope
* @throws Exception the exception
*/
// Updated
@Override
public Boolean doUnSyncFolder(final String folderId) throws Exception {
logger.info("Performing unsync on folder id: " + folderId);
public List<ThCatalogueBean> getAvailableCataloguesForScope(String targetFullScope) throws Exception {
if(targetFullScope==null)
throw new Exception("Invalid scope null");
String originalScope = null;
String originalToken = null;
List<ThCatalogueBean> listCtlgs = null;
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");
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
//Thread Local contexts
originalScope = wsScope;
originalToken = wsUserToken;
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetFullScope, user.getUsername());
listCtlgs = getSyncService().getAvailableCataloguesByToken(targetFullScope, wsUserToken, targetScopeUserToken);
logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+targetFullScope);
if(logger.isDebugEnabled()){
for (ThCatalogueBean thCatalogueBean : listCtlgs) {
logger.debug(thCatalogueBean.toString());
}
}
}catch (Exception e) {
logger.error("Error on checking available Catalogue in the scope: "+targetFullScope, e);
}finally {
if(originalScope!=null && originalScope.compareTo(targetFullScope)!=0) {
logger.info("Resetting the scope: "+originalScope + " which was original WS context");
ScopeProvider.instance.set(originalScope);
if(originalToken!=null) {
logger.info("Resetting the user token: "+originalToken.substring(0,10)+"-MASKED-TOKEN which was original WS context");
SecurityTokenProvider.instance.set(originalToken);
}
}
}
}
return listCtlgs;
}
/**
* Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds
* roles that user has in them.
* Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them.
*
* @return the VREs and Thredds roles for a given user
* @throws Exception the exception
*/
@Override
public Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception {
public Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception{
logger.info("called getScopesWithThreddsRolesForLoggedUser");
GCubeUser user = null;
Map<String, GatewayRolesThredds> mapScopesRoles = null;
// DEV MODE
if (!isWithinPortal()) {
//DEV MODE
if (!isWithinPortal()){
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/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER);
return mapScopesRoles;
}
GCubeUser user = null;
try {
user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String gatewayHostname = GenericUtils.getGatewayClientHostname(this.getThreadLocalRequest());
mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user, gatewayHostname);
logger.info("returning Map(scopes,roles): " + mapScopesRoles);
mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user);
logger.info("returning Map(scopes,roles): "+mapScopesRoles);
return mapScopesRoles;
} catch (Exception e) {
}catch (Exception e) {
String errorMsg = "An error occurred on checking user roles. Refresh the page and try again.";
logger.error("An error occurred on checking user roles for user: " + user, e);
logger.error("An error occurred on checking user roles for user: "+user, e);
throw new Exception(errorMsg);
}
}
}
/**
* Gets the list scope with the role Data-Manager for logged user.
*
@ -288,17 +223,17 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @throws Exception the exception
*/
@Override
public List<GcubeScope> getListOfDataManagerScopesForLoggedUser() throws Exception {
logger.info("called getListOfVREsForLoggedUser...: ");
public List<GcubeScope> getListOfDataManagerScopesForLoggedUser() throws Exception{
logger.info("getListOfVREsForLoggedUser...: ");
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
long userId = user.getUserId();
// Instantiate the manager
// Instanciate the manager
GroupManager groupManager = new LiferayGroupManager();
List<GcubeScope> listOfScopes = new ArrayList<GcubeScope>();
// DEV MODE
if (!isWithinPortal()) {
//DEV MODE
if (!isWithinPortal()){
listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE));
listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE));
listOfScopes.add(new GcubeScope("devNext", "/gcube/devNext", GcubeScopeType.VO));
@ -311,94 +246,159 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try {
String gatewayHostname = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
// list of Scopes filtered for gateway
//list of Scopes filtered for gateway
Set<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);
logger.info("list of VREs in the gateway " + gatewayHostname + " are " + listOfGroups.size());
logger.info("list of VREs in the gateway "+gatewayHostname+" are "+listOfGroups.size());
for (GCubeGroup gCubeGroup : listOfGroups) {
long groupId = gCubeGroup.getGroupId();
String fullScope = groupManager.getInfrastructureScope(groupId);
logger.debug("For groupId: " + groupId + " got full scope: " + fullScope);
GcubeScopeType scopeType = null;
if (groupManager.isVRE(groupId)) {
scopeType = GcubeScopeType.VRE;
} else if (groupManager.isVO(groupId)) {
scopeType = GcubeScopeType.VO;
logger.debug("For groupId: "+groupId+" got full scope: "+fullScope);
GcubeScopeType scopeType=null;
if(groupManager.isVRE(groupId)){
scopeType = GcubeScopeType.VRE;
}else if(groupManager.isVO(groupId)){
scopeType = GcubeScopeType.VO;
}
// }else if(groupManager.isRootVO(gCubeGroup.getGroupId())){
// scopeType = GcubeScopeType.ROOT;
// }
if (scopeType != null) {
if(scopeType!=null){
GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, gCubeGroup);
// Adding only the scope where the user has the THREDDS_ADMIN role
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles,
gCubeGroup.getGroupName(), fullScope, groupManager, scopeType);
if (gcubeScope != null) {
//Adding only the scope where the user has the THREDDS_ADMIN role
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, gCubeGroup.getGroupName(), fullScope, groupManager, scopeType);
if(gcubeScope!=null) {
listOfScopes.add(gcubeScope);
}
}
}
GCubeGroup theRootVO = groupManager.getRootVO();
GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, theRootVO);
String rootVOFullScope = groupManager.getInfrastructureScope(theRootVO.getGroupId());
/// ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the ROOT-VO
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, theRootVO.getGroupName(),
rootVOFullScope, groupManager, GcubeScopeType.ROOT);
if (gcubeScope != null) {
///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the ROOT-VO
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, theRootVO.getGroupName(), rootVOFullScope, groupManager, GcubeScopeType.ROOT);
if(gcubeScope!=null) {
listOfScopes.add(gcubeScope);
}
} 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);
throw new Exception("Sorry, an error occurred server-side getting VRE folders, try again later");
}
if (listOfScopes.isEmpty()) {
throw new Exception(
"No scope detected with the needed role: " + GatewayRolesThredds.DATA_MANAGER.getRoleName()
+ ". Contact the VRE manager or the portal administrator");
if(listOfScopes.isEmpty()) {
throw new Exception("No scope detected with the needed role: "+GatewayRolesThredds.DATA_MANAGER.getRoleName()+". Contact the VRE manager or the portal administrator");
}
Collections.sort(listOfScopes);
logger.info("Returning list of allowed scope/s with: " + GatewayRolesThredds.DATA_MANAGER + " role/s: "
+ listOfScopes);
logger.info("Returning list of allowed scope/s with: "+GatewayRolesThredds.DATA_MANAGER + " role/s: "+listOfScopes);
return listOfScopes;
}
/**
* Checks if for the input scope: - the user has the role
* {@link GatewayRolesThredds.#THREDDS_ADMIN} - the scope has an available
* THREDDS catalogue configured
* Checks if for the input scope:
* - the user has the role {@link GatewayRolesThredds.#THREDDS_ADMIN}
* - the scope has an available THREDDS catalogue configured
*
* @param role the role
* @param scopeName the scope name e.g. devVRE
* @param fullScope the full scope e.g. /gcube/devsec/devVRE
* @param role the role
* @param scopeName the scope name e.g. devVRE
* @param fullScope the full scope e.g. /gcube/devsec/devVRE
* @param groupManager the group manager
* @param scopeType the scope type
* @return the gcube scope {@link GcubeScope} if the two conditions (see
* description) are satisfied, null otherwise
* @param scopeType the scope type
* @return the gcube scope {@link GcubeScope} if the two conditions (see description) are satisfied, null otherwise
* @throws Exception the exception
*/
private GcubeScope checkDataManagerCapacityAndThreddsCatalogue(GatewayRolesThredds role, String scopeName,
String fullScope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception {
logger.debug("checking Data-Manager capacity and THREEDS catalogues for role: " + role,
"scope name: " + scopeName + ", scope: " + fullScope + " scope type: " + scopeType);
if (role != null && role.getRoleName().equalsIgnoreCase(GatewayRolesNames.DATA_MANAGER.getRoleName())) {
private GcubeScope checkDataManagerCapacityAndThreddsCatalogue(GatewayRolesThredds role, String scopeName, String fullScope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception {
logger.debug("checking Data-Manager capacity and THREEDS catalogues for role: "+role, "scope name: "+scopeName+", scope: "+fullScope + " scope type: "+scopeType);
if(role!=null && role.getRoleName().equalsIgnoreCase(GatewayRolesNames.DATA_MANAGER.getRoleName())){
try {
List<ThCatalogueBean> list = getAvailableCataloguesForScope(fullScope);
if (list != null) {
if(list!=null) {
return new GcubeScope(scopeName, fullScope, scopeType);
}
} catch (Exception e) {
logger.error("Error on checking available catalogue for scope: " + fullScope, e);
}catch (Exception e) {
logger.error("Error on checking available catalogue for scope: "+fullScope, e);
}
}
return null;
}
/**
* Checks if is item synched.
*
* @param folderId the folder id
* @return the ws thredds synch folder descriptor
* @throws WorkspaceFolderLocked the workspace folder locked
* @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#isItemSynched(java.lang.String)
*/
@Override
public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception{
logger.debug("Performing isItemSynched for foldeId: "+folderId);
try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
Sync_Status theStatus = getSyncService().getSynchedStatusFromItemProperty(folderId, wsScope, user.getUsername());
if(theStatus!=null) {
logger.info("Folder id: "+folderId+" is synched");
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
ThSyncFolderDescriptor serverFolderSync = getSyncService().checkItemSynched(folderId,wsScope,wsUserToken);
WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(serverFolderSync, theStatus);
logger.debug("IsItemSynched for id: "+folderId +" returning: "+toWsThreddFolder);
return toWsThreddFolder;
}
logger.info("Folder id: "+folderId+" is not synched, returning null descriptor");
return null;
} catch (ItemNotSynched e) {
logger.info("The folderId: "+folderId +" is not synched, returning null FolderDescriptor");
return null;
} catch (WorkspaceFolderLocked e) {
logger.warn(e.getMessage() +", sending exception to client...");
throw new WorkspaceFolderLocked(e.getFolderId(), e.getMessage());
}catch (Exception e) {
logger.info("Error on isItemSynched for folderId: "+folderId, e);
throw new Exception(e);
}
}
/**
* Register callback for id.
*
* @param folderId the folder id
* @throws Exception the exception
*/
public void registerCallbackForId(String folderId) throws Exception{
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
getSyncService().registerCallbackForId(folderId, wsScope, wsUserToken);
}
/**
* Monitor sync status.
@ -406,14 +406,47 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @param folderId the folder id
* @return the th sync status
* @throws ItemNotSynched the item not synched
* @throws Exception the exception
* @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#monitorSyncStatus(java.lang.String)
*/
@Override
public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception {
public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception{
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
return getSyncService().monitorSyncStatus(folderId, wsScope, wsUserToken);
}
/**
* Do sync folder.
*
* @param folderId the folder id
* @return the th sync status
* @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#doSyncFolder(java.lang.String, org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor)
*/
@Override
public Boolean doUnSyncFolder(final String folderId) throws Exception{
logger.info("Performing unsync on folder id: "+folderId);
// String scope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
// GCubeUser username = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
// String groupName = PortalContext.getConfiguration().getCurrentGroupName(this.getThreadLocalRequest());
// new GcubeVRE(groupName, scope)
try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
return getSyncService().doUnSync(folderId, false, wsScope, wsUserToken);
}catch (Exception e) {
logger.error("Do un sync Folder error: ",e);
throw new Exception("Sorry, an error occurred on deleting sync configurations, refresh and try again later");
}
}
}

@ -7,18 +7,24 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
//import org.gcube.common.homelibrary.home.HomeLibrary;
//import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
//import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
//import org.gcube.common.homelibrary.home.workspace.Workspace;
//import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.VirtualGroupNotExistingException;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
@ -33,13 +39,17 @@ import com.liferay.portal.service.UserLocalServiceUtil;
/**
* The Class WsUtil.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Nov 25, 2016
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Nov 25, 2016
*/
public class WsUtil {
/** The logger. */
private static Logger logger = LoggerFactory.getLogger(WsUtil.class);
/**
* Checks if is within portal.
*
@ -49,12 +59,14 @@ public class WsUtil {
try {
UserLocalServiceUtil.getService();
return true;
} catch (Exception ex) {
}
catch (Exception ex) {
logger.trace("Development Mode ON");
return false;
}
}
/**
* Checks if is session expired.
*
@ -64,99 +76,118 @@ public class WsUtil {
*/
public static boolean isSessionExpired(HttpServletRequest httpServletRequest) throws Exception {
logger.trace("workspace session validating...");
return PortalContext.getConfiguration().getCurrentUser(httpServletRequest) == null;
return PortalContext.getConfiguration().getCurrentUser(httpServletRequest)==null;
}
/**
* Gets the workspace from storage hub.
*
* @param httpServletRequest the http servlet request
* @return the workspace from storage hub
* @throws Exception the exception
*/
public Workspace getWorkspaceFromStorageHub(HttpServletRequest httpServletRequest) throws Exception {
logger.trace("Get Workspace");
// String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest);
GCubeUser user = null;
try {
String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest);
user = PortalContext.getConfiguration().getCurrentUser(httpServletRequest);
if (user == null || user.getUsername().isEmpty())
throw new Exception("Session expired");
ScopeProvider.instance.set(scope);
logger.trace("Scope provider instancied at: "+scope);
logger.debug("Getting " + StorageHubWrapper.class.getSimpleName() + " for user: " + user.getUsername()
+ " by using the scope: " + scope);
String token = PortalContext.getConfiguration().getCurrentUserToken(scope, user.getUsername());
StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true);
return shWrapper.getWorkspace();
} catch (Exception e) {
logger.error("Error on getting the Workspace via SHUB wrapper", e);
throw new Exception("Error on gettig the Workspace for userId: " + user);
}
}
/**
* Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds
* roles that user has in them.
* Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them.
*
* @param user the user
* @param gatewayHostname the gateway hostname
* @return the VREs and Thredds roles for a given user
*/
public static Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForUser(GCubeUser user, String gatewayHostname) {
logger.info("called getScopesThreddsRolesForUser user: " + user + ", in the gateway Contexts/VREs");
public static Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForUser(GCubeUser user){
logger.info("called getScopesThreddsRolesForUser user: "+user+", in all contexts");
GroupManager groupManager = new LiferayGroupManager();
Map<String, GatewayRolesThredds> mapRoleByGroupSingleVre = new HashMap<String, GatewayRolesThredds>();
try {
long userId = user.getUserId();
// list of Scopes filtered for gateway
Set<GCubeGroup> filteredGroupsForGatw = groupManager.listGroupsByUserAndSite(userId, gatewayHostname);
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
//Retrieving the list of VOs and VREs
List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(user.getUserId());
//adding also the ROOT-VO
listOfGroups.add(groupManager.getRootVO());
for (GCubeGroup gCubeGroup : listOfGroups) {
GatewayRolesThredds threddsRole = getThreddsRoleFor(user, gCubeGroup);
if (threddsRole != null) {
String toFullScope = groupManager.getInfrastructureScope(gCubeGroup.getGroupId());
mapRoleByGroupSingleVre.put(toFullScope, threddsRole);
if(threddsRole != null) {
mapRoleByGroupSingleVre.put(gCubeGroup.getGroupName(), threddsRole);
}
}
logger.info("For user: " + user + ", returning Map (VRE, ThreddsRoles) " + mapRoleByGroupSingleVre);
logger.info("For user: "+user+", returning Map (VRE, ThreddsRoles) " + mapRoleByGroupSingleVre);
return mapRoleByGroupSingleVre;
} catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e);
return null;
} catch (VirtualGroupNotExistingException e) {
logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e);
}catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
logger.error("An error occurred during geThreddsVreRolesForUser: "+user, e);
return null;
}
}
}
/**
* Gets the (highest) thredds role for the user in the scope
*
* @param user the user
* @param user the user
* @param scope the vre
* @return the thredds role for
*/
public static GatewayRolesThredds getThreddsRoleFor(GCubeUser user, GCubeGroup scope) {
if (user == null || scope == null) {
logger.warn("called getThreddsRoleFor with invalid parameter user: " + user + ", in the scope: " + scope,
", returning null");
public static GatewayRolesThredds getThreddsRoleFor(GCubeUser user, GCubeGroup scope){
if(user==null || scope==null) {
logger.warn("called getThreddsRoleFor with invalid parameter user: "+user+", in the scope: "+scope, ", returning null");
return null;
}
logger.info("called getThreddsRoleFor user: " + user.getUsername() + ", in the scope: " + scope.getGroupName());
logger.info("called getThreddsRoleFor user: "+user.getUsername()+", in the scope: "+scope.getGroupName());
try {
RoleManager roleManager = new LiferayRoleManager();
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(user.getUserId(), scope.getGroupId());
List<GatewayRolesThredds> threddsRoles = new ArrayList<GatewayRolesThredds>();
for (GCubeRole gCubeRole : roles) {
if (gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_MANAGER.getRoleName())) {
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_MANAGER.getRoleName())){
threddsRoles.add(GatewayRolesThredds.DATA_MANAGER);
}
if (gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_EDITOR.getRoleName())) {
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_EDITOR.getRoleName())){
threddsRoles.add(GatewayRolesThredds.DATA_EDITOR);
}
}
logger.info("For user: " + user.getUsername() + " in the scope: " + scope.getGroupName()
+ " read the role/s: " + threddsRoles);
logger.info("For user: "+user.getUsername()+" in the scope: "+scope.getGroupName()+" read the role/s: " + threddsRoles);
GatewayRolesThredds toReturn = null;
if (threddsRoles.contains(GatewayRolesThredds.DATA_MANAGER))
toReturn = GatewayRolesThredds.DATA_MANAGER;
else if (threddsRoles.contains(GatewayRolesThredds.DATA_EDITOR))
toReturn = GatewayRolesThredds.DATA_EDITOR;
logger.info("returning highest role: " + toReturn);
return toReturn;
} catch (UserRetrievalFault | GroupRetrievalFault e) {
logger.error("An error occurred during getVreRoleForUser: " + user, e);
}catch (UserRetrievalFault | GroupRetrievalFault e) {
logger.error("An error occurred during getVreRoleForUser: "+user, e);
return null;
}
}
}

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

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

@ -1,8 +1,17 @@
package org.gcube.portlets.widgets.wsthreddssync;
import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize;
import org.gcube.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds;
import org.gcube.usecases.ws.thredds.SyncEngine;
import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor;
import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus;
import org.gcube.usecases.ws.thredds.faults.WorkspaceLockedException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException;
import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack;
import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration;
// TODO: Auto-generated Javadoc
/**
* The Class TestWsThreddsEngine.
*

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

@ -5,8 +5,18 @@ package org.gcube.portlets.widgets.wsthreddssync;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds;
import org.gcube.usecases.ws.thredds.Constants;
@ -20,7 +30,7 @@ public class UnSyncThreddsFolders {
public static String DEFAULT_SCOPE = "/gcube"; //DEV
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> lstUnSynchedFailedItem = new ArrayList<String>();
@ -34,6 +44,21 @@ public class UnSyncThreddsFolders {
public static SyncronizeWithThredds syncService = new SyncronizeWithThredds();
/**
* Gets the workspace.
*
* @return the workspace
* @throws InternalErrorException the internal error exception
* @throws HomeNotFoundException the home not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
public static Workspace getWorkspace() throws Exception{
ScopeProvider.instance.set(scope);
StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true);
return shWrapper.getWorkspace();
}
/**
* The main method.
@ -43,9 +68,9 @@ public class UnSyncThreddsFolders {
* @throws InternalErrorException the internal error exception
* @throws HomeNotFoundException the home not found exception
*/
/*
public static void main(String[] args) throws Exception {
Workspace ws = getWorkspace();
unsycFirstLevel(ws, ws.getRoot().getId(), false);
System.out.println("UnSync completed");
@ -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{
WorkspaceItem item;
@ -102,19 +135,24 @@ public class UnSyncThreddsFolders {
}
/**
* Unsyn folder.
*
* @param workspaceItem the workspace item
*/
public static void unsynFolder(WorkspaceItem workspaceItem) {
if(workspaceItem==null)
return;
try{
ScopeProvider.instance.set(DEFAULT_SCOPE);
SecurityTokenProvider.instance.set(TEST_USER_TOKEN);
ThSyncFolderDescriptor synched = syncService.isItemSynched(workspaceItem.getId());
boolean synched = syncService.isItemSynched(workspaceItem.getId(), DEFAULT_SCOPE, TEST_USER);
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);
ScopeProvider.instance.set(DEFAULT_SCOPE);
SecurityTokenProvider.instance.set(TEST_USER_TOKEN);
Workspace ws = getWorkspace();
cleanItem(workspaceItem, ws);
totalAttempts++;
@ -146,7 +184,6 @@ public class UnSyncThreddsFolders {
// }
// }
}
*/
}

Loading…
Cancel
Save