ws-task-executor-widget/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidget.java

147 lines
4.4 KiB
Java

package org.gcube.portlets.widgets.wstaskexecutor.client;
import java.util.ArrayList;
import java.util.List;
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration;
import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotConfiguredException;
import org.gcube.common.workspacetaskexecutor.shared.exception.WorkspaceFolderLocked;
import org.gcube.portlets.widgets.wstaskexecutor.client.TaskCompletedNotification.TaskCompletedNotificationListner;
import org.gcube.portlets.widgets.wstaskexecutor.client.rpc.WsTaskExecutorWidgetServiceAsync;
import org.gcube.portlets.widgets.wstaskexecutor.client.view.LoaderIcon;
import org.gcube.portlets.widgets.wstaskexecutor.client.view.WsTaskExecutorWidgetViewManager;
import org.gcube.portlets.widgets.wstaskexecutor.client.view.binder.MonitorFolderTaskExecutionStatusView;
import org.gcube.portlets.widgets.wstaskexecutor.shared.WsFolder;
import com.github.gwtbootstrap.client.ui.Modal;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 4, 2018
*/
public class WsTaskExecutorWidget {
/**
* The message displayed to the user when the server cannot be reached or
* returns an error.
*/
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";
/**
* Create a remote service proxy to talk to the server-side Greeting
* service.
*/
public static final WsTaskExecutorWidgetServiceAsync greetingService = WsTaskExecutorWidgetServiceAsync.Util.getInstance();
/** The Constant eventBus. */
public final static HandlerManager eventBus = new HandlerManager(null);
private WsTaskExecutorWidgetViewManager viewManager = new WsTaskExecutorWidgetViewManager();
private final List<TaskCompletedNotificationListner> taskEventsListeners = new ArrayList<TaskCompletedNotificationListner>();
/**
* Instantiates a new ws task executor widget.
*/
public WsTaskExecutorWidget() {
bindEvents();
// TODO Auto-generated constructor stub
}
/**
* Bind events.
*/
private void bindEvents() {
// TODO Auto-generated method stub
}
/**
* Show task configurations folder info.
*
* @param folder the folder
* @throws Exception the exception
*/
public void showTaskConfigurationsFolderInfo(final WsFolder folder) throws Exception {
if(folder==null || folder.getFolderId()==null)
throw new Exception("Invalid parameter folder null");
MonitorFolderTaskExecutionStatusView monitor = viewManager.getMonitor(folder);
//SHOWING CURRENT ACTIVE MONITOR
if(monitor!=null) {
GWT.log("Monitor for folder: "+folder.getFolderId() +" exists showing it..");
viewManager.showMonitorTaskStatusForFolder(folder, taskEventsListeners);
return;
}
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());
WsTaskExecutorWidget.greetingService.checkItemTaskConfigurations(folder.getFolderId(), new AsyncCallback<List<TaskConfiguration>>() {
@Override
public void onSuccess(List<TaskConfiguration> result) {
// TODO Auto-generated method stub
}
@Override
public void onFailure(Throwable caught) {
if(caught instanceof ItemNotConfiguredException){
}else if(caught instanceof WorkspaceFolderLocked){
viewManager.showMonitorTaskStatusForFolder(folder,taskEventsListeners);
return;
}
}
});
// WsTaskExecutorWidget.greetingService.checkItemTaskConfigurations(folder.getFolderId(), new AsyncCallback<List<TaskConfiguration>>() {
//
// @Override
// public void onSuccess(List<TaskConfiguration> result) {
// box.hide();
// //GWT.log("WsThreddsSynchFolderDescriptor result: "+result);
// viewManager.showThreddsFolderInfo(folder, result);
//
// }
//
// @Override
// public void onFailure(Throwable caught) {
// box.hide();
//
// if(caught instanceof WorkspaceFolderLocked){
// viewManager.showMonitorSyncToFolder(folder,syncEventsListeners);
// return;
// }
//
// viewManager.cancelMonitor(folder);
// // TODO Auto-generated method stub
// Window.alert(caught.getMessage());
// }
// });
box.show();
}
}