Compare commits

...

38 Commits

Author SHA1 Message Date
Francesco Mangiacrapa ae3809efbd removed -SNAPSHOT to be released 2021-07-20 09:49:29 +02:00
Francesco Mangiacrapa 17c705f6db Moved to maven-portal-bom 3.6.3
Just to include new version of ws-thredds
2021-07-20 09:47:39 +02:00
Francesco Mangiacrapa f25dd02ca4 Moved to maven-portal-bom 3.6.3
Just to include new version of ws-thredds
2021-07-20 09:35:57 +02:00
Francesco Mangiacrapa 76b794e07d removed -SNAPSHOT to be released 2021-05-27 17:58:54 +02:00
Francesco Mangiacrapa e5ff5c2f24 reverted to previous oidc-library-portal (1.3.0-SNAPSHOT) as requested
at #21346#note-19
2021-05-27 14:22:03 +02:00
Francesco Mangiacrapa 64ae1604c6 Updated code for oidc-library-portal as requested at
https://support.d4science.org/issues/21346#note-14
2021-05-25 16:50:00 +02:00
Francesco Mangiacrapa 7bc7503c8e removed -SNAPSHOT to be released 2021-05-25 10:42:40 +02:00
Francesco Mangiacrapa 5a0a2f9699 Merge pull request 'task_21379' (#3) from task_21379 into master
Reviewed-on: #3
2021-05-25 10:41:24 +02:00
Francesco Mangiacrapa 23df1ec770 fixing config==null on doSync; improved management of exceptions 2021-05-20 17:32:00 +02:00
Francesco Mangiacrapa 9704fdd3e9 updated changelog 2021-05-20 11:01:19 +02:00
Francesco Mangiacrapa 63c9250ef5 [#21444] Moved to maven-portal-bom >= 3.6.2-SNAPSHOT 2021-05-20 11:01:03 +02:00
Francesco Mangiacrapa a7fb141f1a moved oidc-library-portal to provided 2021-05-19 18:18:01 +02:00
Francesco Mangiacrapa 1aa4d7b3f6 added internal getConfiguration 2021-05-19 17:29:16 +02:00
Francesco Mangiacrapa 64b53656f9 added some comments 2021-05-18 16:25:45 +02:00
Francesco Mangiacrapa d3d1e13b4c updated css 2021-05-18 15:31:58 +02:00
Francesco Mangiacrapa 54600fe288 adding context switch to getConfiguration when needed 2021-05-18 12:55:44 +02:00
Francesco Mangiacrapa 5cc52d9e3c the getConfiguration method has been updated by including also the
engine.check
2021-05-17 18:17:40 +02:00
Francesco Mangiacrapa dd3dc4a0cc integrated with getConfiguration method 2021-05-14 12:34:25 +02:00
Francesco Mangiacrapa 74839e1d03 only formatted 2021-05-13 15:43:39 +02:00
Francesco Mangiacrapa 2cdc935d37 removed geSyncStatus 2021-05-13 15:02:53 +02:00
Francesco Mangiacrapa ac7fb2101b fixing method isItemSynched 2021-05-12 16:32:30 +02:00
Francesco Mangiacrapa 24e6bca0b0 removed unused dependencies 2021-05-11 13:01:01 +02:00
Francesco Mangiacrapa d972d8e2f3 cleaned test cases 2021-05-11 12:51:09 +02:00
Francesco Mangiacrapa 23de9f1abb integrated the getInfo from SyncEngine (it is not implemented in the
library)
2021-05-11 12:05:50 +02:00
Francesco Mangiacrapa 8f191559c3 first complete commit for task #21379 2021-05-11 11:09:02 +02:00
Francesco Mangiacrapa f2dc0cce19 in progess 2021-05-10 18:08:39 +02:00
Francesco Mangiacrapa 5d027814f0 moved to 1.4.0-SNAPSHOT 2021-05-10 17:01:57 +02:00
Francesco Mangiacrapa 1ffc7616c9 starting on #21379 2021-05-10 17:01:32 +02:00
Francesco Mangiacrapa 41159eb8a6 removed -SNAPSHOT to be released 2021-03-17 12:43:08 +01:00
Francesco Mangiacrapa a7f2dde3e6 bug fixing scopeName to fullScope 2021-03-17 11:28:25 +01:00
Francesco Mangiacrapa 660d869ab5 Updated in order to respect the roles assigned for scope 2021-03-11 16:42:09 +01:00
Francesco Mangiacrapa fc274579a4 only updated a label 2021-03-08 13:08:15 +01:00
Francesco Mangiacrapa a6de65a047 removed unused code 2021-03-08 12:39:32 +01:00
Francesco Mangiacrapa b16efacd9f fixing full scope 2021-03-08 12:36:19 +01:00
Francesco Mangiacrapa e72a2b14b1 fixing set token 2021-03-08 11:56:06 +01:00
Francesco Mangiacrapa a342fa4cb7 added checks and improved logs 2021-03-08 11:52:41 +01:00
Francesco Mangiacrapa f0d4347266 Merge pull request 'Changed the roles to "Data-Editor", "Data-Manager" according to #20889' (#2) from feature_20847 into master 2021-03-08 10:58:01 +01:00
Francesco Mangiacrapa fe73dce86d Merge pull request 'feature_20847' (#1) from feature_20847 into master 2021-03-04 16:27:44 +01:00
20 changed files with 1086 additions and 948 deletions

View File

@ -3,10 +3,33 @@
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.3.0-SNAPSHOT] - 2021-03-03
## [v1.5.0] - 2021-07-20
#### Enhancements
[#21346] Moved to AccessTokenProvider for UMA tokens "context switches"
[#21576] Adding filtering for gateway to get scopes with THREDDS role for users
Moved to maven-portal-bom 3.6.3
Including new version of ws-thredds
## [v1.4.1-SNAPSHOT] - 2021-07-20
Moved to maven-portal-bom 3.6.3
Just to include new version of ws-thredds
## [v1.4.0] - 2021-05-10
#### Enhancements
[#21379] Moved to new ws-synchronized-module-library (based on w-thredds 1.x) and performed UMA tokens "context switches"
[#21444] Moved to maven-portal-bom 3.6.2
## [v1.3.0] - 2021-03-17
[#20847] Support the roles of THREDDS Admin and THREDDS Publisher
## [v1.2.0] - 2020-07-21
[#19676] Migrated to git/jenkins

49
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ws-thredds-sync-widget</artifactId>
<packaging>jar</packaging>
<version>1.3.0-SNAPSHOT</version>
<version>1.5.0</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.0</version>
<version>3.6.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -62,19 +62,6 @@
<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>
@ -88,34 +75,38 @@
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.gcube.spatial-data</groupId> -->
<!-- <artifactId>ws-thredds</artifactId> -->
<!-- <version>[0.0.1-SNAPSHOT, 1.0.0-SNAPSHOT)</version> -->
<!-- <scope>compile</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<version>[2.0.0, 3-0-0-SNAPSHOT)</version>
<groupId>org.gcube.portal</groupId>
<artifactId>oidc-library-portal</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-wrapper</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<artifactId>oidc-library</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>
<!-- LOGGER -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -0,0 +1,62 @@
package org.gcube.portlets.widgets.wsthreddssync.client;
/**
* The Class WsThreddsSyncConstants.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Mar 11, 2021
*/
public class WsThreddsSyncConstants {
/**
* The Class RightsMissing.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Mar 11, 2021
*/
public static class RightsMissing {
/** The Constant REQUEST_IT_TO_THE_VRE_MANAGER_OR_THE_PORTAL_ADMINISTRATOR. */
public static final String REQUEST_IT_TO_THE_VRE_MANAGER_OR_THE_PORTAL_ADMINISTRATOR = "Request it to the VRE manager or the portal administrator.";
/**
* No run sync rights.
*
* @param scope the scope
* @return the string
*/
public static String noRunSyncRights(String scope) {
StringBuilder builder = new StringBuilder("It seems you are not authorized to run a syncronization task towards THREDDS Catalogue");
if(scope!=null)
builder.append(" in the scope \""+scope+"\"");
builder.append(". ");
builder.append(REQUEST_IT_TO_THE_VRE_MANAGER_OR_THE_PORTAL_ADMINISTRATOR);
return builder.toString();
}
/**
* No create config rights.
*
* @return the string
*/
public static String noCreateConfigRights() {
StringBuilder builder = new StringBuilder("It seems you are not authorized to create a configuration towards THREDDS Catalogue.");
builder.append(REQUEST_IT_TO_THE_VRE_MANAGER_OR_THE_PORTAL_ADMINISTRATOR);
return builder.toString();
}
}
}

View File

@ -37,7 +37,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HorizontalPanel;
// TODO: Auto-generated Javadoc
/**
* The Class WsThreddsWidget.
*
@ -56,11 +55,7 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
private final List<SyncCompletedNotificationListner> syncEventsListeners = new ArrayList<SyncCompletedNotificationListner>();
public static final String MISSING_THREDDS_ADMIN_RIGHTS = "It seems you are not authorized to create a configuration towards THREDDS Catalogue. Request it to the VRE manager or the portal administrator.";
public static final String MISSING_THREDDS_PUBLISHER_RIGHTS = "It seems you are not authorized to run a syncronization task towards THREDDS Catalogue. Request it to the VRE manager or the portal administrator.";
public static final String MISSING_THREDDS_RIGHTS = "It seems you are not authorized to interact with the facility 'Sync with THREDDS'. Request authorization to the VRE manager or the portal administrator.";
private Map<String, GatewayRolesThredds> mapScopeThreddsRoles = null;
/**
* This is the entry point method.
@ -152,7 +147,8 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
}
final Modal box = new Modal(true);
box.setTitle("Checking configurations...");
box.setWidth(600);
box.setTitle("Checking authorizations and configurations...");
final HorizontalPanel hpLoader = new HorizontalPanel();
LoaderIcon loader = new LoaderIcon("Checking authorizations and folder configurations...");
hpLoader.add(loader);
@ -161,6 +157,8 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
//LAOADING ROLES
WsThreddsWidget.wsThreddsSyncService.getScopesWithThreddsRolesForLoggedUser(new AsyncCallback<Map<String,GatewayRolesThredds>>() {
@Override
public void onFailure(Throwable caught) {
hpLoader.clear();
@ -173,76 +171,65 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
@Override
public void onSuccess(Map<String, GatewayRolesThredds> result) {
try {
hpLoader.clear();
hpLoader.setVisible(false);
}catch (Exception e) {
//Silent
}
GWT.log("Returned Map(Scope,Role): "+result);
mapScopeThreddsRoles = result;
if(result!=null) {
GWT.log("Returned Map(Scope,Role): "+result);
final boolean isThreddsPubliser = result.containsValue(GatewayRolesThredds.DATA_EDITOR);
final boolean isThreddsAdmin = result.containsValue(GatewayRolesThredds.DATA_MANAGER);
//no rights assigned
if(!isThreddsAdmin && !isThreddsPubliser) {
showMissingRights(box);
return;
//at least one THREDDS rights is assigned
GWT.log("Performing isItemSynched: "+folder.getFolderId());
WsThreddsWidget.wsThreddsSyncService.getConfiguration(folder.getFolderId(), true, new AsyncCallback<WsThreddsSynchFolderDescriptor>() {
@Override
public void onSuccess(WsThreddsSynchFolderDescriptor result) {
try {
hpLoader.clear();
hpLoader.setVisible(false);
}catch (Exception e) {
//Silent
}
box.hide();
//GWT.log("WsThreddsSynchFolderDescriptor result: "+result);
viewManager.showThreddsFolderInfo(folder, result, mapScopeThreddsRoles);
}
//at least one THREDDS rights is assigned
GWT.log("Performing isItemSynched: "+folder.getFolderId());
WsThreddsWidget.wsThreddsSyncService.isItemSynched(folder.getFolderId(), new AsyncCallback<WsThreddsSynchFolderDescriptor>() {
@Override
public void onSuccess(WsThreddsSynchFolderDescriptor result) {
box.hide();
//GWT.log("WsThreddsSynchFolderDescriptor result: "+result);
viewManager.showThreddsFolderInfo(folder, result, isThreddsAdmin, isThreddsPubliser);
@Override
public void onFailure(Throwable caught) {
try {
hpLoader.clear();
hpLoader.setVisible(false);
}catch (Exception e) {
//Silent
}
@Override
public void onFailure(Throwable caught) {
box.hide();
if(caught instanceof WorkspaceFolderLocked){
viewManager.showMonitorSyncToFolder(folder,syncEventsListeners);
return;
}
viewManager.cancelMonitor(folder);
Window.alert(caught.getMessage());
if(caught instanceof WorkspaceFolderLocked){
viewManager.showMonitorSyncToFolder(folder,syncEventsListeners);
return;
}
});
}else {
//no rights detected
showMissingRights(box);
return;
}
viewManager.cancelMonitor(folder);
Alert alert = new Alert(caught.getMessage(), AlertType.ERROR);
alert.setClose(false);
box.add(alert);
//Window.alert(caught.getMessage());
}
});
}
});
box.show();
}
private void showMissingRights(Modal box) {
Alert alert = new Alert();
alert.setType(AlertType.WARNING);
alert.setText(MISSING_THREDDS_RIGHTS);
alert.setClose(false);
box.add(alert);
}
// private void showMissingRights(Modal box) {
// Alert alert = new Alert();
// alert.setType(AlertType.WARNING);
// alert.setText(MISSING_THREDDS_RIGHTS);
// alert.setClose(false);
// box.add(alert);
// }
private void performFolderUnSync(final WsFolder folder) {
GWT.log("Performing doSyncFolder on: "+folder);
@ -296,21 +283,29 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
* @param config the config
*/
private void performFolderSync(final WsFolder folder, WsThreddsSynchFolderConfiguration config) {
GWT.log("Performing doSyncFolder on: "+folder);
GWT.log("Performing doSyncFolder on: "+folder+" and config: "+config);
final Modal box = new Modal(true);
box.setTitle("Starting synchronization...");
box.hide(false);
LoaderIcon loader = new LoaderIcon("Inizializiting synchronization to the folder: "+folder.getFoderName());
final LoaderIcon loader = new LoaderIcon("Inizializiting synchronization to the folder: "+folder.getFoderName());
box.add(loader);
wsThreddsSyncService.doSyncFolder(folder.getFolderId(), config, new AsyncCallback<ThSyncStatus>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
//Window.alert(caught.getMessage());
viewManager.cancelMonitor(folder);
if(box!=null)
box.hide();
if(box!=null) {
try {
box.remove(loader);
}catch (Exception e) {
}
Alert alertError = new Alert(caught.getMessage(), AlertType.ERROR);
alertError.setClose(false);
box.add(alertError);
}
}

View File

@ -11,11 +11,13 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds;
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
import org.gcube.usecases.ws.thredds.SyncEngine;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
// TODO: Auto-generated Javadoc
/**
* The Interface ThreddsWorkspaceSyncService.
*
@ -25,15 +27,20 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("wsthreddssync")
public interface ThreddsWorkspaceSyncService extends RemoteService {
/**
* Checks if is item synched.
* Gets the configuration.
*
* @param folderId the folder id
* @param folderId the folder id
* @param loadStatus the load status. If true it loads the status by calling the
* {@link SyncEngine#check(String, boolean)} but it is time
* consuming. No otherwise.
* @return the ws thredds synch folder descriptor
* @throws WorkspaceFolderLocked the workspace folder locked
* @throws Exception the exception
* @throws Exception the exception
*/
WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception;
WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus)
throws WorkspaceFolderLocked, Exception;
/**
* Do sync folder.
@ -85,9 +92,10 @@ public interface ThreddsWorkspaceSyncService extends RemoteService {
/**
* Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them.
*
* @param user the user
* @return the VREs and Thredds roles for a given user
* @throws Exception
* @throws Exception the exception
*/
Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception;
}

View File

@ -13,68 +13,61 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescr
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
// TODO: Auto-generated Javadoc
/**
* The Interface ThreddsWorkspaceSyncServiceAsync.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 8, 2018
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 8, 2018
*/
public interface ThreddsWorkspaceSyncServiceAsync
{
/**
* Utility class to get the RPC Async interface from client-side code.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 8, 2018
*/
public static final class Util
{
private static ThreddsWorkspaceSyncServiceAsync instance;
/**
* Gets the single instance of Util.
*
* @return single instance of Util
*/
public static final ThreddsWorkspaceSyncServiceAsync getInstance()
{
if ( instance == null )
{
instance = (ThreddsWorkspaceSyncServiceAsync) GWT.create( ThreddsWorkspaceSyncService.class );
}
return instance;
}
/**
* Instantiates a new util.
*/
private Util()
{
// Utility class should not be instantiated
}
}
public interface ThreddsWorkspaceSyncServiceAsync {
/**
* Checks if is item synched.
* Utility class to get the RPC Async interface from client-side code.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 8, 2018
*/
public static final class Util {
private static ThreddsWorkspaceSyncServiceAsync instance;
/**
* Gets the single instance of Util.
*
* @return single instance of Util
*/
public static final ThreddsWorkspaceSyncServiceAsync getInstance() {
if (instance == null) {
instance = (ThreddsWorkspaceSyncServiceAsync) GWT.create(ThreddsWorkspaceSyncService.class);
}
return instance;
}
/**
* Instantiates a new util.
*/
private Util() {
// Utility class should not be instantiated
}
}
/**
* Gets the configuration.
*
* @param folderId the folder id
* @param loadStatus the load status
* @param callback the callback
* @return the configuration
*/
void isItemSynched(String folderId, AsyncCallback<WsThreddsSynchFolderDescriptor> callback);
void getConfiguration(String folderId, boolean loadStatus, 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.
@ -84,8 +77,6 @@ public interface ThreddsWorkspaceSyncServiceAsync
*/
void monitorSyncStatus(String folderId, AsyncCallback<ThSyncStatus> callback);
/**
* Gets the list of scopes for logged user.
*
@ -97,13 +88,12 @@ public interface ThreddsWorkspaceSyncServiceAsync
/**
* Gets the available catalogues for scope.
*
* @param scope the scope
* @param scope the scope
* @param callback the callback
* @return the available catalogues for scope
*/
void getAvailableCataloguesForScope(String scope, AsyncCallback<List<ThCatalogueBean>> callback);
/**
* Do un sync folder.
*
@ -112,6 +102,11 @@ 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);
}

View File

@ -8,6 +8,7 @@ import org.gcube.portal.wssynclibrary.shared.thredds.Status;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
import org.gcube.portlets.widgets.wsthreddssync.client.SyncCompletedNotification.SyncCompletedNotificationListner;
import org.gcube.portlets.widgets.wsthreddssync.client.WsThreddsSyncConstants;
import org.gcube.portlets.widgets.wsthreddssync.client.WsThreddsWidget;
import org.gcube.portlets.widgets.wsthreddssync.client.event.PerformDoSyncEvent;
import org.gcube.portlets.widgets.wsthreddssync.client.event.ShowMonitorSyncStatusEvent;
@ -15,6 +16,8 @@ import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.AbstractViewD
import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.CreateThreddsConfigurationView;
import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.MonitorFolderSyncStatusView;
import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.ShowThreddsFolderInfoView;
import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds;
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
@ -330,19 +333,17 @@ public class WsThreddsWidgetViewManager {
*
* @param folder the folder
* @param folderDescriptor the folder descriptor
* @param isThreddsAdmin the is thredds admin
* @param isThreddsPubliser the is thredds publiser
* @param mapScopeThreddsRoles the map scope with thredds roles
*/
public void showThreddsFolderInfo(final WsFolder folder, final WsThreddsSynchFolderDescriptor folderDescriptor, final boolean isThreddsAdmin, final boolean isThreddsPubliser){
public void showThreddsFolderInfo(final WsFolder folder, final WsThreddsSynchFolderDescriptor folderDescriptor, Map<String, GatewayRolesThredds> mapScopeThreddsRoles){
GWT.log("ShowThreddsFolderInfo folder: "+folder);
//GWT.log("WsThreddsSynchFolderDescriptor is: "+folderDescriptor);
final Modal box = new Modal(true);
box.hide(false);
//box.setWidth(WIDHT_DIALOG+"px");
box.getElement().addClassName("modal-sync-widget-config");
box.setWidth(600);
box.setTitle("Thredds Sync Information for: "+FormatUtil.getFolderTitle(folder.getFoderName(), 20));
//box.getElement().getStyle().setZIndex(10000);
final AbstractViewDialogBox panelView = new AbstractViewDialogBox() {
@Override
@ -353,14 +354,19 @@ public class WsThreddsWidgetViewManager {
@Override
public void confirmHanlder(CONFIRM_VALUE confirm, Command command) {
// TODO Auto-generated method stub
}
};
final boolean isCreateConfiguration = folderDescriptor==null?true:false;
//is the user a THREDDS_ADMIN (so DATA_MANAGER) in at least one scope?
boolean isThreddsAdmin = false;
if(mapScopeThreddsRoles!=null) {
isThreddsAdmin = mapScopeThreddsRoles.containsValue(GatewayRolesThredds.DATA_MANAGER);
}
final ShowThreddsFolderInfoView folderInfo = new ShowThreddsFolderInfoView(folder.getFolderId(), isCreateConfiguration) {
@Override
@ -414,27 +420,55 @@ public class WsThreddsWidgetViewManager {
if(isCreateConfiguration) {
folderInfo.getMainPanel().setVisible(false);
//If the user is a THREDDS_ADMIN in at least one scope, he/she can create a configuration.
if(isThreddsAdmin) {
folderInfo.setError(true, THIS_FOLDER_IS_NOT_CONFIGURED_DO_YOU_WANT_CREATE_A_CONFIGURATION);
folderInfo.getPager().getLeft().setText(CREATE_CONFIGURATION);
}else {
//Create Configuration button
folderInfo.getPager().getLeft().setVisible(false);
folderInfo.setError(true, WsThreddsWidget.MISSING_THREDDS_ADMIN_RIGHTS);
folderInfo.setError(true, WsThreddsSyncConstants.RightsMissing.noCreateConfigRights());
}
}else {
//USER CAN PERFORM DO SYNC
//IT IS DO SYNC OR READ/VIEW THE CURRENT CONFIGURATION
//MOREOVER, HE/SHE COULD UPDATE THE CONFIGURATION BUT IT IS NOT SUPPORTED SERVER-SIDE
//hiding create/update configuration
folderInfo.getPager().getLeft().setVisible(false);
//hiding delete syncr
folderInfo.showUnsyncButton(false);
//doSync button
folderInfo.getPager().getRight().setVisible(false);
if(isThreddsPubliser || isThreddsAdmin) {
//Checking the user role in the target scope
GcubeScope targetScope = folderDescriptor.getSelectedScope();
boolean isThreddsPublisherInTheTargetScope = false;
boolean isThreddsAdminInTheTargetScope = false;
//the user has at least one role in one scope
if(mapScopeThreddsRoles!=null) {
GatewayRolesThredds rolesInTheTargetScope = mapScopeThreddsRoles.get(targetScope.getScopeName());
GWT.log("In the target scope: "+targetScope.getScopeName()+" the role of user is: "+rolesInTheTargetScope);
//reading the role for the target scope
if(rolesInTheTargetScope!=null) {
isThreddsAdminInTheTargetScope = rolesInTheTargetScope.equals(GatewayRolesThredds.DATA_MANAGER);
isThreddsPublisherInTheTargetScope = rolesInTheTargetScope.equals(GatewayRolesThredds.DATA_EDITOR);
}
}
//the user is ADMIN or EDITOR in the target scope
if(isThreddsPublisherInTheTargetScope || isThreddsAdminInTheTargetScope) {
//hiding unsync button if the user is a publisher
if(isThreddsPubliser)
folderInfo.showUnsyncButton(false);
//he/she can run doSync
folderInfo.getPager().getRight().setVisible(true);
//showing unsync button if the user is an ADMIN
if(isThreddsAdminInTheTargetScope) {
folderInfo.showUnsyncButton(true);
}
if(folderDescriptor.getServerFolderDescriptor().isLocked()) {
VerticalPanel v = new VerticalPanel();
@ -458,7 +492,7 @@ public class WsThreddsWidgetViewManager {
}else {
//DoSync button
folderInfo.getPager().getRight().setVisible(false);
folderInfo.setError(true, WsThreddsWidget.MISSING_THREDDS_PUBLISHER_RIGHTS);
folderInfo.setError(true, WsThreddsSyncConstants.RightsMissing.noRunSyncRights(targetScope.getScopeTitle()));
}
}
@ -467,7 +501,7 @@ public class WsThreddsWidgetViewManager {
panelView.addViewAsWidget(folderInfo);
box.add(panelView);
box.show();
}
}

View File

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

View File

@ -1,6 +1,5 @@
package org.gcube.portlets.widgets.wsthreddssync.client.view.binder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -31,50 +30,41 @@ import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
// TODO: Auto-generated Javadoc
/**
* 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;
@ -82,16 +72,13 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
@UiField
Button button_do_unsync;
/*@UiField
TextBox field_last_sync;
*/
/*
* @UiField TextBox field_last_sync;
*/
@UiField
ControlGroup cg_catalogue_name;
@UiField
ControlGroup cg_remote_path;
@ -101,25 +88,22 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
@UiField
Pager pager;
/** The folder id. */
private String folderId;
/** The map VR es. */
private Map<String, GcubeScope> mapScopes = new HashMap<String, GcubeScope>();
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.
@ -132,24 +116,22 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
* Sets the error.
*
* @param visible the visible
* @param error the error
* @param error the error
*/
public abstract void setError(boolean visible, String error);
/**
* Because this class has a default constructor, it can
* be used as a binder template. In other words, it can be used in other
* *.ui.xml files as follows:
* <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
*/
public ShowThreddsFolderInfoView(String folderId, boolean isCreateConfiguration) {
this.folderId = folderId;
@ -171,33 +153,34 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
@Override
public void onClick(ClickEvent event) {
setError(false, "");
//boolean isValid = validateSubmit();
//if(isValid)
// boolean isValid = validateSubmit();
// if(isValid)
submitHandler(SUBMIT_ACTION.DO_SYNC);
}
});
if(isCreateConfiguration) {
WsThreddsWidget.wsThreddsSyncService.getListOfDataManagerScopesForLoggedUser(new AsyncCallback<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
}
});
}
});
}
}
@ -205,23 +188,19 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
/**
* Update view to result.
*
* @param folder the folder
* @param folder the folder
* @param syncFolderDesc the sync folder desc
*/
public void updateViewToResult(final WsFolder folder, WsThreddsSynchFolderDescriptor syncFolderDesc) {
this.field_select_scope.clear();
if(syncFolderDesc==null) {
if (syncFolderDesc == null) {
pager.getRight().setVisible(false);
return;
}
if(syncFolderDesc.getSyncStatus()!=null) {
this.field_folder_status.setValue(syncFolderDesc.getSyncStatus().toString());
}
if(syncFolderDesc.getSelectedScope()!=null) {
if (syncFolderDesc.getSelectedScope() != null) {
String toValue = FormatUtil.toScopeValue(syncFolderDesc.getSelectedScope());
this.field_select_scope.addItem(toValue, syncFolderDesc.getSelectedScope().getScopeName());
this.field_select_scope.setValue(0, syncFolderDesc.getSelectedScope().getScopeName());
@ -229,35 +208,38 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
}
ThSyncFolderDescriptor sfd = syncFolderDesc.getServerFolderDescriptor();
if(sfd!=null) {
if (sfd != null) {
this.field_folder_path.setValue(sfd.getFolderPath());
this.field_folder_path.setTitle(sfd.getFolderPath());
this.field_folder_locked.setValue(sfd.isLocked()+"");
this.field_folder_locked.setValue(sfd.isLocked() + "");
if (sfd.getElementInfo() != null) {
this.field_folder_status.setValue(sfd.getElementInfo().getSyncStatus().toString());
}
ThSynchFolderConfiguration config = sfd.getConfiguration();
if(config!=null) {
if (config != null) {
this.field_catalogue_name.setValue(config.getToCreateCatalogName());
this.field_catalogue_name.setTitle(config.getToCreateCatalogName());
this.field_remote_path.setValue(config.getRemotePath());
this.field_remote_path.setTitle(config.getRemotePath());
}
ThProcessDescriptor lpd = sfd.getLocalProcessDescriptor();
if(lpd!=null) {
//this.field_last_sync.setValue(DateTimeFormat.getFormat(DATE_FORMAT_YYYY_MM_DD_HH_MM_SS).format(new Date(lpd.getLaunchTime())));
if (lpd != null) {
// this.field_last_sync.setValue(DateTimeFormat.getFormat(DATE_FORMAT_YYYY_MM_DD_HH_MM_SS).format(new
// Date(lpd.getLaunchTime())));
ThSynchFolderConfiguration sc = lpd.getSynchConfiguration();
if(sc!=null) {
//this.field_select_vre.setValue(sc.get, value);
if (sc != null) {
// this.field_select_vre.setValue(sc.get, value);
}
}
}
button_do_unsync.setVisible(true);
button_do_unsync.addClickHandler(new ClickHandler() {
@ -279,8 +261,6 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
return isCreateConfiguration;
}
/**
* Validate submit.
*
@ -290,13 +270,13 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
cg_catalogue_name.setType(ControlGroupType.NONE);
cg_remote_path.setType(ControlGroupType.NONE);
if(field_catalogue_name.getValue()==null || field_catalogue_name.getValue().isEmpty()){
if (field_catalogue_name.getValue() == null || field_catalogue_name.getValue().isEmpty()) {
cg_catalogue_name.setType(ControlGroupType.ERROR);
setError(true, "Unit Title field is required");
return false;
}
if(field_remote_path.getValue()==null || field_remote_path.getValue().isEmpty()){
if (field_remote_path.getValue() == null || field_remote_path.getValue().isEmpty()) {
cg_remote_path.setType(ControlGroupType.ERROR);
setError(true, "Folder Name field is required");
return false;
@ -305,7 +285,6 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
return true;
}
/**
* Gets the remote path.
*
@ -320,24 +299,21 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
*
* @return the catalogue name
*/
public String getCatalogueName(){
public String getCatalogueName() {
return field_catalogue_name.getValue();
}
/**
* Gets the selected scope.
*
* @return the selected scope
*/
public GcubeScope getSelectedScope(){
//String item = field_select_scope.getSelectedItemText();
public GcubeScope getSelectedScope() {
// String item = field_select_scope.getSelectedItemText();
String scope = field_select_scope.getSelectedValue();
return mapScopes.get(scope);
}
/**
* Gets the pager.
*
@ -352,11 +328,10 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
*
* @return the main panel
*/
public HTMLPanel getMainPanel(){
public HTMLPanel getMainPanel() {
return form_unit_fields;
}
/**
* Show unsync.
*
@ -366,6 +341,4 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
button_do_unsync.setVisible(show);
}
}

View File

@ -1,6 +1,7 @@
<!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;
@ -13,36 +14,46 @@
<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>
@ -50,22 +61,24 @@
<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>

View File

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

View File

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

View File

@ -4,240 +4,451 @@
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
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 7, 2018
* updated May, 2021
*/
public class SyncronizeWithThredds {
/** The logger. */
private Logger logger = LoggerFactory.getLogger(SyncronizeWithThredds.class);
/** The workspace thredds synchronize. */
private WorkspaceThreddsSynchronize workspaceThreddsSynchronize;
private WorkspaceThreddsSynchronize workspaceThreddsSynchronizeLib;
/** The Constant sdf. */
//private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
// private static final SimpleDateFormat sdf = new
// SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
/**
* Instantiates a new publish on thredds.
*
* @param wsScopeUserToken the ws scope user token
* @param username the username
* @param httpSession the http session
* @param username the username
* @param httpSession the http session
*/
public SyncronizeWithThredds() {
this.workspaceThreddsSynchronize = WorkspaceThreddsSynchronize.getInstance();
this.workspaceThreddsSynchronizeLib = WorkspaceThreddsSynchronize.getInstance();
}
/**
* Sets the context parameters.
*
* @param scope the scope
* @param scope the scope
* @param userToken the user token
*/
private void setContextParameters(String scope, String userToken) {
logger.debug("Setting context parameters, scope: "+scope +", user token: "+userToken);
logger.debug("Setting context parameters with scope: " + scope + ", user token: " + userToken.substring(0, 10)
+ "-MASKED-TOKEN");
ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(userToken);
}
/**
* Do sync folder.
* Change context for UMA.
*
* @param folderId the folder id
* @param thConfig the th config
* @param scope the scope
* @param userToken the user token
* @return the th sync status
* @throws Exception the exception
* @param httpRequest the http request
* @param user the user
* @param targetScope the target scope
* @return the string representing the previous UMA Token read from
* {@link UmaJWTProvider#get()}
*/
public synchronized ThSyncStatus doSyncFolder(final String folderId, ThSynchFolderConfiguration thConfig, String scope, String userToken) throws Exception{
logger.debug("Perfoming doSynFolder on folderId: "+folderId);
boolean firstSync = false;
private String changeContextForUMA(HttpServletRequest httpRequest, GCubeUser user, String targetScope) {
logger.debug("Setting UMA context with target scope: " + targetScope + ", user: " + user.getUsername());
String previousUMAToken = null;
try {
setContextParameters(scope, userToken);
ThSyncFolderDescriptor folder = workspaceThreddsSynchronize.checkItemSynched(folderId);
}catch (ItemNotSynched e) {
firstSync = true;
// TODO: handle exception
}catch (Exception e) {
logger.error("Error on check item sync: ",e);
throw new Exception("Sorry an error occurred during folder publishing, refresh and try again");
}
previousUMAToken = AccessTokenProvider.instance.get();
JWTToken umaToken = OIDCUmaUtil.getUMAToken(httpRequest, user.getUsername(), targetScope);
try{
if(firstSync) {
if(thConfig==null)
throw new Exception("A valid folder configuration must be provided to perforom synchronization");
logger.info("First sync setting synchronized folder configuration: "+thConfig);
workspaceThreddsSynchronize.setSynchronizedFolder(thConfig, folderId);
}
logger.info("Calling do sync on folder id: "+folderId);
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");
}
}
/**
* Gets the synched status from item property.
*
* @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 Sync_Status getSynchedStatusFromItemProperty(String folderId, String scope, String username) throws Exception{
try {
try {
ScopeProvider.instance.set(scope);
return workspaceThreddsSynchronize.getSynchedStatusFromItemProperty(folderId, username);
}catch (ItemNotSynched e) {
logger.info("The folder id: "+folderId +" is not synched returning null as "+Sync_Status.class.getSimpleName());
if (umaToken == null) {
logger.info("Uma Token is null or empty, skipping operation and returning null");
return null;
}
}catch (Exception e) {
logger.error("Error on getSynchedStatusFromItemProperty for id: "+folderId, e);
throw new Exception("Sorry, an error occurred during read sync status from HL properties, try again later");
}
}
String subAccessToken = umaToken.getAccessTokenString().substring(0, 10);
logger.info("Going to set UMA Token: " + subAccessToken + "-MASKED-TOKEN");
// UmaJWTProvider.instance.set(umaToken);
AccessTokenProvider.instance.set(JWTTokenUtil.getAccessTokenString(umaToken));
logger.debug("UmaJWTProvider instance set performed to : " + subAccessToken + "-MASKED-TOKEN");
} catch (Exception e) {
logger.warn("Error on set context for UMA: ", e);
if (previousUMAToken != null) {
logger.info("Setting previous UMA Token: " + previousUMAToken.substring(0, 10) + "-MASKED-TOKEN");
AccessTokenProvider.instance.set(previousUMAToken);
}
}
return previousUMAToken;
}
/**
* Checks if is item synched.
*
* @param folderId the folder id
* @param scope the scope
* @param username the username
* @param folderId the folder id
* @param scope the scope
* @param userToken the user token
* @param itemProperties the item properties
* @param itemType the item type
* @return true, if is item synched
* @throws ItemNotSynched the item not synched
* @throws Exception the exception
* @throws Exception the exception
*/
public boolean isItemSynched(String folderId, String scope, String username) throws ItemNotSynched, Exception{
Sync_Status value = getSynchedStatusFromItemProperty(folderId, scope, username);
if(value!=null)
return true;
return false;
}
/**
* Check item synched.
*
* @param folderId the folder id
* @param scope the scope
* @param userToken the user token
* @return the th sync folder descriptor
* @throws ItemNotSynched the item not synched
* @throws WorkspaceFolderLocked the workspace folder locked
* @throws Exception the exception
*/
public ThSyncFolderDescriptor checkItemSynched(String folderId, String scope, String userToken) throws ItemNotSynched, WorkspaceFolderLocked, Exception{
public boolean isItemSynched(String folderId, String scope, String userToken, Map<String, Object> itemProperties,
ContainerType itemType) throws ItemNotSynched, Exception {
setContextParameters(scope, userToken);
return workspaceThreddsSynchronize.checkItemSynched(folderId);
return workspaceThreddsSynchronizeLib.isItemSynched(folderId, itemProperties, itemType);
}
/**
* Gets the configuration.
*
* @param folderId the folder id
* @param loadStatus the load status. If true it loads the status by calling
* the {@link SyncEngine#check(String, boolean)} but it is
* time consuming. Otherwise it calls the
* {@link SyncEngine#getConfig(String)} without sync status
* @param httpRequest the http request
* @param user the user
* @return the configuration
* @throws ItemNotSynched the item not synched
* @throws Exception the exception
*/
public ThSyncFolderDescriptor getConfiguration(String folderId, boolean loadStatus, HttpServletRequest httpRequest,
GCubeUser user) throws ItemNotSynched, Exception {
ThSyncFolderDescriptor config = null;
String wsScope = PortalContext.getConfiguration().getCurrentScope(httpRequest);
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
String originalScope = wsScope;
String originalToken = wsUserToken;
String previousUmaToken = null;
String targetScope = null;
try {
setContextParameters(wsScope, wsUserToken);
if (loadStatus) {
config = workspaceThreddsSynchronizeLib.getConfiguration(folderId);
// context switch for UMA token
targetScope = config.getConfiguration().getTargetContext();
previousUmaToken = changeContextForUMA(httpRequest, user, targetScope);
// context switch for gcube-token and scope
// getting token into target scope
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope,
user.getUsername());
setContextParameters(targetScope, targetScopeUserToken);
config = workspaceThreddsSynchronizeLib.checkItemSynched(folderId);
} else {
config = workspaceThreddsSynchronizeLib.getConfiguration(folderId);
}
} catch (WorkspaceNotSynchedException e) {
logger.debug("WorkspaceNotSynchedException catched. The item with id: " + folderId + " is not synched");
} catch (WorkspaceFolderLocked e1) {
logger.info("The folder with id: " + folderId + " is locked");
throw new Exception(
"The folder with id: " + folderId + " is currently locked. Another sync process is in progress");
} catch (Exception e) {
logger.error("Error on reading the configuration for id: " + folderId, e);
throw e;
} finally {
if (previousUmaToken != null) {
// resetting UMA token in the WS scope
AccessTokenProvider.instance.set(previousUmaToken);
}
if (originalScope != null && targetScope != null && originalScope.compareTo(targetScope) != 0) {
logger.info("Resetting the scope: " + originalScope + " which was original WS context");
ScopeProvider.instance.set(originalScope);
if (originalToken != null) {
logger.info("Resetting the user token: " + originalToken.substring(0, 10)
+ "-MASKED-TOKEN which was original WS context");
SecurityTokenProvider.instance.set(originalToken);
}
}
}
return config;
}
/**
* Gets the available catalogues.
*
* @param httpRequest the http request
* @param user the user
* @param targetScope the target scope
* @return the available catalogues
* @throws Exception the exception
*/
public List<ThCatalogueBean> getAvailableCatalogues(HttpServletRequest httpRequest, GCubeUser user,
String targetScope) throws Exception {
String originalScope = null;
String originalToken = null;
String previousUmaToken = null;
List<ThCatalogueBean> listCatalogues = null;
try {
// context switch for Uma token
previousUmaToken = changeContextForUMA(httpRequest, user, targetScope);
// context switch for gcube-token and scope
PortalContext pConfig = PortalContext.getConfiguration();
String wsScope = pConfig.getCurrentScope(httpRequest);
String wsUserToken = pConfig.getCurrentUserToken(wsScope, user.getUsername());
// Thread Local contexts
originalScope = wsScope;
originalToken = wsUserToken;
// getting token into target scope
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope,
user.getUsername());
setContextParameters(targetScope, targetScopeUserToken);
// calling the engine
listCatalogues = workspaceThreddsSynchronizeLib.getAvailableCatalogues();
} catch (Exception e) {
logger.error("Error on getting available Catalogues in the scope: " + targetScope, e);
} finally {
if (previousUmaToken != null) {
// resetting UMA token in the WS scope
AccessTokenProvider.instance.set(previousUmaToken);
}
if (originalScope != null && originalScope.compareTo(targetScope) != 0) {
logger.info("Resetting the scope: " + originalScope + " which was original WS context");
ScopeProvider.instance.set(originalScope);
if (originalToken != null) {
logger.info("Resetting the user token: " + originalToken.substring(0, 10)
+ "-MASKED-TOKEN which was original WS context");
SecurityTokenProvider.instance.set(originalToken);
}
}
}
return listCatalogues;
}
/**
* Do sync folder.
*
* @param folderId the folder id
* @param thConfig the th config
* @param httpRequest the http request
* @param user the user
* @return the th sync status
* @throws Exception the exception
*/
public synchronized ThSyncStatus doSyncFolder(final String folderId, ThSynchFolderConfiguration thConfig,
HttpServletRequest httpRequest, GCubeUser user) throws Exception {
logger.debug("called doSynFolder for folderId: " + folderId);
boolean firstSync = false;
String originalScope = null;
String originalToken = null;
String previousUmaToken = null;
if (thConfig == null) {
throw new Exception("A valid folder configuration must be provided to perform the synchronization");
}
String targetScope = thConfig.getTargetContext();
if (targetScope == null || targetScope.isEmpty()) {
throw new Exception("Error, the target scope is not valid!");
}
logger.info("going to doSynFolder for folderId: " + folderId + ", target scope is: " + targetScope);
try {
// context switch for Uma token
previousUmaToken = changeContextForUMA(httpRequest, user, targetScope);
// context switch for gcube-token and scope
PortalContext pConfig = PortalContext.getConfiguration();
String wsScope = pConfig.getCurrentScope(httpRequest);
String wsUserToken = pConfig.getCurrentUserToken(wsScope, user.getUsername());
// Thread Local contexts
originalScope = wsScope;
originalToken = wsUserToken;
// getting token into target scope
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope,
user.getUsername());
setContextParameters(targetScope, targetScopeUserToken);
ThSyncFolderDescriptor folder = workspaceThreddsSynchronizeLib.checkItemSynched(folderId);
} catch (ItemNotSynched e) {
firstSync = true;
} catch (Exception e) {
logger.error("Error on check item sync: ", e);
throw e;
}
try {
if (firstSync) {
logger.info("First sync setting the synchronized folder configuration: " + thConfig);
workspaceThreddsSynchronizeLib.setSynchronizedFolder(thConfig, folderId);
}
logger.info("Calling do sync on folder id: " + folderId);
return workspaceThreddsSynchronizeLib.doSync(folderId);
} catch (Exception e) {
logger.error("Error on doSyncFolder for folderId: " + folderId, e);
throw e;
} finally {
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 deleteRemoteContent the delete remote content
* @param thConfig the th config
* @param httpRequest the http request
* @param user the user
* @return the boolean
* @throws Exception the exception
*/
public Boolean doUnSync(String folderId, boolean deleteRemoteContent, ThSynchFolderConfiguration thConfig,
HttpServletRequest httpRequest, GCubeUser user) throws Exception {
logger.debug("called doUnSync for folderId: " + folderId);
String originalScope = null;
String originalToken = null;
String previousUmaToken = null;
if (thConfig == null) {
throw new Exception("A valid folder configuration must be provided to perform the synchronization");
}
String targetScope = thConfig.getTargetContext();
if (targetScope == null || targetScope.isEmpty()) {
throw new Exception("Error, the target scope is not valid!");
}
logger.info("going to doSynFolder for folderId: " + folderId + ", target scope is: " + targetScope);
try {
// context switch for Uma token
previousUmaToken = changeContextForUMA(httpRequest, user, targetScope);
// context switch for gcube-token and scope
PortalContext pConfig = PortalContext.getConfiguration();
String wsScope = pConfig.getCurrentScope(httpRequest);
String wsUserToken = pConfig.getCurrentUserToken(wsScope, user.getUsername());
// Thread Local contexts
originalScope = wsScope;
originalToken = wsUserToken;
// getting token into target scope
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope,
user.getUsername());
setContextParameters(targetScope, targetScopeUserToken);
return workspaceThreddsSynchronizeLib.doUnSync(folderId, deleteRemoteContent);
} catch (ItemNotSynched e) {
throw new Exception("The item with id: " + folderId + " is not synched");
} catch (Exception e) {
logger.error("Error on check item sync: ", e);
throw new Exception("Sorry an error occurred during folder publishing, refresh and try again");
} finally {
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.
*
* @param itemId the item id
* @param scope the scope
* @param itemId the item id
* @param scope the scope
* @param userToken the user token
* @return the sync status
* @throws ItemNotSynched the item not synched
* @throws Exception the exception
* @throws Exception the exception
*/
public ThSyncStatus monitorSyncStatus(String itemId, String scope, String userToken) throws ItemNotSynched, Exception{
public ThSyncStatus monitorSyncStatus(String itemId, String scope, String userToken)
throws ItemNotSynched, Exception {
setContextParameters(scope, userToken);
return workspaceThreddsSynchronize.monitorSyncStatus(itemId);
return workspaceThreddsSynchronizeLib.monitorSyncStatus(itemId);
}
/**
* Do un sync.
*
* @param folderId the folder id
* @param deleteRemoteContent the delete remote content
* @param scope the scope
* @param userToken the user token
* @return the boolean
* @throws Exception the exception
*/
public Boolean doUnSync(String folderId, boolean deleteRemoteContent, String scope, String userToken) throws Exception {
setContextParameters(scope, userToken);
return workspaceThreddsSynchronize.doUnSync(folderId, deleteRemoteContent);
}
/**
* Register callback for id.
*
* @param folderId the folder id
* @param scope the scope
* @param folderId the folder id
* @param scope the scope
* @param userToken the user token
* @throws Exception the exception
*/
public void registerCallbackForId(String folderId, String scope, String userToken) throws Exception {
protected void registerCallbackForId(String folderId, String scope, String userToken) throws Exception {
setContextParameters(scope, userToken);
workspaceThreddsSynchronize.registerCallbackForId(folderId);
}
/**
* Gets the available catalogues by token.
*
* @param scope the scope
* @param userToken the user token
* @param targetToken the target token
* @return the available catalogues by token
* @throws Exception the exception
*/
public List<ThCatalogueBean> getAvailableCataloguesByToken(String scope, String userToken, String targetToken) throws Exception {
setContextParameters(scope, userToken);
return workspaceThreddsSynchronize.getAvailableCataloguesByToken(targetToken);
workspaceThreddsSynchronizeLib.registerCallbackForId(folderId);
}
}

View File

@ -7,10 +7,11 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.gcube.common.portal.PortalContext;
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;
@ -21,6 +22,7 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScopeType;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
import org.gcube.usecases.ws.thredds.SyncEngine;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
@ -39,8 +41,7 @@ import com.liferay.portal.service.UserLocalServiceUtil;
/**
* 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 {
@ -58,10 +59,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
*/
public synchronized SyncronizeWithThredds getSyncService() {
if(syncThredds==null)
if (syncThredds == null)
syncThredds = new SyncronizeWithThredds();
return syncThredds;
return syncThredds;
}
@ -74,123 +75,212 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try {
UserLocalServiceUtil.getService();
return true;
}
catch (Exception ex) {
} catch (Exception ex) {
logger.warn("Development Mode ON");
return false;
}
}
/**
* Do sync folder.
* Gets the available THREDDS catalogues for target scope.
*
* @param folderId the folder id
* @param clientConfig the th config
* @return the th sync status
* @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#doSyncFolder(java.lang.String, org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor)
*/
@Override
public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) throws Exception{
logger.info("Performing doSyncFolder method on id: "+folderId +", config: "+clientConfig);
try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String targetScopeUserToken = null;
ThSynchFolderConfiguration config = null;
if(clientConfig!=null) {
targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(clientConfig.getSelectedScope().getScopeName(), user.getUsername());
config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId, targetScopeUserToken);
logger.debug("Creating server config "+config);
}
logger.info("Calling doSyncFolder on folderId: "+folderId +", config: "+config);
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, wsScope, wsUserToken);
logger.debug("Returning for folderId "+folderId+" the syncStatus: "+status);
return status;
}catch (Exception e) {
logger.error("Do sync Folder error: ",e);
throw new Exception("Sorry, an error occurred during synchonization phase, try again later");
}
}
/**
* Gets the available catalogues for scope.
*
* @param scope the scope
* @param targetFullScope the target scope
* @return the available catalogues for scope
* @throws Exception the exception
*/
// UPDATED
@Override
public List<ThCatalogueBean> getAvailableCataloguesForScope(String scope) throws Exception {
public List<ThCatalogueBean> getAvailableCataloguesForScope(String targetFullScope) throws Exception {
if(scope==null)
if (targetFullScope == null)
throw new Exception("Invalid scope null");
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(scope, user.getUsername());
List<ThCatalogueBean> listCtlgs = getSyncService().getAvailableCataloguesByToken(scope, wsUserToken, targetScopeUserToken);
List<ThCatalogueBean> listCtlgs = null;
try {
logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+scope);
if(logger.isDebugEnabled()){
for (ThCatalogueBean thCatalogueBean : listCtlgs) {
logger.debug(thCatalogueBean.toString());
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 list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them.
* Gets the configuration.
*
* @param folderId the folder id
* @param loadStatus the load status. If true it loads the status by calling the
* {@link SyncEngine#check(String, boolean)} but it is time
* consuming. No otherwise.
* @return the ws thredds synch folder descriptor
* @throws WorkspaceFolderLocked the workspace folder locked
* @throws Exception the exception
*/
@Override
public WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus)
throws WorkspaceFolderLocked, Exception {
logger.debug("called isItemSynched for folderId: " + folderId);
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
return getConfiguration(folderId, loadStatus, this.getThreadLocalRequest(), user);
}
/**
* Gets the configuration.
*
* @param folderId the folder id
* @param loadStatus the load status
* @param httpRequest the http request
* @param user the user
* @return the configuration
* @throws Exception the exception
*/
public WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus,
HttpServletRequest httpRequest, GCubeUser user) throws Exception {
logger.debug("called internal getConfiguration for folderId: " + folderId);
try {
ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, httpRequest,
user);
if (theConfig != null) {
logger.info("Folder id: " + folderId + " is synched");
WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig);
logger.debug("isItemSynched for id: " + folderId + " returning: " + toWsThreddFolder);
return toWsThreddFolder;
}
logger.info("Folder id: " + folderId + " is not synched, returning null descriptor");
return null;
} catch (ItemNotSynched e) {
logger.info("The folderId: " + folderId + " is not synched, returning null for "
+ WsThreddsSynchFolderDescriptor.class.getSimpleName());
return null;
} catch (WorkspaceFolderLocked e) {
logger.warn(e.getMessage() + ", sending exception to client...");
throw new WorkspaceFolderLocked(e.getFolderId(), e.getMessage());
} catch (Exception e) {
logger.info("Error on isItemSynched for folderId: " + folderId, e);
throw new Exception(e);
}
}
/**
* Do sync folder.
*
* @param folderId the folder id
* @param clientConfig the client config
* @return the th sync status
* @throws Exception the exception
*/
// UPDATED
@Override
public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig)
throws Exception {
logger.info("Performing doSyncFolder method on id: " + folderId + ", config: " + clientConfig);
try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
ThSynchFolderConfiguration config = null;
if (clientConfig != null && clientConfig.getSelectedScope() != null) {
config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId,
clientConfig.getSelectedScope().getScopeName());
logger.debug("Creating server config " + config);
} else {
logger.info("The config sent from client is null, Loading it from ws-thredds");
ThSyncFolderDescriptor descr = getSyncService().getConfiguration(folderId, false,
this.getThreadLocalRequest(), user);
logger.info("From ws-thredds loaded the config: " + config);
config = descr.getConfiguration();
}
ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, this.getThreadLocalRequest(), user);
logger.debug("Returning for folderId " + folderId + " the syncStatus: " + status);
return status;
} catch (Exception e) {
logger.error("Do sync Folder error: ", e);
throw new Exception(
"Sorry, an error occurred during synchonization phase. The server encountered the error: "
+ e.getMessage(),
e);
}
}
/**
* Do un sync folder.
*
* @param folderId the folder id
* @return the boolean
* @throws Exception the exception
*/
// Updated
@Override
public Boolean doUnSyncFolder(final String folderId) throws Exception {
logger.info("Performing unsync on folder id: " + folderId);
try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId, false,
this.getThreadLocalRequest(), user);
return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), this.getThreadLocalRequest(),
user);
} catch (Exception e) {
logger.error("Do un sync Folder error: ", e);
throw new Exception(
"Sorry, an error occurred on deleting sync configurations, refresh and try again later");
}
}
/**
* Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds
* roles that user has in them.
*
* @return the VREs and Thredds roles for a given user
* @throws Exception the exception
*/
@Override
public Map<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.THREDDS_PUBLISHER);
mapScopesRoles.put("/gcube/devsec/devVRE", GatewayRolesThredds.DATA_EDITOR);
// 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());
mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user);
logger.info("returning Map(scopes,roles): "+mapScopesRoles);
String gatewayHostname = GenericUtils.getGatewayClientHostname(this.getThreadLocalRequest());
mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user, gatewayHostname);
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.
*
@ -198,17 +288,17 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @throws Exception the exception
*/
@Override
public List<GcubeScope> getListOfDataManagerScopesForLoggedUser() throws Exception{
logger.info("getListOfVREsForLoggedUser...: ");
public List<GcubeScope> getListOfDataManagerScopesForLoggedUser() throws Exception {
logger.info("called getListOfVREsForLoggedUser...: ");
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
long userId = user.getUserId();
// Instanciate the manager
// Instantiate the manager
GroupManager groupManager = new LiferayGroupManager();
List<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));
@ -221,173 +311,94 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
try {
String gatewayHostname = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
//list of Scopes filtered for gateway
// list of Scopes filtered for gateway
Set<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) {
GcubeScopeType scopeType=null;
if(groupManager.isVRE(gCubeGroup.getGroupId())){
scopeType = GcubeScopeType.VRE;
}else if(groupManager.isVO(gCubeGroup.getGroupId())){
scopeType = GcubeScopeType.VO;
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;
}
// }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, 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);
///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the ROOT-VO
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, theRootVO, groupManager, GcubeScopeType.ROOT);
if(gcubeScope!=null) {
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) {
listOfScopes.add(gcubeScope);
}
//ADDING THE ROOT SCOPE
/*String infraName = PortalContext.getConfiguration().getInfrastructureName();
GcubeScope gcubeRoot = new GcubeScope(infraName, "/"+infraName, GcubeScopeType.ROOT);
listOfScopes.add(gcubeRoot)*/
}
catch (UserRetrievalFault | UserManagementSystemException
| GroupRetrievalFault e) {
} catch (UserRetrievalFault | UserManagementSystemException | GroupRetrievalFault e) {
logger.error("Error occurred server-side getting VRE folders: ", e);
throw new Exception("Sorry, an error occurred server-side getting VRE folders, try again later");
}
if(listOfScopes.isEmpty()) {
throw new Exception("No scope detected with the needed role: "+GatewayRolesThredds.DATA_MANAGER.getRoleName()+". Contact the VRE manager or the portal administrator");
if (listOfScopes.isEmpty()) {
throw new Exception(
"No scope detected with the needed role: " + GatewayRolesThredds.DATA_MANAGER.getRoleName()
+ ". Contact the VRE manager or the portal administrator");
}
Collections.sort(listOfScopes);
logger.info("Returning list of allowed scope/s with: "+GatewayRolesThredds.DATA_MANAGER + " role/s: "+listOfScopes);
logger.info("Returning list of allowed scope/s with: " + GatewayRolesThredds.DATA_MANAGER + " role/s: "
+ listOfScopes);
return listOfScopes;
}
/**
* Checks if for the input scope:
* - the user has the role {@link GatewayRolesThredds.#THREDDS_ADMIN}
* - the scope has an available THREDDS catalogue configured
* Checks if for the input scope: - the user has the role
* {@link GatewayRolesThredds.#THREDDS_ADMIN} - the scope has an available
* THREDDS catalogue configured
*
* @param role the role
* @param scope the scope
* @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, GCubeGroup scope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception {
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(scope.getGroupName());
if(list!=null) {
return new GcubeScope(scope.getGroupName(), groupManager.getInfrastructureScope(scope.getGroupId()), scopeType);
List<ThCatalogueBean> list = getAvailableCataloguesForScope(fullScope);
if (list != null) {
return new GcubeScope(scopeName, fullScope, scopeType);
}
}catch (Exception e) {
logger.error("Error on checking available catalogue for scope: "+scope.getGroupName(), e);
} catch (Exception e) {
logger.error("Error on checking available catalogue for scope: " + fullScope, e);
}
}
return null;
}
/**
* Available scope for role , checks if for the input scope the user has the role of {@link GatewayRolesThredds.#THREDDS_ADMIN}
*
* @param role the role
* @param scope the scope
* @param groupManager the group manager
* @param scopeType the scope type
* @return the gcube scope {@link GcubeScope} if the user has the role of {@link GatewayRolesThredds.#THREDDS_ADMIN}, null otherwise
* @throws Exception the exception
*/
private GcubeScope availableScopeForRole(GatewayRolesThredds role, GCubeGroup scope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception {
if(role!=null && role.equals(GatewayRolesThredds.DATA_MANAGER)) {
return new GcubeScope(scope.getGroupName(), groupManager.getInfrastructureScope(scope.getGroupId()), scopeType);
}
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.
@ -395,47 +406,14 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @param folderId the folder id
* @return the th sync status
* @throws ItemNotSynched the item not synched
* @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#monitorSyncStatus(java.lang.String)
* @throws Exception the exception
*/
@Override
public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception{
public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
return getSyncService().monitorSyncStatus(folderId, wsScope, wsUserToken);
}
/**
* Do sync folder.
*
* @param folderId the folder id
* @return the th sync status
* @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#doSyncFolder(java.lang.String, org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor)
*/
@Override
public Boolean doUnSyncFolder(final String folderId) throws Exception{
logger.info("Performing unsync on folder id: "+folderId);
// String scope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
// GCubeUser username = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
// String groupName = PortalContext.getConfiguration().getCurrentGroupName(this.getThreadLocalRequest());
// new GcubeVRE(groupName, scope)
try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
return getSyncService().doUnSync(folderId, false, wsScope, wsUserToken);
}catch (Exception e) {
logger.error("Do un sync Folder error: ",e);
throw new Exception("Sorry, an error occurred on deleting sync configurations, refresh and try again later");
}
}
}

View File

@ -7,24 +7,18 @@ 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;
@ -39,17 +33,13 @@ import com.liferay.portal.service.UserLocalServiceUtil;
/**
* The Class WsUtil.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Nov 25, 2016
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Nov 25, 2016
*/
public class WsUtil {
/** The logger. */
private static Logger logger = LoggerFactory.getLogger(WsUtil.class);
/**
* Checks if is within portal.
*
@ -59,14 +49,12 @@ public class WsUtil {
try {
UserLocalServiceUtil.getService();
return true;
}
catch (Exception ex) {
} catch (Exception ex) {
logger.trace("Development Mode ON");
return false;
}
}
/**
* Checks if is session expired.
*
@ -76,113 +64,99 @@ 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){
logger.info("called getScopesThreddsRolesForUser user: "+user+", in all contexts");
public static Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForUser(GCubeUser user, String gatewayHostname) {
logger.info("called getScopesThreddsRolesForUser user: " + user + ", in the gateway Contexts/VREs");
GroupManager groupManager = new LiferayGroupManager();
Map<String, GatewayRolesThredds> mapRoleByGroupSingleVre = new HashMap<String, GatewayRolesThredds>();
try {
//Retrieving the list of VOs and VREs
List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(user.getUserId());
//adding also the ROOT-VO
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
listOfGroups.add(groupManager.getRootVO());
for (GCubeGroup gCubeGroup : listOfGroups) {
GatewayRolesThredds threddsRole = getThreddsRoleFor(user, gCubeGroup);
if(threddsRole != null) {
mapRoleByGroupSingleVre.put(gCubeGroup.getGroupName(), threddsRole);
if (threddsRole != null) {
String toFullScope = groupManager.getInfrastructureScope(gCubeGroup.getGroupId());
mapRoleByGroupSingleVre.put(toFullScope, threddsRole);
}
}
logger.info("For user: "+user+", returning Map (VRE, ThreddsRoles) " + mapRoleByGroupSingleVre);
logger.info("For user: " + user + ", returning Map (VRE, ThreddsRoles) " + mapRoleByGroupSingleVre);
return mapRoleByGroupSingleVre;
}catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
logger.error("An error occurred during geThreddsVreRolesForUser: "+user, e);
} catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e);
return null;
}
} catch (VirtualGroupNotExistingException e) {
logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e);
return null;
}
}
/**
* Gets the (highest) thredds role for the user in the scope
*
* @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){
logger.info("called getThreddsRoleFor user: "+user+", in the scope: "+scope.getGroupName());
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());
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+" 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 role: " + toReturn);
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;
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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