Merge pull request 'feature_20847' (#1) from feature_20847 into master

feature_20979
Francesco Mangiacrapa 3 years ago
commit fe73dce86d

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

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ws-thredds-sync-widget</artifactId>
<packaging>jar</packaging>
<version>1.2.0</version>
<version>1.3.0-SNAPSHOT</version>
<name>ws-thredds-sync-widget</name>
<description>
gCube ws-thredds-sync-widget is a widget to use and interact with ws-thredds facility in order to syncronize the Workspace folders with Thredds Reporitory folders

@ -2,6 +2,7 @@ package org.gcube.portlets.widgets.wsthreddssync.client;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
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.WsThreddsWidgetViewManager;
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.WsThreddsSynchFolderConfiguration;
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.constants.AlertType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HorizontalPanel;
// TODO: Auto-generated Javadoc
@ -50,7 +55,13 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
private WsThreddsWidgetViewManager viewManager = new WsThreddsWidgetViewManager();
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.
*/
@ -142,38 +153,96 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
final Modal box = new Modal(true);
box.setTitle("Checking configurations...");
LoaderIcon loader = new LoaderIcon("Checking folder configurations...");
box.add(loader);
GWT.log("Performing isItemSynched: "+folder.getFolderId());
WsThreddsWidget.wsThreddsSyncService.isItemSynched(folder.getFolderId(), new AsyncCallback<WsThreddsSynchFolderDescriptor>() {
final HorizontalPanel hpLoader = new HorizontalPanel();
LoaderIcon loader = new LoaderIcon("Checking authorizations and folder configurations...");
hpLoader.add(loader);
box.add(hpLoader);
//LAOADING ROLES
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);
public void onFailure(Throwable caught) {
hpLoader.clear();
hpLoader.setVisible(false);
Alert alert = new Alert();
alert.setType(AlertType.INFO);
alert.setText(caught.getMessage());
box.add(alert);
}
@Override
public void onFailure(Throwable caught) {
box.hide();
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>() {
if(caught instanceof WorkspaceFolderLocked){
viewManager.showMonitorSyncToFolder(folder,syncEventsListeners);
@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;
}
viewManager.cancelMonitor(folder);
// TODO Auto-generated method stub
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 performFolderUnSync(final WsFolder folder) {
GWT.log("Performing doSyncFolder on: "+folder);

@ -1,11 +1,13 @@
package org.gcube.portlets.widgets.wsthreddssync.client.rpc;
import java.util.List;
import java.util.Map;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
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.WsThreddsSynchFolderConfiguration;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
@ -79,4 +81,13 @@ public interface ThreddsWorkspaceSyncService extends RemoteService {
* @throws Exception the 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;
import java.util.List;
import java.util.Map;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
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.WsThreddsSynchFolderConfiguration;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
@ -109,4 +111,7 @@ public interface ThreddsWorkspaceSyncServiceAsync
* @param callback the 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;
import java.util.HashMap;
import java.util.List;
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.VerticalPanel;
// TODO: Auto-generated Javadoc
/**
* The Class WsThreddsWidgetViewManager.
*
@ -44,9 +40,11 @@ import com.google.gwt.user.client.ui.VerticalPanel;
*/
public class WsThreddsWidgetViewManager {
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.
*/
@ -332,8 +330,10 @@ public class WsThreddsWidgetViewManager {
*
* @param folder the folder
* @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("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
public void submitHandler(SUBMIT_ACTION action) {
@ -410,37 +410,59 @@ public class WsThreddsWidgetViewManager {
};
folderInfo.updateViewToResult(folder, folderDescriptor);
if(isCreateConfiguration) {
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 {
//USER CAN PERFORM DO SYNC
//MOREOVER, HE/SHE COULD UPDATE THE CONFIGURATION BUT IT IS NOT SUPPORTED SERVER-SIDE
//hiding create/update configuration
folderInfo.getPager().getLeft().setVisible(false);
if(isThreddsPubliser || isThreddsAdmin) {
//hiding unsync button if the user is a publisher
if(isThreddsPubliser)
folderInfo.showUnsyncButton(false);
if(folderDescriptor.getServerFolderDescriptor().isLocked()) {
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");
butt.addClickHandler(new ClickHandler() {
if(folderDescriptor.getServerFolderDescriptor().isLocked()) {
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");
butt.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
WsThreddsWidget.eventBus.fireEvent(new ShowMonitorSyncStatusEvent(folder));
}
});
@Override
public void onClick(ClickEvent event) {
WsThreddsWidget.eventBus.fireEvent(new ShowMonitorSyncStatusEvent(folder));
}
});
v.add(alert);
v.add(butt);
box.add(v);
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);
box.add(panelView);

@ -355,6 +355,16 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
public HTMLPanel getMainPanel(){
return form_unit_fields;
}
/**
* 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.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gcube.common.portal.PortalContext;
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.ThSynchFolderConfiguration;
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.GcubeScopeType;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
@ -71,7 +75,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
return true;
}
catch (Exception ex) {
logger.trace("Development Mode ON");
logger.warn("Development Mode ON");
return false;
}
}
@ -146,6 +150,44 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
return listCtlgs;
}
/**
* 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);
}
}
/**
@ -156,14 +198,15 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
*/
@Override
public List<GcubeScope> getListOfScopesForLoggedUser() throws Exception{
logger.debug("getListOfVREsForLoggedUser...: ");
logger.info("getListOfVREsForLoggedUser...: ");
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
long userId = user.getUserId();
// Instanciate the manager
GroupManager groupManager = new LiferayGroupManager();
List<GcubeScope> listOfScopes = new ArrayList<GcubeScope>();
//DEV MODE
if (!isWithinPortal()){
listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE));
listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE));
@ -176,7 +219,13 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
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) {
GcubeScopeType scopeType=null;
if(groupManager.isVRE(gCubeGroup.getGroupId())){
@ -189,16 +238,27 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
// }
if(scopeType!=null){
GcubeScope gcubeVRE = new GcubeScope(gCubeGroup.getGroupName(), groupManager.getInfrastructureScope(gCubeGroup.getGroupId()), scopeType);
listOfScopes.add(gcubeVRE);
GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, gCubeGroup);
//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
String infraName = PortalContext.getConfiguration().getInfrastructureName();
/*String infraName = PortalContext.getConfiguration().getInfrastructureName();
GcubeScope gcubeRoot = new GcubeScope(infraName, "/"+infraName, GcubeScopeType.ROOT);
listOfScopes.add(gcubeRoot);
listOfScopes.add(gcubeRoot)*/
}
@ -207,15 +267,72 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
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.THREDDS_ADMIN.getRoleName()+". Contact the VRE manager or the portal administrator");
}
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;
}
/**
* 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)
* @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)
* @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.
*
* @param folderId the folder id
* @param clientConfig the th config
* @return the th sync status
* @throws Exception the exception
*/

@ -3,6 +3,11 @@
*/
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 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.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.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.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
@ -21,7 +36,6 @@ import org.slf4j.LoggerFactory;
import com.liferay.portal.service.UserLocalServiceUtil;
/**
* The Class WsUtil.
*
@ -29,7 +43,10 @@ import com.liferay.portal.service.UserLocalServiceUtil;
* Nov 25, 2016
*/
public class WsUtil {
/** The logger. */
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…
Cancel
Save