Added Time Aggregation Operation

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@101086 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-10-28 15:18:18 +00:00
parent 33e2e4f415
commit ae888c2c08
7 changed files with 279 additions and 75 deletions

View File

@ -62,6 +62,8 @@ public class SessionConstants {
protected static final String GROUPBY_SESSION = "GROUPBY_SESSION";
protected static final String TIME_AGGREGATION_SESSION = "TIME_AGGREGATION_SESSION";
protected static final String UNION_SESSION = "UNION_SESSION";
protected static final String STATISTICAL_OPERATION_SESSION = "STATISTICAL_OPERATION_SESSION";

View File

@ -47,6 +47,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnSessi
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.SplitColumnSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupBySession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.TimeAggregationSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.DenormalizationSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession;
@ -1318,6 +1319,33 @@ public class SessionUtil {
groupBySession);
}
//
public static TimeAggregationSession getTimeAggregationSession(HttpSession httpSession) {
TimeAggregationSession timeAggregationSession = (TimeAggregationSession) httpSession
.getAttribute(SessionConstants.TIME_AGGREGATION_SESSION);
if (timeAggregationSession != null) {
return timeAggregationSession;
} else {
timeAggregationSession = new TimeAggregationSession();
httpSession.setAttribute(SessionConstants.TIME_AGGREGATION_SESSION,
timeAggregationSession);
return timeAggregationSession;
}
}
public static void setTimeAggregationSession(HttpSession httpSession,
TimeAggregationSession timeAggregationSession) {
TimeAggregationSession timeAggr = (TimeAggregationSession) httpSession
.getAttribute(SessionConstants.TIME_AGGREGATION_SESSION);
if (timeAggr != null) {
httpSession.removeAttribute(SessionConstants.TIME_AGGREGATION_SESSION);
}
httpSession.setAttribute(SessionConstants.TIME_AGGREGATION_SESSION,
timeAggregationSession);
}
//
public static CodelistMappingSession getCodelistMappingSession(

View File

@ -132,6 +132,7 @@ import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Repl
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SDMXCodelistImport;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SplitColumn;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4StatisticalOperation;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4TimeAggregation;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Union;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecutionDirector;
import org.gcube.portlets.user.td.gwtservice.server.resource.ResourceTDCreator;
@ -214,6 +215,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.SplitColumnSession
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.mapping.ColumnMappingData;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupBySession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.TimeAggregationSession;
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.TRLicenceMetadata;
@ -808,12 +810,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setRelationship(relData);
}
NamesMetadata labelsMetadata = null;
if (c.contains(NamesMetadata.class)) {
labelsMetadata = c.getMetadata(NamesMetadata.class);
}
}
if (labelsMetadata == null) {
cData.setLabel("nolabel");
logger.debug("LabelsMetadata no labels");
@ -841,17 +843,18 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
dataLocaleMetadata = c
.getMetadata(DataLocaleMetadata.class);
cData.setLocale(dataLocaleMetadata.getLocale());
}
PeriodTypeMetadata periodTypeMetadata= null;
}
PeriodTypeMetadata periodTypeMetadata = null;
if (c.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = c
.getMetadata(PeriodTypeMetadata.class);
PeriodType periodType=periodTypeMetadata.getType();
cData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
PeriodType periodType = periodTypeMetadata
.getType();
cData.setPeriodDataType(PeriodTypeMap
.map(periodType));
}
cData.setTrId(trId);
columns.add(cData);
i++;
@ -925,12 +928,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setRelationship(relData);
}
NamesMetadata labelsMetadata = null;
if (c.contains(NamesMetadata.class)) {
labelsMetadata = c.getMetadata(NamesMetadata.class);
}
}
if (labelsMetadata == null) {
cData.setLabel("nolabel");
logger.debug("LabelsMetadata no labels");
@ -958,15 +961,17 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
dataLocaleMetadata = c
.getMetadata(DataLocaleMetadata.class);
cData.setLocale(dataLocaleMetadata.getLocale());
}
PeriodTypeMetadata periodTypeMetadata= null;
}
PeriodTypeMetadata periodTypeMetadata = null;
if (c.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = c
.getMetadata(PeriodTypeMetadata.class);
PeriodType periodType=periodTypeMetadata.getType();
cData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
PeriodType periodType = periodTypeMetadata
.getType();
cData.setPeriodDataType(PeriodTypeMap
.map(periodType));
}
cData.setTrId(trId);
columns.add(cData);
@ -1042,8 +1047,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
NamesMetadata labelsMetadata = null;
if (c.contains(NamesMetadata.class)) {
labelsMetadata = c.getMetadata(NamesMetadata.class);
}
}
if (labelsMetadata == null) {
cData.setLabel("nolabel");
logger.debug("LabelsMetadata no labels");
@ -1071,17 +1076,16 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
dataLocaleMetadata = c
.getMetadata(DataLocaleMetadata.class);
cData.setLocale(dataLocaleMetadata.getLocale());
}
PeriodTypeMetadata periodTypeMetadata= null;
}
PeriodTypeMetadata periodTypeMetadata = null;
if (c.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = c
.getMetadata(PeriodTypeMetadata.class);
PeriodType periodType=periodTypeMetadata.getType();
PeriodType periodType = periodTypeMetadata.getType();
cData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
}
ViewColumnMetadata viewColumnMetadata = null;
if (c.contains(ViewColumnMetadata.class)) {
viewColumnMetadata = c
@ -1176,8 +1180,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
NamesMetadata labelsMetadata = null;
if (c.contains(NamesMetadata.class)) {
labelsMetadata = c.getMetadata(NamesMetadata.class);
}
}
if (labelsMetadata == null) {
cData.setLabel("nolabel");
logger.debug("LabelsMetadata no labels");
@ -1205,16 +1209,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
dataLocaleMetadata = c
.getMetadata(DataLocaleMetadata.class);
cData.setLocale(dataLocaleMetadata.getLocale());
}
PeriodTypeMetadata periodTypeMetadata= null;
}
PeriodTypeMetadata periodTypeMetadata = null;
if (c.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = c
.getMetadata(PeriodTypeMetadata.class);
PeriodType periodType=periodTypeMetadata.getType();
PeriodType periodType = periodTypeMetadata.getType();
cData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
}
ViewColumnMetadata viewColumnMetadata = null;
if (c.contains(ViewColumnMetadata.class)) {
@ -1255,14 +1258,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (cId != null) {
for (int j = 0; j < columns.size(); j++) {
ColumnData col = columns.get(j);
if (col.getColumnId() != null && !col.getColumnId().isEmpty()
if (col.getColumnId() != null
&& !col.getColumnId().isEmpty()
&& col.isViewColumn()
&& col.getColumnId().compareTo(cId) != 0
&& col.getColumnViewData()
.getSourceTableDimensionColumnId()
.compareTo(
colDimension
.getColumnId()) == 0) {
colDimension.getColumnId()) == 0) {
columns.remove(col);
break;
}
@ -1271,7 +1274,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
return columns;
} catch (TDGWTServiceException e) {
@ -1347,12 +1349,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setRelationship(relData);
}
NamesMetadata labelsMetadata = null;
if (c.contains(NamesMetadata.class)) {
labelsMetadata = c.getMetadata(NamesMetadata.class);
}
}
if (labelsMetadata == null) {
cData.setLabel("nolabel");
logger.debug("LabelsMetadata no labels");
@ -1363,14 +1365,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLabel("nolabel");
logger.debug("ColumnLabel no label in en");
} else {
if (cl.getValue() == null
|| cl.getValue().isEmpty()) {
if (cl.getValue() == null || cl.getValue().isEmpty()) {
cData.setLabel("nolabel");
logger.debug("ColumnLabel no label in en");
} else {
cData.setLabel(cl.getValue());
logger.debug("Column Set Label: "
+ cl.getValue());
logger.debug("Column Set Label: " + cl.getValue());
}
}
}
@ -1380,15 +1380,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
dataLocaleMetadata = c
.getMetadata(DataLocaleMetadata.class);
cData.setLocale(dataLocaleMetadata.getLocale());
}
PeriodTypeMetadata periodTypeMetadata= null;
}
PeriodTypeMetadata periodTypeMetadata = null;
if (c.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = c
.getMetadata(PeriodTypeMetadata.class);
PeriodType periodType=periodTypeMetadata.getType();
PeriodType periodType = periodTypeMetadata.getType();
cData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
}
cData.setTrId(trId);
@ -1472,8 +1472,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
NamesMetadata labelsMetadata = null;
if (c.contains(NamesMetadata.class)) {
labelsMetadata = c.getMetadata(NamesMetadata.class);
}
}
if (labelsMetadata == null) {
cData.setLabel("nolabel");
logger.debug("LabelsMetadata no labels");
@ -1484,14 +1484,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLabel("nolabel");
logger.debug("ColumnLabel no label in en");
} else {
if (cl.getValue() == null
|| cl.getValue().isEmpty()) {
if (cl.getValue() == null || cl.getValue().isEmpty()) {
cData.setLabel("nolabel");
logger.debug("ColumnLabel no label in en");
} else {
cData.setLabel(cl.getValue());
logger.debug("Column Set Label: "
+ cl.getValue());
logger.debug("Column Set Label: " + cl.getValue());
}
}
}
@ -1501,15 +1499,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
dataLocaleMetadata = c
.getMetadata(DataLocaleMetadata.class);
cData.setLocale(dataLocaleMetadata.getLocale());
}
PeriodTypeMetadata periodTypeMetadata= null;
}
PeriodTypeMetadata periodTypeMetadata = null;
if (c.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = c
.getMetadata(PeriodTypeMetadata.class);
PeriodType periodType=periodTypeMetadata.getType();
PeriodType periodType = periodTypeMetadata.getType();
cData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
}
cData.setTrId(trId);
@ -4945,12 +4943,13 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setTypeCode(c.getColumnType().getCode());
cData.setTypeName(c.getColumnType().getName());
cData.setDataTypeName(c.getDataType().getName());
NamesMetadata labelsMetadata = null;
if (c.contains(NamesMetadata.class)) {
labelsMetadata = c.getMetadata(NamesMetadata.class);
}
labelsMetadata = c
.getMetadata(NamesMetadata.class);
}
if (labelsMetadata == null) {
cData.setLabel("nolabel");
logger.debug("LabelsMetadata no labels");
@ -4978,16 +4977,17 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
dataLocaleMetadata = c
.getMetadata(DataLocaleMetadata.class);
cData.setLocale(dataLocaleMetadata.getLocale());
}
PeriodTypeMetadata periodTypeMetadata= null;
}
PeriodTypeMetadata periodTypeMetadata = null;
if (c.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = c
.getMetadata(PeriodTypeMetadata.class);
PeriodType periodType=periodTypeMetadata.getType();
cData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
PeriodType periodType = periodTypeMetadata
.getType();
cData.setPeriodDataType(PeriodTypeMap
.map(periodType));
}
cData.setTrId(trId);
columns.add(cData);
@ -7267,6 +7267,66 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
// TODO
public String startTimeAggregation(
TimeAggregationSession timeAggregationSession, HttpSession session)
throws TDGWTServiceException {
try {
// HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.setTimeAggregationSession(session,
timeAggregationSession);
ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("StartGroupBy: " + timeAggregationSession);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTRId(timeAggregationSession.getTrId());
TabularResourceId tabularResourceId = new TabularResourceId(
Long.valueOf(timeAggregationSession.getTrId().getId()));
TabularResource tabularResource = service
.getTabularResource(tabularResourceId);
checkTabularResourceIsFlow(tabularResource);
checkTabularResourceLocked(tabularResource);
checkTabularResourceIsFinal(tabularResource);
OpExecution4TimeAggregation opEx = new OpExecution4TimeAggregation(
service, timeAggregationSession);
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");
}
logger.debug("OperationInvocation: \n" + invocation.toString());
Task trTask = service.execute(invocation, tabularResourceId);
logger.debug("GroupBy start on service: TaskId " + trTask.getId());
TaskWrapper taskWrapper = new TaskWrapper(trTask,
UIOperationsId.TimeAggregation,
timeAggregationSession.getTrId());
SessionUtil.setStartedTask(session, taskWrapper);
return trTask.getId().getValue();
} catch (TDGWTServiceException e) {
throw e;
} catch (SecurityException e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Security exception, you haven't rights!");
} catch (Throwable e) {
e.printStackTrace();
throw new TDGWTServiceException("Error in start Time Aggregation: "
+ e.getLocalizedMessage());
}
}
@Override
public String startNormalization(NormalizationSession normalizationSession)
throws TDGWTServiceException {

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.TimeAggregationSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Operation Execution for Time Aggregation
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class OpExecution4TimeAggregation extends OpExecutionBuilder {
protected static Logger logger = LoggerFactory
.getLogger(OpExecution4TimeAggregation.class);
private TabularDataService service;
private TimeAggregationSession timeAggregationSession;
public OpExecution4TimeAggregation(TabularDataService service,
TimeAggregationSession timeAggregationSession) {
this.service = service;
this.timeAggregationSession = timeAggregationSession;
}
@Override
public void buildOpEx() throws TDGWTServiceException {
OperationExecution invocation = null;
logger.debug(timeAggregationSession.toString());
OperationDefinition operationDefinition;
HashMap<String,Object> map=timeAggregationSession.getMap();
if(map==null){
logger.error("In TimeAggregationSession map is null");
throw new TDGWTServiceException("In TimeAggregationSession map is null");
}
operationDefinition = OperationDefinitionMap.map(
OperationsId.TimeAggregation.toString(), service);
invocation = new OperationExecution(
operationDefinition.getOperationId(), map);
operationExecutionSpec.setOp(invocation);
}
}

View File

@ -101,6 +101,7 @@ public enum OperationsId {
GroupBy("3006"),
RemoveDuplicateTuples("3007"),
Normalize("3008"),
TimeAggregation("3009"),
ReplaceColumnByExpression("3101"),
ReplaceById("3102"),
FilterByExpression("3201"),

View File

@ -84,6 +84,7 @@ public enum UIOperationsId {
MergeColumn("Merge Column"),
SplitColumn("Split Column"),
Normalize("Normalize"),
TimeAggregation("Time Aggregation"),
ReplaceValue("Replace Value"),
ReplaceByExpression("Replace By Expression"),
ReplaceBatch("Replace Batch"),

View File

@ -0,0 +1,52 @@
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 TimeAggregationSession implements Serializable {
private static final long serialVersionUID = -1896235499708614266L;
protected TRId trId;
protected HashMap<String, Object> map;
public TimeAggregationSession() {
}
public TimeAggregationSession(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 "TimeAggregationSession [trId=" + trId + ", map=" + map + "]";
}
}