diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/DaoColumn.java b/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/DaoColumn.java index af58bd42b4523f525bd487931a57fc122074a273..47f5397652bc8dd6d193aa707f415ca662f1d178 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/DaoColumn.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/DaoColumn.java @@ -37,6 +37,50 @@ public class DaoColumn { return false; } + /** + * Returns the list of all the columns names given a schema name and a table + * name, also if these objects have never been added into the TAP_SCHEMA. + * This can be useful to retrieve the source database structure. + */ + public static List getAllColumnsNames(DBWrapper dbWrapper, TapSchema tapSchema, String schemaName, String tableSimpleName) throws SQLException { + final List allColumns = new ArrayList<>(); + + DataSource dataSource = TSMUtil.getSchemaDataSource(dbWrapper, tapSchema, schemaName); + DatabaseType dbType = TSMUtil.getSchemaDatabaseType(dbWrapper, tapSchema, schemaName); + + String query; + if (dbType == DatabaseType.MYSQL) { + query = String.format("SHOW COLUMNS FROM `%s`.`%s`", schemaName, tableSimpleName); + } else if (dbType == DatabaseType.POSTGRES) { + query = "SELECT column_name FROM information_schema.columns WHERE table_schema = '" + schemaName + "' AND table_name = '" + tableSimpleName + "'"; + } else { + throw new UnsupportedOperationException("Database type " + dbType + " not supported"); + } + + log.debug("Executing query {}", query); + + try (Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(query)) { + + while (resultSet.next()) { + + String columnName; + if (dbType == DatabaseType.MYSQL) { + columnName = resultSet.getString("Field"); + } else if (dbType == DatabaseType.POSTGRES) { + columnName = resultSet.getString("column_name"); + } else { + throw new UnsupportedOperationException("Database type " + dbType + " not supported"); + } + + allColumns.add(columnName); + } + } + + return allColumns; + } + /** * For performance reasons all columns of a {@link Table} are loaded * together using this method. Columns {@link Status} is at first set as diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/DaoKey.java b/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/DaoKey.java index 04dcda26d6225d579b19ac6de1d87c177f04e69b..207f538e9a2e828ad65a9de0917c649394ecbe38 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/DaoKey.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/DaoKey.java @@ -340,13 +340,6 @@ public class DaoKey { } } - if (!fictitiousKeys.isEmpty()) { - log.debug("{} fictitious keys found", fictitiousKeys.size()); - for (Key key : fictitiousKeys) { - log.debug(" {}", key); - } - } - // filling fictitious keys columns for (Key key : fictitiousKeys) { try (PreparedStatement statementKeyColumns = conn.prepareStatement(queryKeyColumns)) { @@ -361,7 +354,7 @@ public class DaoKey { String fromColumn = rsKeyColumns.getString(KeyColumn.FROM_COLUMN_KEY); String targetColumn = rsKeyColumns.getString(KeyColumn.TARGET_COLUMN_KEY); - KeyColumnImpl keyColumn = new KeyColumnImpl(dbWrapper, tapSchema, key, fromColumn, targetColumn); + KeyColumn keyColumn = ((KeyImpl) key).addKeyColumn(fromColumn, targetColumn); if (supportKeyColumnID) { keyColumn.initProperty(KeyColumn.KEY_COLUMN_ID_KEY, TSMUtil.getObject(rsKeyColumns, KeyColumn.KEY_COLUMN_ID_KEY, Long.class)); } @@ -373,6 +366,13 @@ public class DaoKey { ((TapSchemaImpl) tapSchema).getAllKeys().add(key); } + if (!fictitiousKeys.isEmpty()) { + log.debug("{} fictitious keys found", fictitiousKeys.size()); + for (Key key : fictitiousKeys) { + log.debug(" {}", key); + } + } + // Check if there are remaining keys with keyId = null (valid keys // that weren't saved into the TAP_SCHEMA). int keyId = ((TapSchemaImpl) tapSchema).getMaxKeyId() + 1; diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/DaoTable.java b/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/DaoTable.java index 34dbac5acb71ad5dd3c858abd9f6accba01f0b22..79239645ed847a42a737c32dbe5bb2fd92ece21f 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/DaoTable.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/DaoTable.java @@ -32,12 +32,13 @@ public class DaoTable { /** * Retrieve the list of the names of all the tables contained in a schema, - * given their related DataSource and schema name. + * given its name, also if the schema has never been added into the + * TAP_SCHEMA. * * @return list of all tables names alphabetically and case insensitively * ordered. */ - protected static List getAllTablesNames(DBWrapper dbWrapper, TapSchema tapSchema, String schemaName) throws SQLException { + public static List getAllTablesNames(DBWrapper dbWrapper, TapSchema tapSchema, String schemaName) throws SQLException { DataSource dataSource = TSMUtil.getSchemaDataSource(dbWrapper, tapSchema, schemaName); DatabaseType dbType = TSMUtil.getSchemaDatabaseType(dbWrapper, tapSchema, schemaName); diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/TapSchemaImpl.java b/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/TapSchemaImpl.java index 00a424a94c3e70bf714dd3c7fbe52592d847c0ed..deb53eeec64f11e471a7e2810f3bb220f763235d 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/TapSchemaImpl.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/oats/ia2/tapschemamanager/api/TapSchemaImpl.java @@ -242,23 +242,11 @@ public class TapSchemaImpl implements TapSchema, Serializable { */ public int getMaxKeyId() { int maxKeyId = 0; - for (Schema schema : getChildren()) { - for (Table table : schema.getChildren()) { - for (Key key : table.getAllFromKeys()) { - if (key.getId() != null) { - int keyId = Integer.parseInt(key.getId()); - if (keyId > maxKeyId) { - maxKeyId = keyId; - } - } - } - for (Key key : table.getAllTargetKeys()) { - if (key.getId() != null) { - int keyId = Integer.parseInt(key.getId()); - if (keyId > maxKeyId) { - maxKeyId = keyId; - } - } + for (Key key : allKeys) { + if (key.getId() != null) { + int keyId = Integer.parseInt(key.getId()); + if (keyId > maxKeyId) { + maxKeyId = keyId; } } } @@ -327,6 +315,7 @@ public class TapSchemaImpl implements TapSchema, Serializable { targetTable.addTargetKey(key); allKeys.add(key); + checkKeys(); } /** diff --git a/TapSchemaManagerAPI/src/test/java/it/inaf/oats/ia2/tapschemamanager/api/TestAll.java b/TapSchemaManagerAPI/src/test/java/it/inaf/oats/ia2/tapschemamanager/api/TestAll.java index fcb071eb4a79ae32441ff4dcfca2cc93c17a0e54..c8b16fc19a0a49006bf1393229e9b77d9055e15f 100644 --- a/TapSchemaManagerAPI/src/test/java/it/inaf/oats/ia2/tapschemamanager/api/TestAll.java +++ b/TapSchemaManagerAPI/src/test/java/it/inaf/oats/ia2/tapschemamanager/api/TestAll.java @@ -1,11 +1,6 @@ package it.inaf.oats.ia2.tapschemamanager.api; -import it.inaf.oats.ia2.tapschemamanager.api.TapSchemaImpl; import it.inaf.oats.ia2.tapschemamanager.api.contract.DatabaseType; -import it.inaf.oats.ia2.tapschemamanager.api.Credentials; -import it.inaf.oats.ia2.tapschemamanager.api.DBWrapper; -import it.inaf.oats.ia2.tapschemamanager.api.UpdateOperations; -import it.inaf.oats.ia2.tapschemamanager.api.TapSchemaFactory; import it.inaf.oats.ia2.tapschemamanager.api.contract.Column; import it.inaf.oats.ia2.tapschemamanager.api.contract.Key; import it.inaf.oats.ia2.tapschemamanager.api.contract.KeyColumn; @@ -43,20 +38,20 @@ import org.slf4j.LoggerFactory; * @author Sonia Zorba {@literal } */ public class TestAll { - + private static final Logger log = LoggerFactory.getLogger(TestAll.class); - + private static final int SCHEMAS_COUNT = 2; // minimum value: 2 private static final int TABLES_COUNT = 3; - + private static List dbWrappers; - + public TestAll() { } - + @BeforeClass public static void setUpClass() throws SQLException { - + dbWrappers = new ArrayList<>(); // MYSQL @@ -70,11 +65,11 @@ public class TestAll { postgresCredentials.setHostname("localhost"); postgresCredentials.setUsername("postgres"); postgresCredentials.setPassword("pippo"); - + DBWrapper dbWrapper = new DBWrapper(mysqlCredentials); dbWrapper.testConnections(); dbWrappers.add(dbWrapper); - + dbWrapper = new DBWrapper(postgresCredentials); dbWrapper.testConnections(); //dbWrappers.add(dbWrapper); @@ -83,19 +78,19 @@ public class TestAll { //dbWrappers.add(new DBWrapper(mysqlCredentials, postgresCredentials)); //dbWrappers.add(new DBWrapper(postgresCredentials, mysqlCredentials)); } - + @AfterClass public static void tearDownClass() { } - + @Before public void setUp() { } - + @After public void tearDown() { } - + private void removeTestingDatabases() throws SQLException { for (DBWrapper dbWrapper : dbWrappers) { try (Connection sourceConnection = dbWrapper.getSourceConnection(); @@ -120,7 +115,7 @@ public class TestAll { } else { throw new UnsupportedOperationException("Database type " + dbType + " not supported"); } - + for (int i = 0; i < SCHEMAS_COUNT; i++) { if (dbType == DatabaseType.MYSQL) { statement.executeUpdate("DROP DATABASE IF EXISTS sch" + i); @@ -144,18 +139,18 @@ public class TestAll { } } } - + private void setUpTestingDatabases() throws SQLException { removeTestingDatabases(); - + for (DBWrapper dbWrapper : dbWrappers) { - + DatabaseType dbType = dbWrapper.getSourceDatabaseType(); - + try (Connection connection = dbWrapper.getSourceConnection()) { - + try (Statement statement = connection.createStatement()) { - + if (dbType == DatabaseType.MYSQL) { for (int i = 0; i < SCHEMAS_COUNT; i++) { statement.executeUpdate("CREATE DATABASE sch" + i); @@ -182,9 +177,9 @@ public class TestAll { throw new UnsupportedOperationException("Database type " + dbType + " not supported"); } } - + log.info("dbs created"); - + try (Statement statement = connection.createStatement()) { for (int j = 0; j < TABLES_COUNT - 1; j++) { String update1 = "ALTER TABLE sch0.table" + (j + 1) + " ADD COLUMN table" + j + "_id INT"; @@ -195,7 +190,7 @@ public class TestAll { } else { throw new UnsupportedOperationException("Database type " + dbType + " not supported"); } - + statement.executeUpdate(update2); } @@ -215,34 +210,11 @@ public class TestAll { } } } - - @Test - public void testTapSchemaSerialization() throws Exception { - for (DBWrapper dbWrapper : dbWrappers) { - if (dbWrapper.getTapSchemaDatabaseType() == DatabaseType.MYSQL) { // currently "tng_TAP_SCHEMA" exists in a MySQL instance - TapSchema tapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1_IA2, dbWrapper, "test_tap_schema", true); - - File temp = File.createTempFile("test_tap_schema", ".ser"); - - try (FileOutputStream fileOut = new FileOutputStream(temp); - ObjectOutputStream out = new ObjectOutputStream(fileOut)) { - out.writeObject(tapSchema); - } - - try (FileInputStream fileIn = new FileInputStream(temp); - ObjectInputStream in = new ObjectInputStream(fileIn)) { - tapSchema = (TapSchema) in.readObject(); - } - - log.debug(tapSchema.toString()); - } - } - } - + private boolean allKeysHaveDifferentId(TapSchema tapSchema) { boolean differentKeySameId = false; Map keys = new HashMap<>(); - + for (Key key : ((TapSchemaImpl) tapSchema).getAllKeys()) { if (key.getId() != null) { if (keys.get(key.getId()) != null && !key.equals(keys.get(key.getId()))) { @@ -251,17 +223,17 @@ public class TestAll { keys.put(key.getId(), key); } } - + if (differentKeySameId) { log.debug("Found different keys with the same key_id!"); for (Key key : ((TapSchemaImpl) tapSchema).getAllKeys()) { log.debug(key.toString()); } } - + return !differentKeySameId; } - + private void checkKey(Key key, String fromTableCompleteName, String[] fromColumns, String targetTableCompleteName, String[] targetColumns, boolean isVisible) { assertEquals(fromTableCompleteName, key.getFromTableCompleteName()); assertEquals(targetTableCompleteName, key.getTargetTableCompleteName()); @@ -275,20 +247,20 @@ public class TestAll { assertEquals(key.getId(), keyColumn.getKeyId()); } } - + private void checkKey(Key key, String fromTableCompleteName, String fromColumn, String targetTableCompleteName, String targetColumn, boolean isVisible) { checkKey(key, fromTableCompleteName, new String[]{fromColumn}, targetTableCompleteName, new String[]{targetColumn}, isVisible); } - + @Test - public void createNewAndUpdate2() throws SQLException { - log.info("TEST createNewAndUpdate2 STARTED"); - + public void createNewAndUpdate() throws SQLException { + log.info("TEST createNewAndUpdate STARTED"); + try { removeTestingDatabases(); - + setUpTestingDatabases(); - + for (DBWrapper dbWrapper : dbWrappers) { // Initializing a not existing TAP_SCHEMA @@ -300,7 +272,7 @@ public class TestAll { // Schema sch0 = tapSchema.addChild("sch0"); assertEquals(Status.ADDED_NOT_PERSISTED, sch0.getStatus()); - + Set allKeys = ((TapSchemaImpl) tapSchema).getAllKeys(); log.debug("ALL keys:"); for (Key key : allKeys) { @@ -338,9 +310,9 @@ public class TestAll { assertEquals(Status.ADDED_NOT_PERSISTED, sch0table0.getStatus()); assertEquals("sch0.table0", sch0table0.getCompleteName()); assertEquals(1, sch0.getChildren().size()); - + assertEquals(4, sch0table0.getAddableChildrenNames().size()); - + Column sch0table0id = sch0table0.addChild("id"); assertEquals(Status.ADDED_NOT_PERSISTED, sch0table0id.getStatus()); @@ -357,12 +329,12 @@ public class TestAll { // Adding sch0.table1 Table sch0table1 = sch0.addChild("table1"); assertEquals(2, sch0.getChildren().size()); - + assertTrue(sch0table0.getVisibleFromKeys().isEmpty()); assertTrue(sch0table0.getVisibleTargetKeys().isEmpty()); assertTrue(sch0table1.getVisibleFromKeys().isEmpty()); assertTrue(sch0table1.getVisibleTargetKeys().isEmpty()); - + sch0table1.addChild("table0_id"); // Now sch0table0.getVisibleTargetKeys() and sch0table1.getVisibleFromKeys() // have to return the same Key object with id = 1 @@ -398,7 +370,7 @@ public class TestAll { // Adding sch1.table0 Table sch1table0 = sch1.addChild("table0"); - + sch1table0.addChild("id"); sch1table0.addChild("sch0table0id"); // sch1.table0.sch0table0id -> sch0.table0.it obtains keyId = "1" sch0table0.addChild("sch1table0id");// sch0.table0.sch1table0id -> sch1.table0.it obtains keyId = "2" @@ -408,7 +380,7 @@ public class TestAll { assertEquals(1, sch0table0.getVisibleTargetKeys().size()); assertEquals(1, sch1table0.getVisibleFromKeys().size()); assertEquals(1, sch1table0.getVisibleTargetKeys().size()); - + for (Key key : allKeys) { if (key.getId() == null) { assertFalse(key.isVisible()); @@ -426,7 +398,7 @@ public class TestAll { } } } - + assertTrue(allKeysHaveDifferentId(tapSchema)); // Removing sch1 @@ -441,7 +413,7 @@ public class TestAll { assertEquals(Status.ADDED_NOT_PERSISTED, sch1.getStatus()); assertEquals(1, sch0table0.getVisibleTargetKeys().size()); assertEquals(1, sch1table0.getVisibleFromKeys().size()); - + for (Key key : allKeys) { if (key.getId() == null) { assertFalse(key.isVisible()); @@ -465,28 +437,28 @@ public class TestAll { // Table table_x = sch0.addChild("table_x"); Table table_y = sch0.addChild("table_y"); - + assertTrue(table_x.getVisibleFromKeys().isEmpty()); assertTrue(table_x.getVisibleTargetKeys().isEmpty()); assertTrue(table_y.getVisibleFromKeys().isEmpty()); assertTrue(table_y.getVisibleTargetKeys().isEmpty()); - + table_x.addChild("idx1"); table_x.addChild("idx2"); table_y.addChild("idy1"); - + assertTrue(table_x.getVisibleFromKeys().isEmpty()); assertTrue(table_x.getVisibleTargetKeys().isEmpty()); assertTrue(table_y.getVisibleFromKeys().isEmpty()); assertTrue(table_y.getVisibleTargetKeys().isEmpty()); - + table_y.addChild("idy2"); - + assertEquals(1, table_y.getVisibleFromKeys().size()); assertEquals(1, table_x.getVisibleTargetKeys().size()); assertTrue(table_x.getVisibleFromKeys().isEmpty()); assertTrue(table_y.getVisibleTargetKeys().isEmpty()); - + for (Key key : allKeys) { if (key.getId() == null) { assertFalse(key.isVisible()); @@ -507,7 +479,7 @@ public class TestAll { } } } - + assertTrue(allKeysHaveDifferentId(tapSchema)); ///////////////////////////////////// @@ -517,7 +489,7 @@ public class TestAll { sch0table1.addChild("id"); Table sch0table2 = sch0.addChild("table2"); sch0table2.addChild("table1_id"); - + for (Key key : allKeys) { if (key.getId() == null) { assertFalse(key.isVisible()); @@ -542,13 +514,13 @@ public class TestAll { } } assertTrue(allKeysHaveDifferentId(tapSchema)); - + UpdateOperations operations = new UpdateOperations(tapSchema); assertEquals(2, operations.getSchemasToAdd().size()); assertEquals(6, operations.getTablesToAdd().size()); assertEquals(11, operations.getColumnsToAdd().size()); assertEquals(5, operations.getKeysToAdd().size()); - + tapSchema.save(); assertFalse(new UpdateOperations(tapSchema).getHasOperations()); assertTrue(allKeysHaveDifferentId(tapSchema)); @@ -559,7 +531,7 @@ public class TestAll { allKeys = ((TapSchemaImpl) tapSchema).getAllKeys(); assertTrue(allKeysHaveDifferentId(tapSchema)); log.debug(tapSchema.toString()); - + assertNotNull(sch0 = tapSchema.getChild("sch0", Status.ADDED_PERSISTED)); assertNotNull(sch1 = tapSchema.getChild("sch1", Status.ADDED_PERSISTED)); assertNotNull(sch0table0 = sch0.getChild("table0", Status.ADDED_PERSISTED)); @@ -579,7 +551,7 @@ public class TestAll { assertNotNull(table_y.getChild("idy2", Status.ADDED_PERSISTED)); assertNotNull(sch1table0.getChild("id", Status.ADDED_PERSISTED)); assertNotNull(sch1table0.getChild("sch0table0id", Status.ADDED_PERSISTED)); - + for (Key key : allKeys) { if (key.getId() == null) { assertFalse(key.isVisible()); @@ -603,14 +575,14 @@ public class TestAll { } } } - + List sch0table1FromKeys = sch0table1.getVisibleFromKeys(); assertEquals(1, sch0table1FromKeys.size()); assertEquals(1, sch0table1.getVisibleTargetKeys().size()); - + sch0.removeChild("table1"); assertEquals(0, sch0table1.getVisibleFromKeys().size()); - + for (Key key : allKeys) { if (key.getId() == null) { assertFalse(key.isVisible()); @@ -622,7 +594,7 @@ public class TestAll { } } } - + operations = new UpdateOperations(tapSchema); assertFalse(operations.getHasEntitiesToUpdate()); assertFalse(operations.getHasEntitiesToAdd()); @@ -630,7 +602,7 @@ public class TestAll { assertEquals(1, operations.getTablesToRemove().size()); assertEquals(2, operations.getColumnsToRemove().size()); assertEquals(2, operations.getKeysToRemove().size()); - + tapSchema.save(); log.debug(tapSchema.toString()); assertFalse(new UpdateOperations(tapSchema).getHasOperations()); @@ -640,7 +612,7 @@ public class TestAll { tapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1_IA2, dbWrapper, "test_tap_schema", true); allKeys = ((TapSchemaImpl) tapSchema).getAllKeys(); log.debug(tapSchema.toString()); - + assertNotNull(sch0 = tapSchema.getChild("sch0", Status.ADDED_PERSISTED)); assertNotNull(sch1 = tapSchema.getChild("sch1", Status.ADDED_PERSISTED)); assertNotNull(sch0table0 = sch0.getChild("table0", Status.ADDED_PERSISTED)); @@ -657,7 +629,7 @@ public class TestAll { assertNotNull(table_y.getChild("idy2", Status.ADDED_PERSISTED)); assertNotNull(sch1table0.getChild("id", Status.ADDED_PERSISTED)); assertNotNull(sch1table0.getChild("sch0table0id", Status.ADDED_PERSISTED)); - + for (Key key : allKeys) { if (key.getId() == null) { assertFalse(key.isVisible()); @@ -679,6 +651,20 @@ public class TestAll { } } } + + // Test adding ficitious key + sch0table0.addChild("value1"); + sch0table2.addChild("value1"); + ((TapSchemaImpl) tapSchema).addFictitiousKey(sch0table2, new String[]{"value1"}, sch0table0, new String[]{"value1"}); + operations = new UpdateOperations(tapSchema); + assertEquals(1, operations.getKeysToAdd().size()); + tapSchema.save(); + + tapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1_IA2, dbWrapper, "test_tap_schema", true); + + sch0table2 = tapSchema.getChild("sch0").getChild("table2"); + assertEquals(1, sch0table2.getVisibleFromKeys().size()); + checkKey(sch0table2.getVisibleFromKeys().get(0), "sch0.table2", "value1", "sch0.table0", "value1", true); } } catch (SQLException e) { throw e; @@ -686,4 +672,27 @@ public class TestAll { //removeTestingDatabases(credentials); } } + + @Test + public void testTapSchemaSerialization() throws Exception { + for (DBWrapper dbWrapper : dbWrappers) { + if (dbWrapper.getTapSchemaDatabaseType() == DatabaseType.MYSQL) { // currently "tng_TAP_SCHEMA" exists in a MySQL instance + TapSchema tapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1_IA2, dbWrapper, "test_tap_schema", true); + + File temp = File.createTempFile("test_tap_schema", ".ser"); + + try (FileOutputStream fileOut = new FileOutputStream(temp); + ObjectOutputStream out = new ObjectOutputStream(fileOut)) { + out.writeObject(tapSchema); + } + + try (FileInputStream fileIn = new FileInputStream(temp); + ObjectInputStream in = new ObjectInputStream(fileIn)) { + tapSchema = (TapSchema) in.readObject(); + } + + log.debug(tapSchema.toString()); + } + } + } } diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/SchemaSelectionBean.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/SchemaSelectionBean.java index 86ffcc35aca8e4f9a2c514089b67681ba6f80d61..8b25feafd79a8eb5bb8850b5d32aade4639678bc 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/SchemaSelectionBean.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/SchemaSelectionBean.java @@ -148,7 +148,7 @@ public class SchemaSelectionBean implements Serializable { public String edit() { try { - TapSchema tapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1, dbWrapper, selectedTAPSchema, true); + TapSchema tapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1_IA2, dbWrapper, selectedTAPSchema, true); return loadTapSchema(tapSchema); } catch (SQLException e) { throw new RuntimeException(e); @@ -157,7 +157,7 @@ public class SchemaSelectionBean implements Serializable { public String create() { try { - TapSchema tapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1, dbWrapper, tapSchemaName, false); + TapSchema tapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1_IA2, dbWrapper, tapSchemaName, false); return loadTapSchema(tapSchema); } catch (SQLException e) { throw new RuntimeException(e); diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/SearchUCDDialog.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/SearchUCDDialog.java index de5a60cef988c9d44ee4faf0a90a20758056d559..6e4286c8a53ebb2b4a896962001de4d24f09f434 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/SearchUCDDialog.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/SearchUCDDialog.java @@ -30,7 +30,6 @@ public class SearchUCDDialog implements Serializable { private List suggestedUCDs; private ParsedUCD parsedUCD; - private String UCDValidationMessage; public SearchUCDDialog() { suggestedUCDs = new ArrayList<>(); @@ -136,7 +135,7 @@ public class SearchUCDDialog implements Serializable { public void validateManualUCD() { if (UCDManualText == null || UCDManualText.isEmpty() || UCDManualText.trim().isEmpty()) { - UCDValidationMessage = "UCD can't be null"; + parsedUCD = null; } else { parsedUCD = new ParsedUCD(UCDManualText); } @@ -150,10 +149,6 @@ public class SearchUCDDialog implements Serializable { return SearchUCD.REG_EXP_START_WITH_NAMESPACE; } - public String getUCDValidationMessage() { - return UCDValidationMessage; - } - public ParsedUCD getParsedUCD() { return parsedUCD; } diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/TapSchemaEditingBean.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/TapSchemaEditingBean.java index 94fce7ee47dbb2dfda74a166ac0ad3b26440f9dd..c6ca0f94b3320a2f2cb562d169560f53b0276c79 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/TapSchemaEditingBean.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/TapSchemaEditingBean.java @@ -227,10 +227,15 @@ public class TapSchemaEditingBean implements Serializable { return currentAddingContainer; } - public void openAddablesModal(EntitiesContainer currentAddingContainer) { + public void openAddablesModal(EntitiesContainer currentAddingContainer) { this.currentAddingContainer = currentAddingContainer; this.currentAddables = new ArrayList<>(); for (String name : currentAddingContainer.getAddableChildrenNames()) { + if(currentAddingContainer instanceof TapSchema && !tapSchema.exists() && name.equals(tapSchema.getName())) { + // we can't add the TAP_SCHEMA into itself when it doesn't + // created yet. + continue; + } currentAddables.add(new AddableItem(name)); } } diff --git a/TapSchemaManagerWebApp/src/main/webapp/resources/css/style.css b/TapSchemaManagerWebApp/src/main/webapp/resources/css/style.css index 8373e63e6d91c4c5f53aedfb8f3f8de70c403aee..57f6f1c3f5af9560f99f3b3c9569b597415152af 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/resources/css/style.css +++ b/TapSchemaManagerWebApp/src/main/webapp/resources/css/style.css @@ -169,7 +169,8 @@ input[type="checkbox"].changed { bottom: 0; right: 0; left: 0; - background-color: rgba(0, 0, 0, 0.33); + background-color: rgba(255, 255, 255, 0.5); + cursor: wait; z-index: 10000; text-align: center; } diff --git a/TapSchemaManagerWebApp/src/main/webapp/resources/js/edit-tapschema.js b/TapSchemaManagerWebApp/src/main/webapp/resources/js/edit-tapschema.js index 4162c887aa1e56d12bc33af7963ae407081392bc..3aef99bc6853e3e06de47609065d41c16079b267 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/resources/js/edit-tapschema.js +++ b/TapSchemaManagerWebApp/src/main/webapp/resources/js/edit-tapschema.js @@ -128,16 +128,6 @@ $('#updateSuccessModal').modal('show'); } }, - // Show loading div - showLoading: function () { - $('.loading').removeClass('hide'); - }, - // Hide loading div - hideLoading: function (event) { - if (event.status === 'success') { - $('.loading').addClass('hide'); - } - }, UCDDescriptionAdded: function (event, index) { if (event.status === 'success') { $('#searchUCDModal .resultDefinition:eq(' + index + ')').collapse('show'); @@ -145,6 +135,10 @@ }, showUCDDescription: function (event) { $(event.target).closest('.ucd-selector-group').next().collapse('toggle'); + }, + updateFromModal: function () { + $('#updateOperationsModal').modal('hide'); + $('#main\\:update-btn').click(); } }; @@ -160,6 +154,21 @@ $('#errorModal').modal('show'); } }); + + // Setup loading animation + jsf.ajax.addOnEvent(function (data) { + if (data.source.id === 'ucd_search_form:ucd_text_manual') { + return; // special case + } + switch (data.status) { + case "begin": + $('.loading').removeClass('hide'); + break; + case "complete": + $('.loading').addClass('hide'); + break; + } + }); }); })(jQuery); \ No newline at end of file diff --git a/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml b/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml index 427f8c0c8a5b26adcda239c4a8d555135bb5527c..197184e6df5a52704cf4703fc7d02b7e8a6a5d45 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml +++ b/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml @@ -25,7 +25,7 @@   - + Update @@ -70,7 +70,7 @@
- +
@@ -290,7 +290,7 @@
- + #{tapSchemaEditing.selectedColumn.UCD} @@ -404,7 +404,7 @@
UCD: - + @@ -447,8 +447,9 @@ - - Suggested UCD: ${UCDDialog.parsedUCD.suggestedUCD} + + Suggested UCD: ${UCDDialog.parsedUCD.suggestedUCD} +
Advices:
@@ -477,9 +478,9 @@
- + - +
@@ -536,7 +537,7 @@
- + @@ -764,7 +765,9 @@