Commit 39d056ce authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Allowed addition of non-standard tables and columns in TAP_SCHEMA and ivoa schemata

parent 461e793a
Pipeline #116 passed with stage
in 15 seconds
......@@ -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;
}
......
......@@ -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;
}
/**
......
......@@ -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) {
......
......@@ -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>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment