diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/WsTaskExecutorWidget.gwt.xml b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/WsTaskExecutorWidget.gwt.xml
index 66e2baf..48c22e0 100644
--- a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/WsTaskExecutorWidget.gwt.xml
+++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/WsTaskExecutorWidget.gwt.xml
@@ -8,7 +8,8 @@
-
+
@@ -18,6 +19,9 @@
+
+
+
diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/TaskCompletedNotification.java b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/TaskCompletedNotification.java
new file mode 100644
index 0000000..81c9cb0
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/TaskCompletedNotification.java
@@ -0,0 +1,67 @@
+/**
+ *
+ */
+package org.gcube.portlets.widgets.wstaskexecutor.client;
+
+import org.gcube.portlets.widgets.wstaskexecutor.shared.WsFolder;
+
+
+
+/**
+ * The Class TaskCompletedNotification.
+ *
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * May 4, 2018
+ */
+public class TaskCompletedNotification {
+
+
+ /**
+ * The Interface TaskCompletedNotificationListner.
+ *
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * May 4, 2018
+ */
+ public interface TaskCompletedNotificationListner{
+
+
+ /**
+ * On task computation completed.
+ *
+ * @param folder the folder
+ */
+ void onTaskComputationCompleted(WsFolder folder);
+
+ /**
+ * On task computation error.
+ *
+ * @param folder the folder
+ */
+ void onTaskComputationError(WsFolder folder);
+
+ /**
+ * On remove task configurations performed.
+ *
+ * @param folder the folder
+ */
+ void onRemoveTaskConfigurationsPerformed(WsFolder folder);
+ }
+
+
+ /**
+ * The Interface HasWsSyncNotificationListner.
+ *
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * Mar 13, 2018
+ */
+ public interface HasWsSyncNotificationListner {
+
+ /**
+ * Adds the sync completed listner.
+ *
+ * @param listner the listner
+ */
+ public void addTaskCompletedListner(TaskCompletedNotificationListner listner);
+
+ }
+}
diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidget.java b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidget.java
index 5f034f7..5937662 100644
--- a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidget.java
+++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidget.java
@@ -1,13 +1,30 @@
package org.gcube.portlets.widgets.wstaskexecutor.client;
-import org.gcube.portlets.widgets.wstaskexecutor.client.view.WsTaskExecutorWidgetViewManager;
+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 onModuleLoad()
.
+ *
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * May 4, 2018
*/
public class WsTaskExecutorWidget {
@@ -29,11 +46,101 @@ public class WsTaskExecutorWidget {
private WsTaskExecutorWidgetViewManager viewManager = new WsTaskExecutorWidgetViewManager();
- /**
- *
- */
- public WsTaskExecutorWidget() {
+ private final List taskEventsListeners = new ArrayList();
+ /**
+ * 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>() {
+
+ @Override
+ public void onSuccess(List 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>() {
+//
+// @Override
+// public void onSuccess(List 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();
+
+ }
}
diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidgetService.java b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/rpc/WsTaskExecutorWidgetService.java
similarity index 56%
rename from src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidgetService.java
rename to src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/rpc/WsTaskExecutorWidgetService.java
index 87bbf41..0fd3d70 100644
--- a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidgetService.java
+++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/rpc/WsTaskExecutorWidgetService.java
@@ -1,7 +1,9 @@
-package org.gcube.portlets.widgets.wstaskexecutor.client;
+package org.gcube.portlets.widgets.wstaskexecutor.client.rpc;
import java.util.List;
+import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration;
+import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotConfiguredException;
import org.gcube.portlets.widgets.wstaskexecutor.shared.GcubeScope;
import com.google.gwt.user.client.rpc.RemoteService;
@@ -24,4 +26,13 @@ public interface WsTaskExecutorWidgetService extends RemoteService {
* @throws Exception the exception
*/
List getListOfScopesForLoggedUser() throws Exception;
+
+ /**
+ * Check item task configurations.
+ *
+ * @param itemId the item id
+ * @return the list
+ * @throws ItemNotConfiguredException, Exception
+ */
+ List checkItemTaskConfigurations(String itemId) throws ItemNotConfiguredException, Exception;
}
diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidgetServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/rpc/WsTaskExecutorWidgetServiceAsync.java
similarity index 64%
rename from src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidgetServiceAsync.java
rename to src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/rpc/WsTaskExecutorWidgetServiceAsync.java
index 9442f5e..8315660 100644
--- a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidgetServiceAsync.java
+++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/rpc/WsTaskExecutorWidgetServiceAsync.java
@@ -1,18 +1,20 @@
/**
*
*/
-package org.gcube.portlets.widgets.wstaskexecutor.client;
+package org.gcube.portlets.widgets.wstaskexecutor.client.rpc;
import java.util.List;
+import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration;
import org.gcube.portlets.widgets.wstaskexecutor.shared.GcubeScope;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
+
/**
- * The Interface GreetingServiceAsync.
+ * The Interface WsTaskExecutorWidgetServiceAsync.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 4, 2018
@@ -54,8 +56,18 @@ public interface WsTaskExecutorWidgetServiceAsync {
}
/**
- * @param asyncCallback
+ * Gets the list of scopes for logged user.
+ *
+ * @param asyncCallback the async callback
+ * @return the list of scopes for logged user
*/
- void getListOfScopesForLoggedUser(
- AsyncCallback> asyncCallback);
+ void getListOfScopesForLoggedUser(AsyncCallback> asyncCallback);
+
+ /**
+ * Check item task configurations.
+ *
+ * @param folderId the folder id
+ * @param asyncCallback the async callback
+ */
+ void checkItemTaskConfigurations(String folderId, AsyncCallback> asyncCallback);
}
diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/WsTaskExecutorWidgetViewManager.java b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/WsTaskExecutorWidgetViewManager.java
index 4641a65..8d34e61 100644
--- a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/WsTaskExecutorWidgetViewManager.java
+++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/WsTaskExecutorWidgetViewManager.java
@@ -1,5 +1,11 @@
package org.gcube.portlets.widgets.wstaskexecutor.client.view;
+import java.util.List;
+
+import org.gcube.portlets.widgets.wstaskexecutor.client.TaskCompletedNotification.TaskCompletedNotificationListner;
+import org.gcube.portlets.widgets.wstaskexecutor.client.view.binder.MonitorFolderTaskExecutionStatusView;
+import org.gcube.portlets.widgets.wstaskexecutor.shared.WsFolder;
+
@@ -22,6 +28,28 @@ public class WsTaskExecutorWidgetViewManager {
public WsTaskExecutorWidgetViewManager() {
}
+ /**
+ * @param folder
+ * @return
+ */
+ public MonitorFolderTaskExecutionStatusView getMonitor(WsFolder folder) {
+
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * @param folder
+ * @param taskEventsListeners
+ */
+ public void showMonitorTaskStatusForFolder(
+ WsFolder folder,
+ List taskEventsListeners) {
+
+ // TODO Auto-generated method stub
+
+ }
+
// /**
// * Cancel monitor.
diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/MonitorFolderTaskExecutionStatusView.java b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/MonitorFolderTaskExecutionStatusView.java
new file mode 100644
index 0000000..2c6c94a
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/MonitorFolderTaskExecutionStatusView.java
@@ -0,0 +1,291 @@
+package org.gcube.portlets.widgets.wstaskexecutor.client.view.binder;
+
+
+import org.gcube.common.workspacetaskexecutor.shared.TaskStatus;
+import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskExecutionStatus;
+import org.gcube.portlets.widgets.wstaskexecutor.client.view.LoaderIcon;
+import org.gcube.portlets.widgets.wstaskexecutor.shared.WsFolder;
+
+import com.github.gwtbootstrap.client.ui.Alert;
+import com.github.gwtbootstrap.client.ui.Form;
+import com.github.gwtbootstrap.client.ui.Pager;
+import com.github.gwtbootstrap.client.ui.ProgressBar;
+import com.github.gwtbootstrap.client.ui.TextArea;
+import com.github.gwtbootstrap.client.ui.TextBox;
+import com.github.gwtbootstrap.client.ui.constants.AlertType;
+import com.github.gwtbootstrap.client.ui.constants.ResizeType;
+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.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.user.client.Timer;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.HTMLPanel;
+import com.google.gwt.user.client.ui.Widget;
+
+
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class ShowThreddsFolderInfoView.
+ *
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * Feb 15, 2018
+ */
+public abstract class MonitorFolderTaskExecutionStatusView extends Composite {
+
+ //private static final String DATE_FORMAT_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
+
+
+ /**
+ *
+ */
+ public static final String PROCESSING_STATE = "Processing state: ";
+
+ private static final String UNKNOWN = "UNKNOWN";
+
+ /** The ui binder. */
+ private static MonitorFolderTaskExecutionStatusViewUiBinder uiBinder =
+ GWT.create(MonitorFolderTaskExecutionStatusViewUiBinder.class);
+
+ /**
+ * The Interface ShowThreddsFolderInfoViewUiBinder.
+ *
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * Feb 15, 2018
+ */
+ interface MonitorFolderTaskExecutionStatusViewUiBinder
+ extends UiBinder {
+ }
+
+
+ @UiField
+ Pager pager;
+
+ @UiField
+ ProgressBar progress_percentage;
+
+
+ @UiField
+ TextArea field_current_message;
+
+// @UiField
+// TextBox field_queued_items;
+//
+// @UiField
+// TextBox field_transferred_items;
+
+ @UiField
+ TextBox field_number_error;
+
+ @UiField
+ TextArea field_history_messages;
+
+ @UiField
+ HTMLPanel form_monitor_thredds_transfer;
+
+ @UiField
+ HTMLPanel field_loader;
+
+ @UiField
+ Form field_form;
+
+ private WsFolder folder;
+
+
+ /** The scheduler time. */
+ private Timer schedulerTime;
+
+
+ /**
+ * Submit handler.
+ */
+ public abstract void closetHandler();
+
+ /**
+ * Sets the error.
+ *
+ * @param visible the visible
+ * @param error the error
+ */
+ public abstract void setError(boolean visible, String error);
+
+
+ /**
+ * Because this class has a default constructor, it can
+ * be used as a binder template. In other words, it can be used in other
+ * *.ui.xml files as follows:
+ *
+ * Hello!
+ *
+ * Note that depending on the widget that is used, it may be necessary to
+ * implement HasHTML instead of HasText.
+ */
+ public MonitorFolderTaskExecutionStatusView() {
+
+ initWidget(uiBinder.createAndBindUi(this));
+
+ pager.getLeft().setVisible(false);
+
+ pager.getRight().addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ GWT.log("Close Monitor Click");
+ setError(false, "");
+ closetHandler();
+
+ }
+ });
+
+ pager.getRight().setVisible(false);
+
+ field_history_messages.setHeight("200px");
+ field_history_messages.setResize(ResizeType.BOTH);
+ field_current_message.setHeight("80px");
+ field_current_message.setResize(ResizeType.BOTH);
+
+// field_queued_items.addStyleName("myLittleWidth");
+// field_number_error.addStyleName("myLittleWidth");
+// field_transferred_items.addStyleName("myLittleWidth");
+
+// field_current_message.addStyleName("textAreaWidth");
+// field_history_messages.addStyleName("textAreaWidth");
+
+// field_form.addStyleName("myFormWidth");
+ }
+
+
+ /**
+ * Update status view.
+ *
+ * @param folder the folder
+ * @param taskExecutionStatus the sync status
+ */
+ public void updateStatusView(WsFolder folder, TaskExecutionStatus taskExecutionStatus) {
+ this.folder = folder;
+
+ field_loader.clear();
+ LoaderIcon loader = new LoaderIcon("Waiting...");
+ field_loader.add(loader);
+
+ this.folder = folder;
+ this.field_current_message.setValue(UNKNOWN);
+ setFieldValue(this.field_number_error, UNKNOWN);
+// setFieldValue(this.field_queued_items, UNKNOWN);
+// setFieldValue(this.field_transferred_items, UNKNOWN);
+ this.field_history_messages.setValue(UNKNOWN);
+
+ if(folder==null || taskExecutionStatus==null || taskExecutionStatus.getStatus()==null) {
+ //setError(true, "Sync status error: either folder does not exist or the status is null");
+ GWT.log("Sync status error: either folder does not exist or the status is null");
+ return;
+ }
+
+ if(taskExecutionStatus.getPercentCompleted()>=0){
+ float perc = taskExecutionStatus.getPercentCompleted();
+ progress_percentage.setPercent((int)perc);
+ }
+
+ if(taskExecutionStatus.getStatus()!=null)
+
+ if(taskExecutionStatus.getStatus()!=null) {
+ loader.setText(taskExecutionStatus.getStatus().toString());
+
+ switch (taskExecutionStatus.getStatus()) {
+ case INITIALIZING:
+ field_loader.clear();
+ field_loader.add(new LoaderIcon(PROCESSING_STATE+TaskStatus.INITIALIZING.toString()));
+ break;
+
+ case ONGOING:
+ field_loader.clear();
+ field_loader.add(new LoaderIcon(PROCESSING_STATE+TaskStatus.ONGOING.toString()));
+ break;
+ case ACCEPTED:
+ field_loader.clear();
+ field_loader.add(new LoaderIcon(PROCESSING_STATE+TaskStatus.ACCEPTED.toString()));
+ break;
+ case COMPLETED:
+ field_loader.clear();
+ Alert alert = new Alert("Task " +TaskStatus.COMPLETED.toString());
+ alert.setClose(false);
+ alert.setType(AlertType.SUCCESS);
+ field_loader.add(alert);
+ break;
+
+ case CANCELLED:
+ field_loader.clear();
+ Alert alert1 = new Alert("Transferring " +TaskStatus.CANCELLED.toString());
+ alert1.setClose(false);
+ alert1.setType(AlertType.WARNING);
+ field_loader.add(alert1);
+ //progress_percentage.setVisible(false);
+ break;
+ case FAILED:
+ field_loader.clear();
+ Alert alert2 = new Alert(PROCESSING_STATE +TaskStatus.FAILED.toString());
+ alert2.setClose(false);
+ alert2.setType(AlertType.ERROR);
+ field_loader.add(alert2);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if(taskExecutionStatus.getCurrentMessage()!=null)
+ this.field_current_message.setValue(taskExecutionStatus.getCurrentMessage());
+
+ if(taskExecutionStatus.getErrorCount()!=null)
+ this.field_number_error.setValue(taskExecutionStatus.getErrorCount().toString());
+
+ if(taskExecutionStatus.getLog()!=null)
+ this.field_history_messages.setValue(taskExecutionStatus.getLog());
+
+ }
+
+
+ /**
+ * Sets the field value.
+ *
+ * @param box the box
+ * @param value the value
+ */
+ private void setFieldValue(TextBox box, String value) {
+ box.setValue(value);
+ }
+
+
+ /**
+ * Validate submit.
+ *
+ * @return true, if successful
+ */
+ protected boolean validateSubmit() {
+
+ return true;
+ }
+
+
+ /**
+ * Sets the scheduler.
+ *
+ * @param schedulingTimer the new scheduler
+ */
+ public void setScheduler(Timer schedulingTimer) {
+ this.schedulerTime = schedulingTimer;
+ }
+
+ /**
+ * Gets the scheduling time.
+ *
+ * @return the scheduling time
+ */
+ public Timer getSchedulerTime() {
+ return schedulerTime;
+ }
+}
diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/MonitorFolderTaskExecutionStatusView.ui.xml b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/MonitorFolderTaskExecutionStatusView.ui.xml
new file mode 100644
index 0000000..ad6ea91
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/MonitorFolderTaskExecutionStatusView.ui.xml
@@ -0,0 +1,86 @@
+
+
+
+ .noBorder {
+ border: 0px;
+ }
+
+ .myPaddingLeft {
+ padding-left: 180px;
+ }
+
+ .myFormWidth {
+ width: 750px;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Number of Errors
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Status Message
+
+
+
+
+
+
+ Computation History
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/server/WsTaskExecutorWidgetServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/server/WsTaskExecutorWidgetServiceImpl.java
index b4ad33b..db45c46 100644
--- a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/server/WsTaskExecutorWidgetServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/server/WsTaskExecutorWidgetServiceImpl.java
@@ -1,19 +1,73 @@
package org.gcube.portlets.widgets.wstaskexecutor.server;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
-import org.gcube.portlets.widgets.wstaskexecutor.client.WsTaskExecutorWidgetService;
+import org.gcube.common.portal.PortalContext;
+import org.gcube.common.workspacetaskexecutor.dataminer.WorkspaceDataMinerTaskExecutor;
+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.common.workspacetaskexecutor.util.EncrypterUtil;
+import org.gcube.portlets.widgets.wstaskexecutor.client.rpc.WsTaskExecutorWidgetService;
+import org.gcube.portlets.widgets.wstaskexecutor.server.util.PortalContextUtil;
import org.gcube.portlets.widgets.wstaskexecutor.shared.GcubeScope;
+import org.gcube.portlets.widgets.wstaskexecutor.shared.GcubeScopeType;
+import org.gcube.vomanagement.usermanagement.GroupManager;
+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.model.GCubeGroup;
+import org.gcube.vomanagement.usermanagement.model.GCubeUser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+import com.liferay.portal.service.UserLocalServiceUtil;
/**
* The server side implementation of the RPC service.
+ *
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * May 4, 2018
*/
@SuppressWarnings("serial")
public class WsTaskExecutorWidgetServiceImpl extends RemoteServiceServlet implements
WsTaskExecutorWidgetService {
+ private static Logger logger = LoggerFactory.getLogger(WsTaskExecutorWidgetServiceImpl.class);
+
+ /**
+ * Checks if is within portal.
+ *
+ * @return true if you're running into the portal, false if in development
+ */
+ public static boolean isWithinPortal() {
+ try {
+ UserLocalServiceUtil.getService();
+ return true;
+ }
+ catch (Exception ex) {
+ logger.info("Development Mode ON");
+ return false;
+ }
+ }
+
+ /**
+ * Gets the task executor.
+ *
+ * @return the task executor
+ */
+ private WorkspaceDataMinerTaskExecutor getTaskExecutor(){
+
+ GCubeUser user = PortalContextUtil.getUserLogged(this.getThreadLocalRequest());
+ WorkspaceDataMinerTaskExecutor exec = WorkspaceDataMinerTaskExecutor.getInstance();
+ exec.withOwner(user.getUsername());
+ return exec;
+ }
+
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wstaskexecutor.client.GreetingService#getListOfScopesForLoggedUser()
*/
@@ -21,9 +75,141 @@ public class WsTaskExecutorWidgetServiceImpl extends RemoteServiceServlet implem
public List getListOfScopesForLoggedUser()
throws Exception {
- // TODO Auto-generated method stub
- return null;
+ logger.debug("getListOfVREsForLoggedUser...: ");
+ GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
+ long userId = user.getUserId();
+
+ // Instanciate the manager
+ GroupManager groupManager = new LiferayGroupManager();
+ List listOfScopes = new ArrayList();
+
+ if (!isWithinPortal()){
+ listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE));
+ listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE));
+ listOfScopes.add(new GcubeScope("devNext", "/gcube/devNext", GcubeScopeType.VO));
+ listOfScopes.add(new GcubeScope("devsec", "/gcube/devsec", GcubeScopeType.VO));
+ listOfScopes.add(new GcubeScope("gcube", "/gcube", GcubeScopeType.ROOT));
+ Collections.sort(listOfScopes);
+ return listOfScopes;
+ }
+
+ try {
+
+ List listOfGroups = groupManager.listGroupsByUser(userId);
+ for (GCubeGroup gCubeGroup : listOfGroups) {
+ GcubeScopeType scopeType=null;
+ if(groupManager.isVRE(gCubeGroup.getGroupId())){
+ scopeType = GcubeScopeType.VRE;
+ }
+// else if(groupManager.isVO(gCubeGroup.getGroupId())){
+// scopeType = GcubeScopeType.VO;
+// }
+// }else if(groupManager.isRootVO(gCubeGroup.getGroupId())){
+// scopeType = GcubeScopeType.ROOT;
+// }
+
+ if(scopeType!=null){
+ GcubeScope gcubeVRE = new GcubeScope(gCubeGroup.getGroupName(), groupManager.getInfrastructureScope(gCubeGroup.getGroupId()), scopeType);
+ listOfScopes.add(gcubeVRE);
+ }
+
+ }
+
+ //ADDING THE ROOT SCOPE
+// String infraName = PortalContext.getConfiguration().getInfrastructureName();
+// GcubeScope gcubeRoot = new GcubeScope(infraName, "/"+infraName, GcubeScopeType.ROOT);
+// listOfScopes.add(gcubeRoot);
+
+ }
+ catch (UserRetrievalFault | UserManagementSystemException
+ | GroupRetrievalFault e) {
+ 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");
+ }
+
+ Collections.sort(listOfScopes);
+ logger.info("Returning list of VREs: "+listOfScopes);
+ return listOfScopes;
}
+
+
+
+ /**
+ * Creates the task configuration.
+ *
+ * @param workspaceItemId the workspace item id
+ * @param taskConfiguration the task configuration
+ * @return the task configuration
+ * @throws Exception the exception
+ */
+ public TaskConfiguration createTaskConfiguration(String workspaceItemId, TaskConfiguration taskConfiguration) throws Exception{
+
+ WorkspaceDataMinerTaskExecutor exec = getTaskExecutor();
+ taskConfiguration = setMaskedToken(taskConfiguration);
+ exec.setTaskConfiguration(taskConfiguration);
+
+ return taskConfiguration;
+ }
+
+ /**
+ * Check item task configurations.
+ *
+ * @param itemId the item id
+ * @return the list
+ * @throws Exception
+ */
+ @Override
+ public List checkItemTaskConfigurations(String itemId) throws Exception {
+
+ WorkspaceDataMinerTaskExecutor exec = WorkspaceDataMinerTaskExecutor.getInstance();
+ List confs = null;
+ try {
+ confs = exec.checkItemConfigurations(itemId);
+ }
+ catch (ItemNotConfiguredException e){
+ String msg = "No TaskConfiguration found for itemId: "+itemId+", retuning null";
+ logger.info(msg);
+ throw e;
+ }catch (WorkspaceFolderLocked e) {
+ logger.info(e.getMessage());
+ throw e;
+
+ }catch (Exception e) {
+ logger.error("Error on checking TaskConfigurations for itemId: "+itemId,e);
+ throw new Exception("Error occurred during checking Task Configurations for id: "+itemId+ ". Refresh and try again later");
+ }
+
+ logger.debug("Returning configurations: "+confs);
+
+ return confs;
+ }
+
+
+ /**
+ * Sets the masked token.
+ *
+ * @param taskConfiguration the task configuration
+ * @return the task configuration
+ * @throws Exception the exception
+ */
+ private TaskConfiguration setMaskedToken(TaskConfiguration taskConfiguration) throws Exception{
+
+ String scope = taskConfiguration.getScope();
+ if(scope==null)
+ throw new Exception("Missing scope in the input configuration. Set it and try again");
+
+ GCubeUser user = PortalContextUtil.getUserLogged(this.getThreadLocalRequest());
+ String token = PortalContextUtil.getTokenFor(scope, user.getUsername());
+ taskConfiguration.setMaskedToken(EncrypterUtil.encryptString(token));
+
+ return taskConfiguration;
+
+ }
+
+
+
+
+
}
diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/server/util/PortalContextUtil.java b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/server/util/PortalContextUtil.java
new file mode 100644
index 0000000..616b69a
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/server/util/PortalContextUtil.java
@@ -0,0 +1,53 @@
+/**
+ *
+ */
+package org.gcube.portlets.widgets.wstaskexecutor.server.util;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.gcube.common.portal.PortalContext;
+import org.gcube.vomanagement.usermanagement.model.GCubeUser;
+
+
+
+/**
+ * The Class PortalContextUtil.
+ *
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * May 4, 2018
+ */
+public class PortalContextUtil {
+
+
+ /**
+ * Gets the user logged.
+ *
+ * @param request the request
+ * @return the user logged
+ */
+ public static GCubeUser getUserLogged(HttpServletRequest request){
+ return PortalContext.getConfiguration().getCurrentUser(request);
+ }
+
+ /**
+ * Gets the token for.
+ *
+ * @param scope the scope
+ * @param username the username
+ * @return the token for
+ */
+ public static String getTokenFor(String scope, String username){
+ return PortalContext.getConfiguration().getCurrentUserToken(scope, username);
+ }
+
+
+ /**
+ * Gets the current scope.
+ *
+ * @param request the request
+ * @return the current scope
+ */
+ public static String getCurrentScope(HttpServletRequest request){
+ return PortalContext.getConfiguration().getCurrentScope(request);
+ }
+}
diff --git a/src/main/resources/org/gcube/portlets/widgets/wstaskexecutor/WsTaskExecutorWidget.gwt.xml b/src/main/resources/org/gcube/portlets/widgets/wstaskexecutor/WsTaskExecutorWidget.gwt.xml
index 66e2baf..48c22e0 100644
--- a/src/main/resources/org/gcube/portlets/widgets/wstaskexecutor/WsTaskExecutorWidget.gwt.xml
+++ b/src/main/resources/org/gcube/portlets/widgets/wstaskexecutor/WsTaskExecutorWidget.gwt.xml
@@ -8,7 +8,8 @@
-
+
@@ -18,6 +19,9 @@
+
+
+