From 7061c12b4d52c637d8afe660218619cddf463bb7 Mon Sep 17 00:00:00 2001 From: Sonia Zorba Date: Tue, 13 Dec 2016 15:55:19 +0100 Subject: [PATCH] Fixes, added keep alive for conversation --- TapSchemaManagerAPI/pom.xml | 1 - .../java/it/inaf/ia2/tsm/api/DBWrapper.java | 42 ++++++++------- .../main/java/it/inaf/ia2/tsm/api/DaoKey.java | 6 ++- .../src/main/resources/log4j.properties | 2 + .../java/it/inaf/ia2/tsm/api/TestAll.java | 7 +-- TapSchemaManagerWebApp/pom.xml | 12 +++++ .../ia2/tsm/webapp/ApplicationConfig.java | 50 +++++++++++++++++ .../ia2/tsm/webapp/ConsistencyChecksBean.java | 4 +- .../it/inaf/ia2/tsm/webapp/KeepAliveBean.java | 52 ++++++++++++++++++ .../ia2/tsm/webapp/KeepAliveResource.java | 54 +++++++++++++++++++ .../ia2/tsm/webapp/TapSchemaEditingBean.java | 6 ++- .../src/main/webapp/consistencyChecks.xhtml | 4 ++ .../src/main/webapp/index.xhtml | 1 + .../src/main/webapp/resources/js/keepalive.js | 28 ++++++++++ .../src/main/webapp/schemaSelection.xhtml | 4 ++ .../src/main/webapp/tapSchemaEditing.xhtml | 11 +++- 16 files changed, 253 insertions(+), 31 deletions(-) create mode 100644 TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ApplicationConfig.java create mode 100644 TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/KeepAliveBean.java create mode 100644 TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/KeepAliveResource.java create mode 100644 TapSchemaManagerWebApp/src/main/webapp/resources/js/keepalive.js diff --git a/TapSchemaManagerAPI/pom.xml b/TapSchemaManagerAPI/pom.xml index 8acdfc7..d1a5403 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 ae7d8c7..9ed9fe5 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 9d3c4f5..263b043 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 3910611..a4a1eff 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 97b9d99..3295f4c 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 79adade..ccc56f8 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 0000000..3138609 --- /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 c732435..9c4b3e7 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 0000000..34b82a7 --- /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 0000000..4805b20 --- /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 75bcb2e..627bd6b 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 47c942b..ec7ef80 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 241ec34..293702c 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 0000000..2f68ea7 --- /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 da3eff0..a7f422f 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 c06439f..8440fa0 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 +
-- GitLab