Enhancement on Project Activity #11690

Updating widget code

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/ws-task-executor-widget@167327 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-05-04 14:16:28 +00:00
parent 26b6d38dcd
commit 60357cf4d6
11 changed files with 865 additions and 16 deletions

View File

@ -8,7 +8,8 @@
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<inherits name="com.github.gwtbootstrap.Bootstrap" />
<inherits name="org.gcube.common.workspacetaskexecutor.WorkspaceTaskExecutor" />
<inherits
name="org.gcube.common.workspacetaskexecutor.WorkspaceTaskExecutor" />
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
@ -18,6 +19,9 @@
<!-- <entry-point class='org.gcube.portlets.widgets.wstaskexecutor.client.WsTaskExecutorWidget'
/> -->
<!-- Specify the application specific style sheet. -->
<stylesheet src='WsTaskExecutorWidget.css' />
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />

View File

@ -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);
}
}

View File

@ -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 <code>onModuleLoad()</code>.
*
* @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<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();
}
}

View File

@ -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<GcubeScope> getListOfScopesForLoggedUser() throws Exception;
/**
* Check item task configurations.
*
* @param itemId the item id
* @return the list
* @throws ItemNotConfiguredException, Exception
*/
List<TaskConfiguration> checkItemTaskConfigurations(String itemId) throws ItemNotConfiguredException, Exception;
}

View File

@ -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<List<GcubeScope>> asyncCallback);
void getListOfScopesForLoggedUser(AsyncCallback<List<GcubeScope>> asyncCallback);
/**
* Check item task configurations.
*
* @param folderId the folder id
* @param asyncCallback the async callback
*/
void checkItemTaskConfigurations(String folderId, AsyncCallback<List<TaskConfiguration>> asyncCallback);
}

View File

@ -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<TaskCompletedNotificationListner> taskEventsListeners) {
// TODO Auto-generated method stub
}
// /**
// * Cancel monitor.

View File

@ -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<Widget, MonitorFolderTaskExecutionStatusView> {
}
@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:
* <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
* xmlns:g="urn:import:**user's package**">
* <g:**UserClassName**>Hello!</g:**UserClassName>
* </ui:UiBinder>
* 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;
}
}

View File

@ -0,0 +1,86 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.noBorder {
border: 0px;
}
.myPaddingLeft {
padding-left: 180px;
}
.myFormWidth {
width: 750px;
}
</ui:style>
<g:VerticalPanel>
<g:HTMLPanel ui:field="form_monitor_thredds_transfer">
<g:HTMLPanel ui:field="field_loader">
</g:HTMLPanel>
<b:ProgressBar type="DEFAULT" color="INFO" percent="0"
ui:field="progress_percentage" />
<g:HorizontalPanel addStyleNames="myMarginLeft">
<!-- <b:ControlGroup ui:field="cg_queued_items" addStyleNames="myLittleMarginLeft"> -->
<!-- <b:ControlLabel for="cl_queued_items">Items in queue</b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextBox b:id="field_queued_items" ui:field="field_queued_items" -->
<!-- readOnly="true" addStyleNames="myLittleWidth"></b:TextBox> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- <b:ControlGroup ui:field="cg_transferred_items" addStyleNames="myLittleMarginLeft"> -->
<!-- <b:ControlLabel for="cl_transferred_items">Transferred items</b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextBox b:id="field_transferred_items" ui:field="field_transferred_items" -->
<!-- readOnly="true" addStyleNames="myLittleWidth"> -->
<!-- </b:TextBox> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<b:ControlGroup ui:field="cg_number_error" addStyleNames="myLittleMarginLeft">
<b:ControlLabel for="cl_number_error">Number of Errors</b:ControlLabel>
<b:Controls>
<b:TextBox b:id="field_number_error" ui:field="field_number_error"
readOnly="true" addStyleNames="myLittleWidth"></b:TextBox>
</b:Controls>
</b:ControlGroup>
</g:HorizontalPanel>
<b:Form type="HORIZONTAL" addStyleNames="myFormWidth"
ui:field="field_form">
<b:Fieldset styleName="{style.noBorder}">
<!-- <b:ControlGroup ui:field="cg_status"> -->
<!-- <b:ControlLabel for="cl_status">Status</b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextBox b:id="field_status" ui:field="field_status" -->
<!-- readOnly="true" addStyleNames="{style.myWidth}"></b:TextBox> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<b:ControlGroup ui:field="cg_current_message">
<b:ControlLabel for="cl_current_message">Status Message</b:ControlLabel>
<b:Controls>
<b:TextArea b:id="field_current_message" ui:field="field_current_message"
readOnly="true" addStyleNames="textAreaWidth"></b:TextArea>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="cg_history_messages">
<b:ControlLabel for="cl_history_messages">Computation History</b:ControlLabel>
<b:Controls>
<b:TextArea b:id="field_history_messages" ui:field="field_history_messages"
readOnly="true" addStyleNames="textAreaWidth"></b:TextArea>
</b:Controls>
</b:ControlGroup>
<!-- <b:ControlGroup ui:field="cg_last_sync"> -->
<!-- <b:ControlLabel for="cl_last_sync">Last Sync Time</b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextBox b:id="field_last_sync" ui:field="field_last_sync" -->
<!-- readOnly="true"></b:TextBox> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
</b:Fieldset>
</b:Form>
</g:HTMLPanel>
<b:Pager left="" right="Close Monitor" aligned="true"
ui:field="pager" />
</g:VerticalPanel>
</ui:UiBinder>

View File

@ -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<GcubeScope> 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<GcubeScope> listOfScopes = new ArrayList<GcubeScope>();
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<GCubeGroup> 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<TaskConfiguration> checkItemTaskConfigurations(String itemId) throws Exception {
WorkspaceDataMinerTaskExecutor exec = WorkspaceDataMinerTaskExecutor.getInstance();
List<TaskConfiguration> 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;
}
}

View File

@ -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);
}
}

View File

@ -8,7 +8,8 @@
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<inherits name="com.github.gwtbootstrap.Bootstrap" />
<inherits name="org.gcube.common.workspacetaskexecutor.WorkspaceTaskExecutor" />
<inherits
name="org.gcube.common.workspacetaskexecutor.WorkspaceTaskExecutor" />
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
@ -18,6 +19,9 @@
<!-- <entry-point class='org.gcube.portlets.widgets.wstaskexecutor.client.WsTaskExecutorWidget'
/> -->
<!-- Specify the application specific style sheet. -->
<stylesheet src='WsTaskExecutorWidget.css' />
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />