From b40d1ace03d92d3c810529b2c172744cac112b41 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 31 Mar 2015 16:06:16 +0000 Subject: [PATCH] Updated AddColumn git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@113838 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../td/gwtservice/server/SessionUtil.java | 7 +- .../gwtservice/server/TDGWTServiceImpl.java | 23 +++-- .../opexecution/OpExecution4AddColumn.java | 95 ++++++++++++++----- .../td/gwtservice/shared/tr/ColumnMockUp.java | 2 +- .../shared/tr/column/AddColumnSession.java | 30 ++++-- 5 files changed, 108 insertions(+), 49 deletions(-) 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 09a7028..a6b65db 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 @@ -17,7 +17,6 @@ import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portlets.user.td.gwtservice.server.file.CSVFileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.CodelistMappingFileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.trservice.TRTasksManager; -import org.gcube.portlets.user.td.gwtservice.shared.Constants; import org.gcube.portlets.user.td.gwtservice.shared.chart.ChartTopRatingSession; import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; @@ -88,10 +87,10 @@ public class SessionUtil { ASLSession session; if (username == null) { logger.warn("no user found in session, using test one"); - /*throw new TDGWTSessionExpiredException("Session Expired!"); */ + throw new TDGWTSessionExpiredException("Session Expired!"); // Remove comment for Test - + /* username = Constants.DEFAULT_USER; String scope = Constants.DEFAULT_SCOPE; @@ -99,7 +98,7 @@ public class SessionUtil { session = SessionManager.getInstance().getASLSession( httpSession.getId(), username); session.setScope(scope); - + */ } else { session = SessionManager.getInstance().getASLSession( httpSession.getId(), username); 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 882c2b6..651e3ad 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 @@ -5256,14 +5256,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } - /** - * - * {@inheritDoc} - */ - public String startAddColumn(AddColumnSession addColumnSession) + public String startAddColumn(AddColumnSession addColumnSession, + Expression expression, HttpSession session) throws TDGWTServiceException { try { - HttpSession session = this.getThreadLocalRequest().getSession(); SessionUtil.setAddColumnSession(session, addColumnSession); ASLSession aslSession = SessionUtil.getAslSession(session); @@ -5282,7 +5278,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements checkTabularResourceIsFinal(tabularResource); OpExecution4AddColumn opEx = new OpExecution4AddColumn(service, - addColumnSession); + addColumnSession,expression); OpExecutionDirector director = new OpExecutionDirector(); director.setOperationExecutionBuilder(opEx); director.constructOperationExecution(); @@ -5300,9 +5296,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TaskWrapper taskWrapper = new TaskWrapper(trTask, UIOperationsId.AddColumn, addColumnSession.getTrId()); SessionUtil.setStartedTask(session, taskWrapper); - return trTask.getId().getValue(); - } catch (TDGWTServiceException e) { throw e; } catch (SecurityException e) { @@ -5316,6 +5310,17 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } + /** + * + * {@inheritDoc} + */ + @Override + public String startAddColumn(AddColumnSession addColumnSession) + throws TDGWTServiceException { + HttpSession session = this.getThreadLocalRequest().getSession(); + return startAddColumn(addColumnSession,null,session); + } + /** * * {@inheritDoc} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4AddColumn.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4AddColumn.java index 28a26f1..6b0baa8 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4AddColumn.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4AddColumn.java @@ -5,6 +5,7 @@ import java.util.Map; 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.expression.Expression; import org.gcube.data.analysis.tabulardata.model.metadata.common.ImmutableLocalizedText; import org.gcube.data.analysis.tabulardata.service.TabularDataService; import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap; @@ -34,11 +35,13 @@ public class OpExecution4AddColumn extends OpExecutionBuilder { private TabularDataService service; private AddColumnSession addColumnSession; + private Expression expression; public OpExecution4AddColumn(TabularDataService service, - AddColumnSession addColumnSession) { + AddColumnSession addColumnSession, Expression expression) { this.service = service; this.addColumnSession = addColumnSession; + this.expression = expression; } @Override @@ -52,12 +55,10 @@ public class OpExecution4AddColumn extends OpExecutionBuilder { Map map = new HashMap(); - ColumnMockUp defNewColumn = addColumnSession.getColumn(); + ColumnMockUp defNewColumn = addColumnSession.getColumnMockUp(); ColumnTypeCode type = defNewColumn.getColumnType(); - - - + switch (type) { case ANNOTATION: map.put(Constants.PARAMETER_ADD_COLUMN_COLUMN_TYPE, @@ -67,9 +68,19 @@ public class OpExecution4AddColumn extends OpExecutionBuilder { ColumnDataTypeMap.map(ColumnDataType.Text)); map.put(Constants.PARAMETER_ADD_COLUMN_LABEL, new ImmutableLocalizedText(defNewColumn.getLabel())); - map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, - TDTypeValueMap.map(ColumnDataType.Text, - defNewColumn.getDefaultValue())); + + if (defNewColumn.hasExpression()) { + map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, expression); + } else { + if (defNewColumn.getDefaultValue() != null + && !defNewColumn.getDefaultValue().isEmpty()) { + map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, + TDTypeValueMap.map(ColumnDataType.Text, + defNewColumn.getDefaultValue())); + } + + } + invocation = new OperationExecution( operationDefinition.getOperationId(), map); break; @@ -77,13 +88,21 @@ public class OpExecution4AddColumn extends OpExecutionBuilder { map.put(Constants.PARAMETER_ADD_COLUMN_COLUMN_TYPE, ColumnTypeCodeMap.getColumnType(defNewColumn .getColumnType())); - map.put(Constants.PARAMETER_ADD_COLUMN_DATA_TYPE, + map.put(Constants.PARAMETER_ADD_COLUMN_DATA_TYPE, ColumnDataTypeMap.map(defNewColumn.getColumnDataType())); map.put(Constants.PARAMETER_ADD_COLUMN_LABEL, new ImmutableLocalizedText(defNewColumn.getLabel())); - map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, TDTypeValueMap.map( - defNewColumn.getColumnDataType(), - defNewColumn.getDefaultValue())); + if (defNewColumn.hasExpression()) { + map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, expression); + } else { + if (defNewColumn.getDefaultValue() != null + && !defNewColumn.getDefaultValue().isEmpty()) { + map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, + TDTypeValueMap.map( + defNewColumn.getColumnDataType(), + defNewColumn.getDefaultValue())); + } + } invocation = new OperationExecution( operationDefinition.getOperationId(), map); break; @@ -95,9 +114,16 @@ public class OpExecution4AddColumn extends OpExecutionBuilder { ColumnDataTypeMap.map(ColumnDataType.Text)); map.put(Constants.PARAMETER_ADD_COLUMN_LABEL, new ImmutableLocalizedText(defNewColumn.getLabel())); - map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, - TDTypeValueMap.map(ColumnDataType.Text, - defNewColumn.getDefaultValue())); + if (defNewColumn.hasExpression()) { + map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, expression); + } else { + if (defNewColumn.getDefaultValue() != null + && !defNewColumn.getDefaultValue().isEmpty()) { + map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, + TDTypeValueMap.map(ColumnDataType.Text, + defNewColumn.getDefaultValue())); + } + } invocation = new OperationExecution( operationDefinition.getOperationId(), map); break; @@ -109,9 +135,16 @@ public class OpExecution4AddColumn extends OpExecutionBuilder { ColumnDataTypeMap.map(ColumnDataType.Text)); map.put(Constants.PARAMETER_ADD_COLUMN_LABEL, new ImmutableLocalizedText(defNewColumn.getLabel())); - map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, - TDTypeValueMap.map(ColumnDataType.Text, - defNewColumn.getDefaultValue())); + if (defNewColumn.hasExpression()) { + map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, expression); + } else { + if (defNewColumn.getDefaultValue() != null + && !defNewColumn.getDefaultValue().isEmpty()) { + map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, + TDTypeValueMap.map(ColumnDataType.Text, + defNewColumn.getDefaultValue())); + } + } invocation = new OperationExecution( operationDefinition.getOperationId(), map); break; @@ -123,9 +156,13 @@ public class OpExecution4AddColumn extends OpExecutionBuilder { ColumnDataTypeMap.map(ColumnDataType.Text)); map.put(Constants.PARAMETER_ADD_COLUMN_LABEL, new ImmutableLocalizedText(defNewColumn.getLabel())); - map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, - TDTypeValueMap.map(ColumnDataType.Text, - defNewColumn.getDefaultValue())); + if (defNewColumn.hasExpression()) { + map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, expression); + } else { + map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, + TDTypeValueMap.map(ColumnDataType.Text, + defNewColumn.getDefaultValue())); + } invocation = new OperationExecution( operationDefinition.getOperationId(), map); break; @@ -139,9 +176,18 @@ public class OpExecution4AddColumn extends OpExecutionBuilder { ColumnDataTypeMap.map(defNewColumn.getColumnDataType())); map.put(Constants.PARAMETER_ADD_COLUMN_LABEL, new ImmutableLocalizedText(defNewColumn.getLabel())); - map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, TDTypeValueMap.map( - defNewColumn.getColumnDataType(), - defNewColumn.getDefaultValue())); + if (defNewColumn.hasExpression()) { + map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, expression); + + } else { + if (defNewColumn.getDefaultValue() != null + && !defNewColumn.getDefaultValue().isEmpty()) { + map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, + TDTypeValueMap.map( + defNewColumn.getColumnDataType(), + defNewColumn.getDefaultValue())); + } + } invocation = new OperationExecution( operationDefinition.getOperationId(), map); break; @@ -152,7 +198,6 @@ public class OpExecution4AddColumn extends OpExecutionBuilder { } - operationExecutionSpec.setOp(invocation); } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ColumnMockUp.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ColumnMockUp.java index a29d6e8..913d329 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ColumnMockUp.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ColumnMockUp.java @@ -298,7 +298,7 @@ public class ColumnMockUp implements Serializable { this.id = id; } - public boolean isHasExpression() { + public boolean hasExpression() { return hasExpression; } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/AddColumnSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/AddColumnSession.java index 27d8ade..8153787 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/AddColumnSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/AddColumnSession.java @@ -16,38 +16,48 @@ public class AddColumnSession implements Serializable { private static final long serialVersionUID = -1896235499708614266L; private TRId trId; - private ColumnMockUp column; + private ColumnMockUp columnMockUp; public AddColumnSession(){ - + super(); } - public AddColumnSession(TRId trId,ColumnMockUp column){ - this.trId=trId; - this.column=column; + + public AddColumnSession(TRId trId, ColumnMockUp columnMockUp) { + super(); + this.trId = trId; + this.columnMockUp = columnMockUp; } + + public TRId getTrId() { return trId; } + public void setTrId(TRId trId) { this.trId = trId; } - public ColumnMockUp getColumn() { - return column; + + public ColumnMockUp getColumnMockUp() { + return columnMockUp; } - public void setColumn(ColumnMockUp column) { - this.column = column; + + public void setColumnMockUp(ColumnMockUp columnMockUp) { + this.columnMockUp = columnMockUp; } + @Override public String toString() { - return "AddColumnSession [trId=" + trId + ", column=" + column + "]"; + return "AddColumnSession [trId=" + trId + ", columnMockUp=" + + columnMockUp + "]"; } + }