Merge pull request 'feature_20847' (#1) from feature_20847 into master
This commit is contained in:
commit
fe73dce86d
|
@ -3,6 +3,10 @@
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [v1.3.0-SNAPSHOT] - 2021-03-03
|
||||||
|
|
||||||
|
[#20847] Support the roles of THREDDS Admin and THREDDS Publisher
|
||||||
|
|
||||||
## [v1.2.0] - 2020-07-21
|
## [v1.2.0] - 2020-07-21
|
||||||
|
|
||||||
[#19676] Migrated to git/jenkins
|
[#19676] Migrated to git/jenkins
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -12,7 +12,7 @@
|
||||||
<groupId>org.gcube.portlets.widgets</groupId>
|
<groupId>org.gcube.portlets.widgets</groupId>
|
||||||
<artifactId>ws-thredds-sync-widget</artifactId>
|
<artifactId>ws-thredds-sync-widget</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.2.0</version>
|
<version>1.3.0-SNAPSHOT</version>
|
||||||
<name>ws-thredds-sync-widget</name>
|
<name>ws-thredds-sync-widget</name>
|
||||||
<description>
|
<description>
|
||||||
gCube ws-thredds-sync-widget is a widget to use and interact with ws-thredds facility in order to syncronize the Workspace folders with Thredds Reporitory folders
|
gCube ws-thredds-sync-widget is a widget to use and interact with ws-thredds facility in order to syncronize the Workspace folders with Thredds Reporitory folders
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.portlets.widgets.wsthreddssync.client;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
|
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
|
||||||
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
|
||||||
|
@ -19,17 +20,21 @@ import org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncS
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.client.view.LoaderIcon;
|
import org.gcube.portlets.widgets.wsthreddssync.client.view.LoaderIcon;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.client.view.WsThreddsWidgetViewManager;
|
import org.gcube.portlets.widgets.wsthreddssync.client.view.WsThreddsWidgetViewManager;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.MonitorFolderSyncStatusView;
|
import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.MonitorFolderSyncStatusView;
|
||||||
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder;
|
import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
|
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
|
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
|
||||||
|
|
||||||
|
import com.github.gwtbootstrap.client.ui.Alert;
|
||||||
import com.github.gwtbootstrap.client.ui.Modal;
|
import com.github.gwtbootstrap.client.ui.Modal;
|
||||||
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
import com.google.gwt.event.dom.client.ClickEvent;
|
import com.google.gwt.event.dom.client.ClickEvent;
|
||||||
import com.google.gwt.event.dom.client.ClickHandler;
|
import com.google.gwt.event.dom.client.ClickHandler;
|
||||||
import com.google.gwt.event.shared.HandlerManager;
|
import com.google.gwt.event.shared.HandlerManager;
|
||||||
import com.google.gwt.user.client.Window;
|
import com.google.gwt.user.client.Window;
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||||
|
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
// TODO: Auto-generated Javadoc
|
||||||
|
@ -51,6 +56,12 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
|
||||||
|
|
||||||
private final List<SyncCompletedNotificationListner> syncEventsListeners = new ArrayList<SyncCompletedNotificationListner>();
|
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.";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the entry point method.
|
* This is the entry point method.
|
||||||
*/
|
*/
|
||||||
|
@ -142,39 +153,97 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
|
||||||
|
|
||||||
final Modal box = new Modal(true);
|
final Modal box = new Modal(true);
|
||||||
box.setTitle("Checking configurations...");
|
box.setTitle("Checking configurations...");
|
||||||
LoaderIcon loader = new LoaderIcon("Checking folder configurations...");
|
final HorizontalPanel hpLoader = new HorizontalPanel();
|
||||||
box.add(loader);
|
LoaderIcon loader = new LoaderIcon("Checking authorizations and folder configurations...");
|
||||||
|
hpLoader.add(loader);
|
||||||
|
box.add(hpLoader);
|
||||||
|
|
||||||
GWT.log("Performing isItemSynched: "+folder.getFolderId());
|
//LAOADING ROLES
|
||||||
WsThreddsWidget.wsThreddsSyncService.isItemSynched(folder.getFolderId(), new AsyncCallback<WsThreddsSynchFolderDescriptor>() {
|
WsThreddsWidget.wsThreddsSyncService.getScopesWithThreddsRolesForLoggedUser(new AsyncCallback<Map<String,GatewayRolesThredds>>() {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSuccess(WsThreddsSynchFolderDescriptor result) {
|
|
||||||
box.hide();
|
|
||||||
//GWT.log("WsThreddsSynchFolderDescriptor result: "+result);
|
|
||||||
viewManager.showThreddsFolderInfo(folder, result);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
box.hide();
|
hpLoader.clear();
|
||||||
|
hpLoader.setVisible(false);
|
||||||
|
Alert alert = new Alert();
|
||||||
|
alert.setType(AlertType.INFO);
|
||||||
|
alert.setText(caught.getMessage());
|
||||||
|
box.add(alert);
|
||||||
|
}
|
||||||
|
|
||||||
if(caught instanceof WorkspaceFolderLocked){
|
@Override
|
||||||
viewManager.showMonitorSyncToFolder(folder,syncEventsListeners);
|
public void onSuccess(Map<String, GatewayRolesThredds> result) {
|
||||||
|
try {
|
||||||
|
hpLoader.clear();
|
||||||
|
hpLoader.setVisible(false);
|
||||||
|
}catch (Exception e) {
|
||||||
|
//Silent
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result!=null) {
|
||||||
|
|
||||||
|
GWT.log("Returned Map(Scope,Role): "+result);
|
||||||
|
final boolean isThreddsPubliser = result.containsValue(GatewayRolesThredds.THREDDS_PUBLISHER);
|
||||||
|
final boolean isThreddsAdmin = result.containsValue(GatewayRolesThredds.THREDDS_ADMIN);
|
||||||
|
|
||||||
|
//no rights assigned
|
||||||
|
if(!isThreddsAdmin && !isThreddsPubliser) {
|
||||||
|
showMissingRights(box);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//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) {
|
||||||
|
box.hide();
|
||||||
|
|
||||||
|
if(caught instanceof WorkspaceFolderLocked){
|
||||||
|
viewManager.showMonitorSyncToFolder(folder,syncEventsListeners);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
viewManager.cancelMonitor(folder);
|
||||||
|
Window.alert(caught.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}else {
|
||||||
|
//no rights detected
|
||||||
|
showMissingRights(box);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
viewManager.cancelMonitor(folder);
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
Window.alert(caught.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
box.show();
|
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 performFolderUnSync(final WsFolder folder) {
|
private void performFolderUnSync(final WsFolder folder) {
|
||||||
GWT.log("Performing doSyncFolder on: "+folder);
|
GWT.log("Performing doSyncFolder on: "+folder);
|
||||||
final Modal box = new Modal(true);
|
final Modal box = new Modal(true);
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package org.gcube.portlets.widgets.wsthreddssync.client.rpc;
|
package org.gcube.portlets.widgets.wsthreddssync.client.rpc;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
|
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
|
||||||
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
|
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
|
||||||
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
|
||||||
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
|
||||||
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
|
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
|
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
|
||||||
|
@ -79,4 +81,13 @@ public interface ThreddsWorkspaceSyncService extends RemoteService {
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
Boolean doUnSyncFolder(String folderId) throws Exception;
|
Boolean doUnSyncFolder(String folderId) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package org.gcube.portlets.widgets.wsthreddssync.client.rpc;
|
package org.gcube.portlets.widgets.wsthreddssync.client.rpc;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
|
||||||
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
|
||||||
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
|
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
|
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
|
||||||
|
@ -109,4 +111,7 @@ public interface ThreddsWorkspaceSyncServiceAsync
|
||||||
* @param callback the callback
|
* @param callback the callback
|
||||||
*/
|
*/
|
||||||
void doUnSyncFolder(String folderId, AsyncCallback<Boolean> callback);
|
void doUnSyncFolder(String folderId, AsyncCallback<Boolean> callback);
|
||||||
|
|
||||||
|
|
||||||
|
void getScopesWithThreddsRolesForLoggedUser(AsyncCallback<Map<String, GatewayRolesThredds>> callback);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package org.gcube.portlets.widgets.wsthreddssync.client.view;
|
package org.gcube.portlets.widgets.wsthreddssync.client.view;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -34,8 +32,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
import com.google.gwt.user.client.ui.Button;
|
import com.google.gwt.user.client.ui.Button;
|
||||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
|
||||||
/**
|
/**
|
||||||
* The Class WsThreddsWidgetViewManager.
|
* The Class WsThreddsWidgetViewManager.
|
||||||
*
|
*
|
||||||
|
@ -44,8 +40,10 @@ import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
*/
|
*/
|
||||||
public class WsThreddsWidgetViewManager {
|
public class WsThreddsWidgetViewManager {
|
||||||
|
|
||||||
private Map<String, MonitorFolderSyncStatusView> mapMonitor = new HashMap<String, MonitorFolderSyncStatusView>();
|
public static final String CREATE_CONFIGURATION = "Create Configuration";
|
||||||
|
public static final String THIS_FOLDER_IS_NOT_CONFIGURED_DO_YOU_WANT_CREATE_A_CONFIGURATION = "This Folder is not configured. Do you want create a configuration?";
|
||||||
|
|
||||||
|
private Map<String, MonitorFolderSyncStatusView> mapMonitor = new HashMap<String, MonitorFolderSyncStatusView>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new ws thredds widget view manager.
|
* Instantiates a new ws thredds widget view manager.
|
||||||
|
@ -332,8 +330,10 @@ public class WsThreddsWidgetViewManager {
|
||||||
*
|
*
|
||||||
* @param folder the folder
|
* @param folder the folder
|
||||||
* @param folderDescriptor the folder descriptor
|
* @param folderDescriptor the folder descriptor
|
||||||
|
* @param isThreddsAdmin the is thredds admin
|
||||||
|
* @param isThreddsPubliser the is thredds publiser
|
||||||
*/
|
*/
|
||||||
public void showThreddsFolderInfo(final WsFolder folder, final WsThreddsSynchFolderDescriptor folderDescriptor){
|
public void showThreddsFolderInfo(final WsFolder folder, final WsThreddsSynchFolderDescriptor folderDescriptor, final boolean isThreddsAdmin, final boolean isThreddsPubliser){
|
||||||
GWT.log("ShowThreddsFolderInfo folder: "+folder);
|
GWT.log("ShowThreddsFolderInfo folder: "+folder);
|
||||||
//GWT.log("WsThreddsSynchFolderDescriptor is: "+folderDescriptor);
|
//GWT.log("WsThreddsSynchFolderDescriptor is: "+folderDescriptor);
|
||||||
|
|
||||||
|
@ -358,10 +358,10 @@ public class WsThreddsWidgetViewManager {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
boolean isCreateConfiguration = folderDescriptor==null?true:false;
|
final boolean isCreateConfiguration = folderDescriptor==null?true:false;
|
||||||
|
|
||||||
|
|
||||||
ShowThreddsFolderInfoView folderInfo = new ShowThreddsFolderInfoView(folder.getFolderId(), isCreateConfiguration) {
|
final ShowThreddsFolderInfoView folderInfo = new ShowThreddsFolderInfoView(folder.getFolderId(), isCreateConfiguration) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void submitHandler(SUBMIT_ACTION action) {
|
public void submitHandler(SUBMIT_ACTION action) {
|
||||||
|
@ -413,35 +413,57 @@ public class WsThreddsWidgetViewManager {
|
||||||
|
|
||||||
if(isCreateConfiguration) {
|
if(isCreateConfiguration) {
|
||||||
folderInfo.getMainPanel().setVisible(false);
|
folderInfo.getMainPanel().setVisible(false);
|
||||||
folderInfo.setError(true, "This Folder is not configured. Do you want create a configuration?");
|
|
||||||
folderInfo.getPager().getLeft().setText("Create 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);
|
||||||
|
}
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
//USER CAN PERFORM DO SYNC
|
//USER CAN PERFORM DO SYNC
|
||||||
//MOREOVER, HE/SHE COULD UPDATE THE CONFIGURATION BUT IT IS NOT SUPPORTED SERVER-SIDE
|
//MOREOVER, HE/SHE COULD UPDATE THE CONFIGURATION BUT IT IS NOT SUPPORTED SERVER-SIDE
|
||||||
|
|
||||||
|
//hiding create/update configuration
|
||||||
folderInfo.getPager().getLeft().setVisible(false);
|
folderInfo.getPager().getLeft().setVisible(false);
|
||||||
|
|
||||||
if(folderDescriptor.getServerFolderDescriptor().isLocked()) {
|
if(isThreddsPubliser || isThreddsAdmin) {
|
||||||
VerticalPanel v = new VerticalPanel();
|
|
||||||
Alert alert = new Alert("Current Folder synchronization is locked by another proccess. Do you want see synchronization status?");
|
|
||||||
alert.setClose(true);
|
|
||||||
alert.setType(AlertType.INFO);
|
|
||||||
|
|
||||||
Button butt = new Button("Show Status");
|
//hiding unsync button if the user is a publisher
|
||||||
butt.addClickHandler(new ClickHandler() {
|
if(isThreddsPubliser)
|
||||||
|
folderInfo.showUnsyncButton(false);
|
||||||
|
|
||||||
@Override
|
if(folderDescriptor.getServerFolderDescriptor().isLocked()) {
|
||||||
public void onClick(ClickEvent event) {
|
VerticalPanel v = new VerticalPanel();
|
||||||
WsThreddsWidget.eventBus.fireEvent(new ShowMonitorSyncStatusEvent(folder));
|
Alert alert = new Alert("Current Folder synchronization is locked by another proccess. Do you want see synchronization status?");
|
||||||
}
|
alert.setClose(true);
|
||||||
});
|
alert.setType(AlertType.INFO);
|
||||||
|
|
||||||
v.add(alert);
|
Button butt = new Button("Show Status");
|
||||||
v.add(butt);
|
butt.addClickHandler(new ClickHandler() {
|
||||||
box.add(v);
|
|
||||||
|
@Override
|
||||||
|
public void onClick(ClickEvent event) {
|
||||||
|
WsThreddsWidget.eventBus.fireEvent(new ShowMonitorSyncStatusEvent(folder));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
v.add(alert);
|
||||||
|
v.add(butt);
|
||||||
|
box.add(v);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
//DoSync button
|
||||||
|
folderInfo.getPager().getRight().setVisible(false);
|
||||||
|
folderInfo.setError(true, WsThreddsWidget.MISSING_THREDDS_PUBLISHER_RIGHTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
panelView.addViewAsWidget(folderInfo);
|
panelView.addViewAsWidget(folderInfo);
|
||||||
box.add(panelView);
|
box.add(panelView);
|
||||||
box.show();
|
box.show();
|
||||||
|
|
|
@ -357,5 +357,15 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show unsync.
|
||||||
|
*
|
||||||
|
* @param show the show
|
||||||
|
*/
|
||||||
|
public void showUnsyncButton(boolean show) {
|
||||||
|
button_do_unsync.setVisible(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package org.gcube.portlets.widgets.wsthreddssync.server;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class GenericUtils.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||||
|
*
|
||||||
|
* Mar 3, 2021
|
||||||
|
*/
|
||||||
|
public class GenericUtils {
|
||||||
|
|
||||||
|
public static Logger LOG = LoggerFactory.getLogger(GenericUtils.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the gateway client hostname.
|
||||||
|
*
|
||||||
|
* @param httpServletRequest the http servlet request
|
||||||
|
* @return the gateway client hostname
|
||||||
|
*/
|
||||||
|
public static String getGatewayClientHostname(HttpServletRequest httpServletRequest) {
|
||||||
|
try {
|
||||||
|
String clientURL = httpServletRequest.getRequestURL().toString();
|
||||||
|
URL gURL = new URL(clientURL);
|
||||||
|
StringBuilder theURL = new StringBuilder();
|
||||||
|
// theURL.append(gURL.getProtocol());
|
||||||
|
// theURL.append("://");
|
||||||
|
theURL.append(gURL.getHost());
|
||||||
|
return theURL.toString();
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
LOG.warn("Failed to determine the gateway from the client url: "+httpServletRequest.getRequestURL());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -2,7 +2,10 @@ package org.gcube.portlets.widgets.wsthreddssync.server;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
|
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
|
||||||
|
@ -13,6 +16,7 @@ import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
|
||||||
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
|
||||||
import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration;
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService;
|
import org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService;
|
||||||
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScopeType;
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScopeType;
|
||||||
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
|
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
|
||||||
|
@ -71,7 +75,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.trace("Development Mode ON");
|
logger.warn("Development Mode ON");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,6 +152,44 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception{
|
||||||
|
logger.info("called getScopesWithThreddsRolesForLoggedUser");
|
||||||
|
|
||||||
|
GCubeUser user = null;
|
||||||
|
Map<String, GatewayRolesThredds> mapScopesRoles = null;
|
||||||
|
|
||||||
|
//DEV MODE
|
||||||
|
if (!isWithinPortal()){
|
||||||
|
mapScopesRoles = new HashMap<String, GatewayRolesThredds>();
|
||||||
|
// mapScopesRoles.put( "/gcube/devsec/devVRE", GatewayRolesThredds.THREDDS_PUBLISHER);
|
||||||
|
// mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER);
|
||||||
|
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER);
|
||||||
|
return mapScopesRoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
||||||
|
mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user);
|
||||||
|
|
||||||
|
logger.info("returning Map(scopes,roles): "+mapScopesRoles);
|
||||||
|
return mapScopesRoles;
|
||||||
|
}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);
|
||||||
|
throw new Exception(errorMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the list of VR es for logged user.
|
* Gets the list of VR es for logged user.
|
||||||
*
|
*
|
||||||
|
@ -156,7 +198,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GcubeScope> getListOfScopesForLoggedUser() throws Exception{
|
public List<GcubeScope> getListOfScopesForLoggedUser() throws Exception{
|
||||||
logger.debug("getListOfVREsForLoggedUser...: ");
|
logger.info("getListOfVREsForLoggedUser...: ");
|
||||||
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
||||||
long userId = user.getUserId();
|
long userId = user.getUserId();
|
||||||
|
|
||||||
|
@ -164,6 +206,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
|
||||||
GroupManager groupManager = new LiferayGroupManager();
|
GroupManager groupManager = new LiferayGroupManager();
|
||||||
List<GcubeScope> listOfScopes = new ArrayList<GcubeScope>();
|
List<GcubeScope> listOfScopes = new ArrayList<GcubeScope>();
|
||||||
|
|
||||||
|
//DEV MODE
|
||||||
if (!isWithinPortal()){
|
if (!isWithinPortal()){
|
||||||
listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE));
|
listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE));
|
||||||
listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE));
|
listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE));
|
||||||
|
@ -176,7 +219,13 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(userId);
|
String gatewayHostname = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
|
||||||
|
//list of Scopes filtered for gateway
|
||||||
|
Set<GCubeGroup> filteredGroupsForGatw = groupManager.listGroupsByUserAndSite(userId, gatewayHostname);
|
||||||
|
|
||||||
|
//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());
|
||||||
for (GCubeGroup gCubeGroup : listOfGroups) {
|
for (GCubeGroup gCubeGroup : listOfGroups) {
|
||||||
GcubeScopeType scopeType=null;
|
GcubeScopeType scopeType=null;
|
||||||
if(groupManager.isVRE(gCubeGroup.getGroupId())){
|
if(groupManager.isVRE(gCubeGroup.getGroupId())){
|
||||||
|
@ -189,16 +238,27 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if(scopeType!=null){
|
if(scopeType!=null){
|
||||||
GcubeScope gcubeVRE = new GcubeScope(gCubeGroup.getGroupName(), groupManager.getInfrastructureScope(gCubeGroup.getGroupId()), scopeType);
|
GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, gCubeGroup);
|
||||||
listOfScopes.add(gcubeVRE);
|
//Adding only the scope where the user has the THREDDS_ADMIN role
|
||||||
|
GcubeScope gcubeScope = availableScopeForRoleAndCatalogue(roles, gCubeGroup, 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 = availableScopeForRoleAndCatalogue(roles, theRootVO, groupManager, GcubeScopeType.ROOT);
|
||||||
|
if(gcubeScope!=null) {
|
||||||
|
listOfScopes.add(gcubeScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
//ADDING THE ROOT SCOPE
|
//ADDING THE ROOT SCOPE
|
||||||
String infraName = PortalContext.getConfiguration().getInfrastructureName();
|
/*String infraName = PortalContext.getConfiguration().getInfrastructureName();
|
||||||
GcubeScope gcubeRoot = new GcubeScope(infraName, "/"+infraName, GcubeScopeType.ROOT);
|
GcubeScope gcubeRoot = new GcubeScope(infraName, "/"+infraName, GcubeScopeType.ROOT);
|
||||||
listOfScopes.add(gcubeRoot);
|
listOfScopes.add(gcubeRoot)*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -208,14 +268,71 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
|
||||||
throw new Exception("Sorry, an error occurred server-side getting VRE folders, try again later");
|
throw new Exception("Sorry, an error occurred server-side getting VRE folders, try again later");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(listOfScopes.isEmpty()) {
|
||||||
|
throw new Exception("No scope detected with the needed role: "+GatewayRolesThredds.THREDDS_ADMIN.getRoleName()+". Contact the VRE manager or the portal administrator");
|
||||||
|
}
|
||||||
|
|
||||||
Collections.sort(listOfScopes);
|
Collections.sort(listOfScopes);
|
||||||
logger.info("Returning list of VREs: "+listOfScopes);
|
logger.info("Returning list of allowed scope/s with: "+GatewayRolesThredds.THREDDS_ADMIN + " role/s: "+listOfScopes);
|
||||||
return listOfScopes;
|
return listOfScopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available scope for role and catalogue, 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 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
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
private GcubeScope availableScopeForRoleAndCatalogue(GatewayRolesThredds role, GCubeGroup scope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception {
|
||||||
|
|
||||||
|
if(role!=null && role.equals(GatewayRolesThredds.THREDDS_ADMIN)) {
|
||||||
|
try {
|
||||||
|
List<ThCatalogueBean> list = getAvailableCataloguesForScope(scope.getGroupName());
|
||||||
|
if(list!=null) {
|
||||||
|
return new GcubeScope(scope.getGroupName(), groupManager.getInfrastructureScope(scope.getGroupId()), scopeType);
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
logger.error("Error on checking available catalogue for scope: "+scope.getGroupName(), 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.THREDDS_ADMIN)) {
|
||||||
|
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)
|
/* (non-Javadoc)
|
||||||
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#isItemSynched(java.lang.String)
|
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#isItemSynched(java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
@ -271,6 +388,14 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monitor sync status.
|
||||||
|
*
|
||||||
|
* @param folderId the folder id
|
||||||
|
* @return the th sync status
|
||||||
|
* @throws ItemNotSynched the item not synched
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#monitorSyncStatus(java.lang.String)
|
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#monitorSyncStatus(java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
@ -287,7 +412,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
|
||||||
* Do sync folder.
|
* Do sync folder.
|
||||||
*
|
*
|
||||||
* @param folderId the folder id
|
* @param folderId the folder id
|
||||||
* @param clientConfig the th config
|
|
||||||
* @return the th sync status
|
* @return the th sync status
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.portlets.widgets.wsthreddssync.server;
|
package org.gcube.portlets.widgets.wsthreddssync.server;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||||
|
@ -14,6 +19,16 @@ import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
||||||
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
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.impl.LiferayGroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
||||||
//import org.gcube.portlets.user.workspace.server.util.WsUtil;
|
//import org.gcube.portlets.user.workspace.server.util.WsUtil;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -21,7 +36,6 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class WsUtil.
|
* The Class WsUtil.
|
||||||
*
|
*
|
||||||
|
@ -30,6 +44,9 @@ import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
*/
|
*/
|
||||||
public class WsUtil {
|
public class WsUtil {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** The logger. */
|
||||||
private static Logger logger = LoggerFactory.getLogger(WsUtil.class);
|
private static Logger logger = LoggerFactory.getLogger(WsUtil.class);
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,4 +113,76 @@ public class WsUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them.
|
||||||
|
*
|
||||||
|
* @param user the user
|
||||||
|
* @return the VREs and Thredds roles for a given user
|
||||||
|
*/
|
||||||
|
public static Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForUser(GCubeUser user){
|
||||||
|
logger.info("called getScopesThreddsRolesForUser user: "+user+", in all contexts");
|
||||||
|
|
||||||
|
GroupManager groupManager = new LiferayGroupManager();
|
||||||
|
Map<String, GatewayRolesThredds> mapRoleByGroupSingleVre = new HashMap<String, GatewayRolesThredds>();
|
||||||
|
try {
|
||||||
|
|
||||||
|
//Retrieving the list of VOs and VREs
|
||||||
|
List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(user.getUserId());
|
||||||
|
//adding also the ROOT-VO
|
||||||
|
listOfGroups.add(groupManager.getRootVO());
|
||||||
|
for (GCubeGroup gCubeGroup : listOfGroups) {
|
||||||
|
GatewayRolesThredds threddsRole = getThreddsRoleFor(user, gCubeGroup);
|
||||||
|
if(threddsRole != null) {
|
||||||
|
mapRoleByGroupSingleVre.put(gCubeGroup.getGroupName(), threddsRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("For user: "+user+", returning Map (VRE, ThreddsRoles) " + mapRoleByGroupSingleVre);
|
||||||
|
return mapRoleByGroupSingleVre;
|
||||||
|
}catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
|
||||||
|
logger.error("An error occurred during geThreddsVreRolesForUser: "+user, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the (highest) thredds role for the user in the scope
|
||||||
|
*
|
||||||
|
* @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());
|
||||||
|
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.THREDDS_ADMIN.getRoleName())){
|
||||||
|
threddsRoles.add(GatewayRolesThredds.THREDDS_ADMIN);
|
||||||
|
}
|
||||||
|
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.THREDDS_PUBLISHER.getRoleName())){
|
||||||
|
threddsRoles.add(GatewayRolesThredds.THREDDS_PUBLISHER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("For user: "+user+" in the scope: "+scope.getGroupName()+" read the role/s: " + threddsRoles);
|
||||||
|
|
||||||
|
GatewayRolesThredds toReturn = null;
|
||||||
|
if (threddsRoles.contains(GatewayRolesThredds.THREDDS_ADMIN))
|
||||||
|
toReturn = GatewayRolesThredds.THREDDS_ADMIN;
|
||||||
|
else if (threddsRoles.contains(GatewayRolesThredds.THREDDS_PUBLISHER))
|
||||||
|
toReturn = GatewayRolesThredds.THREDDS_PUBLISHER;
|
||||||
|
|
||||||
|
logger.info("returning role: " + toReturn);
|
||||||
|
return toReturn;
|
||||||
|
}catch (UserRetrievalFault | GroupRetrievalFault e) {
|
||||||
|
logger.error("An error occurred during getVreRoleForUser: "+user, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package org.gcube.portlets.widgets.wsthreddssync.shared;
|
||||||
|
|
||||||
|
public enum GatewayRolesThredds {
|
||||||
|
|
||||||
|
THREDDS_ADMIN("Thredds-Admin"),
|
||||||
|
THREDDS_PUBLISHER("Thredds-Publisher");
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private GatewayRolesThredds(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoleName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue