2018-03-02 17:03:57 +01:00
package org.gcube.portlets.widgets.wsthreddssync.client.view ;
import java.util.HashMap ;
2018-03-14 15:37:08 +01:00
import java.util.List ;
2018-03-02 17:03:57 +01:00
import java.util.Map ;
import org.gcube.portal.wssynclibrary.shared.thredds.Status ;
2018-03-08 17:59:33 +01:00
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean ;
2018-03-02 17:03:57 +01:00
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus ;
2018-03-14 15:37:08 +01:00
import org.gcube.portlets.widgets.wsthreddssync.client.SyncCompletedNotification.SyncCompletedNotificationListner ;
2021-03-11 16:42:09 +01:00
import org.gcube.portlets.widgets.wsthreddssync.client.WsThreddsSyncConstants ;
2018-03-02 17:03:57 +01:00
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 ;
import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.AbstractViewDialogBox ;
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 ;
2021-03-11 16:42:09 +01:00
import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds ;
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope ;
2018-03-02 17:03:57 +01:00
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.shared.GWT ;
import com.google.gwt.event.dom.client.ClickEvent ;
import com.google.gwt.event.dom.client.ClickHandler ;
2018-03-13 15:09:36 +01:00
import com.google.gwt.user.client.Command ;
2018-03-02 17:03:57 +01:00
import com.google.gwt.user.client.Timer ;
2018-03-13 15:09:36 +01:00
import com.google.gwt.user.client.Window ;
2018-03-02 17:03:57 +01:00
import com.google.gwt.user.client.rpc.AsyncCallback ;
import com.google.gwt.user.client.ui.Button ;
import com.google.gwt.user.client.ui.VerticalPanel ;
/ * *
* The Class WsThreddsWidgetViewManager .
*
* @author Francesco Mangiacrapa francesco . mangiacrapa @isti.cnr.it
* Feb 19 , 2018
* /
public class WsThreddsWidgetViewManager {
2018-03-05 15:44:51 +01:00
2021-03-04 16:24:54 +01:00
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? " ;
2018-03-02 17:03:57 +01:00
private Map < String , MonitorFolderSyncStatusView > mapMonitor = new HashMap < String , MonitorFolderSyncStatusView > ( ) ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
/ * *
* Instantiates a new ws thredds widget view manager .
* /
public WsThreddsWidgetViewManager ( ) {
}
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
/ * *
* Cancel monitor .
*
* @param folder the folder
* /
public void cancelMonitor ( WsFolder folder ) {
try {
2018-03-05 10:59:30 +01:00
MonitorFolderSyncStatusView monitor = cancelScheduler ( folder ) ;
2018-03-05 11:31:46 +01:00
if ( monitor ! = null ) {
GWT . log ( " Removed monitor for folder: " + folder . getFolderId ( ) ) ;
2018-03-05 10:59:30 +01:00
mapMonitor . remove ( folder . getFolderId ( ) ) ;
2018-03-05 11:31:46 +01:00
}
2018-03-02 17:03:57 +01:00
} catch ( Exception e ) {
2018-03-05 10:59:30 +01:00
GWT . log ( " Error on removing map monitor for id: " + folder . getFolderId ( ) ) ;
2018-03-02 17:03:57 +01:00
}
}
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
/ * *
* Gets the monitor .
*
* @param folder the folder
* @return the monitor
* /
public MonitorFolderSyncStatusView getMonitor ( WsFolder folder ) {
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
if ( folder = = null )
return null ;
return mapMonitor . get ( folder . getFolderId ( ) ) ;
}
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
/ * *
* Save monitor .
*
* @param folder the folder
* @param monitor the monitor
* /
private void saveMonitor ( WsFolder folder , MonitorFolderSyncStatusView monitor ) {
2018-03-02 17:26:44 +01:00
GWT . log ( " Saving monitor for folder: " + folder . getFolderId ( ) ) ;
2018-03-02 17:03:57 +01:00
mapMonitor . put ( folder . getFolderId ( ) , monitor ) ;
}
2018-03-05 15:44:51 +01:00
2018-03-05 10:59:30 +01:00
/ * *
* Cancel scheduler .
*
* @param folder the folder
2018-03-05 15:44:51 +01:00
* @return
2018-03-05 10:59:30 +01:00
* /
private MonitorFolderSyncStatusView cancelScheduler ( final WsFolder folder ) {
2018-03-05 15:44:51 +01:00
2018-03-05 10:59:30 +01:00
MonitorFolderSyncStatusView monitor = getMonitor ( folder ) ;
if ( monitor . getSchedulerTime ( ) ! = null ) {
GWT . log ( " Cancelling scheduler time on folder: " + folder . getFolderId ( ) ) ;
monitor . getSchedulerTime ( ) . cancel ( ) ;
}
2018-03-05 15:44:51 +01:00
2018-03-05 10:59:30 +01:00
return monitor ;
2018-03-05 15:44:51 +01:00
2018-03-05 10:59:30 +01:00
}
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
/ * *
* Show monitor sync to folder .
*
* @param folder the folder
2018-03-14 15:37:08 +01:00
* @param syncEventsListeners
2018-03-02 17:03:57 +01:00
* /
2018-03-14 15:37:08 +01:00
public void showMonitorSyncToFolder ( final WsFolder folder , final List < SyncCompletedNotificationListner > syncEventsListeners ) {
2018-03-05 15:44:51 +01:00
GWT . log ( " showMonitorSyncToFolder for folder: " + folder . getFolderId ( ) ) ;
2018-03-02 17:03:57 +01:00
final Modal box = new Modal ( true ) ;
box . addStyleName ( " ws-thredds-modal-body " ) ;
box . setTitle ( " Monitor transferring of: " + FormatUtil . getFolderTitle ( folder . getFoderName ( ) , 20 ) ) ;
box . setWidth ( 800 ) ;
2018-03-05 11:54:33 +01:00
box . hide ( false ) ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
MonitorFolderSyncStatusView monitorView = getMonitor ( folder ) ;
2018-03-05 15:44:51 +01:00
GWT . log ( " monitorView is: " + monitorView ) ;
2018-03-02 17:26:44 +01:00
2018-03-02 17:03:57 +01:00
final AbstractViewDialogBox panelView = new AbstractViewDialogBox ( ) {
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
@Override
public void closeHandler ( ) {
2018-03-05 10:59:30 +01:00
//cancelScheduler(folder);
2018-03-02 17:03:57 +01:00
box . hide ( ) ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
}
2018-03-13 15:09:36 +01:00
@Override
public void confirmHanlder ( CONFIRM_VALUE confirm , Command command ) {
// TODO Auto-generated method stub
}
2018-03-02 17:03:57 +01:00
} ;
2018-03-05 10:59:30 +01:00
2018-03-02 17:03:57 +01:00
if ( monitorView = = null ) {
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
monitorView = new MonitorFolderSyncStatusView ( ) {
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
@Override
2018-03-05 15:44:51 +01:00
public void closetHandler ( ) {
2018-03-02 17:03:57 +01:00
//TODO CLIENT SIDE?
2018-03-02 17:26:44 +01:00
//cancelMonitor(folder);
2018-03-05 15:44:51 +01:00
panelView . closeHandler ( ) ;
2018-03-02 17:03:57 +01:00
}
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
@Override
public void setError ( boolean visible , String error ) {
panelView . setError ( visible , error ) ;
}
} ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
}
2018-03-05 15:44:51 +01:00
2018-03-05 11:20:58 +01:00
if ( monitorView . getSchedulerTime ( ) = = null ) {
2018-03-05 15:44:51 +01:00
2018-03-05 11:20:58 +01:00
//Removing old monitor
//cancelMonitor(folder);
//Creating new one
final MonitorFolderSyncStatusView currentMonitor = monitorView ;
2018-03-05 15:44:51 +01:00
2018-03-05 11:20:58 +01:00
Timer schedulingTimer = new Timer ( ) {
2018-03-05 15:44:51 +01:00
2018-03-05 11:20:58 +01:00
@Override
public void run ( ) {
2018-03-05 15:44:51 +01:00
2018-03-05 11:20:58 +01:00
WsThreddsWidget . wsThreddsSyncService . monitorSyncStatus ( folder . getFolderId ( ) , new AsyncCallback < ThSyncStatus > ( ) {
2018-03-05 15:44:51 +01:00
2018-03-05 11:20:58 +01:00
@Override
public void onFailure ( Throwable caught ) {
cancelMonitor ( folder ) ;
2018-03-13 15:09:36 +01:00
Window . alert ( caught . getMessage ( ) ) ;
2018-03-14 15:37:08 +01:00
//CALLING METHOD ON SYNC ERROR TO THE LISTENERS
for ( SyncCompletedNotificationListner listener : syncEventsListeners ) {
listener . onSyncError ( folder ) ;
}
2018-03-05 11:20:58 +01:00
}
2018-03-05 15:44:51 +01:00
2018-03-05 11:20:58 +01:00
@Override
public void onSuccess ( ThSyncStatus status ) {
2018-03-05 15:44:51 +01:00
GWT . log ( " monitorSyncStatus: " + status ) ;
2018-03-05 11:54:33 +01:00
if ( status = = null ) {
GWT . log ( " The status is null server-side, cancelling polling " ) ;
cancelMonitor ( folder ) ;
}
2018-03-05 15:44:51 +01:00
2018-03-05 11:20:58 +01:00
currentMonitor . updateStatusView ( folder , status ) ;
2018-03-05 15:44:51 +01:00
2018-03-05 11:20:58 +01:00
if ( status ! = null & & status . getProcessStatus ( ) ! = null ) {
2018-03-05 15:44:51 +01:00
2018-03-05 11:20:58 +01:00
if ( status . getProcessStatus ( ) . getStatus ( ) . equals ( Status . COMPLETED ) ) {
GWT . log ( " Sync completed cancel the polling: " + status ) ;
cancelMonitor ( folder ) ;
2018-03-14 15:37:08 +01:00
//CALLING METHOD ON SYNC COMPLETED TO THE LISTENERS
for ( SyncCompletedNotificationListner listener : syncEventsListeners ) {
listener . onSyncCompleted ( folder ) ;
}
2018-03-05 11:20:58 +01:00
}
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
}
}
2018-03-05 11:20:58 +01:00
} ) ;
}
} ;
2018-03-05 15:44:51 +01:00
2018-03-05 11:20:58 +01:00
schedulingTimer . scheduleRepeating ( 2000 ) ;
currentMonitor . setScheduler ( schedulingTimer ) ;
saveMonitor ( folder , currentMonitor ) ;
2018-03-05 15:44:51 +01:00
2018-03-05 11:20:58 +01:00
}
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
panelView . addViewAsWidget ( monitorView ) ;
box . add ( panelView ) ;
box . show ( ) ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
}
/ * *
* Show create configuration folder .
*
* @param folder the folder
* @param conf the conf
* /
public void showCreateConfigurationFolder ( final WsFolder folder , WsThreddsSynchFolderDescriptor conf ) {
final Modal box = new Modal ( true ) ;
box . setTitle ( " Create Thredds Sync Configuration for: " + FormatUtil . getFolderTitle ( folder . getFoderName ( ) , 20 ) ) ;
//box.getElement().getStyle().setZIndex(10000);
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
final AbstractViewDialogBox panelView = new AbstractViewDialogBox ( ) {
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
@Override
public void closeHandler ( ) {
box . hide ( ) ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
}
2018-03-13 15:09:36 +01:00
@Override
public void confirmHanlder ( CONFIRM_VALUE confirm , Command command ) {
if ( confirm . equals ( CONFIRM_VALUE . YES ) ) {
box . hide ( ) ;
}
if ( command ! = null )
command . execute ( ) ;
}
2018-03-02 17:03:57 +01:00
} ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
CreateThreddsConfigurationView createThreddsConfiguration = new CreateThreddsConfigurationView ( folder . getFolderId ( ) ) {
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
@Override
public void submitHandler ( ) {
2018-03-05 15:44:51 +01:00
panelView . closeHandler ( ) ;
2018-03-02 17:03:57 +01:00
WsThreddsSynchFolderConfiguration conf = new WsThreddsSynchFolderConfiguration ( ) ;
conf . setFilter ( null ) ;
2018-03-08 17:59:33 +01:00
ThCatalogueBean catalogueSelected = getSelectedCatalogue ( ) ;
2018-03-09 12:46:50 +01:00
String remotePath = catalogueSelected . getPath ( ) ! = null ? catalogueSelected . getPath ( ) : " " ;
remotePath = remotePath . isEmpty ( ) ? getFolderName ( ) : remotePath + " / " + getFolderName ( ) ;
conf . setRemotePath ( remotePath ) ;
2018-03-08 17:59:33 +01:00
conf . setCatalogName ( catalogueSelected . getName ( ) ) ;
2018-03-12 17:43:51 +01:00
conf . setSelectedScope ( getSelectedScope ( ) ) ;
2018-03-28 14:55:45 +02:00
conf . setRootFolderId ( folder . getFolderId ( ) ) ;
2018-03-02 17:03:57 +01:00
WsThreddsWidget . eventBus . fireEvent ( new PerformDoSyncEvent ( folder , conf ) ) ;
}
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
@Override
public void setError ( boolean visible , String error ) {
panelView . setError ( visible , error ) ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
}
2018-03-13 15:09:36 +01:00
@Override
public void setConfirm ( boolean visible , String msg ) {
Command yes = new Command ( ) {
@Override
public void execute ( ) {
submitHandler ( ) ;
}
} ;
Command no = new Command ( ) {
@Override
public void execute ( ) {
panelView . setConfirm ( false , " " , null , null ) ;
}
} ;
panelView . setConfirm ( visible , msg , yes , no ) ;
}
2018-03-02 17:03:57 +01:00
} ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
panelView . addViewAsWidget ( createThreddsConfiguration ) ;
box . add ( panelView ) ;
box . show ( ) ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
}
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
/ * *
* Show thredds folder info .
*
* @param folder the folder
* @param folderDescriptor the folder descriptor
2021-03-11 16:42:09 +01:00
* @param mapScopeThreddsRoles the map scope with thredds roles
2018-03-02 17:03:57 +01:00
* /
2021-03-11 16:42:09 +01:00
public void showThreddsFolderInfo ( final WsFolder folder , final WsThreddsSynchFolderDescriptor folderDescriptor , Map < String , GatewayRolesThredds > mapScopeThreddsRoles ) {
2018-03-02 17:03:57 +01:00
GWT . log ( " ShowThreddsFolderInfo folder: " + folder ) ;
2018-03-05 15:44:51 +01:00
//GWT.log("WsThreddsSynchFolderDescriptor is: "+folderDescriptor);
2018-03-02 17:03:57 +01:00
final Modal box = new Modal ( true ) ;
2021-05-18 15:31:58 +02:00
box . getElement ( ) . addClassName ( " modal-sync-widget-config " ) ;
box . setWidth ( 600 ) ;
2018-03-02 17:03:57 +01:00
box . setTitle ( " Thredds Sync Information for: " + FormatUtil . getFolderTitle ( folder . getFoderName ( ) , 20 ) ) ;
2021-03-11 16:42:09 +01:00
2018-03-02 17:03:57 +01:00
final AbstractViewDialogBox panelView = new AbstractViewDialogBox ( ) {
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
@Override
public void closeHandler ( ) {
box . hide ( ) ;
}
2018-03-13 15:09:36 +01:00
@Override
public void confirmHanlder ( CONFIRM_VALUE confirm , Command command ) {
}
2018-03-02 17:03:57 +01:00
} ;
2018-03-05 15:44:51 +01:00
2021-03-04 16:24:54 +01:00
final boolean isCreateConfiguration = folderDescriptor = = null ? true : false ;
2021-03-11 16:42:09 +01:00
//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 ) ;
}
2021-03-04 16:24:54 +01:00
final ShowThreddsFolderInfoView folderInfo = new ShowThreddsFolderInfoView ( folder . getFolderId ( ) , isCreateConfiguration ) {
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
@Override
public void submitHandler ( SUBMIT_ACTION action ) {
2018-03-05 15:44:51 +01:00
panelView . closeHandler ( ) ;
2018-03-02 17:03:57 +01:00
if ( action = = null )
return ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
switch ( action ) {
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
case CREATE_UPDATE_CONFIGURATION :
2018-03-13 17:39:09 +01:00
2018-03-02 17:03:57 +01:00
if ( folderDescriptor = = null ) {
GWT . log ( " Performing a create configuration " ) ;
//PERFORM A CREATE CONFIGURATION (AT FIRST TIME), THE CONFIGURATION DOES NOT EXITS
showCreateConfigurationFolder ( folder , null ) ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
}
// else {
// GWT.log("Performing an updated configuration");
// //PERFORM AN UPDATE CONFIGURATION. THE CONFIGURATION EXIST
// //BeanConverter.toWsThreddsFolderConfig(t, vre);
// showCreateConfigurationFolder(folder, result);
// }
2018-03-05 15:44:51 +01:00
//
2018-03-02 17:03:57 +01:00
break ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
case DO_SYNC :
GWT . log ( " Performing a do sync using server folder configuration " ) ;
//PERFORM A DO SYNC BUT NOT AT FIRST TIME
WsThreddsWidget . eventBus . fireEvent ( new PerformDoSyncEvent ( folder , null ) ) ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
break ;
default :
break ;
}
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
}
@Override
public void setError ( boolean visible , String error ) {
2018-03-05 15:44:51 +01:00
//panelView.setError(visible, error);
panelView . setInfo ( visible , error ) ;
2018-03-02 17:03:57 +01:00
}
} ;
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
folderInfo . updateViewToResult ( folder , folderDescriptor ) ;
2021-03-04 16:24:54 +01:00
2018-03-02 17:03:57 +01:00
if ( isCreateConfiguration ) {
folderInfo . getMainPanel ( ) . setVisible ( false ) ;
2021-03-04 16:24:54 +01:00
2021-03-11 16:42:09 +01:00
//If the user is a THREDDS_ADMIN in at least one scope, he/she can create a configuration.
2021-03-04 16:24:54 +01:00
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 ) ;
2021-03-11 16:42:09 +01:00
folderInfo . setError ( true , WsThreddsSyncConstants . RightsMissing . noCreateConfigRights ( ) ) ;
2021-03-04 16:24:54 +01:00
}
2018-03-02 17:03:57 +01:00
} else {
2021-03-11 16:42:09 +01:00
//IT IS DO SYNC OR READ/VIEW THE CURRENT CONFIGURATION
2018-03-02 17:03:57 +01:00
//MOREOVER, HE/SHE COULD UPDATE THE CONFIGURATION BUT IT IS NOT SUPPORTED SERVER-SIDE
2021-03-04 16:24:54 +01:00
//hiding create/update configuration
2018-03-05 15:44:51 +01:00
folderInfo . getPager ( ) . getLeft ( ) . setVisible ( false ) ;
2021-03-11 16:42:09 +01:00
//hiding delete syncr
folderInfo . showUnsyncButton ( false ) ;
//doSync button
folderInfo . getPager ( ) . getRight ( ) . setVisible ( false ) ;
//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 ) ;
}
}
2021-03-04 16:24:54 +01:00
2021-03-11 16:42:09 +01:00
//the user is ADMIN or EDITOR in the target scope
if ( isThreddsPublisherInTheTargetScope | | isThreddsAdminInTheTargetScope ) {
//he/she can run doSync
folderInfo . getPager ( ) . getRight ( ) . setVisible ( true ) ;
2021-03-04 16:24:54 +01:00
2021-03-11 16:42:09 +01:00
//showing unsync button if the user is an ADMIN
if ( isThreddsAdminInTheTargetScope ) {
folderInfo . showUnsyncButton ( true ) ;
}
2021-03-04 16:24:54 +01:00
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 ( ) {
2018-03-05 15:44:51 +01:00
2021-03-04 16:24:54 +01:00
@Override
public void onClick ( ClickEvent event ) {
WsThreddsWidget . eventBus . fireEvent ( new ShowMonitorSyncStatusEvent ( folder ) ) ;
}
} ) ;
2018-03-05 15:44:51 +01:00
2021-03-04 16:24:54 +01:00
v . add ( alert ) ;
v . add ( butt ) ;
box . add ( v ) ;
}
} else {
//DoSync button
folderInfo . getPager ( ) . getRight ( ) . setVisible ( false ) ;
2021-03-11 16:42:09 +01:00
folderInfo . setError ( true , WsThreddsSyncConstants . RightsMissing . noRunSyncRights ( targetScope . getScopeTitle ( ) ) ) ;
2018-03-02 17:03:57 +01:00
}
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
}
2021-03-04 16:24:54 +01:00
2018-03-05 15:44:51 +01:00
2018-03-02 17:03:57 +01:00
panelView . addViewAsWidget ( folderInfo ) ;
box . add ( panelView ) ;
box . show ( ) ;
2021-03-11 16:42:09 +01:00
2018-03-05 15:44:51 +01:00
}
2018-03-02 17:03:57 +01:00
}