add Do UnSync interaction

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/ws-thredds-sync-widget@165023 82a268e6-3cf1-43bd-a215-b396298e98cf
pull/1/head
Francesco Mangiacrapa 6 years ago
parent 2e43561c98
commit dba7f8f501

@ -36,6 +36,14 @@ public class SyncCompletedNotification {
* @param folder the folder
*/
void onSyncError(WsFolder folder);
/**
* On un sync performed.
*
* @param folder the folder
*/
void onUnSyncPerformed(WsFolder folder);
}

@ -4,8 +4,12 @@ import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
import org.gcube.portlets.widgets.wsthreddssync.client.SyncCompletedNotification.HasWsSyncNotificationListner;
import org.gcube.portlets.widgets.wsthreddssync.client.SyncCompletedNotification.SyncCompletedNotificationListner;
import org.gcube.portlets.widgets.wsthreddssync.client.dialog.DialogConfirm;
import org.gcube.portlets.widgets.wsthreddssync.client.dialog.DialogResult;
import org.gcube.portlets.widgets.wsthreddssync.client.event.PerformDoSyncEvent;
import org.gcube.portlets.widgets.wsthreddssync.client.event.PerformDoSyncEventHandler;
import org.gcube.portlets.widgets.wsthreddssync.client.event.PerformDoUnSyncEvent;
import org.gcube.portlets.widgets.wsthreddssync.client.event.PerformDoUnSyncEventHandler;
import org.gcube.portlets.widgets.wsthreddssync.client.event.ShowMonitorSyncStatusEvent;
import org.gcube.portlets.widgets.wsthreddssync.client.event.ShowMonitorSyncStatusEventHandler;
import org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncServiceAsync;
@ -18,6 +22,8 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescr
import com.github.gwtbootstrap.client.ui.Modal;
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;
@ -80,6 +86,28 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
}
});
eventBus.addHandler(PerformDoUnSyncEvent.TYPE, new PerformDoUnSyncEventHandler() {
@Override
public void onPerformDoUnSync(final PerformDoUnSyncEvent performDoUnSyncEvent) {
if(performDoUnSyncEvent.getFolder()!=null){
DialogConfirm confirm = new DialogConfirm(null, "Unsync confirm?", "Deleting sync configurations to the folder: "+performDoUnSyncEvent.getFolder().getFoderName() +", Confirm?");
confirm.getYesButton().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
performFolderUnSync(performDoUnSyncEvent.getFolder());
}
});
}
}
});
}
@ -140,6 +168,41 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner {
}
private void performFolderUnSync(WsFolder folder) {
this.currentFolder = folder;
GWT.log("Performing doSyncFolder on: "+folder);
final Modal box = new Modal(true);
box.setTitle("Deleting...");
box.hide(false);
LoaderIcon loader = new LoaderIcon("Deleting sync configurations to the folder: "+folder.getFoderName());
box.add(loader);
wsThreddsSyncService.doUnSyncFolder(folder.getFolderId(), new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
if(box!=null)
box.hide();
}
@Override
public void onSuccess(Boolean result) {
box.hide();
if(result){
DialogResult dlg = new DialogResult(null, "Unsync performed", "Unsync was performed correctly");
dlg.show();
}
}
});
box.show();
}
/**
* Perform folder sync.

@ -0,0 +1,57 @@
package org.gcube.portlets.widgets.wsthreddssync.client.event;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder;
import com.google.gwt.event.shared.GwtEvent;
/**
* The Class PerformDoUnSyncEvent.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 13, 2018
*/
public class PerformDoUnSyncEvent extends GwtEvent<PerformDoUnSyncEventHandler> {
/** The type. */
public static Type<PerformDoUnSyncEventHandler> TYPE = new Type<PerformDoUnSyncEventHandler>();
private WsFolder folder;
/**
* Instantiates a new perform do sync event.
*
* @param folder the folder
*/
public PerformDoUnSyncEvent(WsFolder folder) {
this.folder = folder;
}
/* (non-Javadoc)
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
*/
@Override
public Type<PerformDoUnSyncEventHandler> getAssociatedType() {
return TYPE;
}
/* (non-Javadoc)
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
*/
@Override
protected void dispatch(PerformDoUnSyncEventHandler handler) {
handler.onPerformDoUnSync(this);
}
/**
* Gets the folder.
*
* @return the folder
*/
public WsFolder getFolder() {
return folder;
}
}

