Added GroupBy

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@97668 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-06-24 09:24:04 +00:00
parent 2b87495ef6
commit aff928bb7b
8 changed files with 391 additions and 1 deletions

View File

@ -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
/**

View File

@ -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<Void> callback);*/
void getMergeColumnMonitor(AsyncCallback<MergeColumnMonitor> callback);
/*void startSplitColumn(MergeColumnSession mergeColumnSession,AsyncCallback<Void> callback); */
void getGroupByMonitor(AsyncCallback<GroupByMonitor> callback);
/*void startGroupBy(GroupBySession groupBySession,AsyncCallback<Void> callback);*/
//BatchReplace Operation
void getOccurrencesForBatchReplace(OccurrencesForReplaceBatchColumnSession occurrencesForReplaceBatchColumnSession, AsyncCallback<ArrayList<Occurrences>> callback);

View File

@ -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";

View File

@ -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) {

View File

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

View File

@ -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: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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<String,Object> 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);
}
}

View File

@ -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"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GroupByMonitor extends OperationMonitor implements Serializable {
private static final long serialVersionUID = -7694151843138161474L;
}

View File

@ -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" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GroupBySession implements Serializable {
private static final long serialVersionUID = -1896235499708614266L;
protected TRId trId;
protected HashMap<String, Object> map;
public GroupBySession() {
}
public GroupBySession(TRId trId, HashMap<String, Object> map) {
this.trId = trId;
this.map = map;
}
public TRId getTrId() {
return trId;
}
public void setTrId(TRId trId) {
this.trId = trId;
}
public HashMap<String, Object> getMap() {
return map;
}
public void setMap(HashMap<String, Object> map) {
this.map = map;
}
@Override
public String toString() {
return "GroupBySession [trId=" + trId + ", map=" + map + "]";
}
}