Loading TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/CredentialsBean.java +10 −6 Original line number Original line Diff line number Diff line Loading @@ -81,10 +81,11 @@ public class CredentialsBean implements Serializable { currentEditingRow = index; currentEditingRow = index; } } public void editSeparateCredentials(SeparateCredentials separateCredentials, int index) { public void editSeparateCredentials(SeparateCredentials sc, int index) { this.sourceCredentials = separateCredentials.getSourceCredentials(); this.sourceCredentials = sc.getSourceCredentials(); this.tapSchemaCredentials = separateCredentials.getTapSchemaCredentials(); this.tapSchemaCredentials = sc.getTapSchemaCredentials(); currentEditingRow = index; currentEditingRow = index; separateCredentials = true; } } public void addNewCredentials() { public void addNewCredentials() { Loading @@ -94,11 +95,13 @@ public class CredentialsBean implements Serializable { currentEditingRow = ccBean.getConfig().getCredentialsInfo().size(); currentEditingRow = ccBean.getConfig().getCredentialsInfo().size(); } } public String login(Credentials credentials) { public String loginWithSingleCredentials(Credentials credentials) { log.debug("Login with single credentials"); return loginWithDBWrapper(new DBWrapper(credentials)); return loginWithDBWrapper(new DBWrapper(credentials)); } } public String login(Credentials sourceCredentials, Credentials tapSchemaCredentials) { public String loginWithSeparatedCredentials(Credentials sourceCredentials, Credentials tapSchemaCredentials) { log.debug("Login with separated credentials"); return loginWithDBWrapper(new DBWrapper(sourceCredentials, tapSchemaCredentials)); return loginWithDBWrapper(new DBWrapper(sourceCredentials, tapSchemaCredentials)); } } Loading Loading @@ -181,10 +184,11 @@ public class CredentialsBean implements Serializable { this.loggedIn = loggedIn; this.loggedIn = loggedIn; } } public void logout() { public String logout() { HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); if (request.isRequestedSessionIdValid()) { if (request.isRequestedSessionIdValid()) { request.getSession().invalidate(); request.getSession().invalidate(); } } return "index.xhtml?faces-redirect=true"; } } } } TapSchemaManager/src/main/webapp/index.xhtml +7 −7 Original line number Original line Diff line number Diff line Loading @@ -25,12 +25,12 @@ <div class="form-group"> <div class="form-group"> <h:outputLabel for="password" class="col-sm-3 control-label">Password</h:outputLabel> <h:outputLabel for="password" class="col-sm-3 control-label">Password</h:outputLabel> <div class="col-sm-9"> <div class="col-sm-9"> <h:inputSecret class="form-control" id="password" value="#{credentialsInsertion.adminPassword}" /> <h:inputSecret class="form-control" id="password" value="#{credentialsInsertion.adminPassword}" onkeypress="credentials.adminLoginClicked(event)" /> <p class="text-danger"><h:message for="password"/></p> <p class="text-danger"><h:message for="password"/></p> </div> </div> </div> </div> <div class="text-center"> <div class="text-center"> <h:commandLink action="#{credentialsInsertion.login()}" class="btn btn-primary"> <h:commandLink id="admin-login-btn" action="#{credentialsInsertion.login()}" class="btn btn-primary"> Login Login <f:ajax execute="@form" render="@form" /> <f:ajax execute="@form" render="@form" /> </h:commandLink> </h:commandLink> Loading Loading @@ -60,7 +60,7 @@ (${c.databaseType eq 'MYSQL' ? 'MySQL' : 'Postgres'}) ${c.hostname}:${c.port} ${c.username} (${c.databaseType eq 'MYSQL' ? 'MySQL' : 'Postgres'}) ${c.hostname}:${c.port} ${c.username} </div> </div> <div class="col-xs-2 text-right"> <div class="col-xs-2 text-right"> <h:commandLink action="#{credentialsInsertion.login(c)}" title="Login"> <h:commandLink action="#{credentialsInsertion.loginWithSingleCredentials(c)}" title="Login" immediate="true"> <span class="glyphicon glyphicon-log-in"></span> <span class="glyphicon glyphicon-log-in"></span> </h:commandLink> </h:commandLink> </div> </div> Loading @@ -81,7 +81,7 @@ (${c.tapSchemaCredentials.databaseType eq 'MYSQL' ? 'MySQL' : 'Postgres'}) ${c.tapSchemaCredentials.hostname}:${c.tapSchemaCredentials.port} ${c.tapSchemaCredentials.username} (${c.tapSchemaCredentials.databaseType eq 'MYSQL' ? 'MySQL' : 'Postgres'}) ${c.tapSchemaCredentials.hostname}:${c.tapSchemaCredentials.port} ${c.tapSchemaCredentials.username} </div> </div> <div class="col-xs-2 text-right"> <div class="col-xs-2 text-right"> <h:commandLink action="#{credentialsInsertion.login(c.sourceCredentials, c.tapSchemaCredentials)}" title="Login"> <h:commandLink action="#{credentialsInsertion.loginWithSeparatedCredentials(c.sourceCredentials, c.tapSchemaCredentials)}" title="Login" immediate="true"> <span class="glyphicon glyphicon-log-in"></span> <span class="glyphicon glyphicon-log-in"></span> </h:commandLink> </h:commandLink> </div> </div> Loading Loading @@ -159,7 +159,7 @@ <div class="form-group"> <div class="form-group"> <h:outputLabel for="source_password" class="col-sm-2 control-label">Password</h:outputLabel> <h:outputLabel for="source_password" class="col-sm-2 control-label">Password</h:outputLabel> <div class="col-sm-10"> <div class="col-sm-10"> <h:inputSecret id="source_password" value="#{credentialsInsertion.sourceCredentials.password}" class="form-control" /> <h:inputSecret id="source_password" value="#{credentialsInsertion.sourceCredentials.password}" class="form-control" redisplay="true" /> <h:message for="source_password" class="text-danger" /> <h:message for="source_password" class="text-danger" /> </div> </div> </div> </div> Loading Loading @@ -230,7 +230,7 @@ <div class="form-group"> <div class="form-group"> <h:outputLabel for="tap_schema_password" class="col-sm-2 control-label">Password</h:outputLabel> <h:outputLabel for="tap_schema_password" class="col-sm-2 control-label">Password</h:outputLabel> <div class="col-sm-10"> <div class="col-sm-10"> <h:inputSecret id="tap_schema_password" value="#{credentialsInsertion.tapSchemaCredentials.password}" class="form-control" /> <h:inputSecret id="tap_schema_password" value="#{credentialsInsertion.tapSchemaCredentials.password}" class="form-control" redisplay="true" /> <h:message for="tap_schema_password" class="text-danger" /> <h:message for="tap_schema_password" class="text-danger" /> </div> </div> </div> </div> Loading Loading @@ -260,7 +260,7 @@ <div> <div> <br/><br/><br/><br/> <br/><br/><br/><br/> <h:commandButton value="Logout" action="#{credentialsInsertion.logout()}" class="btn btn-primary pull-right"></h:commandButton> <h:commandButton value="Logout" action="#{credentialsInsertion.logout()}" class="btn btn-primary pull-right" immediate="true"></h:commandButton> </div> </div> </h:panelGroup> </h:panelGroup> </h:form> </h:form> Loading TapSchemaManager/src/main/webapp/resources/js/credentials.js +7 −0 Original line number Original line Diff line number Diff line (function () { (function () { window.credentials = { window.credentials = { adminLoginClicked: function (event) { if (event.keyCode === 13) { $('#main\\:admin-login-btn').click(); event.preventDefault(); return false; } }, editClicked: function (event) { editClicked: function (event) { if (event.status === 'success') { if (event.status === 'success') { $('#credentials-modal').modal('show'); $('#credentials-modal').modal('show'); Loading TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/DataProvider.java +8 −16 Original line number Original line Diff line number Diff line Loading @@ -180,9 +180,7 @@ public class DataProvider { } } } } protected static ArrayList<String> getAllTablesNames(DBWrapper dbs, String schemaName) throws SQLException { protected static ArrayList<String> getAllTablesNames(DataSource dataSource, DatabaseType dbType, String schemaName) throws SQLException { DatabaseType dbType = dbs.getSourceDatabaseType(); String query; String query; if (dbType == DatabaseType.MYSQL) { if (dbType == DatabaseType.MYSQL) { Loading @@ -194,7 +192,7 @@ public class DataProvider { } } ArrayList<String> allTables = new ArrayList<>(); ArrayList<String> allTables = new ArrayList<>(); try (Connection connection = dbs.getSourceConnection(); try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query)) { ResultSet resultSet = statement.executeQuery(query)) { while (resultSet.next()) { while (resultSet.next()) { Loading @@ -205,11 +203,9 @@ public class DataProvider { return allTables; return allTables; } } protected static Map<String, String> getTablesTypes(DBWrapper dbs, String schemaName) throws SQLException { protected static Map<String, String> getTablesTypes(DataSource dataSource, DatabaseType dbType, String schemaName) throws SQLException { final Map<String, String> tablesTypes = new HashMap<>(); final Map<String, String> tablesTypes = new HashMap<>(); DatabaseType dbType = dbs.getSourceDatabaseType(); String query; String query; if (dbType == DatabaseType.MYSQL) { if (dbType == DatabaseType.MYSQL) { query = "SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = '" + schemaName + "'"; query = "SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = '" + schemaName + "'"; Loading @@ -224,7 +220,7 @@ public class DataProvider { throw new UnsupportedOperationException("Database type " + dbType + " not supported"); throw new UnsupportedOperationException("Database type " + dbType + " not supported"); } } try (Connection connection = dbs.getSourceConnection(); try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query)) { ResultSet resultSet = statement.executeQuery(query)) { while (resultSet.next()) { while (resultSet.next()) { Loading @@ -246,12 +242,10 @@ public class DataProvider { * @return * @return * @throws SQLException * @throws SQLException */ */ protected static List<KeyEntity> getSchemaKeys(DBWrapper dbs, String schemaName) throws SQLException { protected static List<KeyEntity> getSchemaKeys(DataSource dataSource, DatabaseType dbType, String schemaName) throws SQLException { final Map<String, KeyEntity> schemaKeysMap = new HashMap<>(); final Map<String, KeyEntity> schemaKeysMap = new HashMap<>(); DatabaseType dbType = dbs.getSourceDatabaseType(); String query; String query; if (dbType == DatabaseType.MYSQL) { if (dbType == DatabaseType.MYSQL) { Loading @@ -278,7 +272,7 @@ public class DataProvider { throw new UnsupportedOperationException("Database type " + dbType + " not supported"); throw new UnsupportedOperationException("Database type " + dbType + " not supported"); } } try (Connection connection = dbs.getSourceConnection(); try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query)) { ResultSet resultSet = statement.executeQuery(query)) { while (resultSet.next()) { while (resultSet.next()) { Loading Loading @@ -327,11 +321,9 @@ public class DataProvider { return false; return false; } } protected static List<ColumnInfo> getAllColumns(DBWrapper dbs, TableEntity table) throws SQLException { protected static List<ColumnInfo> getAllColumns(DataSource dataSource, DatabaseType dbType, TableEntity table) throws SQLException { final List<ColumnInfo> allColumns = new ArrayList<>(); final List<ColumnInfo> allColumns = new ArrayList<>(); DatabaseType dbType = dbs.getSourceDatabaseType(); String query; String query; if (dbType == DatabaseType.MYSQL) { if (dbType == DatabaseType.MYSQL) { query = String.format("SHOW COLUMNS FROM `%s`.`%s`", table.getSchemaName(), table.getShortTableName()); query = String.format("SHOW COLUMNS FROM `%s`.`%s`", table.getSchemaName(), table.getShortTableName()); Loading @@ -345,7 +337,7 @@ public class DataProvider { throw new UnsupportedOperationException("Database type " + dbType + " not supported"); throw new UnsupportedOperationException("Database type " + dbType + " not supported"); } } try (Connection connection = dbs.getSourceConnection(); try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query)) { ResultSet resultSet = statement.executeQuery(query)) { Loading TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/TapSchemaHandler.java +44 −31 Original line number Original line Diff line number Diff line Loading @@ -14,6 +14,7 @@ import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery; import javax.sql.DataSource; import org.slf4j.Logger; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory; Loading @@ -25,10 +26,10 @@ class SchemaInfo implements Serializable { private final List<KeyEntity> schemaKeys; private final List<KeyEntity> schemaKeys; private final Map<String, String> tablesType; private final Map<String, String> tablesType; SchemaInfo(DBWrapper dbWrapper, String schemaName) throws SQLException { SchemaInfo(DataSource dataSource, DatabaseType dbType, String schemaName) throws SQLException { allSchemaTables = DataProvider.getAllTablesNames(dbWrapper, schemaName); allSchemaTables = DataProvider.getAllTablesNames(dataSource, dbType, schemaName); schemaKeys = DataProvider.getSchemaKeys(dbWrapper, schemaName); schemaKeys = DataProvider.getSchemaKeys(dataSource, dbType, schemaName); tablesType = DataProvider.getTablesTypes(dbWrapper, schemaName); tablesType = DataProvider.getTablesTypes(dataSource, dbType, schemaName); } } public List<String> getAllSchemaTables() { public List<String> getAllSchemaTables() { Loading @@ -48,9 +49,11 @@ class ColumnsInfo implements Serializable { private static final long serialVersionUID = -3407052226160044192L; private static final long serialVersionUID = -3407052226160044192L; private final String tapSchemaName; private final Map<String, Map<String, List<ColumnInfo>>> columnsInfo; private final Map<String, Map<String, List<ColumnInfo>>> columnsInfo; ColumnsInfo() { ColumnsInfo(String tapSchemaName) { this.tapSchemaName = tapSchemaName; this.columnsInfo = new HashMap<>(); this.columnsInfo = new HashMap<>(); } } Loading @@ -61,7 +64,14 @@ class ColumnsInfo implements Serializable { map = new HashMap<>(); map = new HashMap<>(); columnsInfo.put(schemaName, map); columnsInfo.put(schemaName, map); } } map.put(tableEntity.getShortTableName(), DataProvider.getAllColumns(dbWrapper, tableEntity)); List<ColumnInfo> allColumns; if (schemaName.equals(tapSchemaName)) { allColumns = DataProvider.getAllColumns(dbWrapper.getTapSchemaDataSource(), dbWrapper.getTapSchemaDatabaseType(), tableEntity); } else { allColumns = DataProvider.getAllColumns(dbWrapper.getSourceDataSource(), dbWrapper.getSourceDatabaseType(), tableEntity); } map.put(tableEntity.getShortTableName(), allColumns); } } List<ColumnInfo> getColumnsInfo(String schemaName, String shortTableName) { List<ColumnInfo> getColumnsInfo(String schemaName, String shortTableName) { Loading @@ -85,7 +95,7 @@ public class TapSchemaHandler implements Serializable, Closeable { //private final Credentials sourceCredentials; //private final Credentials sourceCredentials; //private final Credentials tapSchemaCredentials; //private final Credentials tapSchemaCredentials; private final String name; private final String tapSchemaName; private boolean exists; private boolean exists; private final List<String> allSchemas; private final List<String> allSchemas; Loading @@ -101,7 +111,7 @@ public class TapSchemaHandler implements Serializable, Closeable { public TapSchemaHandler(DBWrapper dbWrapper, String tapSchemaName, boolean exists) throws SQLException { public TapSchemaHandler(DBWrapper dbWrapper, String tapSchemaName, boolean exists) throws SQLException { this.dbWrapper = dbWrapper; this.dbWrapper = dbWrapper; this.name = tapSchemaName; this.tapSchemaName = tapSchemaName; this.exists = exists; this.exists = exists; this.allSchemas = DataProvider.getAllSchemasNames(dbWrapper.getSourceDataSource(), dbWrapper.getSourceDatabaseType()); this.allSchemas = DataProvider.getAllSchemasNames(dbWrapper.getSourceDataSource(), dbWrapper.getSourceDatabaseType()); Loading @@ -112,7 +122,7 @@ public class TapSchemaHandler implements Serializable, Closeable { this.allSchemaInfos = new HashMap<>(); this.allSchemaInfos = new HashMap<>(); this.columnsInfo = new ColumnsInfo(); this.columnsInfo = new ColumnsInfo(tapSchemaName); if (exists) { if (exists) { loadEntityManager(); loadEntityManager(); Loading @@ -123,8 +133,13 @@ public class TapSchemaHandler implements Serializable, Closeable { String schemaName = schemaEntity.getName(); String schemaName = schemaEntity.getName(); addSchema(schemaEntity); addSchema(schemaEntity); //Connection conn = name.equals(schemaName) ? tapSchemaCredentials.getConnection() : sourceConn; SchemaInfo schemaInfo; SchemaInfo schemaInfo = new SchemaInfo(dbWrapper, schemaName); if (schemaName.equals(tapSchemaName)) { schemaInfo = new SchemaInfo(dbWrapper.getTapSchemaDataSource(), dbWrapper.getTapSchemaDatabaseType(), schemaName); } else { schemaInfo = new SchemaInfo(dbWrapper.getSourceDataSource(), dbWrapper.getSourceDatabaseType(), schemaName); } allSchemaInfos.put(schemaName, schemaInfo); allSchemaInfos.put(schemaName, schemaInfo); persistedSchemas.add(schemaName); persistedSchemas.add(schemaName); Loading @@ -137,7 +152,7 @@ public class TapSchemaHandler implements Serializable, Closeable { public SchemaEntity getNewSchema(String schemaName) throws SQLException { public SchemaEntity getNewSchema(String schemaName) throws SQLException { SchemaEntity schemaEntity = new SchemaEntity(schemaName); SchemaEntity schemaEntity = new SchemaEntity(schemaName); allSchemaInfos.put(schemaName, new SchemaInfo(dbWrapper, schemaName)); allSchemaInfos.put(schemaName, new SchemaInfo(dbWrapper.getSourceDataSource(), dbWrapper.getSourceDatabaseType(), schemaName)); return schemaEntity; return schemaEntity; } } Loading Loading @@ -292,7 +307,7 @@ public class TapSchemaHandler implements Serializable, Closeable { } } entityManager.getTransaction().commit(); entityManager.getTransaction().commit(); } else { } else { DataProvider.createTapSchemaSchema(dbWrapper, name); DataProvider.createTapSchemaSchema(dbWrapper, tapSchemaName); loadEntityManager(); loadEntityManager(); Loading @@ -303,16 +318,15 @@ public class TapSchemaHandler implements Serializable, Closeable { entityManager.getTransaction().commit(); entityManager.getTransaction().commit(); // Adding TAP_SCHEMA into TAP_SCHEMA // Adding TAP_SCHEMA into TAP_SCHEMA if (!dbWrapper.isSeparatedSources()) { log.info("Adding TAP_SCHEMA into TAP_SCHEMA"); log.info("Adding TAP_SCHEMA into TAP_SCHEMA"); SchemaEntity tapSchemaSchema; SchemaEntity tapSchemaSchema; tapSchemaSchema = getNewSchema(name); tapSchemaSchema = getNewSchema(tapSchemaName); addSchema(tapSchemaSchema); addSchema(tapSchemaSchema); for (String shortTableName : allSchemaInfos.get(name).getAllSchemaTables()) { for (String shortTableName : allSchemaInfos.get(tapSchemaName).getAllSchemaTables()) { TableEntity tableEntity = getNewTable(name, shortTableName); TableEntity tableEntity = getNewTable(tapSchemaName, shortTableName); addTable(name, tableEntity); addTable(tapSchemaName, tableEntity); for (ColumnInfo ci : columnsInfo.getColumnsInfo(name, shortTableName)) { for (ColumnInfo ci : columnsInfo.getColumnsInfo(tapSchemaName, shortTableName)) { addColumn(tableEntity, ci.getColumnEntity()); addColumn(tableEntity, ci.getColumnEntity()); } } } } Loading @@ -322,7 +336,6 @@ public class TapSchemaHandler implements Serializable, Closeable { entityManager.getTransaction().begin(); entityManager.getTransaction().begin(); entityManager.merge(tapSchemaSchema); entityManager.merge(tapSchemaSchema); entityManager.getTransaction().commit(); entityManager.getTransaction().commit(); } exists = true; exists = true; } } Loading @@ -330,7 +343,7 @@ public class TapSchemaHandler implements Serializable, Closeable { private void loadEntityManager() { private void loadEntityManager() { if (entityManager == null) { if (entityManager == null) { entityManager = DataProvider.getEntityManager(dbWrapper.getTapSchemaCredentials(), name); entityManager = DataProvider.getEntityManager(dbWrapper.getTapSchemaCredentials(), tapSchemaName); } } } } Loading Loading
TapSchemaManager/src/main/java/it/inaf/oats/ia2/tapschemamanager/webapp/CredentialsBean.java +10 −6 Original line number Original line Diff line number Diff line Loading @@ -81,10 +81,11 @@ public class CredentialsBean implements Serializable { currentEditingRow = index; currentEditingRow = index; } } public void editSeparateCredentials(SeparateCredentials separateCredentials, int index) { public void editSeparateCredentials(SeparateCredentials sc, int index) { this.sourceCredentials = separateCredentials.getSourceCredentials(); this.sourceCredentials = sc.getSourceCredentials(); this.tapSchemaCredentials = separateCredentials.getTapSchemaCredentials(); this.tapSchemaCredentials = sc.getTapSchemaCredentials(); currentEditingRow = index; currentEditingRow = index; separateCredentials = true; } } public void addNewCredentials() { public void addNewCredentials() { Loading @@ -94,11 +95,13 @@ public class CredentialsBean implements Serializable { currentEditingRow = ccBean.getConfig().getCredentialsInfo().size(); currentEditingRow = ccBean.getConfig().getCredentialsInfo().size(); } } public String login(Credentials credentials) { public String loginWithSingleCredentials(Credentials credentials) { log.debug("Login with single credentials"); return loginWithDBWrapper(new DBWrapper(credentials)); return loginWithDBWrapper(new DBWrapper(credentials)); } } public String login(Credentials sourceCredentials, Credentials tapSchemaCredentials) { public String loginWithSeparatedCredentials(Credentials sourceCredentials, Credentials tapSchemaCredentials) { log.debug("Login with separated credentials"); return loginWithDBWrapper(new DBWrapper(sourceCredentials, tapSchemaCredentials)); return loginWithDBWrapper(new DBWrapper(sourceCredentials, tapSchemaCredentials)); } } Loading Loading @@ -181,10 +184,11 @@ public class CredentialsBean implements Serializable { this.loggedIn = loggedIn; this.loggedIn = loggedIn; } } public void logout() { public String logout() { HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); if (request.isRequestedSessionIdValid()) { if (request.isRequestedSessionIdValid()) { request.getSession().invalidate(); request.getSession().invalidate(); } } return "index.xhtml?faces-redirect=true"; } } } }
TapSchemaManager/src/main/webapp/index.xhtml +7 −7 Original line number Original line Diff line number Diff line Loading @@ -25,12 +25,12 @@ <div class="form-group"> <div class="form-group"> <h:outputLabel for="password" class="col-sm-3 control-label">Password</h:outputLabel> <h:outputLabel for="password" class="col-sm-3 control-label">Password</h:outputLabel> <div class="col-sm-9"> <div class="col-sm-9"> <h:inputSecret class="form-control" id="password" value="#{credentialsInsertion.adminPassword}" /> <h:inputSecret class="form-control" id="password" value="#{credentialsInsertion.adminPassword}" onkeypress="credentials.adminLoginClicked(event)" /> <p class="text-danger"><h:message for="password"/></p> <p class="text-danger"><h:message for="password"/></p> </div> </div> </div> </div> <div class="text-center"> <div class="text-center"> <h:commandLink action="#{credentialsInsertion.login()}" class="btn btn-primary"> <h:commandLink id="admin-login-btn" action="#{credentialsInsertion.login()}" class="btn btn-primary"> Login Login <f:ajax execute="@form" render="@form" /> <f:ajax execute="@form" render="@form" /> </h:commandLink> </h:commandLink> Loading Loading @@ -60,7 +60,7 @@ (${c.databaseType eq 'MYSQL' ? 'MySQL' : 'Postgres'}) ${c.hostname}:${c.port} ${c.username} (${c.databaseType eq 'MYSQL' ? 'MySQL' : 'Postgres'}) ${c.hostname}:${c.port} ${c.username} </div> </div> <div class="col-xs-2 text-right"> <div class="col-xs-2 text-right"> <h:commandLink action="#{credentialsInsertion.login(c)}" title="Login"> <h:commandLink action="#{credentialsInsertion.loginWithSingleCredentials(c)}" title="Login" immediate="true"> <span class="glyphicon glyphicon-log-in"></span> <span class="glyphicon glyphicon-log-in"></span> </h:commandLink> </h:commandLink> </div> </div> Loading @@ -81,7 +81,7 @@ (${c.tapSchemaCredentials.databaseType eq 'MYSQL' ? 'MySQL' : 'Postgres'}) ${c.tapSchemaCredentials.hostname}:${c.tapSchemaCredentials.port} ${c.tapSchemaCredentials.username} (${c.tapSchemaCredentials.databaseType eq 'MYSQL' ? 'MySQL' : 'Postgres'}) ${c.tapSchemaCredentials.hostname}:${c.tapSchemaCredentials.port} ${c.tapSchemaCredentials.username} </div> </div> <div class="col-xs-2 text-right"> <div class="col-xs-2 text-right"> <h:commandLink action="#{credentialsInsertion.login(c.sourceCredentials, c.tapSchemaCredentials)}" title="Login"> <h:commandLink action="#{credentialsInsertion.loginWithSeparatedCredentials(c.sourceCredentials, c.tapSchemaCredentials)}" title="Login" immediate="true"> <span class="glyphicon glyphicon-log-in"></span> <span class="glyphicon glyphicon-log-in"></span> </h:commandLink> </h:commandLink> </div> </div> Loading Loading @@ -159,7 +159,7 @@ <div class="form-group"> <div class="form-group"> <h:outputLabel for="source_password" class="col-sm-2 control-label">Password</h:outputLabel> <h:outputLabel for="source_password" class="col-sm-2 control-label">Password</h:outputLabel> <div class="col-sm-10"> <div class="col-sm-10"> <h:inputSecret id="source_password" value="#{credentialsInsertion.sourceCredentials.password}" class="form-control" /> <h:inputSecret id="source_password" value="#{credentialsInsertion.sourceCredentials.password}" class="form-control" redisplay="true" /> <h:message for="source_password" class="text-danger" /> <h:message for="source_password" class="text-danger" /> </div> </div> </div> </div> Loading Loading @@ -230,7 +230,7 @@ <div class="form-group"> <div class="form-group"> <h:outputLabel for="tap_schema_password" class="col-sm-2 control-label">Password</h:outputLabel> <h:outputLabel for="tap_schema_password" class="col-sm-2 control-label">Password</h:outputLabel> <div class="col-sm-10"> <div class="col-sm-10"> <h:inputSecret id="tap_schema_password" value="#{credentialsInsertion.tapSchemaCredentials.password}" class="form-control" /> <h:inputSecret id="tap_schema_password" value="#{credentialsInsertion.tapSchemaCredentials.password}" class="form-control" redisplay="true" /> <h:message for="tap_schema_password" class="text-danger" /> <h:message for="tap_schema_password" class="text-danger" /> </div> </div> </div> </div> Loading Loading @@ -260,7 +260,7 @@ <div> <div> <br/><br/><br/><br/> <br/><br/><br/><br/> <h:commandButton value="Logout" action="#{credentialsInsertion.logout()}" class="btn btn-primary pull-right"></h:commandButton> <h:commandButton value="Logout" action="#{credentialsInsertion.logout()}" class="btn btn-primary pull-right" immediate="true"></h:commandButton> </div> </div> </h:panelGroup> </h:panelGroup> </h:form> </h:form> Loading
TapSchemaManager/src/main/webapp/resources/js/credentials.js +7 −0 Original line number Original line Diff line number Diff line (function () { (function () { window.credentials = { window.credentials = { adminLoginClicked: function (event) { if (event.keyCode === 13) { $('#main\\:admin-login-btn').click(); event.preventDefault(); return false; } }, editClicked: function (event) { editClicked: function (event) { if (event.status === 'success') { if (event.status === 'success') { $('#credentials-modal').modal('show'); $('#credentials-modal').modal('show'); Loading
TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/DataProvider.java +8 −16 Original line number Original line Diff line number Diff line Loading @@ -180,9 +180,7 @@ public class DataProvider { } } } } protected static ArrayList<String> getAllTablesNames(DBWrapper dbs, String schemaName) throws SQLException { protected static ArrayList<String> getAllTablesNames(DataSource dataSource, DatabaseType dbType, String schemaName) throws SQLException { DatabaseType dbType = dbs.getSourceDatabaseType(); String query; String query; if (dbType == DatabaseType.MYSQL) { if (dbType == DatabaseType.MYSQL) { Loading @@ -194,7 +192,7 @@ public class DataProvider { } } ArrayList<String> allTables = new ArrayList<>(); ArrayList<String> allTables = new ArrayList<>(); try (Connection connection = dbs.getSourceConnection(); try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query)) { ResultSet resultSet = statement.executeQuery(query)) { while (resultSet.next()) { while (resultSet.next()) { Loading @@ -205,11 +203,9 @@ public class DataProvider { return allTables; return allTables; } } protected static Map<String, String> getTablesTypes(DBWrapper dbs, String schemaName) throws SQLException { protected static Map<String, String> getTablesTypes(DataSource dataSource, DatabaseType dbType, String schemaName) throws SQLException { final Map<String, String> tablesTypes = new HashMap<>(); final Map<String, String> tablesTypes = new HashMap<>(); DatabaseType dbType = dbs.getSourceDatabaseType(); String query; String query; if (dbType == DatabaseType.MYSQL) { if (dbType == DatabaseType.MYSQL) { query = "SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = '" + schemaName + "'"; query = "SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = '" + schemaName + "'"; Loading @@ -224,7 +220,7 @@ public class DataProvider { throw new UnsupportedOperationException("Database type " + dbType + " not supported"); throw new UnsupportedOperationException("Database type " + dbType + " not supported"); } } try (Connection connection = dbs.getSourceConnection(); try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query)) { ResultSet resultSet = statement.executeQuery(query)) { while (resultSet.next()) { while (resultSet.next()) { Loading @@ -246,12 +242,10 @@ public class DataProvider { * @return * @return * @throws SQLException * @throws SQLException */ */ protected static List<KeyEntity> getSchemaKeys(DBWrapper dbs, String schemaName) throws SQLException { protected static List<KeyEntity> getSchemaKeys(DataSource dataSource, DatabaseType dbType, String schemaName) throws SQLException { final Map<String, KeyEntity> schemaKeysMap = new HashMap<>(); final Map<String, KeyEntity> schemaKeysMap = new HashMap<>(); DatabaseType dbType = dbs.getSourceDatabaseType(); String query; String query; if (dbType == DatabaseType.MYSQL) { if (dbType == DatabaseType.MYSQL) { Loading @@ -278,7 +272,7 @@ public class DataProvider { throw new UnsupportedOperationException("Database type " + dbType + " not supported"); throw new UnsupportedOperationException("Database type " + dbType + " not supported"); } } try (Connection connection = dbs.getSourceConnection(); try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query)) { ResultSet resultSet = statement.executeQuery(query)) { while (resultSet.next()) { while (resultSet.next()) { Loading Loading @@ -327,11 +321,9 @@ public class DataProvider { return false; return false; } } protected static List<ColumnInfo> getAllColumns(DBWrapper dbs, TableEntity table) throws SQLException { protected static List<ColumnInfo> getAllColumns(DataSource dataSource, DatabaseType dbType, TableEntity table) throws SQLException { final List<ColumnInfo> allColumns = new ArrayList<>(); final List<ColumnInfo> allColumns = new ArrayList<>(); DatabaseType dbType = dbs.getSourceDatabaseType(); String query; String query; if (dbType == DatabaseType.MYSQL) { if (dbType == DatabaseType.MYSQL) { query = String.format("SHOW COLUMNS FROM `%s`.`%s`", table.getSchemaName(), table.getShortTableName()); query = String.format("SHOW COLUMNS FROM `%s`.`%s`", table.getSchemaName(), table.getShortTableName()); Loading @@ -345,7 +337,7 @@ public class DataProvider { throw new UnsupportedOperationException("Database type " + dbType + " not supported"); throw new UnsupportedOperationException("Database type " + dbType + " not supported"); } } try (Connection connection = dbs.getSourceConnection(); try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query)) { ResultSet resultSet = statement.executeQuery(query)) { Loading
TapSchemaManagerDL/src/main/java/it/inaf/oats/ia2/tapschemamanager/datalayer/TapSchemaHandler.java +44 −31 Original line number Original line Diff line number Diff line Loading @@ -14,6 +14,7 @@ import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery; import javax.sql.DataSource; import org.slf4j.Logger; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory; Loading @@ -25,10 +26,10 @@ class SchemaInfo implements Serializable { private final List<KeyEntity> schemaKeys; private final List<KeyEntity> schemaKeys; private final Map<String, String> tablesType; private final Map<String, String> tablesType; SchemaInfo(DBWrapper dbWrapper, String schemaName) throws SQLException { SchemaInfo(DataSource dataSource, DatabaseType dbType, String schemaName) throws SQLException { allSchemaTables = DataProvider.getAllTablesNames(dbWrapper, schemaName); allSchemaTables = DataProvider.getAllTablesNames(dataSource, dbType, schemaName); schemaKeys = DataProvider.getSchemaKeys(dbWrapper, schemaName); schemaKeys = DataProvider.getSchemaKeys(dataSource, dbType, schemaName); tablesType = DataProvider.getTablesTypes(dbWrapper, schemaName); tablesType = DataProvider.getTablesTypes(dataSource, dbType, schemaName); } } public List<String> getAllSchemaTables() { public List<String> getAllSchemaTables() { Loading @@ -48,9 +49,11 @@ class ColumnsInfo implements Serializable { private static final long serialVersionUID = -3407052226160044192L; private static final long serialVersionUID = -3407052226160044192L; private final String tapSchemaName; private final Map<String, Map<String, List<ColumnInfo>>> columnsInfo; private final Map<String, Map<String, List<ColumnInfo>>> columnsInfo; ColumnsInfo() { ColumnsInfo(String tapSchemaName) { this.tapSchemaName = tapSchemaName; this.columnsInfo = new HashMap<>(); this.columnsInfo = new HashMap<>(); } } Loading @@ -61,7 +64,14 @@ class ColumnsInfo implements Serializable { map = new HashMap<>(); map = new HashMap<>(); columnsInfo.put(schemaName, map); columnsInfo.put(schemaName, map); } } map.put(tableEntity.getShortTableName(), DataProvider.getAllColumns(dbWrapper, tableEntity)); List<ColumnInfo> allColumns; if (schemaName.equals(tapSchemaName)) { allColumns = DataProvider.getAllColumns(dbWrapper.getTapSchemaDataSource(), dbWrapper.getTapSchemaDatabaseType(), tableEntity); } else { allColumns = DataProvider.getAllColumns(dbWrapper.getSourceDataSource(), dbWrapper.getSourceDatabaseType(), tableEntity); } map.put(tableEntity.getShortTableName(), allColumns); } } List<ColumnInfo> getColumnsInfo(String schemaName, String shortTableName) { List<ColumnInfo> getColumnsInfo(String schemaName, String shortTableName) { Loading @@ -85,7 +95,7 @@ public class TapSchemaHandler implements Serializable, Closeable { //private final Credentials sourceCredentials; //private final Credentials sourceCredentials; //private final Credentials tapSchemaCredentials; //private final Credentials tapSchemaCredentials; private final String name; private final String tapSchemaName; private boolean exists; private boolean exists; private final List<String> allSchemas; private final List<String> allSchemas; Loading @@ -101,7 +111,7 @@ public class TapSchemaHandler implements Serializable, Closeable { public TapSchemaHandler(DBWrapper dbWrapper, String tapSchemaName, boolean exists) throws SQLException { public TapSchemaHandler(DBWrapper dbWrapper, String tapSchemaName, boolean exists) throws SQLException { this.dbWrapper = dbWrapper; this.dbWrapper = dbWrapper; this.name = tapSchemaName; this.tapSchemaName = tapSchemaName; this.exists = exists; this.exists = exists; this.allSchemas = DataProvider.getAllSchemasNames(dbWrapper.getSourceDataSource(), dbWrapper.getSourceDatabaseType()); this.allSchemas = DataProvider.getAllSchemasNames(dbWrapper.getSourceDataSource(), dbWrapper.getSourceDatabaseType()); Loading @@ -112,7 +122,7 @@ public class TapSchemaHandler implements Serializable, Closeable { this.allSchemaInfos = new HashMap<>(); this.allSchemaInfos = new HashMap<>(); this.columnsInfo = new ColumnsInfo(); this.columnsInfo = new ColumnsInfo(tapSchemaName); if (exists) { if (exists) { loadEntityManager(); loadEntityManager(); Loading @@ -123,8 +133,13 @@ public class TapSchemaHandler implements Serializable, Closeable { String schemaName = schemaEntity.getName(); String schemaName = schemaEntity.getName(); addSchema(schemaEntity); addSchema(schemaEntity); //Connection conn = name.equals(schemaName) ? tapSchemaCredentials.getConnection() : sourceConn; SchemaInfo schemaInfo; SchemaInfo schemaInfo = new SchemaInfo(dbWrapper, schemaName); if (schemaName.equals(tapSchemaName)) { schemaInfo = new SchemaInfo(dbWrapper.getTapSchemaDataSource(), dbWrapper.getTapSchemaDatabaseType(), schemaName); } else { schemaInfo = new SchemaInfo(dbWrapper.getSourceDataSource(), dbWrapper.getSourceDatabaseType(), schemaName); } allSchemaInfos.put(schemaName, schemaInfo); allSchemaInfos.put(schemaName, schemaInfo); persistedSchemas.add(schemaName); persistedSchemas.add(schemaName); Loading @@ -137,7 +152,7 @@ public class TapSchemaHandler implements Serializable, Closeable { public SchemaEntity getNewSchema(String schemaName) throws SQLException { public SchemaEntity getNewSchema(String schemaName) throws SQLException { SchemaEntity schemaEntity = new SchemaEntity(schemaName); SchemaEntity schemaEntity = new SchemaEntity(schemaName); allSchemaInfos.put(schemaName, new SchemaInfo(dbWrapper, schemaName)); allSchemaInfos.put(schemaName, new SchemaInfo(dbWrapper.getSourceDataSource(), dbWrapper.getSourceDatabaseType(), schemaName)); return schemaEntity; return schemaEntity; } } Loading Loading @@ -292,7 +307,7 @@ public class TapSchemaHandler implements Serializable, Closeable { } } entityManager.getTransaction().commit(); entityManager.getTransaction().commit(); } else { } else { DataProvider.createTapSchemaSchema(dbWrapper, name); DataProvider.createTapSchemaSchema(dbWrapper, tapSchemaName); loadEntityManager(); loadEntityManager(); Loading @@ -303,16 +318,15 @@ public class TapSchemaHandler implements Serializable, Closeable { entityManager.getTransaction().commit(); entityManager.getTransaction().commit(); // Adding TAP_SCHEMA into TAP_SCHEMA // Adding TAP_SCHEMA into TAP_SCHEMA if (!dbWrapper.isSeparatedSources()) { log.info("Adding TAP_SCHEMA into TAP_SCHEMA"); log.info("Adding TAP_SCHEMA into TAP_SCHEMA"); SchemaEntity tapSchemaSchema; SchemaEntity tapSchemaSchema; tapSchemaSchema = getNewSchema(name); tapSchemaSchema = getNewSchema(tapSchemaName); addSchema(tapSchemaSchema); addSchema(tapSchemaSchema); for (String shortTableName : allSchemaInfos.get(name).getAllSchemaTables()) { for (String shortTableName : allSchemaInfos.get(tapSchemaName).getAllSchemaTables()) { TableEntity tableEntity = getNewTable(name, shortTableName); TableEntity tableEntity = getNewTable(tapSchemaName, shortTableName); addTable(name, tableEntity); addTable(tapSchemaName, tableEntity); for (ColumnInfo ci : columnsInfo.getColumnsInfo(name, shortTableName)) { for (ColumnInfo ci : columnsInfo.getColumnsInfo(tapSchemaName, shortTableName)) { addColumn(tableEntity, ci.getColumnEntity()); addColumn(tableEntity, ci.getColumnEntity()); } } } } Loading @@ -322,7 +336,6 @@ public class TapSchemaHandler implements Serializable, Closeable { entityManager.getTransaction().begin(); entityManager.getTransaction().begin(); entityManager.merge(tapSchemaSchema); entityManager.merge(tapSchemaSchema); entityManager.getTransaction().commit(); entityManager.getTransaction().commit(); } exists = true; exists = true; } } Loading @@ -330,7 +343,7 @@ public class TapSchemaHandler implements Serializable, Closeable { private void loadEntityManager() { private void loadEntityManager() { if (entityManager == null) { if (entityManager == null) { entityManager = DataProvider.getEntityManager(dbWrapper.getTapSchemaCredentials(), name); entityManager = DataProvider.getEntityManager(dbWrapper.getTapSchemaCredentials(), tapSchemaName); } } } } Loading