From 39d056ce14b2903fc73cd8fdb8d9a10679590eba Mon Sep 17 00:00:00 2001 From: Sonia Zorba <zorba@oats.inaf.it> Date: Thu, 12 Apr 2018 16:36:09 +0200 Subject: [PATCH] Allowed addition of non-standard tables and columns in TAP_SCHEMA and ivoa schemata --- .../src/main/java/it/inaf/ia2/tsm/Table.java | 6 ++- .../main/java/it/inaf/ia2/tsm/TapSchema.java | 6 ++- .../java/it/inaf/ia2/tsm/TapSchemaLoader.java | 40 +++++++++++++++---- .../schema_definition/tap_schema-1_1-IA2.xml | 5 --- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/Table.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/Table.java index 7dab2cf..0f92212 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/Table.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/Table.java @@ -23,6 +23,7 @@ package it.inaf.ia2.tsm; import it.inaf.ia2.tsm.datalayer.DBBroker; +import it.inaf.ia2.tsm.model.ColumnModel; import it.inaf.ia2.tsm.model.TableModel; import java.sql.SQLException; import java.util.List; @@ -148,7 +149,10 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu private boolean isMandatory(String columnName) { if (tableTableModel != null) { - return tableTableModel.get(columnName).isMandatory(); + ColumnModel columnModel = tableTableModel.get(columnName); + if (columnModel != null) { + return columnModel.isMandatory(); + } } return false; } diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchema.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchema.java index c8b2a85..a6fb6d8 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchema.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchema.java @@ -627,7 +627,11 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { * Returns the {@link SchemaModel} for the TAP_SCHEMA schema. */ public final SchemaModel getTapSchemaModel() { - return SchemaModels.getTapSchemaModel(getVersion()); + SchemaModel tapSchemaModel = SchemaModels.getTapSchemaModel(getVersion()); + if (tapSchemaModel == null) { + throw new IllegalStateException("TAP_SCHEMA model is null for version " + getVersion()); + } + return tapSchemaModel; } /** diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaLoader.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaLoader.java index bf09a08..a016ed7 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaLoader.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaLoader.java @@ -159,18 +159,42 @@ public class TapSchemaLoader { if (!ep.isUpdatable()) { return true; } + + // Here we check fixed values for columns having a XML model. + // We need to be aware that the user could alter these structures + // adding custom tables and columns, so we have to check for null + // parts of the models. + // Schema parentSchema = column.getParent().getParent(); + + SchemaModel schemaModel; if (parentSchema.getName().equals(tapSchema.getName())) { - return equalsOneOf(key, Column.STD_KEY, Column.PRINCIPAL_KEY); - } else { - SchemaModel ivoaSchemaModel = tapSchema.getIvoaSchemaModel(); - if (ivoaSchemaModel != null - && parentSchema.getName().equals(ivoaSchemaModel.getName())) { - return equalsOneOf(key, Column.STD_KEY, Column.PRINCIPAL_KEY, - Column.UCD_KEY, Column.UNIT_KEY, Column.UTYPE_KEY, Column.DATATYPE_KEY); + + if (parentSchema.getName().equals(tapSchema.getName())) { + schemaModel = tapSchema.getTapSchemaModel(); + } else { + schemaModel = tapSchema.getIvoaSchemaModel(); + } + + if (schemaModel != null) { + TableModel tableModel = schemaModel.getTable(column.getParent().getName()); + if (tableModel != null) { + ColumnModel columnModel = tableModel.get(column.getName()); + if (columnModel != null) { + if (parentSchema.getName().equals(tapSchema.getName())) { + // is a TAP_SCHEMA column + return equalsOneOf(key, Column.STD_KEY, Column.PRINCIPAL_KEY); + } else { + // is an obscore column + return equalsOneOf(key, Column.STD_KEY, Column.PRINCIPAL_KEY, + Column.UCD_KEY, Column.UNIT_KEY, Column.UTYPE_KEY, Column.DATATYPE_KEY); + } + } + } } - return false; } + + return false; } private Object getCompatibleIntOrBoolValue(String key, boolean value) { diff --git a/TASMAN-core/src/main/resources/schema_definition/tap_schema-1_1-IA2.xml b/TASMAN-core/src/main/resources/schema_definition/tap_schema-1_1-IA2.xml index 1cfde66..0745682 100644 --- a/TASMAN-core/src/main/resources/schema_definition/tap_schema-1_1-IA2.xml +++ b/TASMAN-core/src/main/resources/schema_definition/tap_schema-1_1-IA2.xml @@ -23,11 +23,6 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. --> <schema name="TAP_SCHEMA" version="1.1-IA2" extends="1.1" datatype="VOTable"> <table name="schemas"> - <column name="schemaID"> - <type>BIGINT</type> - <updatable>true</updatable> - <standard>false</standard> - </column> <column name="schemaID"> <type>BIGINT</type> <updatable>true</updatable> -- GitLab