@ -0,0 +1,21 @@
package org.gcube.portlets.widgets.wsthreddssync.client.event;
import com.google.gwt.event.shared.EventHandler;
/**
* The Interface PerformDoUnSyncEventHandler.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 13, 2018
*/
public interface PerformDoUnSyncEventHandler extends EventHandler {
/**
* On perform do un sync.
*
* @param performDoUnSyncEvent the perform do un sync event
*/
void onPerformDoUnSync(PerformDoUnSyncEvent performDoUnSyncEvent);
}

@ -69,4 +69,14 @@ public interface ThreddsWorkspaceSyncService extends RemoteService {
* @throws Exception the exception
*/
List<ThCatalogueBean> getAvailableCataloguesForScope(String scope) throws Exception;
/**
* Do un sync folder.
*
* @param folderId the folder id
* @return the boolean
* @throws Exception the exception
*/
Boolean doUnSyncFolder(String folderId) throws Exception;
}

@ -100,4 +100,13 @@ public interface ThreddsWorkspaceSyncServiceAsync
* @return the available catalogues for scope
*/
void getAvailableCataloguesForScope(String scope, AsyncCallback<List<ThCatalogueBean>> callback);
/**
* Do un sync folder.
*
* @param folderId the folder id
* @param callback the callback
*/
void doUnSyncFolder(String folderId, AsyncCallback<Boolean> callback);
}

@ -359,6 +359,7 @@ public class WsThreddsWidgetViewManager {
switch (action) {
case CREATE_UPDATE_CONFIGURATION:
if(folderDescriptor==null) {
GWT.log("Performing a create configuration");
//PERFORM A CREATE CONFIGURATION (AT FIRST TIME), THE CONFIGURATION DOES NOT EXITS

@ -14,6 +14,7 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.github.gwtbootstrap.client.ui.Pager;
@ -40,8 +41,6 @@ import com.google.gwt.user.client.ui.Widget;
*/
public abstract class ShowThreddsFolderInfoView extends Composite {
private static final String DATE_FORMAT_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
/** The ui binder. */
private static ShowThreddsFolderInfoViewUiBinder uiBinder =
@ -79,6 +78,9 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
@UiField
TextBox field_folder_locked;
@UiField
Button button_do_unsync;
/*@UiField
TextBox field_last_sync;
@ -116,7 +118,7 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 12, 2018
*/
public static enum SUBMIT_ACTION {CREATE_UPDATE_CONFIGURATION, DO_SYNC};
public static enum SUBMIT_ACTION {CREATE_UPDATE_CONFIGURATION, DO_UNSYNC, DO_SYNC};
/**
* Submit handler.
@ -253,6 +255,18 @@ public abstract class ShowThreddsFolderInfoView extends Composite {
}
}
}
button_do_unsync.setVisible(true);
button_do_unsync.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
}
});
}
/**

@ -65,6 +65,7 @@
</b:Fieldset>
</b:Form>
</g:HTMLPanel>
<b:Button type="LINK" ui:field="button_do_unsync" visible="false">Do UnSync</b:Button>
<b:Pager left="Update Configuration" right="Do Synchronize"
aligned="true" ui:field="pager" />
</g:HTMLPanel>

@ -192,6 +192,23 @@ public class SyncronizeWithThredds {
}
/**
* Do un sync.
*
* @param itemId the item id
* @param deleteRemoteContent the delete remote content
* @param scope the scope
* @param userToken the user token
* @return the boolean
* @throws Exception the exception
*/
public Boolean doUnSync(String itemId, boolean deleteRemoteContent, String scope, String userToken) throws Exception {
setContextParameters(scope, userToken);
return workspaceThreddsSynchronize.doUnSync(itemId, deleteRemoteContent);
}
/**
* Register callback for id.

@ -280,4 +280,34 @@ 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
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#doSyncFolder(java.lang.String, org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor)
*/
@Override
public Boolean doUnSyncFolder(final String folderId) throws Exception{
logger.info("Performing unsync on folder id: "+folderId);
// String scope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
// GCubeUser username = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
// String groupName = PortalContext.getConfiguration().getCurrentGroupName(this.getThreadLocalRequest());
// new GcubeVRE(groupName, scope)
try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
return getSyncService().doUnSync(folderId, false, wsScope, wsUserToken);
}catch (Exception e) {
logger.error("Do un sync Folder error: ",e);
throw new Exception("Sorry, an error occurred on deleting sync configurations, refresh and try again later");
}
}
}

Loading…
Cancel
Save