diff --git a/datastore/pom.xml b/datastore/pom.xml index 91b77133d0322388bba35f8f49aa488c3f46a945..4d44f5da8eee9aadd26f5bfa699e4ab8832bbf22 100644 --- a/datastore/pom.xml +++ b/datastore/pom.xml @@ -23,10 +23,9 @@ <version>${debry.version}</version> </dependency> <dependency> - <groupId>net.jami</groupId> - <artifactId>jams-common</artifactId> - <version>${revision}</version> - <scope>compile</scope> + <groupId>org.flywaydb</groupId> + <artifactId>flyway-core</artifactId> + <version>${flyway.version}</version> </dependency> </dependencies> diff --git a/datastore/src/main/java/net/jami/datastore/dao/ContactDao.java b/datastore/src/main/java/net/jami/datastore/dao/ContactDao.java index 15fb7e524bd529f40f840e881bfc6d4cdafb30f4..df7b71da7fa874812feb2b612ecfbc0317d0b351 100644 --- a/datastore/src/main/java/net/jami/datastore/dao/ContactDao.java +++ b/datastore/src/main/java/net/jami/datastore/dao/ContactDao.java @@ -36,24 +36,8 @@ import java.util.List; public class ContactDao extends AbstractDao<Contact> { public ContactDao() { - SQLConnection connection = DataStore.connectionPool.getConnection(); - try { - this.setTableName("contacts"); - this.setTClass(Contact.class); - String createTable = "CREATE TABLE contacts (" + - "owner varchar(255), " + - "uri varchar(255)," + - "displayName varchar(255)," + - "`timestamp` bigint," + - "status int," + - "PRIMARY KEY (owner,uri))"; - PreparedStatement ps = connection.getConnection().prepareStatement(createTable); - ps.execute(); - } catch (SQLException e) { - log.error("Could not create the contacts table with error " + e.getMessage()); - } finally { - DataStore.connectionPool.returnConnection(connection); - } + this.setTableName("contacts"); + this.setTClass(Contact.class); } //Not used because the strategy here is different. diff --git a/datastore/src/main/java/net/jami/datastore/dao/DeviceDao.java b/datastore/src/main/java/net/jami/datastore/dao/DeviceDao.java index 08d61c6a117041bb563b757f006f47e71fd3d27f..88fb2fce3577f1ba9d87860e8aba4d409a95036b 100644 --- a/datastore/src/main/java/net/jami/datastore/dao/DeviceDao.java +++ b/datastore/src/main/java/net/jami/datastore/dao/DeviceDao.java @@ -1,25 +1,26 @@ /* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* 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, see <https://www.gnu.org/licenses/>. -*/ + * Copyright (C) 2020 by Savoir-faire Linux + * Authors: William Enright <william.enright@savoirfairelinux.com> + * Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> + * Johnny Flores <johnny.flores@savoirfairelinux.com> + * Mohammed Raza <mohammed.raza@savoirfairelinux.com> + * Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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, see <https://www.gnu.org/licenses/>. + */ + package net.jami.datastore.dao; import lombok.extern.slf4j.Slf4j; @@ -35,44 +36,24 @@ import java.sql.SQLException; public class DeviceDao extends AbstractDao<Device> { public DeviceDao() { - SQLConnection connection = DataStore.connectionPool.getConnection(); - try { - this.setTableName("devices"); - this.setTClass(Device.class); - String createTable = "CREATE TABLE devices (" + - "deviceId varchar(255), " + - "owner varchar(255)," + - "displayName varchar(255)," + - "certificate varchar(5000), "+ - "privatekey varchar(5000)," + - "PRIMARY KEY (deviceId))"; - PreparedStatement ps = connection.getConnection().prepareStatement(createTable); - ps.execute(); - } - catch (SQLException e){ - log.error("Could not create the device table with error " + e.getMessage()); - } - finally { - DataStore.connectionPool.returnConnection(connection); - } + this.setTableName("devices"); + this.setTClass(Device.class); } @Override public boolean storeObject(Device object) { SQLConnection connection = DataStore.connectionPool.getConnection(); - try{ + try { PreparedStatement ps = connection.getConnection().prepareStatement("INSERT INTO devices " + - "(deviceId, owner, displayName, certificate, privatekey) " + - "VALUES " + - "(?, ?, ?, ?, ?)"); + "(deviceId, owner, displayName, certificate, privatekey) " + + "VALUES " + + "(?, ?, ?, ?, ?)"); ps = object.getInsert(ps); return ps.executeUpdate() != 0; - } - catch (Exception e){ + } catch (Exception e) { log.error("An error has occurred while trying to store a user: " + e.toString()); return false; - } - finally { + } finally { DataStore.connectionPool.returnConnection(connection); } } @@ -85,18 +66,16 @@ public class DeviceDao extends AbstractDao<Device> { SQLConnection connection = DataStore.connectionPool.getConnection(); - try{ + try { PreparedStatement ps = connection.getConnection().prepareStatement("UPDATE devices SET displayName = ? WHERE owner = ? AND deviceId = ?"); ps.setString(1, deviceName); ps.setString(2, user); ps.setString(3, deviceId); return ps.executeUpdate() != 0; - } - catch (Exception e){ + } catch (Exception e) { log.error("An error has occurred while trying to update a user: " + e.toString()); return false; - } - finally { + } finally { DataStore.connectionPool.returnConnection(connection); } } diff --git a/datastore/src/main/java/net/jami/datastore/dao/JwtDao.java b/datastore/src/main/java/net/jami/datastore/dao/JwtDao.java index 9912250a4c3a30a13eb310cf52ed0f8aff31b7a3..f989d0572c4fc7682ca4eca3f4f02cd16c1e56f0 100644 --- a/datastore/src/main/java/net/jami/datastore/dao/JwtDao.java +++ b/datastore/src/main/java/net/jami/datastore/dao/JwtDao.java @@ -1,25 +1,26 @@ /* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* 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, see <https://www.gnu.org/licenses/>. -*/ + * Copyright (C) 2020 by Savoir-faire Linux + * Authors: William Enright <william.enright@savoirfairelinux.com> + * Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> + * Johnny Flores <johnny.flores@savoirfairelinux.com> + * Mohammed Raza <mohammed.raza@savoirfairelinux.com> + * Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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, see <https://www.gnu.org/licenses/>. + */ + package net.jami.datastore.dao; import com.nimbusds.jwt.SignedJWT; @@ -35,44 +36,26 @@ import java.util.List; @Slf4j public class JwtDao extends AbstractDao<SignedJWT> { - private static final String SQL_STORE_TOKEN = "INSERT INTO tokens (userid,deviceId,token) VALUES (?,?,?)"; + private static final String SQL_STORE_TOKEN = "INSERT INTO tokens (userid,deviceId,token) VALUES (?,?,?)"; private static final String SQL_DELETE_TOKEN = "DELETE FROM tokens WHERE userid = ? AND deviceId = ?"; - private static final String SQL_GET_TOKEN = "SELECT COUNT(token) FROM tokens WHERE token = ?"; + private static final String SQL_GET_TOKEN = "SELECT COUNT(token) FROM tokens WHERE token = ?"; public JwtDao() { - SQLConnection connection = DataStore.connectionPool.getConnection(); - try { - this.setTableName("tokens"); - this.setTClass(SignedJWT.class); - String createTable = "CREATE TABLE tokens (" + - "userid varchar(255), " + - "deviceId varchar(255)," + - "token varchar(255)," + - "PRIMARY KEY (userid, deviceId))"; - PreparedStatement ps = connection.getConnection().prepareStatement(createTable); - ps.execute(); - } - catch (SQLException e){ - log.error("Could not create the device table with error " + e.getMessage()); - } - finally { - DataStore.connectionPool.returnConnection(connection); - } + this.setTableName("tokens"); + this.setTClass(SignedJWT.class); } - @Override public boolean storeObject(SignedJWT object) { //TODO: Implement this. return true; } - public boolean validateToken(SignedJWT signedJWT){ + public boolean validateToken(SignedJWT signedJWT) { //TODO: Implement this. return true; } - //This method is not needed because we are only concerned with the existence of a token, //we never actually look them up. @Override diff --git a/datastore/src/main/java/net/jami/datastore/dao/SystemDao.java b/datastore/src/main/java/net/jami/datastore/dao/SystemDao.java index 16ab23ef28997befc1e5af3259f16f6a9d2a5fdd..99becf31c77e0deeb0bc6cbe85694dd8d7c85fb2 100644 --- a/datastore/src/main/java/net/jami/datastore/dao/SystemDao.java +++ b/datastore/src/main/java/net/jami/datastore/dao/SystemDao.java @@ -1,25 +1,26 @@ /* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* 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, see <https://www.gnu.org/licenses/>. -*/ + * Copyright (C) 2020 by Savoir-faire Linux + * Authors: William Enright <william.enright@savoirfairelinux.com> + * Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> + * Johnny Flores <johnny.flores@savoirfairelinux.com> + * Mohammed Raza <mohammed.raza@savoirfairelinux.com> + * Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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, see <https://www.gnu.org/licenses/>. + */ + package net.jami.datastore.dao; import lombok.extern.slf4j.Slf4j; @@ -35,42 +36,24 @@ import java.sql.SQLException; public class SystemDao extends AbstractDao<SystemAccount> { public SystemDao() { - SQLConnection connection = DataStore.connectionPool.getConnection(); - try { - this.setTableName("system"); - this.setTClass(SystemAccount.class); - String createTable = "CREATE TABLE "+ this.getTableName() + " (" + - "entity varchar(255), " + - "certificate varchar(5000), "+ - "privatekey varchar(5000)," + - "PRIMARY KEY (entity))"; - PreparedStatement ps = connection.getConnection().prepareStatement(createTable); - ps.execute(); - } - catch (SQLException e){ - log.error("Could not create the device table with error " + e.getMessage()); - } - finally { - DataStore.connectionPool.returnConnection(connection); - } + this.setTableName("system"); + this.setTClass(SystemAccount.class); } @Override public boolean storeObject(SystemAccount object) { SQLConnection connection = DataStore.connectionPool.getConnection(); - try{ + try { PreparedStatement ps = connection.getConnection().prepareStatement("INSERT INTO system " + - "(entity,certificate,privatekey)" + - "VALUES " + - "(?, ?, ?)"); + "(entity,certificate,privatekey)" + + "VALUES " + + "(?, ?, ?)"); ps = object.getInsert(ps); return ps.executeUpdate() != 0; - } - catch (Exception e){ + } catch (Exception e) { log.error("An error has occurred while trying to store a system entity: " + e.toString()); return false; - } - finally { + } finally { DataStore.connectionPool.returnConnection(connection); } } diff --git a/datastore/src/main/java/net/jami/datastore/dao/UserDao.java b/datastore/src/main/java/net/jami/datastore/dao/UserDao.java index ca2c69cc7478bc3d24f35ead311cf9b0b56972fe..632b0d0c3aacf148b7b26924ac406dab698b5199 100644 --- a/datastore/src/main/java/net/jami/datastore/dao/UserDao.java +++ b/datastore/src/main/java/net/jami/datastore/dao/UserDao.java @@ -1,25 +1,26 @@ /* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* 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, see <https://www.gnu.org/licenses/>. -*/ + * Copyright (C) 2020 by Savoir-faire Linux + * Authors: William Enright <william.enright@savoirfairelinux.com> + * Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> + * Johnny Flores <johnny.flores@savoirfairelinux.com> + * Mohammed Raza <mohammed.raza@savoirfairelinux.com> + * Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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, see <https://www.gnu.org/licenses/>. + */ + package net.jami.datastore.dao; import lombok.extern.slf4j.Slf4j; @@ -35,51 +36,25 @@ import java.sql.SQLException; public class UserDao extends AbstractDao<User> { public UserDao() { - SQLConnection connection = DataStore.connectionPool.getConnection(); - try { - this.setTableName("users"); - this.setTClass(User.class); - String createTable = "CREATE TABLE users (" + - "username varchar(255), " + - "password varchar(255)," + - "userType varchar(10)," + - "realm varchar(255)," + - "ethAddress varchar(255)," + - "ethKey varchar(255)," + - "jamiId varchar(255)," + - "certificate varchar(5000), "+ - "privatekey varchar(5000)," + - "accessLevel varchar(10),"+ - "needsPasswordReset varchar(10),"+ - "PRIMARY KEY (username))"; - PreparedStatement ps = connection.getConnection().prepareStatement(createTable); - ps.execute(); - } - catch (SQLException e){ - log.error("Could not create the device table with error " + e.getMessage()); - } - finally { - DataStore.connectionPool.returnConnection(connection); - } + this.setTableName("users"); + this.setTClass(User.class); } @Override public boolean storeObject(User object) { SQLConnection connection = DataStore.connectionPool.getConnection(); - try{ + try { PreparedStatement ps = connection.getConnection().prepareStatement("INSERT INTO users " + - "(username, password, userType, realm, ethAddress, ethKey, jamiId,certificate, privatekey, accessLevel," + - "needsPasswordReset) " + - "VALUES " + - "(?, ?, ?, ?, ?, ?, ?,?, ?,?, ?)"); + "(username, password, userType, realm, ethAddress, ethKey, jamiId,certificate, privatekey, accessLevel," + + "needsPasswordReset) " + + "VALUES " + + "(?, ?, ?, ?, ?, ?, ?,?, ?,?, ?)"); ps = object.getInsert(ps); return ps.executeUpdate() != 0; - } - catch (Exception e){ + } catch (Exception e) { log.error("An error has occurred while trying to store a user: " + e.toString()); return false; - } - finally { + } finally { DataStore.connectionPool.returnConnection(connection); } } @@ -91,12 +66,13 @@ public class UserDao extends AbstractDao<User> { String user = constraints.getStatements().get(0).getValue(); String pwReset = "false"; - if (update.getStatements().size() > 1) + if (update.getStatements().size() > 1) { pwReset = update.getStatements().get(1).getValue(); + } SQLConnection connection = DataStore.connectionPool.getConnection(); - try{ + try { PreparedStatement ps = connection.getConnection().prepareStatement("UPDATE users SET password = ? WHERE username = ?"); ps.setString(1, pw); ps.setString(2, user); @@ -107,12 +83,10 @@ public class UserDao extends AbstractDao<User> { ps.setString(2, user); return ps.executeUpdate() != 0; - } - catch (Exception e){ + } catch (Exception e) { log.error("An error has occurred while trying to update a user: " + e.toString()); return false; - } - finally { + } finally { DataStore.connectionPool.returnConnection(connection); } } diff --git a/datastore/src/main/java/net/jami/datastore/dao/UserProfileDao.java b/datastore/src/main/java/net/jami/datastore/dao/UserProfileDao.java index ac0fbd74b4e63e73686918ea46415894b717c0a3..19e0b9fcf38dac16edb1af4af61d183fba20a857 100644 --- a/datastore/src/main/java/net/jami/datastore/dao/UserProfileDao.java +++ b/datastore/src/main/java/net/jami/datastore/dao/UserProfileDao.java @@ -1,25 +1,26 @@ /* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* 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, see <https://www.gnu.org/licenses/>. -*/ + * Copyright (C) 2020 by Savoir-faire Linux + * Authors: William Enright <william.enright@savoirfairelinux.com> + * Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> + * Johnny Flores <johnny.flores@savoirfairelinux.com> + * Mohammed Raza <mohammed.raza@savoirfairelinux.com> + * Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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, see <https://www.gnu.org/licenses/>. + */ + package net.jami.datastore.dao; import lombok.extern.slf4j.Slf4j; @@ -37,73 +38,43 @@ public class UserProfileDao extends AbstractDao<UserProfile> { //Fis this to include the fields from AD/LDAP. public UserProfileDao() { - SQLConnection connection = DataStore.connectionPool.getConnection(); - try { - this.setTableName("local_directory"); - this.setTClass(UserProfile.class); - - String createTable = "CREATE TABLE local_directory (" + - "username varchar(255), " + - "firstName varchar(255), " + - "lastName varchar(255), " + - "email varchar(255), " + - "profilePicture CLOB, " + - "organization varchar(255), " + - "phoneNumber varchar(255), " + - "phoneNumberExtension varchar(255), " + - "faxNumber varchar(255), " + - "mobileNumber varchar(255), " + - "PRIMARY KEY (username))"; - - - PreparedStatement ps = connection.getConnection().prepareStatement(createTable); - ps.execute(); - } - catch (SQLException e){ - log.error("Could not create the user profile table with error " + e.getMessage()); - } - finally { - DataStore.connectionPool.returnConnection(connection); - } + this.setTableName("local_directory"); + this.setTClass(UserProfile.class); } @Override public boolean storeObject(UserProfile object) { SQLConnection connection = DataStore.connectionPool.getConnection(); - try{ + try { PreparedStatement ps = connection.getConnection().prepareStatement("INSERT INTO local_directory " + - "(username, firstName, lastName, email, profilePicture, organization, phoneNumber, phoneNumberExtension, faxNumber, mobileNumber)" + - " VALUES " + "(?,?,?,?,?,?,?,?,?,?)"); + "(username, firstName, lastName, email, profilePicture, organization, phoneNumber, phoneNumberExtension, faxNumber, mobileNumber)" + + " VALUES " + "(?,?,?,?,?,?,?,?,?,?)"); ps = object.getInsert(ps); return ps.executeUpdate() != 0; - } - catch (Exception e){ + } catch (Exception e) { log.error("An error has occurred while trying to store a user profile: " + e.toString()); return false; - } - finally { + } finally { DataStore.connectionPool.returnConnection(connection); } } @Override - public boolean updateObject(StatementList update, StatementList constraints){ + public boolean updateObject(StatementList update, StatementList constraints) { SQLConnection connection = DataStore.connectionPool.getConnection(); - try{ + try { PreparedStatement ps = connection.getConnection().prepareStatement("UPDATE local_directory SET firstname = ?, lastName = ?, email = ?, profilePicture = ?, organization = ?, phoneNumber = ?, phoneNumberExtension = ?, faxNumber = ?, mobileNumber = ? WHERE username = ?"); - for(int i=1;i<update.getStatements().size();i++){ + for (int i = 1; i < update.getStatements().size(); i++) { ps.setString(i, update.getStatements().get(i).getValue()); } ps.setString(update.getStatements().size(), update.getStatements().get(0).getValue()); return ps.executeUpdate() != 0; - } - catch(Exception e){ + } catch (Exception e) { log.error("An error has occurred while trying to update a user profile: " + e.toString()); return false; - } - finally { + } finally { DataStore.connectionPool.returnConnection(connection); } } diff --git a/datastore/src/main/java/net/jami/datastore/main/DataStore.java b/datastore/src/main/java/net/jami/datastore/main/DataStore.java index 508711af0f47cea1a412f85449dc3f40c384ea95..2765ad302280b85d344102a19b55c133b3126581 100644 --- a/datastore/src/main/java/net/jami/datastore/main/DataStore.java +++ b/datastore/src/main/java/net/jami/datastore/main/DataStore.java @@ -38,6 +38,7 @@ import net.jami.jams.common.dao.StatementList; import net.jami.jams.common.dao.connectivity.ConnectionPool; import net.jami.jams.common.objects.user.User; import net.jami.jams.common.objects.user.UserProfile; +import org.flywaydb.core.Flyway; import java.util.List; @@ -55,6 +56,8 @@ public class DataStore implements AuthenticationSource { //Implicitly connect to derby. public DataStore(String connectionString) { + Flyway flyway = Flyway.configure().dataSource(connectionString,"", "").load(); + flyway.migrate(); connectionPool = new ConnectionPool(connectionString); userDao = new UserDao(); deviceDao = new DeviceDao(); diff --git a/datastore/src/main/resources/db/migration/V10__Contacts.sql b/datastore/src/main/resources/db/migration/V10__Contacts.sql new file mode 100644 index 0000000000000000000000000000000000000000..b293ce84fa922b4b266ca6a63305890c504b14c5 --- /dev/null +++ b/datastore/src/main/resources/db/migration/V10__Contacts.sql @@ -0,0 +1,4 @@ +CREATE TABLE contacts (owner varchar(255), +uri varchar(255), displayName varchar(255) , +timestamp bigint, status int, +PRIMARY KEY (owner,uri)); \ No newline at end of file diff --git a/datastore/src/main/resources/db/migration/V11__Devices.sql b/datastore/src/main/resources/db/migration/V11__Devices.sql new file mode 100644 index 0000000000000000000000000000000000000000..9cb38eb599ae07970491e4a4a61715fc14710e8c --- /dev/null +++ b/datastore/src/main/resources/db/migration/V11__Devices.sql @@ -0,0 +1,4 @@ +CREATE TABLE devices (deviceId varchar(255), +owner varchar(255), displayName varchar(255), +certificate varchar(5000), privatekey varchar(5000), +PRIMARY KEY (deviceId)); \ No newline at end of file diff --git a/datastore/src/main/resources/db/migration/V12__System.sql b/datastore/src/main/resources/db/migration/V12__System.sql new file mode 100644 index 0000000000000000000000000000000000000000..00992c3527ad7eed4a5c0599b0ea1112cc502ddf --- /dev/null +++ b/datastore/src/main/resources/db/migration/V12__System.sql @@ -0,0 +1,3 @@ +CREATE TABLE system (entity varchar(255), +certificate varchar(5000), privatekey varchar(5000), +PRIMARY KEY (entity)); \ No newline at end of file diff --git a/datastore/src/main/resources/db/migration/V13__Users.sql b/datastore/src/main/resources/db/migration/V13__Users.sql new file mode 100644 index 0000000000000000000000000000000000000000..983f850bd02946e1cb23446d186b21b0be712f8b --- /dev/null +++ b/datastore/src/main/resources/db/migration/V13__Users.sql @@ -0,0 +1,7 @@ +CREATE TABLE users ( username varchar(255), +password varchar(255),userType varchar(10), +realm varchar(255),ethAddress varchar(255), +ethKey varchar(255),jamiId varchar(255), +certificate varchar(5000),privatekey varchar(5000), +accessLevel varchar(10),needsPasswordReset varchar(10), +PRIMARY KEY (username)); \ No newline at end of file diff --git a/datastore/src/main/resources/db/migration/V14__Userprofile.sql b/datastore/src/main/resources/db/migration/V14__Userprofile.sql new file mode 100644 index 0000000000000000000000000000000000000000..534bfb98df4cc4a4ec96b58c3bd1ee1d7aefcbbc --- /dev/null +++ b/datastore/src/main/resources/db/migration/V14__Userprofile.sql @@ -0,0 +1,7 @@ +CREATE TABLE local_directory ( username varchar(255), +firstName varchar(255),lastName varchar(255), +email varchar(255),profilePicture CLOB, +organization varchar(255),phoneNumber varchar(255), +phoneNumberExtension varchar(255), +faxNumber varchar(255),mobileNumber varchar(255), +PRIMARY KEY (username)); \ No newline at end of file diff --git a/datastore/src/test/java/net/jami/datastore/dao/DAOTest.java b/datastore/src/test/java/net/jami/datastore/dao/DAOTest.java index 633459fae91ef307dc9afae9dd101efdc91f58ba..09468ff0f0e3bb8af78f6f61deca918477bf373b 100644 --- a/datastore/src/test/java/net/jami/datastore/dao/DAOTest.java +++ b/datastore/src/test/java/net/jami/datastore/dao/DAOTest.java @@ -30,6 +30,7 @@ import net.jami.jams.common.objects.devices.Device; import net.jami.jams.common.objects.user.AccessLevel; import net.jami.jams.common.objects.user.User; import net.jami.jams.common.utils.X509Utils; +import org.flywaydb.core.Flyway; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; diff --git a/datastore/src/test/resources/db/migration/V10__Contacts.sql b/datastore/src/test/resources/db/migration/V10__Contacts.sql new file mode 100644 index 0000000000000000000000000000000000000000..b293ce84fa922b4b266ca6a63305890c504b14c5 --- /dev/null +++ b/datastore/src/test/resources/db/migration/V10__Contacts.sql @@ -0,0 +1,4 @@ +CREATE TABLE contacts (owner varchar(255), +uri varchar(255), displayName varchar(255) , +timestamp bigint, status int, +PRIMARY KEY (owner,uri)); \ No newline at end of file diff --git a/datastore/src/test/resources/db/migration/V11__Devices.sql b/datastore/src/test/resources/db/migration/V11__Devices.sql new file mode 100644 index 0000000000000000000000000000000000000000..9cb38eb599ae07970491e4a4a61715fc14710e8c --- /dev/null +++ b/datastore/src/test/resources/db/migration/V11__Devices.sql @@ -0,0 +1,4 @@ +CREATE TABLE devices (deviceId varchar(255), +owner varchar(255), displayName varchar(255), +certificate varchar(5000), privatekey varchar(5000), +PRIMARY KEY (deviceId)); \ No newline at end of file diff --git a/datastore/src/test/resources/db/migration/V12__System.sql b/datastore/src/test/resources/db/migration/V12__System.sql new file mode 100644 index 0000000000000000000000000000000000000000..00992c3527ad7eed4a5c0599b0ea1112cc502ddf --- /dev/null +++ b/datastore/src/test/resources/db/migration/V12__System.sql @@ -0,0 +1,3 @@ +CREATE TABLE system (entity varchar(255), +certificate varchar(5000), privatekey varchar(5000), +PRIMARY KEY (entity)); \ No newline at end of file diff --git a/datastore/src/test/resources/db/migration/V13__Users.sql b/datastore/src/test/resources/db/migration/V13__Users.sql new file mode 100644 index 0000000000000000000000000000000000000000..983f850bd02946e1cb23446d186b21b0be712f8b --- /dev/null +++ b/datastore/src/test/resources/db/migration/V13__Users.sql @@ -0,0 +1,7 @@ +CREATE TABLE users ( username varchar(255), +password varchar(255),userType varchar(10), +realm varchar(255),ethAddress varchar(255), +ethKey varchar(255),jamiId varchar(255), +certificate varchar(5000),privatekey varchar(5000), +accessLevel varchar(10),needsPasswordReset varchar(10), +PRIMARY KEY (username)); \ No newline at end of file diff --git a/datastore/src/test/resources/db/migration/V14__Userprofile.sql b/datastore/src/test/resources/db/migration/V14__Userprofile.sql new file mode 100644 index 0000000000000000000000000000000000000000..534bfb98df4cc4a4ec96b58c3bd1ee1d7aefcbbc --- /dev/null +++ b/datastore/src/test/resources/db/migration/V14__Userprofile.sql @@ -0,0 +1,7 @@ +CREATE TABLE local_directory ( username varchar(255), +firstName varchar(255),lastName varchar(255), +email varchar(255),profilePicture CLOB, +organization varchar(255),phoneNumber varchar(255), +phoneNumberExtension varchar(255), +faxNumber varchar(255),mobileNumber varchar(255), +PRIMARY KEY (username)); \ No newline at end of file diff --git a/pom.xml b/pom.xml index 296734b9fbc3c463d48462961a1591c529c954ca..955ffde5d58d9bcaf3a30a33b656859cc7b96328 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ <junit.surefire.version>1.1.0</junit.surefire.version> <jsoniter.version>0.9.23</jsoniter.version> <javassist.version>3.27.0-GA</javassist.version> - <debry.version>10.11.1.1</debry.version> + <debry.version>10.14.2.0</debry.version> <msgpack.version>0.8.16</msgpack.version> <commons.codec.version>1.11</commons.codec.version> <xbean.version>4.17</xbean.version> @@ -58,6 +58,7 @@ <embedded.ldap.unit>0.8.1</embedded.ldap.unit> <maven.exec.version>1.1.1</maven.exec.version> <zmq.version>0.5.2</zmq.version> + <flyway.version>6.5.1</flyway.version> </properties> <dependencies>