diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java index a23038a..f584b94 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java @@ -57,6 +57,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnSessi import org.gcube.portlets.user.td.gwtservice.shared.tr.column.SplitColumnMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupByMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata; import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadConfig; @@ -818,6 +819,25 @@ public interface TDGWTService extends RemoteService { */ + /** + * Get Operation Monitor during the Group By operation + * + * + * @return + * @throws TDGWTServiceException + */ + public GroupByMonitor getGroupByMonitor() + throws TDGWTServiceException; + + /** + * Start group by + * + * @param groupBySession + * @throws TDGWTServiceException + + public void startGroupBy(GroupBySession groupBySession) + throws TDGWTServiceException; + */ // BatchReplace Operations /** diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java index 2b52c0c..c56d307 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java @@ -56,6 +56,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnSessi import org.gcube.portlets.user.td.gwtservice.shared.tr.column.SplitColumnMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupByMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata; import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadConfig; @@ -222,7 +223,10 @@ public interface TDGWTServiceAsync { /*void startSplitColumn(SplitColumnSession splitColumnSession,AsyncCallback callback);*/ void getMergeColumnMonitor(AsyncCallback callback); /*void startSplitColumn(MergeColumnSession mergeColumnSession,AsyncCallback callback); */ - + void getGroupByMonitor(AsyncCallback callback); + /*void startGroupBy(GroupBySession groupBySession,AsyncCallback callback);*/ + + //BatchReplace Operation void getOccurrencesForBatchReplace(OccurrencesForReplaceBatchColumnSession occurrencesForReplaceBatchColumnSession, AsyncCallback> callback); diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java index eb23793..b98a677 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java @@ -58,6 +58,11 @@ public class SessionConstants { protected static final String REPLACE_COLUMN_MONITOR = "REPLACE_COLUMN_MONITOR"; protected static final String REPLACE_COLUMN_TASK = "REPLACE_COLUMN_TASK"; + protected static final String GROUPBY_SESSION = "GROUPBY_SESSION"; + protected static final String GROUPBY_MONITOR = "GROUPBY_MONITOR"; + protected static final String GROUPBY_TASK = "GROUPBY_TASK"; + + protected static final String REPLACE_BATCH_COLUMN_SESSION = "REPLACE_BATCH_COLUMN_SESSION"; protected static final String REPLACE_BATCH_COLUMN_MONITOR = "REPLACE_BATCH_COLUMN_MONITOR"; protected static final String REPLACE_BATCH_COLUMN_TASK = "REPLACE_BATCH_COLUMN_TASK"; diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java index 1f3fe6b..8c667b5 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java @@ -54,6 +54,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.SplitColumnMonitor import org.gcube.portlets.user.td.gwtservice.shared.tr.column.SplitColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupByMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupBySession; import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsSession; @@ -1801,6 +1803,72 @@ public class SessionUtil { httpSession.setAttribute(SessionConstants.MERGE_COLUMN_TASK, task); } + // + public static GroupBySession getGroupBySession( + HttpSession httpSession) { + GroupBySession groupBySession = (GroupBySession) httpSession + .getAttribute(SessionConstants.GROUPBY_SESSION); + if (groupBySession != null) { + return groupBySession; + } else { + groupBySession = new GroupBySession(); + httpSession + .setAttribute(SessionConstants.GROUPBY_SESSION, groupBySession); + return groupBySession; + } + } + + public static void setGroupBySession(HttpSession httpSession, + GroupBySession groupBySession) { + GroupBySession gb = (GroupBySession) httpSession + .getAttribute(SessionConstants.GROUPBY_SESSION); + if (gb != null) { + httpSession.removeAttribute(SessionConstants.GROUPBY_SESSION); + } + httpSession.setAttribute(SessionConstants.GROUPBY_SESSION, groupBySession); + + } + + public static GroupByMonitor getGroupByMonitor( + HttpSession httpSession) { + GroupByMonitor groupByMonitor = (GroupByMonitor) httpSession + .getAttribute(SessionConstants.GROUPBY_MONITOR); + if (groupByMonitor != null) { + return groupByMonitor; + } else { + groupByMonitor = new GroupByMonitor(); + httpSession + .setAttribute(SessionConstants.GROUPBY_MONITOR, groupByMonitor); + return groupByMonitor; + } + } + + public static void setGroupByMonitor(HttpSession httpSession, + GroupByMonitor groupByMonitor) { + GroupByMonitor gb = (GroupByMonitor) httpSession + .getAttribute(SessionConstants.GROUPBY_MONITOR); + if (gb != null) { + httpSession.removeAttribute(SessionConstants.GROUPBY_MONITOR); + } + httpSession.setAttribute(SessionConstants.GROUPBY_MONITOR, groupByMonitor); + + } + + public static Task getGroupByTask(HttpSession httpSession) { + Task monitor = (Task) httpSession.getAttribute(SessionConstants.GROUPBY_TASK); + if (monitor == null) { + logger.error("GROUPBY_TASK was not acquired"); + } + return monitor; + } + + public static void setGroupByTask(HttpSession httpSession, Task task) { + Task monitor = (Task) httpSession.getAttribute(SessionConstants.GROUPBY_TASK); + if (monitor != null) + httpSession.removeAttribute(SessionConstants.GROUPBY_TASK); + httpSession.setAttribute(SessionConstants.GROUPBY_TASK, task); + } + // public static CodelistMappingSession getCodelistMappingSession(HttpSession httpSession) { diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index be8df79..f9cbe88 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java @@ -105,6 +105,7 @@ import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Dele import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Duplicates; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4EditRow; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ExtractCodelist; +import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4GroupBy; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4LabelColumn; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4MergeColumn; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ReplaceBatch; @@ -183,6 +184,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.SplitColumnMonitor import org.gcube.portlets.user.td.gwtservice.shared.tr.column.SplitColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupByMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupBySession; import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRAgencyMetadata; import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRDescriptionMetadata; import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRLocalizedText; @@ -7800,4 +7803,162 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements return; } + + //TODO + public void startGroupBy( + GroupBySession groupBySession,HttpSession session) + throws TDGWTServiceException { + try { + // HttpSession session = this.getThreadLocalRequest().getSession(); + SessionUtil.setGroupBySession(session, groupBySession); + ASLSession aslSession = SessionUtil.getAslSession(session); + if (groupBySession == null) { + logger.error("GroupBySession is null"); + throw new TDGWTServiceException( + "Error in groupby : GroupBySession is null"); + } + + logger.debug("StartGroupBy: " + groupBySession); + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername())); + TabularDataService service = TabularDataServiceFactory.getService(); + + OpExecution4GroupBy opEx=new OpExecution4GroupBy(service, groupBySession); + OpExecutionDirector director=new OpExecutionDirector(); + director.setOperationExecutionBuilder(opEx); + director.constructOperationExecution(); + OperationExecution invocation = director.getOperationExecution(); + + + if (invocation == null) { + throw new TDGWTServiceException( + "Error in invocation: Operation not supported"); + } + Long id = Long.valueOf(groupBySession.getTrId() + .getId()); + + TabularResourceId serviceTR = new TabularResourceId(id); + logger.debug("OperationInvocation: \n" + invocation.toString()); + Task trTask = service.execute(invocation, serviceTR); + logger.debug("GroupBy start on service: TaskId " + trTask.getId()); + SessionUtil.setGroupByTask(session, trTask); + return; + + } catch (TDGWTSessionExpiredException e) { + throw e; + } catch (SecurityException e) { + e.printStackTrace(); + throw new TDGWTServiceException(e.getLocalizedMessage()); + } catch (Throwable e) { + e.printStackTrace(); + throw new TDGWTServiceException("Error in start group by: " + + e.getLocalizedMessage()); + } + } + + + @Override + public GroupByMonitor getGroupByMonitor() + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + GroupBySession groupBySession = SessionUtil + .getGroupBySession(session); + + Task task = SessionUtil.getGroupByTask(session); + GroupByMonitor groupByMonitor = new GroupByMonitor(); + + if (task == null) { + logger.debug("Task null"); + throw new TDGWTServiceException( + "Error in GroupByMonitor task null"); + } else { + TaskStatus status = task.getStatus(); + if (status == null) { + logger.debug("Services TaskStatus : null"); + throw new TDGWTServiceException( + "Error in GroupByMonitor Status null"); + } else { + logger.debug("Services TaskStatus: " + task.getStatus()); + + groupByMonitor.setStatus(TaskStateMap.map(task + .getStatus())); + + TRId trId; + TabResource tabResource; + switch (groupByMonitor.getStatus()) { + case FAILED: + if (task.getResult() != null) { + logger.debug("Task exception:" + + task.getErrorCause()); + task.getErrorCause().printStackTrace(); + groupByMonitor.setError(new Throwable(task + .getErrorCause())); + } else { + logger.debug("Task exception: Error In GroupByMonitor"); + groupByMonitor.setError(new Throwable( + "Error task resume")); + } + groupByMonitor.setProgress(task.getProgress()); + break; + case SUCCEDED: + logger.debug("Task Result:" + task.getResult()); + groupByMonitor.setProgress(task.getProgress()); + trId = new TRId(); + trId.setId(groupBySession.getTrId() + .getId()); + trId = retrieveTabularResourceBasicData(trId); + groupByMonitor.setTrId(trId); + tabResource = SessionUtil.getTabResource(session); + tabResource.setTrId(trId); + SessionUtil.setTabResource(session, tabResource); + SessionUtil.setTRId(session, trId); + break; + case IN_PROGRESS: + groupByMonitor.setProgress(task.getProgress()); + break; + case VALIDATING_RULES: + groupByMonitor.setProgress(task.getProgress()); + break; + case GENERATING_VIEW: + break; + case ABORTED: + break; + case STOPPED: + logger.debug("Task Result:" + task.getResult()); + groupByMonitor.setProgress(task.getProgress()); + + trId = retrieveTabularResourceBasicData(groupBySession + .getTrId()); + + groupByMonitor.setTrId(trId); + tabResource = SessionUtil.getTabResource(session); + tabResource.setTrId(trId); + SessionUtil.setTabResource(session, tabResource); + SessionUtil.setTRId(session, trId); + break; + case INITIALIZING: + break; + default: + break; + } + } + SessionUtil.setGroupByTask(session, task); + } + + logger.debug("GroupByMonitor(): " + groupByMonitor); + return groupByMonitor; + } catch (TDGWTSessionExpiredException e) { + throw e; + } catch (Throwable e) { + logger.debug("Error in GroupByMonitor: " + + e.getLocalizedMessage()); + e.printStackTrace(); + throw new TDGWTServiceException("Error: " + e.getLocalizedMessage()); + + } + } + + + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4GroupBy.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4GroupBy.java new file mode 100644 index 0000000..a45c500 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4GroupBy.java @@ -0,0 +1,60 @@ +package org.gcube.portlets.user.td.gwtservice.server.opexecution; + +import java.util.HashMap; + +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition; +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution; +import org.gcube.data.analysis.tabulardata.service.TabularDataService; +import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap; +import org.gcube.portlets.user.td.gwtservice.shared.OperationsId; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; +import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupBySession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Operation Execution for groupBy + * + * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it + * + */ +public class OpExecution4GroupBy extends OpExecutionBuilder { + protected static Logger logger = LoggerFactory + .getLogger(OpExecution4GroupBy.class); + + private TabularDataService service; + private GroupBySession groupBySession; + + public OpExecution4GroupBy(TabularDataService service, + GroupBySession groupBySession) { + this.service = service; + this.groupBySession = groupBySession; + } + + @Override + public void buildOpEx() throws TDGWTServiceException { + + OperationExecution invocation = null; + + logger.debug(groupBySession.toString()); + OperationDefinition operationDefinition; + + HashMap map=groupBySession.getMap(); + + if(map==null){ + logger.error("In GroupBySession map is null"); + throw new TDGWTServiceException("In GroupBySession map is null"); + } + + operationDefinition = OperationDefinitionMap.map( + OperationsId.GroupBy.toString(), service); + + invocation = new OperationExecution( + operationDefinition.getOperationId(), map); + + operationExecutionSpec.setOp(invocation); + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/groupby/GroupByMonitor.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/groupby/GroupByMonitor.java new file mode 100644 index 0000000..5fbeebb --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/groupby/GroupByMonitor.java @@ -0,0 +1,21 @@ +/** + * + */ +package org.gcube.portlets.user.td.gwtservice.shared.tr.groupby; + +import java.io.Serializable; + +import org.gcube.portlets.user.td.gwtservice.shared.OperationMonitor; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class GroupByMonitor extends OperationMonitor implements Serializable { + + + private static final long serialVersionUID = -7694151843138161474L; + +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/groupby/GroupBySession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/groupby/GroupBySession.java new file mode 100644 index 0000000..d91f458 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/groupby/GroupBySession.java @@ -0,0 +1,51 @@ +package org.gcube.portlets.user.td.gwtservice.shared.tr.groupby; + +import java.io.Serializable; +import java.util.HashMap; + +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class GroupBySession implements Serializable { + + private static final long serialVersionUID = -1896235499708614266L; + + protected TRId trId; + protected HashMap map; + + public GroupBySession() { + + } + + public GroupBySession(TRId trId, HashMap map) { + this.trId = trId; + this.map = map; + } + + public TRId getTrId() { + return trId; + } + + public void setTrId(TRId trId) { + this.trId = trId; + } + + public HashMap getMap() { + return map; + } + + public void setMap(HashMap map) { + this.map = map; + } + + @Override + public String toString() { + return "GroupBySession [trId=" + trId + ", map=" + map + "]"; + } + +}