diff --git a/TapSchemaManagerAPI/pom.xml b/TapSchemaManagerAPI/pom.xml index d1a5403b7328e638d6747af1478ea32a464010a7..a8b0ed42b1283a2dc7a0a4d75b092b707ee8e6a8 100644 --- a/TapSchemaManagerAPI/pom.xml +++ b/TapSchemaManagerAPI/pom.xml @@ -3,7 +3,7 @@ 4.0.0 it.inaf.ia2.tap TapSchemaManagerAPI - 1.0.1 + 1.0.3 jar UTF-8 diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/Credentials.java b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/Credentials.java index 006d1073343e3874fd76e2940d62b942dfc29bac..c3ad13438e3ad3bfafb188233c927820bf4383a8 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/Credentials.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/Credentials.java @@ -153,4 +153,11 @@ public class Credentials implements Serializable { } return null; } + + @Override + public String toString() { + return String.format("[%s] type=%s, hostname=%s, port=%s, username=%s, password=%s, database=%s", + Credentials.class.getCanonicalName(), + databaseType, hostname, port, username, password, database); + } } diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/DBWrapper.java b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/DBWrapper.java index 9ed9fe55dcf203644441b50d24360a7fe64f85a3..4a81333ad7e358ea7a404ab06c6e34870f0e2d9c 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/DBWrapper.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/DBWrapper.java @@ -22,13 +22,11 @@ */ package it.inaf.ia2.tsm.api; -import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; import it.inaf.ia2.tsm.api.contract.DatabaseType; import java.io.Serializable; import java.sql.Connection; import java.sql.SQLException; import javax.sql.DataSource; -import org.postgresql.ds.PGPoolingDataSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -161,12 +159,12 @@ public class DBWrapper implements Serializable { public DataSource getTapSchemaDataSource() { if (credentials != null) { if (dataSource == null) { - dataSource = createDataSource(credentials); + dataSource = TSMUtil.createDataSource(credentials); } return dataSource; } if (tapSchemaDataSource == null) { - tapSchemaDataSource = createDataSource(tapSchemaCredentials); + tapSchemaDataSource = TSMUtil.createDataSource(tapSchemaCredentials); } return tapSchemaDataSource; } @@ -174,44 +172,14 @@ public class DBWrapper implements Serializable { public DataSource getSourceDataSource() { if (credentials != null) { if (dataSource == null) { - dataSource = createDataSource(credentials); + dataSource = TSMUtil.createDataSource(credentials); } return dataSource; } if (sourceDataSource == null) { - sourceDataSource = createDataSource(sourceCredentials); + sourceDataSource = TSMUtil.createDataSource(sourceCredentials); } return sourceDataSource; } - - private DataSource createDataSource(Credentials credentials) { - - switch (credentials.getDatabaseType()) { - - case MYSQL: - MysqlDataSource myds = new MysqlDataSource(); - - myds.setServerName(credentials.getHostname()); - myds.setPortNumber(credentials.getPort()); - myds.setUser(credentials.getUsername()); - myds.setPassword(credentials.getPassword()); - - return myds; - - case POSTGRES: - PGPoolingDataSource pgds = new PGPoolingDataSource(); - - pgds.setServerName(credentials.getHostname()); - pgds.setPortNumber(credentials.getPort()); - pgds.setUser(credentials.getUsername()); - pgds.setPassword(credentials.getPassword()); - pgds.setDatabaseName(credentials.getDatabase()); - - return pgds; - - default: - throw new UnsupportedOperationException(credentials.getDatabaseType() + " not supported yet."); - } - } } } diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/Dao.java b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/Dao.java index 2f37989164348dfe49b6864fde7f0590a917fc96..164994dac953065af38a9a32b6a004393421df2e 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/Dao.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/Dao.java @@ -582,11 +582,22 @@ public class Dao { } } + public static List getAllTAPSchemasNames(Credentials credentials) throws SQLException { + DatabaseType dbType = credentials.getDatabaseType(); + DataSource ds = TSMUtil.createDataSource(credentials); + List allSchemas = DaoSchema.getAllSchemasNames(ds, dbType); + return getAllTAPSchemasNames(ds, dbType, allSchemas); + } + public static List getAllTAPSchemasNames(DBWrapper dbs) throws SQLException { List allSchemas = DaoSchema.getAllSchemasNames(dbs.getTapSchemaDataSource(), dbs.getTapSchemaDatabaseType()); return getAllTAPSchemasNames(dbs, allSchemas); } + public static List getAllTAPSchemasNames(DBWrapper dbs, List allSchemas) throws SQLException { + return getAllTAPSchemasNames(dbs.getTapSchemaDataSource(), dbs.getTapSchemaDatabaseType(), allSchemas); + } + /** * Retrieve the list of all TAP_SCHEMA schemas names contained in the * TAP_SCHEMA DataSource.
@@ -600,7 +611,7 @@ public class Dao { * @return list of all TAP_SCHEMA schemas names alphabetically and case * insensitively ordered. */ - public static List getAllTAPSchemasNames(DBWrapper dbs, List allSchemas) throws SQLException { + public static List getAllTAPSchemasNames(DataSource dataSource, DatabaseType dbType, List allSchemas) throws SQLException { List allTAPSchemas = new ArrayList<>(); @@ -612,8 +623,6 @@ public class Dao { keys = false, keyColumns = false; - DatabaseType dbType = dbs.getTapSchemaDatabaseType(); - String query; if (dbType == DatabaseType.MYSQL) { query = "SHOW TABLES FROM `" + schemaName + "`"; @@ -625,7 +634,7 @@ public class Dao { log.debug("Executing query {}", query); - try (Connection connection = dbs.getTapSchemaConnection(); + try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query)) { while (resultSet.next()) { diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/DaoSchema.java b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/DaoSchema.java index bc492d4826cf97bb0cbaf68cbe491ad43a8f51e5..32257b6ec90fafaef6f2dfec7357072053182168 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/DaoSchema.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/DaoSchema.java @@ -48,6 +48,11 @@ public class DaoSchema { private static final Logger log = LoggerFactory.getLogger(DaoSchema.class); + public static List getAllSchemasNames(Credentials credentials) throws SQLException { + DataSource ds = TSMUtil.createDataSource(credentials); + return getAllSchemasNames(ds, credentials.getDatabaseType()); + } + /** * Retrieve the list of the names of the all the schemas contained into the * database specified by the DataSource parameter. @@ -99,7 +104,7 @@ public class DaoSchema { protected TapSchemaEntity getEntity(ResultSet rs) throws SQLException { String schemaName = rs.getString("schema_name"); Schema schema = tapSchema.addChild(schemaName); - if(schema == null) { + if (schema == null) { return null; } schema.setStatus(Status.ADDED_PERSISTED); diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/TSMUtil.java b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/TSMUtil.java index c7306d9f3b3364aa23d0fef926de84b7330f6c43..8548bdf7c8adc56f34fca053a09f490b80b75896 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/TSMUtil.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/TSMUtil.java @@ -22,6 +22,7 @@ */ package it.inaf.ia2.tsm.api; +import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; import it.inaf.ia2.tsm.api.contract.DatabaseType; import it.inaf.ia2.tsm.api.contract.ChildEntity; import it.inaf.ia2.tsm.api.contract.Column; @@ -40,6 +41,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; import javax.sql.DataSource; +import org.postgresql.ds.PGPoolingDataSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,6 +55,36 @@ public class TSMUtil { private static final Logger log = LoggerFactory.getLogger(TSMUtil.class); + public static DataSource createDataSource(Credentials credentials) { + + switch (credentials.getDatabaseType()) { + + case MYSQL: + MysqlDataSource myds = new MysqlDataSource(); + + myds.setServerName(credentials.getHostname()); + myds.setPortNumber(credentials.getPort()); + myds.setUser(credentials.getUsername()); + myds.setPassword(credentials.getPassword()); + + return myds; + + case POSTGRES: + PGPoolingDataSource pgds = new PGPoolingDataSource(); + + pgds.setServerName(credentials.getHostname()); + pgds.setPortNumber(credentials.getPort()); + pgds.setUser(credentials.getUsername()); + pgds.setPassword(credentials.getPassword()); + pgds.setDatabaseName(credentials.getDatabase()); + + return pgds; + + default: + throw new UnsupportedOperationException(credentials.getDatabaseType() + " not supported yet."); + } + } + protected static List sortStringsList(List list) { Collections.sort(list, String.CASE_INSENSITIVE_ORDER); return list; diff --git a/TapSchemaManagerWebApp/pom.xml b/TapSchemaManagerWebApp/pom.xml index 8926c58e27d6682427a372fa6b4a7f3e9db76c75..7deef3bd013309f407a251932deaae4b014f5808 100644 --- a/TapSchemaManagerWebApp/pom.xml +++ b/TapSchemaManagerWebApp/pom.xml @@ -4,7 +4,7 @@ it.inaf.ia2.tap TapSchemaManagerWebApp - 1.0.2 + 1.0.3 war TapSchemaManagerWebApp @@ -87,7 +87,7 @@ it.inaf.ia2.tap TapSchemaManagerAPI - 1.0.2 + 1.0.3 ari.ucd diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SchemaSelectionBean.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SchemaSelectionBean.java index 6c9a06bcbc823ce152a1d42a7d0c5d02ff7bd32b..9d6077230f5d10c5c3592fd48aa49aba51f7e8ba 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SchemaSelectionBean.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SchemaSelectionBean.java @@ -197,7 +197,7 @@ public class SchemaSelectionBean implements Serializable { throw new RuntimeException(e); } } - + public String getTapSchemaName() { return tapSchemaName; } diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SearchUCDDialog.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SearchUCDDialog.java index dd206544843237059a5d0c914e488ef75fa9b096..a9019d737e624a99defe8dc10ae1a2e2d7d4bc2b 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SearchUCDDialog.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SearchUCDDialog.java @@ -90,11 +90,8 @@ public class SearchUCDDialog implements Serializable { UCDServiceErrorMessage = null; } - public void search(String description) { + public void search() { try { - setDefault(); - this.description = description; - String assignResponse = SearchUCD.assign(description); if (assignResponse == null) { UCDnotFound = true; diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java index f06737e6b4abe16202a1ea8a0551e36d34560ff8..9f59b795373924277ba035dcbe6883839e3370ab 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java @@ -337,7 +337,7 @@ public class TapSchemaEditingBean implements Serializable { String description = selectedColumn.getDescription(); if (description != null && !description.isEmpty()) { searchUCDDialog.setDescription(description); - searchUCDDialog.search(description); + searchUCDDialog.search(); } } @@ -408,6 +408,17 @@ public class TapSchemaEditingBean implements Serializable { } public String reload() { - return schemaSelection.edit(); + + if (schemaSelection.getSelectedRadioOption().equals("edit")) { + return schemaSelection.edit(); + } else { + if (tapSchema.exists()) { + schemaSelection.setSelectedRadioOption("edit"); + schemaSelection.setSelectedTAPSchema(tapSchema.getName()); + return schemaSelection.edit(); + } else { + return schemaSelection.create(); + } + } } } diff --git a/TapSchemaManagerWebApp/src/main/webapp/resources/css/style.css b/TapSchemaManagerWebApp/src/main/webapp/resources/css/style.css index 57f6f1c3f5af9560f99f3b3c9569b597415152af..0e000b97ddf2a3cd1e4ea02efe51fbdcfbdc03f7 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/resources/css/style.css +++ b/TapSchemaManagerWebApp/src/main/webapp/resources/css/style.css @@ -135,6 +135,9 @@ input[type="checkbox"].changed { .removable-tab.to-remove a { padding-right: 15px !important; } +.removable-tab.unremovable-tab a { + padding-right: 15px !important; +} .strikeout, .strikeout:hover { text-decoration: line-through !important; } diff --git a/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml b/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml index 9806f514a58c94283c3292b10dbce525720db97a..0eaaae3dd652f4dcfa43d2a34381591865102a7e 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml +++ b/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml @@ -58,11 +58,11 @@