216 lines
6.7 KiB
Java
216 lines
6.7 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.event.CreateTaskConfigurationEvent;
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.event.CreateTaskConfigurationEventHandler;
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.event.PerformRunTaskEvent;
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.event.PerformRunTaskEventHandler;
|
|
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.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.Button;
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
|
|
/**
|
|
* 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 wsTaskService = 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() {
|
|
|
|
eventBus.addHandler(PerformRunTaskEvent.TYPE, new PerformRunTaskEventHandler() {
|
|
|
|
@Override
|
|
public void onPerformRunTask(PerformRunTaskEvent perforRunTaskEvent) {
|
|
|
|
try {
|
|
performRunTask(perforRunTaskEvent.getFolder(), perforRunTaskEvent.getConf());
|
|
}
|
|
catch (Exception e) {
|
|
Window.alert(e.getMessage());
|
|
}
|
|
}
|
|
});
|
|
|
|
eventBus.addHandler(CreateTaskConfigurationEvent.TYPE, new CreateTaskConfigurationEventHandler() {
|
|
|
|
@Override
|
|
public void onCreateConfiguration(
|
|
final CreateTaskConfigurationEvent createTCE) {
|
|
|
|
if(createTCE.getFolder()!=null && createTCE.getConf()!=null){
|
|
WsTaskExecutorWidget.wsTaskService.createTaskConfiguration(createTCE.getFolder().getFolderId(), createTCE.getConf(), createTCE.isUpdate(), new AsyncCallback<Boolean>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
|
|
Window.alert(caught.getMessage());
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(Boolean result) {
|
|
|
|
try {
|
|
showTaskConfigurationsForFolder(createTCE.getFolder());
|
|
}
|
|
catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Perform run task.
|
|
*
|
|
* @param folder the folder
|
|
* @param conf the conf
|
|
* @throws Exception the exception
|
|
*/
|
|
public void performRunTask(WsFolder folder, TaskConfiguration conf) throws Exception {
|
|
|
|
if(folder==null || folder.getFolderId()==null)
|
|
throw new Exception("Invalid parameter folder null");
|
|
|
|
if(conf==null)
|
|
throw new Exception("Invalid parameter the configuration is null");
|
|
|
|
|
|
//WsTaskExecutorWidget.wsTaskService.runTask()
|
|
}
|
|
|
|
|
|
/**
|
|
* Show task configurations for folder.
|
|
*
|
|
* @param folder the folder
|
|
* @throws Exception the exception
|
|
*/
|
|
public void showTaskConfigurationsForFolder(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.showMonitorTaskStatusFor(folder, monitor.getTaskConfiguration(), monitor.getTaskComputation(), 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 checkItemTaskConfigurations: "+folder.getFolderId());
|
|
|
|
WsTaskExecutorWidget.wsTaskService.checkItemTaskConfigurations(folder.getFolderId(), new AsyncCallback<List<TaskConfiguration>>() {
|
|
|
|
@Override
|
|
public void onSuccess(List<TaskConfiguration> result) {
|
|
box.hide();
|
|
|
|
viewManager.showTaskConfigurationsFolderInfo(folder, result, taskEventsListeners);
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
box.hide();
|
|
|
|
if(caught instanceof ItemNotConfiguredException){
|
|
|
|
viewManager.showCreateTaskConfigurationForFolder(folder, null);
|
|
|
|
}else if(caught instanceof WorkspaceFolderLocked){
|
|
VerticalPanel v = new VerticalPanel();
|
|
Alert alert = new Alert("Current Folder is locked by another proccess. Do you want see Task 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));
|
|
}
|
|
});
|
|
|
|
v.add(alert);
|
|
v.add(butt);
|
|
box.add(v);
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
box.show();
|
|
|
|
}
|
|
}
|