From ab53cf28d487b4a2f234860352afaab1aeb23b5d Mon Sep 17 00:00:00 2001 From: Julian Dehne <julian.dehne@uni-potsdam.de> Date: Fri, 1 Jun 2018 11:37:02 +0200 Subject: [PATCH] feat: implemented Group and Project DB access and interface --- .../gf/core/database/GFDatabaseConfig.java | 13 + .../gf/core/database/mysql/MysqlConnect.java | 142 +++ .../mysql/VereinfachtesResultSet.java | 861 ++++++++++++++++++ .../gf/core/management/Management.java | 61 ++ .../gf/core/management/ManagementImpl.java | 111 +++ .../gf/core/management/project/Project.java | 91 ++ .../gf/core/management/user/User.java | 57 ++ .../core/management/user/UserInterests.java | 8 + .../gf/core/management/user/UserProfile.java | 8 + .../gf/interfaces/ResearchReport.java | 2 + .../src/scripts/dbschema}/createDummyUser.sql | 0 .../src/scripts/dbschema}/fltrail.sql | 6 + .../src/scripts/dbschema/fltrail_users.sql | 0 .../gf/interfaces/ManagementTest.java | 92 ++ 14 files changed, 1452 insertions(+) create mode 100644 gemeinsamforschen/src/main/java/unipotsdam/gf/core/database/GFDatabaseConfig.java create mode 100644 gemeinsamforschen/src/main/java/unipotsdam/gf/core/database/mysql/MysqlConnect.java create mode 100644 gemeinsamforschen/src/main/java/unipotsdam/gf/core/database/mysql/VereinfachtesResultSet.java create mode 100644 gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/Management.java create mode 100644 gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/ManagementImpl.java create mode 100644 gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/project/Project.java create mode 100644 gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/User.java create mode 100644 gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/UserInterests.java create mode 100644 gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/UserProfile.java rename {dbschema => gemeinsamforschen/src/scripts/dbschema}/createDummyUser.sql (100%) rename {dbschema => gemeinsamforschen/src/scripts/dbschema}/fltrail.sql (89%) create mode 100644 gemeinsamforschen/src/scripts/dbschema/fltrail_users.sql create mode 100644 gemeinsamforschen/src/test/java/unipotsdam/gf/interfaces/ManagementTest.java diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/database/GFDatabaseConfig.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/database/GFDatabaseConfig.java new file mode 100644 index 00000000..7678f2f7 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/database/GFDatabaseConfig.java @@ -0,0 +1,13 @@ +package unipotsdam.gf.core.database; + +/** + * Created by dehne on 31.05.2018. + */ +public class GFDatabaseConfig { + public static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; + public static final String DB_URL = "jdbc:mysql://localhost"; + // Database credentials + public static final String USER = "root2"; + public static final String PASS = "voyager2"; + public static final String DB_NAME = "fltrail"; +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/database/mysql/MysqlConnect.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/database/mysql/MysqlConnect.java new file mode 100644 index 00000000..884ed62c --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/database/mysql/MysqlConnect.java @@ -0,0 +1,142 @@ +package unipotsdam.gf.core.database.mysql; + +import unipotsdam.gf.core.database.GFDatabaseConfig; + +import java.sql.*; +import java.util.Date; + +public class MysqlConnect { + + public Connection conn = null; + + private static String createConnectionString() { + + String connString = "jdbc:mysql://" + "localhost" + + "/" + GFDatabaseConfig.DB_NAME + + "?user=" + GFDatabaseConfig.USER + + "&password=" + GFDatabaseConfig.PASS; + return String.format(connString, GFDatabaseConfig.DB_NAME); + } + + public void connect() { + try { + try { + Class.forName("com.mysql.jdbc.Driver"); + } catch (ClassNotFoundException ex) { + System.out.println(ex); //logger? + } + conn = DriverManager.getConnection(createConnectionString()); + } catch (SQLException ex) { + System.out.println("SQLException: " + ex.getMessage()); + System.out.println("SQLState: " + ex.getSQLState()); + System.out.println("VendorError: " + ex.getErrorCode()); + throw new Error("could not connect to mysql"); + } + } + + + public void close() { + try { + if (conn != null) { + conn.close(); + } + } catch (final SQLException e) { + throw new Error("could not close mysql"); + } + } + + private PreparedStatement addParameters(final String statement, final Object[] args) { + try { + final PreparedStatement ps = conn.prepareStatement(statement); + if (args != null) { + for (int i = 0; i < args.length; i++) { + final Object arg = args[i]; + setParam(ps, arg, i + 1); + } + } + return ps; + } catch (SQLException ex) { + System.out.println(ex); + } + return null; + } + + + public VereinfachtesResultSet issueSelectStatement(final String statement, final Object... args) { + try { + PreparedStatement ps = addParameters(statement, args); + ResultSet queryResult = ps.executeQuery(); + return new VereinfachtesResultSet(queryResult); + } catch (SQLException ex) { + System.out.println(ex); + } + return null; + } + + + public void otherStatements(final String statement) { + try { + this.conn.createStatement().execute(statement); + } catch (SQLException ex) { + System.out.println(ex); + } + } + + + public Integer issueUpdateStatement(final String statement, final Object... args) { + PreparedStatement ps = addParameters(statement, args); + try { + return ps.executeUpdate(); + } catch (SQLException ex) { + System.out.println(ex); + } + return null; + } + + + public void issueInsertOrDeleteStatement(final String statement, final Object... args) { + PreparedStatement ps = addParameters(statement, args); + try { + ps.execute(); + } catch (SQLException ex) { + System.out.println(ex); + } + } + + private void setParam(final PreparedStatement ps, final Object arg, final int i) throws SQLException { + if (arg instanceof String) { + ps.setString(i, (String) arg); + } else if (arg instanceof Integer) { + ps.setInt(i, (Integer) arg); + } else if (arg instanceof Double) { + ps.setDouble(i, (Double) arg); + } else if (arg instanceof Boolean) { + ps.setBoolean(i, (Boolean) arg); + } else if (arg instanceof Float) { + ps.setFloat(i, (Float) arg); + } else if (arg instanceof Short) { + ps.setShort(i, (Short) arg); + } else if (arg instanceof Long) { + ps.setLong(i, (Long) arg); + } else if (arg instanceof Byte) { + ps.setByte(i, (Byte) arg); + } else if (arg instanceof Character) { + ps.setString(i, arg.toString()); + } else if (arg instanceof Date) { + final java.sql.Date d = new java.sql.Date(((Date) arg).getTime()); + ps.setDate(i, d); + } else if (arg == null) { + ps.setNull(i, Types.NULL); + } else { + ps.setString(i, arg.toString()); + } + } + + public Connection getConnection() { + return conn; + } + + public void setConnection(Connection conn) { + this.conn = conn; + } +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/database/mysql/VereinfachtesResultSet.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/database/mysql/VereinfachtesResultSet.java new file mode 100644 index 00000000..e997c2bd --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/database/mysql/VereinfachtesResultSet.java @@ -0,0 +1,861 @@ +package unipotsdam.gf.core.database.mysql; + +import java.sql.*; + + +public class VereinfachtesResultSet { + + private ResultSet resultSet; + + public VereinfachtesResultSet(ResultSet resultset) { + if (resultset == null) { + throw new Error("kein Resultset"); + } + this.resultSet = resultset; + } + + public boolean next() { + try { + return resultSet.next(); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + + public int getInt(int columnIndex) { + try { + return resultSet.getInt(columnIndex); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public float getFloat(int columnIndex) { + try { + return resultSet.getFloat(columnIndex); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public double getDouble(int columnIndex) { + try { + return resultSet.getDouble(columnIndex); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + + public Date getDate(int columnIndex) { + try { + return resultSet.getDate(columnIndex); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + + public Timestamp getTimestamp(int columnIndex) { + try { + return resultSet.getTimestamp(columnIndex); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + + public String getString(String columnLabel) { + try { + return resultSet.getString(columnLabel); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public boolean getBoolean(String columnLabel) { + try { + return resultSet.getBoolean(columnLabel); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public int getInt(String columnLabel) { + try { + return resultSet.getInt(columnLabel); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public long getLong(String columnLabel) { + try { + return resultSet.getLong(columnLabel); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public float getFloat(String columnLabel) { + try { + return resultSet.getFloat(columnLabel); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public double getDouble(String columnLabel) { + try { + return resultSet.getDouble(columnLabel); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public ResultSetMetaData getMetaData() { + try { + return resultSet.getMetaData(); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public Object getObject(int columnIndex) { + try { + return resultSet.getObject(columnIndex); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public Object getObject(String columnLabel) { + try { + return resultSet.getObject(columnLabel); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public int findColumn(String columnLabel) { + try { + return resultSet.findColumn(columnLabel); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public boolean isBeforeFirst() { + try { + return resultSet.isBeforeFirst(); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public boolean isAfterLast() { + try { + return resultSet.isAfterLast(); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public boolean isFirst() { + try { + return resultSet.isFirst(); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public boolean isLast() { + try { + return resultSet.isLast(); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public void beforeFirst() { + try { + resultSet.beforeFirst(); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public void afterLast() { + try { + resultSet.afterLast(); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public boolean first() { + try { + return resultSet.first(); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public boolean last() { + try { + return resultSet.last(); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + public int getRow() { + try { + return resultSet.getRow(); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + throw new Error("error in VereinfachtesResultSet"); + } + + // public boolean absolute(int row) { + // try { return + // resultSet.ab + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public boolean relative(int rows) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public boolean previous() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void setFetchDirection(int direction) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public int getFetchDirection() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void setFetchSize(int rows) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public int getFetchSize() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public int getType() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public int getConcurrency() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public boolean rowUpdated() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public boolean rowInserted() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public boolean rowDeleted() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateNull(int columnIndex) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateBoolean(int columnIndex, boolean x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateByte(int columnIndex, byte x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateShort(int columnIndex, short x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateInt(int columnIndex, int x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateLong(int columnIndex, long x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateFloat(int columnIndex, float x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateDouble(int columnIndex, double x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateBigDecimal(int columnIndex, BigDecimal x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateString(int columnIndex, String x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateBytes(int columnIndex, byte[] x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateDate(int columnIndex, Date x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateTime(int columnIndex, Time x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateTimestamp(int columnIndex, Timestamp x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateAsciiStream(int columnIndex, InputStream x, int length) + // { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateBinaryStream(int columnIndex, InputStream x, int + // length) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateCharacterStream(int columnIndex, Reader x, int length) + // { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateObject(int columnIndex, Object x, int scaleOrLength) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateObject(int columnIndex, Object x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateNull(String columnLabel) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateBoolean(String columnLabel, boolean x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateByte(String columnLabel, byte x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateShort(String columnLabel, short x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateInt(String columnLabel, int x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateLong(String columnLabel, long x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateFloat(String columnLabel, float x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateDouble(String columnLabel, double x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateBigDecimal(String columnLabel, BigDecimal x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateString(String columnLabel, String x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateBytes(String columnLabel, byte[] x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateDate(String columnLabel, Date x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateTime(String columnLabel, Time x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateTimestamp(String columnLabel, Timestamp x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateAsciiStream(String columnLabel, InputStream x, int + // length) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateBinaryStream(String columnLabel, InputStream x, int + // length) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateCharacterStream(String columnLabel, Reader reader, int + // length) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateObject(String columnLabel, Object x, int scaleOrLength) + // { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateObject(String columnLabel, Object x) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void insertRow() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void updateRow() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void deleteRow() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void refreshRow() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void cancelRowUpdates() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void moveToInsertRow() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public void moveToCurrentRow() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Statement getStatement() { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Object getObject(int columnIndex, Map<String, Class<?>> map) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Ref getRef(int columnIndex) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Blob getBlob(int columnIndex) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Clob getClob(int columnIndex) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Array getArray(int columnIndex) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Object getObject(String columnLabel, Map<String, Class<?>> map) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Ref getRef(String columnLabel) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Blob getBlob(String columnLabel) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Clob getClob(String columnLabel) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Array getArray(String columnLabel) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Date getDate(int columnIndex, Calendar cal) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Date getDate(String columnLabel, Calendar cal) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Time getTime(int columnIndex, Calendar cal) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Time getTime(String columnLabel, Calendar cal) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Timestamp getTimestamp(int columnIndex, Calendar cal) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public Timestamp getTimestamp(String columnLabel, Calendar cal) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public URL getURL(int columnIndex) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } + // + // public URL getURL(String columnLabel) { + // try { return + // } catch (SQLException ex) { + // System.err.println(ex.getMessage()); + // } + // throw new Error("error in VereinfachtesResultSet"); + // } +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/Management.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/Management.java new file mode 100644 index 00000000..449b8751 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/Management.java @@ -0,0 +1,61 @@ +package unipotsdam.gf.core.management; + +import unipotsdam.gf.core.management.project.Project; +import unipotsdam.gf.core.management.user.User; +import unipotsdam.gf.core.management.user.UserInterests; +import unipotsdam.gf.core.management.user.UserProfile; +import unipotsdam.gf.modules.assessment.controller.StudentIdentifier; + +/** + * Created by dehne on 31.05.2018. + * TODO in DAOs refaktorisieren, sobald es mehr wird + */ +public interface Management { + /** + * delete a User in the database + * @param identifier + */ + void delete(StudentIdentifier identifier); + + /** + * create a User in the database + * @param user + * @param profile + */ + void create(User user, UserProfile profile); + + /** + * create a Project in the database + * @param project + */ + void create(Project project); + + /** + * Delete a Project in the database + * @param project + */ + void delete(Project project); + + /** + * Add an entry in the M:N table linking users and projects + * @param user + * @param project + * @param interests + */ + void register(User user, Project project, UserInterests interests); + + /** + * Check if a user exists in the DB + * @param user + * @return + */ + Boolean exists(User user); + + /** + * Get all the users linked to a project + * @param project + * @return + */ + java.util.List<User> getUsers(Project project); +} + diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/ManagementImpl.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/ManagementImpl.java new file mode 100644 index 00000000..8a26c0a1 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/ManagementImpl.java @@ -0,0 +1,111 @@ +package unipotsdam.gf.core.management; + +import unipotsdam.gf.core.database.mysql.MysqlConnect; +import unipotsdam.gf.core.database.mysql.VereinfachtesResultSet; +import unipotsdam.gf.core.management.project.Project; +import unipotsdam.gf.core.management.user.User; +import unipotsdam.gf.core.management.user.UserInterests; +import unipotsdam.gf.core.management.user.UserProfile; +import unipotsdam.gf.modules.assessment.controller.StudentIdentifier; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * Created by dehne on 31.05.2018. + */ +public class ManagementImpl implements Management { + @Override + public void delete(StudentIdentifier identifier) { + MysqlConnect connect = new MysqlConnect(); + connect.connect(); + String mysqlRequest = "DELETE FROM users where email = (?)"; + connect.issueInsertOrDeleteStatement(mysqlRequest, identifier.getStudentId()); + connect.close(); + } + + @Override + public void create(User user, UserProfile profile) { + UUID uuid = UUID.randomUUID(); + String token = uuid.toString(); + + MysqlConnect connect = new MysqlConnect(); + connect.connect(); + String mysqlRequest = "INSERT INTO users (`name`, `password`, `email`, `token`) values (?,?,?,?)"; + connect.issueInsertOrDeleteStatement(mysqlRequest, user.getName(), user.getPassword(), user.getEmail(), token); + connect.close(); + + // TODO implmement UserProfile @Mar + } + + @Override + public void create(Project project) { + UUID uuid = UUID.randomUUID(); + String token = uuid.toString(); + + MysqlConnect connect = new MysqlConnect(); + connect.connect(); + String mysqlRequest = + "INSERT INTO projects (`id`, `password`, `activ`, `timecreated`, `author`, " + "`adminpassword`, `token`) values (?,?,?,?,?,?,?)"; + connect.issueInsertOrDeleteStatement(mysqlRequest, project.getId(), project.getPassword(), project.getActiv(), + project.getTimecreated(), project.getAuthor(), project.getAdminpassword(), token); + connect.close(); + } + + @Override + public void delete(Project project) { + MysqlConnect connect = new MysqlConnect(); + connect.connect(); + String mysqlRequest = "DELETE FROM projects where id = (?)"; + connect.issueInsertOrDeleteStatement(mysqlRequest, project.getId()); + connect.close(); + } + + @Override + public void register(User user, Project project, UserInterests interests) { + MysqlConnect connect = new MysqlConnect(); + connect.connect(); + String mysqlRequest = + "INSERT INTO projectuser (`projectId`, `userId`) values (?,?)"; + connect.issueInsertOrDeleteStatement(mysqlRequest, project.getId(), user.getId()); + connect.close(); + } + + @Override + public Boolean exists(User user) { + Boolean result = false; + MysqlConnect connect = new MysqlConnect(); + connect.connect(); + String mysqlRequest = "SELECT * FROM users where email = (?)"; + VereinfachtesResultSet vereinfachtesResultSet = connect.issueSelectStatement(mysqlRequest, user.getEmail()); + result = vereinfachtesResultSet.next(); + connect.close(); + return result; + } + + @Override + public List<User> getUsers(Project project) { + String query = "SELECT * FROM users u " + + " JOIN projectuser pu ON u.email=pu.userId" + + " JOIN projects p ON pu.projectId = p.id" + + " WHERE pu.projectId = ?"; + + ArrayList<User> result = new ArrayList<User>(); + MysqlConnect connect = new MysqlConnect(); + connect.connect(); + VereinfachtesResultSet vereinfachtesResultSet = connect.issueSelectStatement(query, project.getId()); + while (!vereinfachtesResultSet.isLast()) { + vereinfachtesResultSet.next(); + String name = vereinfachtesResultSet.getString("name"); + String password = vereinfachtesResultSet.getString("password"); + String email = vereinfachtesResultSet.getString("email"); + String token = vereinfachtesResultSet.getString("token"); + User user = new User(name, password, email); + user.setToken(token); + result.add(user); + } + connect.close(); + return result; + } +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/project/Project.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/project/Project.java new file mode 100644 index 00000000..de780722 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/project/Project.java @@ -0,0 +1,91 @@ +package unipotsdam.gf.core.management.project; + +import org.glassfish.grizzly.http.util.TimeStamp; + +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.time.ZoneId; + +/** + * Created by dehne on 31.05.2018. + */ +public class Project { + + private String id; + private String password; + private String activ; + private Timestamp timecreated; + private String author; + private String adminpassword; + private String token; + + public Project() { + } + + public Project( + String id, String password, String activ, String author, String adminpassword) { + this.id = id; + this.password = password; + this.activ = activ; + this.author = author; + this.adminpassword = adminpassword; + + Timestamp ts = Timestamp.valueOf(LocalDateTime.now(ZoneId.of("UTC"))); + this.timecreated = ts; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getActiv() { + return activ; + } + + public void setActiv(String activ) { + this.activ = activ; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getAdminpassword() { + return adminpassword; + } + + public void setAdminpassword(String adminpassword) { + this.adminpassword = adminpassword; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + + public Timestamp getTimecreated() { + return timecreated; + } + + +} \ No newline at end of file diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/User.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/User.java new file mode 100644 index 00000000..d2992816 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/User.java @@ -0,0 +1,57 @@ +package unipotsdam.gf.core.management.user; + +/** + * Created by dehne on 31.05.2018. + */ +public class User { + + public User() { + } + + public User(String name, String password, String email) { + this.name = name; + this.password = password; + this.email = email; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + // the email is the id! + public String getId() { + return this.email; + } + private String name; + private String password; + private String email; + private String token; +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/UserInterests.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/UserInterests.java new file mode 100644 index 00000000..229421d5 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/UserInterests.java @@ -0,0 +1,8 @@ +package unipotsdam.gf.core.management.user; + +/** + * Created by dehne on 31.05.2018. + */ +// user data that is created on a project basis +public class UserInterests { +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/UserProfile.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/UserProfile.java new file mode 100644 index 00000000..40698684 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/UserProfile.java @@ -0,0 +1,8 @@ +package unipotsdam.gf.core.management.user; + +/** + * Created by dehne on 31.05.2018. + */ +// User data specific to Group Formation or Asessment +public class UserProfile { +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/interfaces/ResearchReport.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/interfaces/ResearchReport.java index 4f3d4e98..0106d107 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/interfaces/ResearchReport.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/interfaces/ResearchReport.java @@ -1,6 +1,8 @@ package unipotsdam.gf.interfaces; +import java.io.File; + /** * Created by Johannes Zeiße on 30.05.2018. */ diff --git a/dbschema/createDummyUser.sql b/gemeinsamforschen/src/scripts/dbschema/createDummyUser.sql similarity index 100% rename from dbschema/createDummyUser.sql rename to gemeinsamforschen/src/scripts/dbschema/createDummyUser.sql diff --git a/dbschema/fltrail.sql b/gemeinsamforschen/src/scripts/dbschema/fltrail.sql similarity index 89% rename from dbschema/fltrail.sql rename to gemeinsamforschen/src/scripts/dbschema/fltrail.sql index 8c364d3e..a70ccaed 100644 --- a/dbschema/fltrail.sql +++ b/gemeinsamforschen/src/scripts/dbschema/fltrail.sql @@ -31,6 +31,12 @@ CREATE TABLE `users` ( `token` varchar(800) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE projectuser + ( + projectId varchar(400) NOT NULL, + userId varchar(400) NOT NULL +); ENGINE=InnoDB DEFAULT CHARSET=utf8; + diff --git a/gemeinsamforschen/src/scripts/dbschema/fltrail_users.sql b/gemeinsamforschen/src/scripts/dbschema/fltrail_users.sql new file mode 100644 index 00000000..e69de29b diff --git a/gemeinsamforschen/src/test/java/unipotsdam/gf/interfaces/ManagementTest.java b/gemeinsamforschen/src/test/java/unipotsdam/gf/interfaces/ManagementTest.java new file mode 100644 index 00000000..d5c4fd11 --- /dev/null +++ b/gemeinsamforschen/src/test/java/unipotsdam/gf/interfaces/ManagementTest.java @@ -0,0 +1,92 @@ +package unipotsdam.gf.interfaces; + +import org.junit.Test; +import unipotsdam.gf.core.management.ManagementImpl; +import unipotsdam.gf.core.management.project.Project; +import unipotsdam.gf.core.management.user.User; +import unipotsdam.gf.core.management.user.UserProfile; + +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by dehne on 01.06.2018. + */ +public class ManagementTest { + + @Test + public void testDelete() throws Exception { + + } + + /** + * CREATE a user in the DB using the + * @throws Exception + */ + @Test + public void testExists() throws Exception { + ManagementImpl management = new ManagementImpl(); + User user = new User("julian", "1234", "from1123123123@stuff.com"); + assert !management.exists(user); + } + + /** + * CREATE a user in the DB using the + * @throws Exception + */ + @Test + public void testCreate() throws Exception { + ManagementImpl management = new ManagementImpl(); + User user = new User("julian", "1234", "from@stuff.com"); + management.create(user, new UserProfile()); + assert management.exists(user); + } + + /** + * Test creating a user in the DB + * @throws Exception + */ + @Test + public void testCreate1() throws Exception { + ManagementImpl management = new ManagementImpl(); + management.create(new Project("Gemainsam Forschen", "1235", "1", "me", "keins")); + + } + + @Test + public void testRegister() throws Exception { + ManagementImpl management = new ManagementImpl(); + User user = new User("julian", "1234", "from@stuff.com"); + management.create(user, new UserProfile()); + assert management.exists(user); + + Project project = new Project("Gemainsam Forschen", "1235", "1", "me", "keins"); + management.create(project); + management.register(user, project, null); + } + + @Test + public void testGetUsers() throws Exception { + ManagementImpl management = new ManagementImpl(); + User user = new User("julian", "1234", "from@stuff.com"); + management.create(user, new UserProfile()); + assert management.exists(user); + + Project project = new Project("Gemainsam Forschen", "1235", "1", "me", "keins"); + management.create(project); + management.register(user, project, null); + + User user2 = new User("julian2", "12345", "from2@stuff.com"); + management.create(user2, new UserProfile()); + assert management.exists(user2); + + List<User> users = management.getUsers(project); + assert users != null; + assert !users.isEmpty(); + + } +} \ No newline at end of file -- GitLab