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:
parent
d93fecc5c1
commit
d70ea84ca9
|
@ -1,12 +1,12 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<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>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</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>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
@ -33,5 +33,5 @@
|
||||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</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>
|
</classpath>
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
<ReleaseNotes>
|
<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">
|
<Changeset component="org.gcube.portlets-user.tabular-data-gwt-service.2-12-0" date="2016-07-15">
|
||||||
<Change>Updated to Liferay 6.2</Change>
|
<Change>Updated to Liferay 6.2</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
|
@ -9,7 +12,7 @@
|
||||||
<Change>Fixed SDMX Export no ExportMetadata is supported on service</Change>
|
<Change>Fixed SDMX Export no ExportMetadata is supported on service</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="org.gcube.portlets-user.tabular-data-gwt-service.2-9-0" date="2015-10-15">
|
<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>
|
||||||
<Changeset component="org.gcube.portlets-user.tabular-data-gwt-service.2-8-0" date="2015-07-03">
|
<Changeset component="org.gcube.portlets-user.tabular-data-gwt-service.2-8-0" date="2015-07-03">
|
||||||
<Change>Added Delete Validations</Change>
|
<Change>Added Delete Validations</Change>
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -14,7 +14,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.gcube.portlets.user</groupId>
|
<groupId>org.gcube.portlets.user</groupId>
|
||||||
<artifactId>tabular-data-gwt-service</artifactId>
|
<artifactId>tabular-data-gwt-service</artifactId>
|
||||||
<version>2.12.0-SNAPSHOT</version>
|
<version>2.13.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>tabular-data-gwt-service</name>
|
<name>tabular-data-gwt-service</name>
|
||||||
<description>tabular-data-gwt-service allows communication between the GUI and services</description>
|
<description>tabular-data-gwt-service allows communication between the GUI and services</description>
|
||||||
|
|
|
@ -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.OperationDefinition;
|
||||||
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution;
|
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.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.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.expression.logical.And;
|
||||||
import org.gcube.data.analysis.tabulardata.model.column.ColumnLocalId;
|
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.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.model.table.TableId;
|
||||||
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
|
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.server.trservice.OperationDefinitionMap;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
|
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.exception.TDGWTServiceException;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.replacebyexternal.ReplaceByExternalColumnsMapping;
|
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.gwtservice.shared.tr.replacebyexternal.ReplaceByExternalSession;
|
||||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.operations.OperationsId;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -36,8 +44,7 @@ public class OpExecution4ReplaceByExternal extends OpExecutionBuilder {
|
||||||
private TabularDataService service;
|
private TabularDataService service;
|
||||||
private ReplaceByExternalSession replaceByExternalSession;
|
private ReplaceByExternalSession replaceByExternalSession;
|
||||||
|
|
||||||
public OpExecution4ReplaceByExternal(
|
public OpExecution4ReplaceByExternal(TabularDataService service,
|
||||||
TabularDataService service,
|
|
||||||
ReplaceByExternalSession replaceByExternalSession) {
|
ReplaceByExternalSession replaceByExternalSession) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.replaceByExternalSession = replaceByExternalSession;
|
this.replaceByExternalSession = replaceByExternalSession;
|
||||||
|
@ -53,54 +60,159 @@ public class OpExecution4ReplaceByExternal extends OpExecutionBuilder {
|
||||||
|
|
||||||
operationDefinition = OperationDefinitionMap.map(
|
operationDefinition = OperationDefinitionMap.map(
|
||||||
OperationsId.ReplaceColumnByExpression.toString(), service);
|
OperationsId.ReplaceColumnByExpression.toString(), service);
|
||||||
|
|
||||||
TableId currentTableId=null;
|
TableId currentTableId = null;
|
||||||
if(replaceByExternalSession.getCurrentTabularResource().getTrId().isViewTable()){
|
if (replaceByExternalSession.getCurrentTabularResource().getTrId()
|
||||||
currentTableId=new TableId(Long.valueOf(replaceByExternalSession.getCurrentTabularResource().getTrId().getReferenceTargetTableId()));
|
.isViewTable()) {
|
||||||
|
currentTableId = new TableId(Long.valueOf(replaceByExternalSession
|
||||||
|
.getCurrentTabularResource().getTrId()
|
||||||
|
.getReferenceTargetTableId()));
|
||||||
} else {
|
} else {
|
||||||
currentTableId=new TableId(Long.valueOf(replaceByExternalSession.getCurrentTabularResource().getTrId().getTableId()));
|
currentTableId = new TableId(Long.valueOf(replaceByExternalSession
|
||||||
|
.getCurrentTabularResource().getTrId().getTableId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TableId externalTableId=null;
|
TableId externalTableId = null;
|
||||||
if(replaceByExternalSession.getExternalTabularResource().getTrId().isViewTable()){
|
if (replaceByExternalSession.getExternalTabularResource().getTrId()
|
||||||
externalTableId=new TableId(Long.valueOf(replaceByExternalSession.getExternalTabularResource().getTrId().getReferenceTargetTableId()));
|
.isViewTable()) {
|
||||||
|
externalTableId = new TableId(Long.valueOf(replaceByExternalSession
|
||||||
|
.getExternalTabularResource().getTrId()
|
||||||
|
.getReferenceTargetTableId()));
|
||||||
} else {
|
} 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>();
|
ArrayList<Expression> conditions = new ArrayList<Expression>();
|
||||||
for(ReplaceByExternalColumnsMapping colMapping:replaceByExternalSession.getColumnsMatch()){
|
for (ReplaceByExternalColumnsMapping colMapping : replaceByExternalSession
|
||||||
ColumnReference currentColumn=new ColumnReference(currentTableId, new ColumnLocalId(colMapping.getCurrentColumn().getColumnId()));
|
.getColumnsMatch()) {
|
||||||
ColumnReference externalColumn=new ColumnReference(externalTableId, new ColumnLocalId(colMapping.getExternalColumn().getColumnId()));
|
logger.debug("ColumnsMapping: " + colMapping);
|
||||||
Equals eq=new Equals(currentColumn, externalColumn);
|
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);
|
conditions.add(eq);
|
||||||
}
|
}
|
||||||
|
|
||||||
Expression condition=null;
|
Expression condition = null;
|
||||||
if(conditions.size()<=0){
|
if (conditions.size() <= 0) {
|
||||||
logger.error("No columns selected");
|
logger.error("No columns selected");
|
||||||
throw new TDGWTServiceException("No columns selected");
|
throw new TDGWTServiceException("No columns selected");
|
||||||
} else {
|
} else {
|
||||||
if(conditions.size()==1){
|
if (conditions.size() == 1) {
|
||||||
condition=conditions.get(0);
|
condition = conditions.get(0);
|
||||||
} else {
|
} else {
|
||||||
And andCond=new And(conditions);
|
And andCond = new And(conditions);
|
||||||
condition=andCond;
|
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,
|
map.put(Constants.PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_CONDITION,
|
||||||
condition);
|
condition);
|
||||||
map.put(Constants.PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_VALUE,
|
map.put(Constants.PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_VALUE,
|
||||||
replaceColumn);
|
replaceColumn);
|
||||||
|
|
||||||
|
invocation = new OperationExecution(replaceByExternalSession
|
||||||
invocation = new OperationExecution(replaceByExternalSession.getCurrentColumn().getColumnId(),
|
.getCurrentColumn().getColumnId(),
|
||||||
operationDefinition.getOperationId(), map);
|
operationDefinition.getOperationId(), map);
|
||||||
|
|
||||||
|
|
||||||
operationExecutionSpec.setOp(invocation);
|
operationExecutionSpec.setOp(invocation);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue