From dd9e461075a23bc75f9db708609a9d0f0ece3901 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 31 Aug 2018 13:13:07 +0200 Subject: more updates --- .../DAO/eIDASPersonalIdStoreDAO.java | 123 +++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/DAO/eIDASPersonalIdStoreDAO.java (limited to 'eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/DAO/eIDASPersonalIdStoreDAO.java') diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/DAO/eIDASPersonalIdStoreDAO.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/DAO/eIDASPersonalIdStoreDAO.java new file mode 100644 index 00000000..b0f957a5 --- /dev/null +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/DAO/eIDASPersonalIdStoreDAO.java @@ -0,0 +1,123 @@ +package at.asitplus.eidas.specific.modules.authmodule_eIDASv2.DAO; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import at.gv.egiz.eaaf.core.impl.data.Pair; + +public class eIDASPersonalIdStoreDAO { + public static final String NAME = "foreigneIDMap"; + + //Enum with all cols of this table + public enum COLS { + timestamp, transactionId, eidasId, eidasSourceCountry, eidasDestinationCountry, ernbId + } + + public enum T { + ID("INTEGER"), + BIGINT("VARCHAR(265)"), + URI("VARCHAR(256)"), + DATE("Long"), + TEXT("TEXT"), + Long("BIGINT"), + Int("INTEGER"), + BLOB("BLOB"), + CC("CHAR(2)"), + BOOL("INTEGER"); + + public String s_; + + private T(String s) { + s_ = s; + } + + @Override + public String toString() { + return s_; + } + } + + //define Cols of the table + public static final List> TABLE_COLS; + static { + List> cols = new ArrayList>(); + cols.add(Pair.newInstance(COLS.timestamp.name(), T.DATE)); + cols.add(Pair.newInstance(COLS.transactionId.name(), T.TEXT)); + cols.add(Pair.newInstance(COLS.eidasId.name(), T.TEXT)); + cols.add(Pair.newInstance(COLS.eidasSourceCountry.name(), T.CC)); + cols.add(Pair.newInstance(COLS.eidasDestinationCountry.name(), T.CC)); + cols.add(Pair.newInstance(COLS.ernbId.name(), T.TEXT)); + + TABLE_COLS = Collections.unmodifiableList(cols); + + } + + public static final String CREATE = "CREATE TABLE " + NAME + + " (" + "id" + " " + T.ID.toString() + + " PRIMARY KEY AUTOINCREMENT, " + buildCreateTableQuery(TABLE_COLS) + ")"; + + public static final String INSERT = "INSERT INTO " + NAME + + "(" + buildInsertQueryKeys(TABLE_COLS) + ")" + + " VALUES (" + buildInsertQueryValues(TABLE_COLS) + ");"; + + public static final String SELECT_BY_ERNB_ID = "SELECT * FROM " + NAME + + " WHERE " + COLS.ernbId.name() + "=?;"; + + public static final String SELECT_BY_EIDAS_RAW_ID = "SELECT * FROM " + NAME + + " WHERE " + COLS.eidasId.name() + "=?" + + " and " + COLS.eidasSourceCountry.name() + "=?" + ";"; + + + /** + * Build a part of a SQL query, which contains the cols of a table that should be created + * + * @param cols List of DB col definitions {@link Pair} + * @return Part of a SQL query, which contains cols that should be created + */ + private static String buildCreateTableQuery(List> cols) { + String sql = ""; + + for (Pair el : cols) { + sql += el.getFirst() + " " + el.getSecond().toString() + ","; + + } + + return sql.substring(0, sql.length()-1); + } + + /** + * Build a part of a SQL query, which contains the cols keys of a table for insert operation + * + * @param cols List of DB col definitions {@link Pair} + * @return Part of a SQL query, which contains cols that should be created + */ + protected static String buildInsertQueryKeys(List> cols) { + String sql = ""; + + for (Pair el : cols) { + sql += el.getFirst() + ","; + + } + + return sql.substring(0, sql.length()-1); + } + + /** + * Build a part of a SQL query, which contains the cols values of a table for insert operation + * + * @param cols List of DB col definitions {@link Pair} + * @return Part of a SQL query, which contains cols that should be created + */ + protected static String buildInsertQueryValues(List> cols) { + String sql = ""; + + for (Pair el : cols) { + sql += "?,"; + + } + + return sql.substring(0, sql.length()-1); + } + +} -- cgit v1.2.3