diff --git a/TapSchemaManagerAPI/pom.xml b/TapSchemaManagerAPI/pom.xml index 8acdfc7929758d0ff7f153918632fe22dbe3fda6..d1a5403b7328e638d6747af1478ea32a464010a7 100644 --- a/TapSchemaManagerAPI/pom.xml +++ b/TapSchemaManagerAPI/pom.xml @@ -16,7 +16,6 @@ mysql mysql-connector-java 5.1.37 - jar org.postgresql 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 ae7d8c75bf4d5bcac4a71a60c3e4ddbac3b2f9e9..9ed9fe55dcf203644441b50d24360a7fe64f85a3 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,15 @@ */ package it.inaf.ia2.tsm.api; -import it.inaf.ia2.tsm.api.contract.DatabaseType; 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; /** * This class is used to silently manage the possibility to have separate data @@ -44,6 +46,7 @@ import org.postgresql.ds.PGPoolingDataSource; public class DBWrapper implements Serializable { private static final long serialVersionUID = 1721030677924066695L; + private final static Logger log = LoggerFactory.getLogger(DBWrapper.class); // Same credentials private Credentials credentials; @@ -182,30 +185,33 @@ public class DBWrapper implements Serializable { } private DataSource createDataSource(Credentials credentials) { - if (credentials.getDatabaseType() == DatabaseType.MYSQL) { - MysqlDataSource ds = new MysqlDataSource(); + switch (credentials.getDatabaseType()) { - ds.setServerName(credentials.getHostname()); - ds.setPortNumber(credentials.getPort()); - ds.setUser(credentials.getUsername()); - ds.setPassword(credentials.getPassword()); + case MYSQL: + MysqlDataSource myds = new MysqlDataSource(); - return ds; - } else if (credentials.getDatabaseType() == DatabaseType.POSTGRES) { + myds.setServerName(credentials.getHostname()); + myds.setPortNumber(credentials.getPort()); + myds.setUser(credentials.getUsername()); + myds.setPassword(credentials.getPassword()); - PGPoolingDataSource ds = new PGPoolingDataSource(); + return myds; - ds.setServerName(credentials.getHostname()); - ds.setPortNumber(credentials.getPort()); - ds.setUser(credentials.getUsername()); - ds.setPassword(credentials.getPassword()); - ds.setDatabaseName("postgres"); + case POSTGRES: + PGPoolingDataSource pgds = new PGPoolingDataSource(); - return ds; - } + pgds.setServerName(credentials.getHostname()); + pgds.setPortNumber(credentials.getPort()); + pgds.setUser(credentials.getUsername()); + pgds.setPassword(credentials.getPassword()); + pgds.setDatabaseName(credentials.getDatabase()); - throw new UnsupportedOperationException(credentials.getDatabaseType() + " not supported yet."); + return pgds; + + default: + throw new UnsupportedOperationException(credentials.getDatabaseType() + " not supported yet."); + } } } } diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/DaoKey.java b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/DaoKey.java index 9d3c4f54c0743216aab57007bf05d561e0415903..263b043e6d3c68e4ce94b5953a7f5e6e86aa6b6a 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/DaoKey.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/DaoKey.java @@ -40,7 +40,6 @@ import java.util.List; import java.util.Map; import java.util.regex.Pattern; import javax.sql.DataSource; -import org.postgresql.ds.PGPoolingDataSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -113,7 +112,10 @@ public class DaoKey { } else if (dbType == DatabaseType.POSTGRES) { - String databaseName = ((PGPoolingDataSource) dataSource).getDatabaseName(); + String databaseName + = schemaName.equals(tapSchema.getName()) + ? dbWrapper.getTapSchemaCredentials().getDatabase() + : dbWrapper.getSourceCredentials().getDatabase(); List schemaKeys = new ArrayList<>(); diff --git a/TapSchemaManagerAPI/src/main/resources/log4j.properties b/TapSchemaManagerAPI/src/main/resources/log4j.properties index 3910611c808e65a03dbca5828cb69f27fbfd7d6d..a4a1effff9111f08292fe86628cfa11f47548bcf 100644 --- a/TapSchemaManagerAPI/src/main/resources/log4j.properties +++ b/TapSchemaManagerAPI/src/main/resources/log4j.properties @@ -11,6 +11,8 @@ log4j.appender.IA2.layout.ConversionPattern=[%c{1}]: %m%n # Root Logger log4j.rootLogger=WARN,AD +log4j.logger.org.apache.commons.dbcp2=DEBUG,AD + # IA2 Logger log4j.logger.it.inaf.ia2=TRACE,IA2 log4j.additivity.it.inaf.ia2=false diff --git a/TapSchemaManagerAPI/src/test/java/it/inaf/ia2/tsm/api/TestAll.java b/TapSchemaManagerAPI/src/test/java/it/inaf/ia2/tsm/api/TestAll.java index 97b9d9924ed1f34710baa933b46d045823fccaf1..3295f4c08cf36c92aad4289f6618bd1805e8ab29 100644 --- a/TapSchemaManagerAPI/src/test/java/it/inaf/ia2/tsm/api/TestAll.java +++ b/TapSchemaManagerAPI/src/test/java/it/inaf/ia2/tsm/api/TestAll.java @@ -22,11 +22,6 @@ */ package it.inaf.ia2.tsm.api; -import it.inaf.ia2.tsm.api.TapSchemaFactory; -import it.inaf.ia2.tsm.api.TapSchemaImpl; -import it.inaf.ia2.tsm.api.UpdateOperations; -import it.inaf.ia2.tsm.api.DBWrapper; -import it.inaf.ia2.tsm.api.Credentials; import it.inaf.ia2.tsm.api.contract.DatabaseType; import it.inaf.ia2.tsm.api.contract.Column; import it.inaf.ia2.tsm.api.contract.Key; @@ -289,7 +284,7 @@ public class TestAll { setUpTestingDatabases(); for (DBWrapper dbWrapper : dbWrappers) { - + // Initializing a not existing TAP_SCHEMA TapSchema tapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1_IA2, dbWrapper, "test_tap_schema", false); diff --git a/TapSchemaManagerWebApp/pom.xml b/TapSchemaManagerWebApp/pom.xml index 79adade7c42dd7e62d7b55cf3399f3c9758cf860..ccc56f80a94db3cd418706d17a21ee811930c015 100644 --- a/TapSchemaManagerWebApp/pom.xml +++ b/TapSchemaManagerWebApp/pom.xml @@ -48,6 +48,18 @@ 2.3.4.Final runtime + + org.glassfish.jersey.containers + jersey-container-servlet + ${jersey.version} + runtime + + + org.glassfish.jersey.ext.cdi + jersey-cdi1x + ${jersey.version} + runtime + org.glassfish javax.json diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ApplicationConfig.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ApplicationConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..3138609dfd1f6a87466a5950bcc091c2506d1a6e --- /dev/null +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ApplicationConfig.java @@ -0,0 +1,50 @@ +/* + * _____________________________________________________________________________ + * + * INAF - OATS National Institute for Astrophysics - Astronomical Observatory of + * Trieste INAF - IA2 Italian Center for Astronomical Archives + * _____________________________________________________________________________ + * + * Copyright (C) 2016 Istituto Nazionale di Astrofisica + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License Version 3 as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package it.inaf.ia2.tsm.webapp; + +import java.util.Set; +import javax.ws.rs.core.Application; + +/** + * + * @author Sonia Zorba + */ +@javax.ws.rs.ApplicationPath("rest") +public class ApplicationConfig extends Application { + + @Override + public Set> getClasses() { + Set> resources = new java.util.HashSet<>(); + addRestResourceClasses(resources); + return resources; + } + + /** + * Do not modify addRestResourceClasses() method. It is automatically + * populated with all resources defined in the project. If required, comment + * out calling this method in getClasses(). + */ + private void addRestResourceClasses(Set> resources) { + resources.add(it.inaf.ia2.tsm.webapp.KeepAliveResource.class); + } +} diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ConsistencyChecksBean.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ConsistencyChecksBean.java index c732435779d20de6690766d994a349eb00f18808..9c4b3e7ed6030fd8f783621942728f975653d06a 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ConsistencyChecksBean.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ConsistencyChecksBean.java @@ -26,7 +26,7 @@ import it.inaf.ia2.tsm.api.DBWrapper; import it.inaf.ia2.tsm.api.contract.TapSchema; import java.io.Serializable; import java.sql.SQLException; -import javax.enterprise.context.SessionScoped; +import javax.enterprise.context.ConversationScoped; import javax.inject.Inject; import javax.inject.Named; @@ -34,7 +34,7 @@ import javax.inject.Named; * * @author Sonia Zorba */ -@SessionScoped +@ConversationScoped @Named("consistency") public class ConsistencyChecksBean implements Serializable { diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/KeepAliveBean.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/KeepAliveBean.java new file mode 100644 index 0000000000000000000000000000000000000000..34b82a721503464c95974a72f9f300a918499acc --- /dev/null +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/KeepAliveBean.java @@ -0,0 +1,52 @@ +/* + * _____________________________________________________________________________ + * + * INAF - OATS National Institute for Astrophysics - Astronomical Observatory of + * Trieste INAF - IA2 Italian Center for Astronomical Archives + * _____________________________________________________________________________ + * + * Copyright (C) 2016 Istituto Nazionale di Astrofisica + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License Version 3 as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package it.inaf.ia2.tsm.webapp; + +import java.io.Serializable; +import javax.enterprise.context.Conversation; +import javax.enterprise.context.ConversationScoped; +import javax.faces.context.FacesContext; +import javax.inject.Inject; +import javax.inject.Named; + +/** + * + * @author Sonia Zorba + */ +@Named("keepalive") +@ConversationScoped +public class KeepAliveBean implements Serializable { + + private static final long serialVersionUID = 8899457623621886668L; + + @Inject + private Conversation conversation; + + public String getRestPath() { + return FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/rest"; + } + + public String getConversationId() { + return conversation.getId(); + } +} diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/KeepAliveResource.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/KeepAliveResource.java new file mode 100644 index 0000000000000000000000000000000000000000..4805b20f41546db9a50a2a9b205ef4dfdbf72926 --- /dev/null +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/KeepAliveResource.java @@ -0,0 +1,54 @@ +/* + * _____________________________________________________________________________ + * + * INAF - OATS National Institute for Astrophysics - Astronomical Observatory of + * Trieste INAF - IA2 Italian Center for Astronomical Archives + * _____________________________________________________________________________ + * + * Copyright (C) 2016 Istituto Nazionale di Astrofisica + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License Version 3 as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package it.inaf.ia2.tsm.webapp; + +import java.io.Serializable; +import javax.enterprise.context.Conversation; +import javax.enterprise.context.ConversationScoped; +import javax.ws.rs.Produces; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.inject.Inject; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +/** + * REST Web Service + * + * @author Sonia Zorba + */ +@Path("keepalive") +@ConversationScoped +public class KeepAliveResource implements Serializable { + + private static final long serialVersionUID = 3477976029207874216L; + + @Inject + Conversation conversation; + + @GET + @Produces(MediaType.TEXT_PLAIN) + public Response keepAlive() { + return Response.ok(conversation.getId()).build(); + } +} 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 75bcb2e69b76f65e6ffd27be86657770f606e2ee..627bd6b3af587419da0b10d57f0f746ca202655e 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 @@ -253,7 +253,7 @@ public class TapSchemaEditingBean implements Serializable { this.currentAddingContainer = currentAddingContainer; this.currentAddables = new ArrayList<>(); for (String name : currentAddingContainer.getAddableChildrenNames()) { - if(currentAddingContainer instanceof TapSchema && !tapSchema.exists() && name.equals(tapSchema.getName())) { + 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; @@ -385,4 +385,8 @@ public class TapSchemaEditingBean implements Serializable { } }); } + + public String reload() { + return schemaSelection.edit(); + } } diff --git a/TapSchemaManagerWebApp/src/main/webapp/consistencyChecks.xhtml b/TapSchemaManagerWebApp/src/main/webapp/consistencyChecks.xhtml index 47c942b22e73bbed06ba833c839d982dcba3b89e..ec7ef80d846c62f6bab39c72249bbe0a135f36c9 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/consistencyChecks.xhtml +++ b/TapSchemaManagerWebApp/src/main/webapp/consistencyChecks.xhtml @@ -6,6 +6,10 @@ xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"> Consistency problems for #{consistency.tapSchema.name} + + + +
diff --git a/TapSchemaManagerWebApp/src/main/webapp/index.xhtml b/TapSchemaManagerWebApp/src/main/webapp/index.xhtml index 241ec345d37a8fa3aa68b934d83a4071834e9116..293702c4d113731c9c7f48d4fcac186e55991b2b 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/index.xhtml +++ b/TapSchemaManagerWebApp/src/main/webapp/index.xhtml @@ -98,6 +98,7 @@
+
#{credentialsInsertion.loginError} diff --git a/TapSchemaManagerWebApp/src/main/webapp/resources/js/keepalive.js b/TapSchemaManagerWebApp/src/main/webapp/resources/js/keepalive.js new file mode 100644 index 0000000000000000000000000000000000000000..2f68ea7501dafc14e5204bffceafddaade198258 --- /dev/null +++ b/TapSchemaManagerWebApp/src/main/webapp/resources/js/keepalive.js @@ -0,0 +1,28 @@ +/* + * _____________________________________________________________________________ + * + * INAF - OATS National Institute for Astrophysics - Astronomical Observatory of + * Trieste INAF - IA2 Italian Center for Astronomical Archives + * _____________________________________________________________________________ + * + * Copyright (C) 2016 Istituto Nazionale di Astrofisica + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License Version 3 as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +window.startKeepAlive = function (restPath, conversationId) { + setInterval(function () { + $.get(restPath + '/keepalive?cid=' + conversationId); + }, 60000); +}; diff --git a/TapSchemaManagerWebApp/src/main/webapp/schemaSelection.xhtml b/TapSchemaManagerWebApp/src/main/webapp/schemaSelection.xhtml index da3eff0ea24f8b852d283236680d00fdf18f57c9..a7f422f7748e22c4eb227b4a8fcff35d2b66c908 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/schemaSelection.xhtml +++ b/TapSchemaManagerWebApp/src/main/webapp/schemaSelection.xhtml @@ -5,6 +5,10 @@ xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" > TapSchema Manager - Schemata selection page + + + + diff --git a/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml b/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml index c06439ffca62d5cc15c3558de6cfff4d7cfebd02..8440fa0f6b131e8866f3735e84fb3df161536e5f 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml +++ b/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml @@ -11,12 +11,16 @@ + + -

Editing #{tapSchemaEditing.tapSchema.name}

+

+ Editing #{tapSchemaEditing.tapSchema.name} +

@@ -30,6 +34,11 @@ Update +   + + + Reload all +