Skip to content
Snippets Groups Projects
Commit 146d00e7 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Bugfix NPE and integer/boolean conversion

parent 615b59cf
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>it.inaf.ia2.tap</groupId> <groupId>it.inaf.ia2.tap</groupId>
<artifactId>tasman-core</artifactId> <artifactId>tasman-core</artifactId>
<version>1.3.0</version> <version>1.3.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>tasman-core</name> <name>tasman-core</name>
<properties> <properties>
......
...@@ -71,6 +71,23 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu ...@@ -71,6 +71,23 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu
return null; return null;
} }
/**
* Special behavior for retro-compatibility with oldest TAP_SCHEMA versions
* in which the indexed column was represented using 1 and 0 instead boolean
* values.
*/
private void fixIndexedMetadataValues() {
boolean useIntForBool = tapSchema.getTapSchemaModel()
.getTable(TapSchema.COLUMNS_TABLE)
.get(Column.INDEXED_KEY).getJavaType() == Integer.class;
if (useIntForBool) {
for (Map<String, Object> cm : columnsMetadata.values()) {
boolean indexed = (boolean) cm.get(Column.INDEXED_KEY);
cm.put(Column.INDEXED_KEY, indexed ? 1 : 0);
}
}
}
protected Table(TapSchema tapSchema, Schema schema, String tableSimpleName) throws SQLException { protected Table(TapSchema tapSchema, Schema schema, String tableSimpleName) throws SQLException {
super(tapSchema, tapSchema.getTableModel(TapSchema.TABLES_TABLE), schema.getTableMetadata(tableSimpleName)); super(tapSchema, tapSchema.getTableModel(TapSchema.TABLES_TABLE), schema.getTableMetadata(tableSimpleName));
...@@ -82,6 +99,7 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu ...@@ -82,6 +99,7 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu
DBBroker broker = tapSchema.getDBBroker(schema.getName()); DBBroker broker = tapSchema.getDBBroker(schema.getName());
tableTableModel = getTableTableModel(); tableTableModel = getTableTableModel();
columnsMetadata = broker.getAllColumnsMetadata(schema.getName(), tableSimpleName, tableTableModel, tapSchema.getDataTypeMode()); columnsMetadata = broker.getAllColumnsMetadata(schema.getName(), tableSimpleName, tableTableModel, tapSchema.getDataTypeMode());
fixIndexedMetadataValues();
for (Map.Entry<String, Map<String, Object>> entry : columnsMetadata.entrySet()) { for (Map.Entry<String, Map<String, Object>> entry : columnsMetadata.entrySet()) {
// Adding table names to columns metadata // Adding table names to columns metadata
......
...@@ -162,12 +162,23 @@ public class TapSchemaLoader { ...@@ -162,12 +162,23 @@ public class TapSchemaLoader {
Schema parentSchema = column.getParent().getParent(); Schema parentSchema = column.getParent().getParent();
if (parentSchema.getName().equals(tapSchema.getName())) { if (parentSchema.getName().equals(tapSchema.getName())) {
return equalsOneOf(key, Column.STD_KEY, Column.PRINCIPAL_KEY); return equalsOneOf(key, Column.STD_KEY, Column.PRINCIPAL_KEY);
} else if (parentSchema.getName().equals(tapSchema.getIvoaSchemaModel().getName())) { } else {
SchemaModel ivoaSchemaModel = tapSchema.getIvoaSchemaModel();
if (ivoaSchemaModel != null
&& parentSchema.getName().equals(ivoaSchemaModel.getName())) {
return equalsOneOf(key, Column.STD_KEY, Column.PRINCIPAL_KEY, return equalsOneOf(key, Column.STD_KEY, Column.PRINCIPAL_KEY,
Column.UCD_KEY, Column.UNIT_KEY, Column.UTYPE_KEY, Column.DATATYPE_KEY); Column.UCD_KEY, Column.UNIT_KEY, Column.UTYPE_KEY, Column.DATATYPE_KEY);
} }
return false; return false;
} }
}
private Object getCompatibleIntOrBoolValue(String key, boolean value) {
if (tapSchema.getTapSchemaModel().getTable(COLUMNS_TABLE).get(key).getJavaType() == Integer.class) {
return value ? 1 : 0;
}
return value;
}
private Object getCorrectValue(Column column, String key) { private Object getCorrectValue(Column column, String key) {
...@@ -187,9 +198,9 @@ public class TapSchemaLoader { ...@@ -187,9 +198,9 @@ public class TapSchemaLoader {
ColumnModel columnModel = schemaModel.getTable(column.getParent().getName()).get(column.getName()); ColumnModel columnModel = schemaModel.getTable(column.getParent().getName()).get(column.getName());
switch (key) { switch (key) {
case Column.STD_KEY: case Column.STD_KEY:
return columnModel.isStandard(); return getCompatibleIntOrBoolValue(Column.STD_KEY, columnModel.isStandard());
case Column.PRINCIPAL_KEY: case Column.PRINCIPAL_KEY:
return columnModel.isPrincipal(); return getCompatibleIntOrBoolValue(Column.PRINCIPAL_KEY, columnModel.isPrincipal());
case Column.UCD_KEY: case Column.UCD_KEY:
return columnModel.getUcd(); return columnModel.getUcd();
case Column.UNIT_KEY: case Column.UNIT_KEY:
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<groupId>it.inaf.ia2.tap</groupId> <groupId>it.inaf.ia2.tap</groupId>
<artifactId>tasman-webapp</artifactId> <artifactId>tasman-webapp</artifactId>
<version>1.3.0</version> <version>1.3.1</version>
<packaging>war</packaging> <packaging>war</packaging>
<name>tasman-webapp</name> <name>tasman-webapp</name>
...@@ -107,7 +107,7 @@ ...@@ -107,7 +107,7 @@
<dependency> <dependency>
<groupId>it.inaf.ia2.tap</groupId> <groupId>it.inaf.ia2.tap</groupId>
<artifactId>tasman-core</artifactId> <artifactId>tasman-core</artifactId>
<version>1.2.0</version> <version>1.3.1</version>
<exclusions> <exclusions>
<!-- exclusion due to tomcat-jdbc dependency conflicting with Jetty --> <!-- exclusion due to tomcat-jdbc dependency conflicting with Jetty -->
<exclusion> <exclusion>
...@@ -124,7 +124,7 @@ ...@@ -124,7 +124,7 @@
<dependency> <dependency>
<groupId>it.inaf.ia2.tap</groupId> <groupId>it.inaf.ia2.tap</groupId>
<artifactId>tasman-core</artifactId> <artifactId>tasman-core</artifactId>
<version>1.2.0</version> <version>1.3.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ari.ucidy</groupId> <groupId>ari.ucidy</groupId>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment