refs 4883: TabMan / Replace by External / Error

https://support.d4science.org/issues/4883

Fixed column cast on Replace by External

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@131044 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-08-30 14:54:55 +00:00
parent d93fecc5c1
commit d70ea84ca9
4 changed files with 151 additions and 36 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java">
<classpathentry kind="src" output="target/tabular-data-gwt-service-2.13.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/tabular-data-gwt-service-2.13.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -33,5 +33,5 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/tabular-data-gwt-service-2.12.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/tabular-data-gwt-service-2.13.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -1,4 +1,7 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-user.tabular-data-gwt-service.2-13-0" date="2016-09-30">
<Change>Fixed cast on Replace by External[issue #4883]</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.tabular-data-gwt-service.2-12-0" date="2016-07-15">
<Change>Updated to Liferay 6.2</Change>
</Changeset>
@ -9,7 +12,7 @@
<Change>Fixed SDMX Export no ExportMetadata is supported on service</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.tabular-data-gwt-service.2-9-0" date="2015-10-15">
<Change>Added support to WorkspaceExplorer [ticket #428]</Change>
<Change>Added support to WorkspaceExplorer [issue #428]</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.tabular-data-gwt-service.2-8-0" date="2015-07-03">
<Change>Added Delete Validations</Change>

View File

@ -14,7 +14,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-gwt-service</artifactId>
<version>2.12.0-SNAPSHOT</version>
<version>2.13.0-SNAPSHOT</version>
<name>tabular-data-gwt-service</name>
<description>tabular-data-gwt-service allows communication between the GUI and services</description>

View File

@ -7,18 +7,26 @@ 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.expression.NotEvaluableDataTypeException;
import org.gcube.data.analysis.tabulardata.expression.composite.comparable.Equals;
import org.gcube.data.analysis.tabulardata.expression.functions.Cast;
import org.gcube.data.analysis.tabulardata.expression.logical.And;
import org.gcube.data.analysis.tabulardata.model.column.ColumnLocalId;
import org.gcube.data.analysis.tabulardata.model.column.ColumnReference;
import org.gcube.data.analysis.tabulardata.model.datatype.DataType;
import org.gcube.data.analysis.tabulardata.model.datatype.IntegerType;
import org.gcube.data.analysis.tabulardata.model.datatype.NumericType;
import org.gcube.data.analysis.tabulardata.model.datatype.TextType;
import org.gcube.data.analysis.tabulardata.model.table.TableId;
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap;
import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap;
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.tr.replacebyexternal.ReplaceByExternalColumnsMapping;
import org.gcube.portlets.user.td.gwtservice.shared.tr.replacebyexternal.ReplaceByExternalSession;
import org.gcube.portlets.user.td.widgetcommonevent.shared.operations.OperationsId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -36,8 +44,7 @@ public class OpExecution4ReplaceByExternal extends OpExecutionBuilder {
private TabularDataService service;
private ReplaceByExternalSession replaceByExternalSession;
public OpExecution4ReplaceByExternal(
TabularDataService service,
public OpExecution4ReplaceByExternal(TabularDataService service,
ReplaceByExternalSession replaceByExternalSession) {
this.service = service;
this.replaceByExternalSession = replaceByExternalSession;
@ -53,54 +60,159 @@ public class OpExecution4ReplaceByExternal extends OpExecutionBuilder {
operationDefinition = OperationDefinitionMap.map(
OperationsId.ReplaceColumnByExpression.toString(), service);
TableId currentTableId=null;
if(replaceByExternalSession.getCurrentTabularResource().getTrId().isViewTable()){
currentTableId=new TableId(Long.valueOf(replaceByExternalSession.getCurrentTabularResource().getTrId().getReferenceTargetTableId()));
TableId currentTableId = null;
if (replaceByExternalSession.getCurrentTabularResource().getTrId()
.isViewTable()) {
currentTableId = new TableId(Long.valueOf(replaceByExternalSession
.getCurrentTabularResource().getTrId()
.getReferenceTargetTableId()));
} else {
currentTableId=new TableId(Long.valueOf(replaceByExternalSession.getCurrentTabularResource().getTrId().getTableId()));
currentTableId = new TableId(Long.valueOf(replaceByExternalSession
.getCurrentTabularResource().getTrId().getTableId()));
}
TableId externalTableId=null;
if(replaceByExternalSession.getExternalTabularResource().getTrId().isViewTable()){
externalTableId=new TableId(Long.valueOf(replaceByExternalSession.getExternalTabularResource().getTrId().getReferenceTargetTableId()));
TableId externalTableId = null;
if (replaceByExternalSession.getExternalTabularResource().getTrId()
.isViewTable()) {
externalTableId = new TableId(Long.valueOf(replaceByExternalSession
.getExternalTabularResource().getTrId()
.getReferenceTargetTableId()));
} else {
externalTableId=new TableId(Long.valueOf(replaceByExternalSession.getExternalTabularResource().getTrId().getTableId()));
externalTableId = new TableId(Long.valueOf(replaceByExternalSession
.getExternalTabularResource().getTrId().getTableId()));
}
ArrayList<Expression> conditions=new ArrayList<Expression>();
for(ReplaceByExternalColumnsMapping colMapping:replaceByExternalSession.getColumnsMatch()){
ColumnReference currentColumn=new ColumnReference(currentTableId, new ColumnLocalId(colMapping.getCurrentColumn().getColumnId()));
ColumnReference externalColumn=new ColumnReference(externalTableId, new ColumnLocalId(colMapping.getExternalColumn().getColumnId()));
Equals eq=new Equals(currentColumn, externalColumn);
ArrayList<Expression> conditions = new ArrayList<Expression>();
for (ReplaceByExternalColumnsMapping colMapping : replaceByExternalSession
.getColumnsMatch()) {
logger.debug("ColumnsMapping: " + colMapping);
DataType currentColumnDataType = ColumnDataTypeMap
.map(ColumnDataType.getColumnDataTypeFromId(colMapping
.getCurrentColumn().getDataTypeName()));
DataType externalColumnDataType = ColumnDataTypeMap
.map(ColumnDataType.getColumnDataTypeFromId(colMapping
.getExternalColumn().getDataTypeName()));
ColumnReference currentColumn = new ColumnReference(currentTableId,
new ColumnLocalId(colMapping.getCurrentColumn()
.getColumnId()), currentColumnDataType);
ColumnReference externalColumn = new ColumnReference(
externalTableId, new ColumnLocalId(colMapping
.getExternalColumn().getColumnId()),
externalColumnDataType);
logger.debug("CurrentColumn: " + currentColumn);
logger.debug("ExternalColumn: " + externalColumn);
if (!Cast.isCastSupported(currentColumnDataType,
externalColumnDataType)) {
logger.error("Error casting columns, types not compatible! Types: ["+currentColumnDataType+","+externalColumnDataType+"]");
throw new TDGWTServiceException(
"Error casting columns, types not compatible! Types: ["+currentColumnDataType+","+externalColumnDataType+"]");
}
logger.debug("Cast columns if need");
Equals eq;
if (currentColumnDataType.equals(externalColumnDataType)) {
eq = new Equals(currentColumn, externalColumn);
} else {
if (currentColumnDataType instanceof TextType) {
Expression externalColumnCasted;
try {
externalColumnCasted = new Cast(externalColumn,
currentColumn.getReturnedDataType());
} catch (NotEvaluableDataTypeException e) {
logger.error("Error casting external column to Text data type! "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException(
"Error casting external column to Text data type!");
}
eq = new Equals(currentColumn, externalColumnCasted);
} else {
if (externalColumnDataType instanceof TextType) {
Expression currentColumnCasted;
try {
currentColumnCasted = new Cast(currentColumn,
externalColumn.getReturnedDataType());
} catch (NotEvaluableDataTypeException e) {
logger.error("Error casting current column to Text data type! "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException(
"Error casting current column to Text data type!");
}
eq = new Equals(currentColumnCasted, externalColumn);
} else {
if (currentColumnDataType instanceof IntegerType
&& externalColumnDataType instanceof NumericType) {
Expression currentColumnCasted;
try {
currentColumnCasted = new Cast(currentColumn,
externalColumn.getReturnedDataType());
} catch (NotEvaluableDataTypeException e) {
logger.error("Error casting current column to Numeric data type! "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException(
"Error casting current column to Numeric data type!");
}
eq = new Equals(currentColumnCasted, externalColumn);
} else {
if (currentColumnDataType instanceof NumericType
&& externalColumnDataType instanceof IntegerType) {
Expression externalColumnCasted;
try {
externalColumnCasted = new Cast(externalColumn,
currentColumn.getReturnedDataType());
} catch (NotEvaluableDataTypeException e) {
logger.error("Error casting external column to Numeric data type! "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException(
"Error casting external column to Numeric data type!");
}
eq = new Equals(currentColumn, externalColumnCasted);
} else {
logger.error("Error casting columns, types not compatible! Types: ["+currentColumnDataType+","+externalColumnDataType+"]");
throw new TDGWTServiceException(
"Error casting columns, types not compatible! Types: ["+currentColumnDataType+","+externalColumnDataType+"]");
}
}
}
}
}
conditions.add(eq);
}
Expression condition=null;
if(conditions.size()<=0){
Expression condition = null;
if (conditions.size() <= 0) {
logger.error("No columns selected");
throw new TDGWTServiceException("No columns selected");
} else {
if(conditions.size()==1){
condition=conditions.get(0);
if (conditions.size() == 1) {
condition = conditions.get(0);
} else {
And andCond=new And(conditions);
condition=andCond;
And andCond = new And(conditions);
condition = andCond;
}
}
ColumnReference replaceColumn=new ColumnReference(externalTableId, new ColumnLocalId(replaceByExternalSession.getReplaceColumn().getColumnId()));
ColumnReference replaceColumn = new ColumnReference(externalTableId,
new ColumnLocalId(replaceByExternalSession.getReplaceColumn()
.getColumnId()));
map.put(Constants.PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_CONDITION,
condition);
map.put(Constants.PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_VALUE,
replaceColumn);
invocation = new OperationExecution(replaceByExternalSession.getCurrentColumn().getColumnId(),
invocation = new OperationExecution(replaceByExternalSession
.getCurrentColumn().getColumnId(),
operationDefinition.getOperationId(), map);
operationExecutionSpec.setOp(invocation);
}