From 2b6ce209aaf648ae0dc233e603183b1a9625e1e5 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Fri, 1 Apr 2011 16:53:37 +0000 Subject: [PATCH] Datenbank Module --- hsarback/conf/META-INF/persistence.xml | 6 +- hsarback/src/de/hsadmin/mods/db/Database.java | 23 ++- .../src/de/hsadmin/mods/db/DatabaseUser.java | 20 ++- .../src/de/hsadmin/mods/db/MySqlDatabase.java | 12 +- .../mods/db/MySqlDatabaseModuleImpl.java | 2 +- .../src/de/hsadmin/mods/db/MySqlUser.java | 16 +- .../hsadmin/mods/db/MySqlUserModuleImpl.java | 2 +- .../src/de/hsadmin/mods/db/PgSqlDatabase.java | 14 +- .../mods/db/PgSqlDatabaseModuleImpl.java | 2 +- .../src/de/hsadmin/mods/db/PgSqlUser.java | 14 +- .../hsadmin/mods/db/PgSqlUserModuleImpl.java | 2 +- .../src/de/hsadmin/remote/MysqlDbRemote.java | 57 +++++++ .../de/hsadmin/remote/MysqlUserRemote.java | 49 ++++++ .../src/de/hsadmin/remote/PgsqlDbRemote.java | 57 +++++++ .../de/hsadmin/remote/PgsqlUserRemote.java | 49 ++++++ .../xmlrpc/webserver/XmlRpcServlet.properties | 4 + .../test/de/hsadmin/remote/MysqlDbTest.java | 111 ++++++++++++ .../test/de/hsadmin/remote/MysqlUserTest.java | 110 ++++++++++++ .../test/de/hsadmin/remote/PgsqlDbTest.java | 111 ++++++++++++ .../test/de/hsadmin/remote/PgsqlUserTest.java | 110 ++++++++++++ .../src/de/hsadmin/web/AbstractModule.java | 7 +- .../src/de/hsadmin/web/DatabaseModule.java | 161 ++++++++++++++++++ .../de/hsadmin/web/DatabaseUserModule.java | 81 +++++++++ hsarweb/src/de/hsadmin/web/DomainModule.java | 3 +- .../de/hsadmin/web/DomainReadonlyModule.java | 3 +- .../src/de/hsadmin/web/MainApplication.java | 2 +- .../de/hsadmin/web/MysqlDatabaseModule.java | 22 +++ .../src/de/hsadmin/web/MysqlUserModule.java | 12 ++ .../de/hsadmin/web/PacketReadonlyModule.java | 3 +- .../de/hsadmin/web/PgsqlDatabaseModule.java | 22 +++ .../src/de/hsadmin/web/PgsqlUserModule.java | 12 ++ .../src/de/hsadmin/web/QueueTaskModule.java | 5 +- .../web/vaadin/DatePropertyFieldFactory.java | 70 ++++++++ hsarweb/src/texts/main.properties | 6 +- hsarweb/src/texts/mysqldb.properties | 9 + hsarweb/src/texts/mysqldb_de.properties | 9 + hsarweb/src/texts/mysqluser.properties | 10 ++ hsarweb/src/texts/mysqluser_de.properties | 10 ++ hsarweb/src/texts/pac.properties | 2 +- hsarweb/src/texts/pac_de.properties | 2 +- hsarweb/src/texts/postgresqldb.properties | 9 + hsarweb/src/texts/postgresqldb_de.properties | 9 + hsarweb/src/texts/postgresqluser.properties | 10 ++ .../src/texts/postgresqluser_de.properties | 10 ++ 44 files changed, 1195 insertions(+), 65 deletions(-) create mode 100644 hsarback/src/de/hsadmin/remote/MysqlDbRemote.java create mode 100644 hsarback/src/de/hsadmin/remote/MysqlUserRemote.java create mode 100644 hsarback/src/de/hsadmin/remote/PgsqlDbRemote.java create mode 100644 hsarback/src/de/hsadmin/remote/PgsqlUserRemote.java create mode 100644 hsarback/test/de/hsadmin/remote/MysqlDbTest.java create mode 100644 hsarback/test/de/hsadmin/remote/MysqlUserTest.java create mode 100644 hsarback/test/de/hsadmin/remote/PgsqlDbTest.java create mode 100644 hsarback/test/de/hsadmin/remote/PgsqlUserTest.java create mode 100644 hsarweb/src/de/hsadmin/web/DatabaseModule.java create mode 100644 hsarweb/src/de/hsadmin/web/DatabaseUserModule.java create mode 100644 hsarweb/src/de/hsadmin/web/MysqlDatabaseModule.java create mode 100644 hsarweb/src/de/hsadmin/web/MysqlUserModule.java create mode 100644 hsarweb/src/de/hsadmin/web/PgsqlDatabaseModule.java create mode 100644 hsarweb/src/de/hsadmin/web/PgsqlUserModule.java create mode 100644 hsarweb/src/de/hsadmin/web/vaadin/DatePropertyFieldFactory.java create mode 100644 hsarweb/src/texts/mysqldb.properties create mode 100644 hsarweb/src/texts/mysqldb_de.properties create mode 100644 hsarweb/src/texts/mysqluser.properties create mode 100644 hsarweb/src/texts/mysqluser_de.properties create mode 100644 hsarweb/src/texts/postgresqldb.properties create mode 100644 hsarweb/src/texts/postgresqldb_de.properties create mode 100644 hsarweb/src/texts/postgresqluser.properties create mode 100644 hsarweb/src/texts/postgresqluser_de.properties diff --git a/hsarback/conf/META-INF/persistence.xml b/hsarback/conf/META-INF/persistence.xml index ed005fe..4ef3d2a 100644 --- a/hsarback/conf/META-INF/persistence.xml +++ b/hsarback/conf/META-INF/persistence.xml @@ -19,12 +19,12 @@ de.hsadmin.mods.dom.Domain de.hsadmin.mods.email.EMailAddress de.hsadmin.mods.email.EMailAlias - diff --git a/hsarback/src/de/hsadmin/mods/db/Database.java b/hsarback/src/de/hsadmin/mods/db/Database.java index c51eebe..bb64ba5 100644 --- a/hsarback/src/de/hsadmin/mods/db/Database.java +++ b/hsarback/src/de/hsadmin/mods/db/Database.java @@ -6,15 +6,20 @@ import static javax.persistence.GenerationType.SEQUENCE; import java.io.Serializable; import javax.persistence.Column; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.DiscriminatorType; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; -import javax.persistence.MappedSuperclass; import javax.persistence.NoResultException; import javax.persistence.Query; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; import de.hsadmin.core.model.AbstractEntity; import de.hsadmin.core.model.AbstractModuleImpl; @@ -23,8 +28,12 @@ import de.hsadmin.core.model.SearchFilter; import de.hsadmin.mods.pac.Pac; import de.hsadmin.mods.user.UnixUser; -@MappedSuperclass -@SearchFilter("pac = :loginUserPac OR pac.customer.memberCode = :loginUserName") +@Entity +@Table(name = "database") +@Inheritance(strategy=InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name="engine", discriminatorType=DiscriminatorType.STRING) +@SequenceGenerator(name = "DatabaseSeqGen", sequenceName = "database_database_id_seq") +@SearchFilter("obj.pac = :loginUserPac OR obj.pac.customer.name = :loginUserName") public abstract class Database extends AbstractEntity implements Serializable { private static final long serialVersionUID = 6243815106074846080L; @@ -82,8 +91,8 @@ public abstract class Database extends AbstractEntity implements Serializable { String pacName = name.substring(0, 5); try { // get the entities name (query part from FROM to WHERE) - javax.persistence.Entity entityAnnot = Pac.class.getAnnotation(Entity.class); - String queryString = "FROM " + entityAnnot.name() + " WHERE " + Entity entityAnnot = Pac.class.getAnnotation(Entity.class); + String queryString = "SELECT obj FROM " + entityAnnot.name() + " obj WHERE " + Pac.createQueryFromStringKey(pacName); // set parameters @@ -215,8 +224,8 @@ public abstract class Database extends AbstractEntity implements Serializable { public static String restriction() { return // all databases of all pacs of customer - "pac.customer.memberCode=:loginUserName OR " + + "obj.pac.customer.name=:loginUserName OR " + // all aliases of packet admin - "pac.name=:loginUserName"; + "obj.pac.name=:loginUserName"; } } diff --git a/hsarback/src/de/hsadmin/mods/db/DatabaseUser.java b/hsarback/src/de/hsadmin/mods/db/DatabaseUser.java index a53e33a..d352f87 100644 --- a/hsarback/src/de/hsadmin/mods/db/DatabaseUser.java +++ b/hsarback/src/de/hsadmin/mods/db/DatabaseUser.java @@ -6,14 +6,20 @@ import static javax.persistence.GenerationType.SEQUENCE; import java.io.Serializable; import javax.persistence.Column; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.DiscriminatorType; +import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; -import javax.persistence.MappedSuperclass; import javax.persistence.NoResultException; import javax.persistence.Query; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; import javax.persistence.Transient; import de.hsadmin.core.model.AbstractEntity; @@ -22,7 +28,11 @@ import de.hsadmin.core.model.FieldValidation; import de.hsadmin.mods.pac.Pac; import de.hsadmin.mods.user.UnixUser; -@MappedSuperclass +@Entity +@Table(name = "database_user") +@Inheritance(strategy=InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name="engine", discriminatorType=DiscriminatorType.STRING) +@SequenceGenerator(name = "DatabaseUserSeqGen", sequenceName = "dbuser_dbuser_id_seq") public abstract class DatabaseUser extends AbstractEntity implements Serializable { private static final long serialVersionUID = -4840133372566213014L; @@ -72,7 +82,7 @@ public abstract class DatabaseUser extends AbstractEntity implements Serializabl // get the entities name (query part from FROM to WHERE) javax.persistence.Entity entityAnnot = Pac.class .getAnnotation(javax.persistence.Entity.class); - String queryString = "FROM " + entityAnnot.name() + " WHERE " + String queryString = "SELECT obj FROM " + entityAnnot.name() + " obj WHERE " + Pac.createQueryFromStringKey(pacName); // set parameters @@ -193,8 +203,8 @@ public abstract class DatabaseUser extends AbstractEntity implements Serializabl public static String restriction() { return // all databases of all pacs of customer - "pac.customer.memberCode=:loginUserName OR " + + "obj.pac.customer.name=:loginUserName OR " + // all aliases of packet admin - "pac.name=:loginUserName"; + "obj.pac.name=:loginUserName"; } } diff --git a/hsarback/src/de/hsadmin/mods/db/MySqlDatabase.java b/hsarback/src/de/hsadmin/mods/db/MySqlDatabase.java index 3c578e1..dd19bc1 100644 --- a/hsarback/src/de/hsadmin/mods/db/MySqlDatabase.java +++ b/hsarback/src/de/hsadmin/mods/db/MySqlDatabase.java @@ -2,20 +2,18 @@ package de.hsadmin.mods.db; import java.io.Serializable; +import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; -import javax.persistence.SequenceGenerator; -import javax.persistence.Table; import de.hsadmin.core.model.EntityInfo; import de.hsadmin.core.model.SearchFilter; import de.hsadmin.mods.pac.Pac; @Entity(name = "MySqlDatabases") -@Table(name = "database") -@SequenceGenerator(name = "DatabaseSeqGen", sequenceName = "database_database_id_seq") +@DiscriminatorValue("mysql") @EntityInfo(name = "MySQL Datenbank") -@SearchFilter("instance = 'mysql' AND (" + " pac = :loginUserPac OR " - + " pac.customer.memberCode = :loginUserName )") +@SearchFilter("obj.instance = 'mysql' AND (" + " obj.pac = :loginUserPac OR " + + " obj.pac.customer.memberCode = :loginUserName )") public class MySqlDatabase extends Database implements Serializable { private static final long serialVersionUID = 2862112440807946042L; @@ -40,7 +38,7 @@ public class MySqlDatabase extends Database implements Serializable { } public static String restriction() { - return "instance='mysql' AND ( " + Database.restriction() + " )"; + return "obj.instance='mysql' AND ( " + Database.restriction() + " )"; } } diff --git a/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseModuleImpl.java b/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseModuleImpl.java index 9ef0f73..167488e 100644 --- a/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseModuleImpl.java @@ -16,7 +16,7 @@ public class MySqlDatabaseModuleImpl extends AbstractModuleImpl { public List search(Class entityClass, String condition, String orderBy) throws HSAdminException { if (orderBy == null || orderBy.length() == 0) { - orderBy = "ORDER BY name ASC"; + orderBy = "ORDER BY obj.name ASC"; } return super.search(entityClass, condition, orderBy); } diff --git a/hsarback/src/de/hsadmin/mods/db/MySqlUser.java b/hsarback/src/de/hsadmin/mods/db/MySqlUser.java index 942286e..8668948 100644 --- a/hsarback/src/de/hsadmin/mods/db/MySqlUser.java +++ b/hsarback/src/de/hsadmin/mods/db/MySqlUser.java @@ -2,27 +2,25 @@ package de.hsadmin.mods.db; import java.io.Serializable; +import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; -import javax.persistence.SequenceGenerator; -import javax.persistence.Table; import de.hsadmin.core.model.EntityInfo; import de.hsadmin.core.model.SearchFilter; import de.hsadmin.mods.pac.Pac; @Entity(name = "MySqlUsers") -@Table(name = "database_user") -@SequenceGenerator(name = "DatabaseUserSeqGen", sequenceName = "dbuser_dbuser_id_seq") +@DiscriminatorValue("mysql") @EntityInfo(name = "MySQL Konto") -@SearchFilter("instance = 'mysql' AND (" - + " pac = :loginUserPac OR " - + " pac.customer.memberCode = :loginUserName )") +@SearchFilter("obj.instance = 'mysql' AND (" + + " obj.pac = :loginUserPac OR " + + " obj.pac.customer.memberCode = :loginUserName )") public class MySqlUser extends DatabaseUser implements Serializable { private static final long serialVersionUID = 6218494776881999478L; public static String createQueryFromStringKey(String humanKey) { - return "name='" + humanKey + "' AND instance='mysql'"; + return "obj.name='" + humanKey + "' AND obj.instance='mysql'"; } public MySqlUser() { @@ -37,7 +35,7 @@ public class MySqlUser extends DatabaseUser implements Serializable { * query restriction for access control */ public static String restriction() { - return "instance='mysql' AND ( " + DatabaseUser.restriction() + " )"; + return "obj.instance='mysql' AND ( " + DatabaseUser.restriction() + " )"; } } diff --git a/hsarback/src/de/hsadmin/mods/db/MySqlUserModuleImpl.java b/hsarback/src/de/hsadmin/mods/db/MySqlUserModuleImpl.java index 696d2f0..e3a8094 100644 --- a/hsarback/src/de/hsadmin/mods/db/MySqlUserModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/db/MySqlUserModuleImpl.java @@ -22,7 +22,7 @@ public class MySqlUserModuleImpl extends AbstractModuleImpl { public List search(Class entityClass, String condition, String orderBy) throws HSAdminException { if (orderBy == null || orderBy.length() == 0) { - orderBy = "ORDER BY name ASC"; + orderBy = "ORDER BY obj.name ASC"; } return super.search(entityClass, condition, orderBy); } diff --git a/hsarback/src/de/hsadmin/mods/db/PgSqlDatabase.java b/hsarback/src/de/hsadmin/mods/db/PgSqlDatabase.java index a889085..fd6c0c8 100644 --- a/hsarback/src/de/hsadmin/mods/db/PgSqlDatabase.java +++ b/hsarback/src/de/hsadmin/mods/db/PgSqlDatabase.java @@ -2,21 +2,19 @@ package de.hsadmin.mods.db; import java.io.Serializable; +import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; -import javax.persistence.SequenceGenerator; -import javax.persistence.Table; import de.hsadmin.core.model.EntityInfo; import de.hsadmin.core.model.SearchFilter; import de.hsadmin.mods.pac.Pac; @Entity(name = "PgSqlDatabases") -@Table(name = "database") -@SequenceGenerator(name = "DatabaseSeqGen", sequenceName = "database_database_id_seq") +@DiscriminatorValue("pgsql") @EntityInfo(name = "PostgreSQL Datenbank") -@SearchFilter("instance = 'pgsql' AND (" - + " pac = :loginUserPac OR " - + " pac.customer.memberCode = :loginUserName )") +@SearchFilter("obj.instance = 'pgsql' AND (" + + " obj.pac = :loginUserPac OR " + + " obj.pac.customer.memberCode = :loginUserName )") public class PgSqlDatabase extends Database implements Serializable { private static final long serialVersionUID = 6688358817554938015L; @@ -43,7 +41,7 @@ public class PgSqlDatabase extends Database implements Serializable { * query restriction for access control */ public static String restriction() { - return "instance='pgsql' AND ( " + Database.restriction() + " )"; + return "obj.instance='pgsql' AND ( " + Database.restriction() + " )"; } } diff --git a/hsarback/src/de/hsadmin/mods/db/PgSqlDatabaseModuleImpl.java b/hsarback/src/de/hsadmin/mods/db/PgSqlDatabaseModuleImpl.java index ff344a2..475d387 100644 --- a/hsarback/src/de/hsadmin/mods/db/PgSqlDatabaseModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/db/PgSqlDatabaseModuleImpl.java @@ -15,7 +15,7 @@ public class PgSqlDatabaseModuleImpl extends AbstractModuleImpl { @Override public List search(Class entityClass, String condition, String orderBy) throws HSAdminException { if (orderBy == null || orderBy.length() == 0) { - orderBy = "ORDER BY name ASC"; + orderBy = "ORDER BY obj.name ASC"; } return super.search(entityClass, condition, orderBy); } diff --git a/hsarback/src/de/hsadmin/mods/db/PgSqlUser.java b/hsarback/src/de/hsadmin/mods/db/PgSqlUser.java index 023d74b..92c171a 100644 --- a/hsarback/src/de/hsadmin/mods/db/PgSqlUser.java +++ b/hsarback/src/de/hsadmin/mods/db/PgSqlUser.java @@ -2,26 +2,24 @@ package de.hsadmin.mods.db; import java.io.Serializable; +import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; -import javax.persistence.SequenceGenerator; -import javax.persistence.Table; import de.hsadmin.core.model.EntityInfo; import de.hsadmin.core.model.SearchFilter; import de.hsadmin.mods.pac.Pac; @Entity(name = "PgSqlUsers") -@Table(name = "database_user") -@SequenceGenerator(name = "DatabaseUserSeqGen", sequenceName = "dbuser_dbuser_id_seq") +@DiscriminatorValue("pgsql") @EntityInfo(name = "PostgreSQL Konto") -@SearchFilter("instance = 'pgsql' AND (" + " pac = :loginUserPac OR " - + " pac.customer.memberCode = :loginUserName )") +@SearchFilter("obj.instance = 'pgsql' AND (" + " obj.pac = :loginUserPac OR " + + " obj.pac.customer.memberCode = :loginUserName )") public class PgSqlUser extends DatabaseUser implements Serializable { private static final long serialVersionUID = -1097602753310286629L; public static String createQueryFromStringKey(String humanKey) { - return "name='" + humanKey + "' AND instance='pgsql'"; + return "obj.name='" + humanKey + "' AND obj.instance='pgsql'"; } public PgSqlUser() { @@ -36,7 +34,7 @@ public class PgSqlUser extends DatabaseUser implements Serializable { * query restriction for access control */ public static String restriction() { - return "instance='pgsql' AND ( " + DatabaseUser.restriction() + " )"; + return "obj.instance='pgsql' AND ( " + DatabaseUser.restriction() + " )"; } } diff --git a/hsarback/src/de/hsadmin/mods/db/PgSqlUserModuleImpl.java b/hsarback/src/de/hsadmin/mods/db/PgSqlUserModuleImpl.java index 8fb17ed..74057ab 100644 --- a/hsarback/src/de/hsadmin/mods/db/PgSqlUserModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/db/PgSqlUserModuleImpl.java @@ -12,7 +12,7 @@ public class PgSqlUserModuleImpl extends AbstractModuleImpl { public List search(Class entityClass, String condition, String orderBy) throws HSAdminException { if (orderBy == null || orderBy.length() == 0) { - orderBy = "ORDER BY name ASC"; + orderBy = "ORDER BY obj.name ASC"; } return super.search(entityClass, condition, orderBy); } diff --git a/hsarback/src/de/hsadmin/remote/MysqlDbRemote.java b/hsarback/src/de/hsadmin/remote/MysqlDbRemote.java new file mode 100644 index 0000000..041ac55 --- /dev/null +++ b/hsarback/src/de/hsadmin/remote/MysqlDbRemote.java @@ -0,0 +1,57 @@ +package de.hsadmin.remote; + +import java.util.Map; + +import de.hsadmin.core.model.AbstractEntity; +import de.hsadmin.mods.db.MySqlDatabase; + +public class MysqlDbRemote extends AbstractRemote { + + @Override + protected void entity2map(AbstractEntity entity, Map map) { + MySqlDatabase db = (MySqlDatabase) entity; + String id = Long.toString(db.getId()); + String name = db.getName(); + String instance = db.getInstance(); + String owner = db.getOwner(); + String encoding = db.getEncoding(); + String pac = db.getPac().getName(); + String hive = db.getHiveName(); + map.put("id", id); + map.put("name", name); + map.put("instance", instance); + map.put("pac", pac); + map.put("hive", hive); + map.put("owner", owner); + map.put("encoding", encoding); + } + + @Override + protected Class getEntityClass() { + return MySqlDatabase.class; + } + + @Override + protected void map2entity(Map map, AbstractEntity entity) { + MySqlDatabase db = (MySqlDatabase) entity; + db.setInstance("mysql"); + String name = map.get("name"); + String owner = map.get("owner"); + String encoding = map.get("encoding"); + if (assertNotNull(name)) { + db.setName(name); + } + if (assertNotNull(owner)) { + db.setOwner(owner); + } + if (assertNotNull(encoding)) { + db.setEncoding(encoding); + } + } + + @Override + protected void regularizeKeys(Map whereParams) { + replaceKey(whereParams, "pac", "pac.name"); + } + +} diff --git a/hsarback/src/de/hsadmin/remote/MysqlUserRemote.java b/hsarback/src/de/hsadmin/remote/MysqlUserRemote.java new file mode 100644 index 0000000..11816b3 --- /dev/null +++ b/hsarback/src/de/hsadmin/remote/MysqlUserRemote.java @@ -0,0 +1,49 @@ +package de.hsadmin.remote; + +import java.util.Map; + +import de.hsadmin.core.model.AbstractEntity; +import de.hsadmin.mods.db.MySqlUser; + +public class MysqlUserRemote extends AbstractRemote { + + @Override + protected void entity2map(AbstractEntity entity, Map map) { + MySqlUser user = (MySqlUser) entity; + String id = Long.toString(user.getId()); + String name = user.getName(); + String instance = user.getInstance(); + String pac = user.getPac().getName(); + String hive = user.getHiveName(); + map.put("id", id); + map.put("name", name); + map.put("pac", pac); + map.put("hive", hive); + map.put("instance", instance); + } + + @Override + protected Class getEntityClass() { + return MySqlUser.class; + } + + @Override + protected void map2entity(Map map, AbstractEntity entity) { + MySqlUser user = (MySqlUser) entity; + user.setInstance("mysql"); + String name = map.get("name"); + String password = map.get("password"); + if (assertNotNull(name)) { + user.setName(name); + } + if (assertNotNull(password)) { + user.setPassword(password); + } + } + + @Override + protected void regularizeKeys(Map whereParams) { + replaceKey(whereParams, "pac", "pac.name"); + } + +} diff --git a/hsarback/src/de/hsadmin/remote/PgsqlDbRemote.java b/hsarback/src/de/hsadmin/remote/PgsqlDbRemote.java new file mode 100644 index 0000000..1aae396 --- /dev/null +++ b/hsarback/src/de/hsadmin/remote/PgsqlDbRemote.java @@ -0,0 +1,57 @@ +package de.hsadmin.remote; + +import java.util.Map; + +import de.hsadmin.core.model.AbstractEntity; +import de.hsadmin.mods.db.PgSqlDatabase; + +public class PgsqlDbRemote extends AbstractRemote { + + @Override + protected void entity2map(AbstractEntity entity, Map map) { + PgSqlDatabase db = (PgSqlDatabase) entity; + String id = Long.toString(db.getId()); + String name = db.getName(); + String instance = db.getInstance(); + String owner = db.getOwner(); + String encoding = db.getEncoding(); + String pac = db.getPac().getName(); + String hive = db.getHiveName(); + map.put("id", id); + map.put("name", name); + map.put("instance", instance); + map.put("pac", pac); + map.put("hive", hive); + map.put("owner", owner); + map.put("encoding", encoding); + } + + @Override + protected Class getEntityClass() { + return PgSqlDatabase.class; + } + + @Override + protected void map2entity(Map map, AbstractEntity entity) { + PgSqlDatabase db = (PgSqlDatabase) entity; + db.setInstance("pgsql"); + String name = map.get("name"); + String owner = map.get("owner"); + String encoding = map.get("encoding"); + if (assertNotNull(name)) { + db.setName(name); + } + if (assertNotNull(owner)) { + db.setOwner(owner); + } + if (assertNotNull(encoding)) { + db.setEncoding(encoding); + } + } + + @Override + protected void regularizeKeys(Map whereParams) { + replaceKey(whereParams, "pac", "pac.name"); + } + +} diff --git a/hsarback/src/de/hsadmin/remote/PgsqlUserRemote.java b/hsarback/src/de/hsadmin/remote/PgsqlUserRemote.java new file mode 100644 index 0000000..fd6f69e --- /dev/null +++ b/hsarback/src/de/hsadmin/remote/PgsqlUserRemote.java @@ -0,0 +1,49 @@ +package de.hsadmin.remote; + +import java.util.Map; + +import de.hsadmin.core.model.AbstractEntity; +import de.hsadmin.mods.db.PgSqlUser; + +public class PgsqlUserRemote extends AbstractRemote { + + @Override + protected void entity2map(AbstractEntity entity, Map map) { + PgSqlUser user = (PgSqlUser) entity; + String id = Long.toString(user.getId()); + String name = user.getName(); + String instance = user.getInstance(); + String pac = user.getPac().getName(); + String hive = user.getHiveName(); + map.put("id", id); + map.put("name", name); + map.put("pac", pac); + map.put("hive", hive); + map.put("instance", instance); + } + + @Override + protected Class getEntityClass() { + return PgSqlUser.class; + } + + @Override + protected void map2entity(Map map, AbstractEntity entity) { + PgSqlUser user = (PgSqlUser) entity; + user.setInstance("pgsql"); + String name = map.get("name"); + String password = map.get("password"); + if (assertNotNull(name)) { + user.setName(name); + } + if (assertNotNull(password)) { + user.setPassword(password); + } + } + + @Override + protected void regularizeKeys(Map whereParams) { + replaceKey(whereParams, "pac", "pac.name"); + } + +} diff --git a/hsarback/src/org/apache/xmlrpc/webserver/XmlRpcServlet.properties b/hsarback/src/org/apache/xmlrpc/webserver/XmlRpcServlet.properties index 5c73e91..70f0887 100644 --- a/hsarback/src/org/apache/xmlrpc/webserver/XmlRpcServlet.properties +++ b/hsarback/src/org/apache/xmlrpc/webserver/XmlRpcServlet.properties @@ -6,3 +6,7 @@ emailalias=de.hsadmin.remote.EMailAliasRemote emailaddress=de.hsadmin.remote.EMailAddressRemote q=de.hsadmin.remote.QueueTaskRemote role=de.hsadmin.remote.RoleRemote +mysqluser=de.hsadmin.remote.MysqlUserRemote +postgresqluser=de.hsadmin.remote.PgsqlUserRemote +mysqldb=de.hsadmin.remote.MysqlDbRemote +postgresqldb=de.hsadmin.remote.PgsqlDbRemote \ No newline at end of file diff --git a/hsarback/test/de/hsadmin/remote/MysqlDbTest.java b/hsarback/test/de/hsadmin/remote/MysqlDbTest.java new file mode 100644 index 0000000..77d7c3d --- /dev/null +++ b/hsarback/test/de/hsadmin/remote/MysqlDbTest.java @@ -0,0 +1,111 @@ +package de.hsadmin.remote; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class MysqlDbTest { + + private static final String MODULE = "mysqldb"; + + private XmlRpcClient client; + private RemoteCASHelper cas; + + @Before + public void setUp() throws Exception { + client = RemoteTestHelper.getClient(); + cas = new RemoteCASHelper(); + } + + @After + public void tearDown() throws Exception { + client = null; + cas = null; + } + + @Test + public void testCreate() { + int count = getDBsCount(); + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map setParams = new HashMap(); + setParams.put("name", "aaa00_db1"); + setParams.put("owner", "aaa00_dba"); + setParams.put("encoding", "utf8"); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + setParams }; + try { + Object execute = client.execute(MODULE + ".add", params); + assertTrue(execute instanceof Map); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + assertEquals(count + 1, getDBsCount()); + } + + @Test + public void testSearch() { + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + whereParams }; + try { + Object execute = client.execute(MODULE + ".search", params); + Object[] result = (Object[]) execute; + assertEquals(1, result.length); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + } + + @Test + public void testDelete() { + int count = getDBsCount(); + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + whereParams.put("name", "aaa00_db1"); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + whereParams }; + try { + Object execute = client.execute(MODULE + ".delete", params); + assertNull(execute); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + assertEquals(count - 1, getDBsCount()); + } + + private int getDBsCount() { + int count = 0; + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + whereParams }; + try { + Object execute = client.execute(MODULE + ".search", params); + Object[] result = (Object[]) execute; + count = result.length; + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + return count; + } + +} diff --git a/hsarback/test/de/hsadmin/remote/MysqlUserTest.java b/hsarback/test/de/hsadmin/remote/MysqlUserTest.java new file mode 100644 index 0000000..eacbaf2 --- /dev/null +++ b/hsarback/test/de/hsadmin/remote/MysqlUserTest.java @@ -0,0 +1,110 @@ +package de.hsadmin.remote; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class MysqlUserTest { + + private static final String MODULE = "mysqluser"; + + private XmlRpcClient client; + private RemoteCASHelper cas; + + @Before + public void setUp() throws Exception { + client = RemoteTestHelper.getClient(); + cas = new RemoteCASHelper(); + } + + @After + public void tearDown() throws Exception { + client = null; + cas = null; + } + + @Test + public void testCreate() { + int count = getDBsCount(); + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map setParams = new HashMap(); + setParams.put("name", "aaa00_dba"); + setParams.put("password", "geHeimNis"); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + setParams }; + try { + Object execute = client.execute(MODULE + ".add", params); + assertTrue(execute instanceof Map); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + assertEquals(count + 1, getDBsCount()); + } + + @Test + public void testSearch() { + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + whereParams }; + try { + Object execute = client.execute(MODULE + ".search", params); + Object[] result = (Object[]) execute; + assertEquals(1, result.length); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + } + + @Test + public void testDelete() { + int count = getDBsCount(); + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + whereParams.put("name", "aaa00_dba"); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + whereParams }; + try { + Object execute = client.execute(MODULE + ".delete", params); + assertNull(execute); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + assertEquals(count - 1, getDBsCount()); + } + + private int getDBsCount() { + int count = 0; + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + whereParams }; + try { + Object execute = client.execute(MODULE + ".search", params); + Object[] result = (Object[]) execute; + count = result.length; + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + return count; + } + +} diff --git a/hsarback/test/de/hsadmin/remote/PgsqlDbTest.java b/hsarback/test/de/hsadmin/remote/PgsqlDbTest.java new file mode 100644 index 0000000..fbcb45a --- /dev/null +++ b/hsarback/test/de/hsadmin/remote/PgsqlDbTest.java @@ -0,0 +1,111 @@ +package de.hsadmin.remote; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class PgsqlDbTest { + + private static final String MODULE = "postgresqldb"; + + private XmlRpcClient client; + private RemoteCASHelper cas; + + @Before + public void setUp() throws Exception { + client = RemoteTestHelper.getClient(); + cas = new RemoteCASHelper(); + } + + @After + public void tearDown() throws Exception { + client = null; + cas = null; + } + + @Test + public void testCreate() { + int count = getDBsCount(); + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map setParams = new HashMap(); + setParams.put("name", "aaa00_db1"); + setParams.put("owner", "aaa00_dba"); + setParams.put("encoding", "UTF-8"); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + setParams }; + try { + Object execute = client.execute(MODULE + ".add", params); + assertTrue(execute instanceof Map); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + assertEquals(count + 1, getDBsCount()); + } + + @Test + public void testSearch() { + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + whereParams }; + try { + Object execute = client.execute(MODULE + ".search", params); + Object[] result = (Object[]) execute; + assertEquals(1, result.length); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + } + + @Test + public void testDelete() { + int count = getDBsCount(); + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + whereParams.put("name", "aaa00_db1"); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + whereParams }; + try { + Object execute = client.execute(MODULE + ".delete", params); + assertNull(execute); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + assertEquals(count - 1, getDBsCount()); + } + + private int getDBsCount() { + int count = 0; + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + whereParams }; + try { + Object execute = client.execute(MODULE + ".search", params); + Object[] result = (Object[]) execute; + count = result.length; + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + return count; + } + +} diff --git a/hsarback/test/de/hsadmin/remote/PgsqlUserTest.java b/hsarback/test/de/hsadmin/remote/PgsqlUserTest.java new file mode 100644 index 0000000..66cdb4c --- /dev/null +++ b/hsarback/test/de/hsadmin/remote/PgsqlUserTest.java @@ -0,0 +1,110 @@ +package de.hsadmin.remote; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class PgsqlUserTest { + + private static final String MODULE = "postgresqluser"; + + private XmlRpcClient client; + private RemoteCASHelper cas; + + @Before + public void setUp() throws Exception { + client = RemoteTestHelper.getClient(); + cas = new RemoteCASHelper(); + } + + @After + public void tearDown() throws Exception { + client = null; + cas = null; + } + + @Test + public void testCreate() { + int count = getDBsCount(); + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map setParams = new HashMap(); + setParams.put("name", "aaa00_dba"); + setParams.put("password", "geHeimNis"); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + setParams }; + try { + Object execute = client.execute(MODULE + ".add", params); + assertTrue(execute instanceof Map); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + assertEquals(count + 1, getDBsCount()); + } + + @Test + public void testSearch() { + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + whereParams }; + try { + Object execute = client.execute(MODULE + ".search", params); + Object[] result = (Object[]) execute; + assertEquals(1, result.length); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + } + + @Test + public void testDelete() { + int count = getDBsCount(); + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + whereParams.put("name", "aaa00_dba"); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + whereParams }; + try { + Object execute = client.execute(MODULE + ".delete", params); + assertNull(execute); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + assertEquals(count - 1, getDBsCount()); + } + + private int getDBsCount() { + int count = 0; + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + whereParams }; + try { + Object execute = client.execute(MODULE + ".search", params); + Object[] result = (Object[]) execute; + count = result.length; + } catch (XmlRpcException e) { + fail(e.getMessage()); + } + return count; + } + +} diff --git a/hsarweb/src/de/hsadmin/web/AbstractModule.java b/hsarweb/src/de/hsadmin/web/AbstractModule.java index 47c4fbc..4b37670 100644 --- a/hsarweb/src/de/hsadmin/web/AbstractModule.java +++ b/hsarweb/src/de/hsadmin/web/AbstractModule.java @@ -1,16 +1,15 @@ package de.hsadmin.web; +import java.io.Serializable; import java.util.HashMap; import java.util.Map; -import com.vaadin.terminal.ExternalResource; import com.vaadin.terminal.Sizeable; import com.vaadin.terminal.ThemeResource; import com.vaadin.ui.Button; import com.vaadin.ui.Component; import com.vaadin.ui.Form; import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Link; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; import com.vaadin.ui.Button.ClickEvent; @@ -21,8 +20,10 @@ import de.hsadmin.web.config.ModuleConfig; import de.hsadmin.web.vaadin.GenericForm; import de.hsadmin.web.vaadin.TableComponentFactory; -public abstract class AbstractModule implements Module { +public abstract class AbstractModule implements Module, Serializable { + private static final long serialVersionUID = 1L; + private MainApplication application; private VerticalLayout layout; private Component component; diff --git a/hsarweb/src/de/hsadmin/web/DatabaseModule.java b/hsarweb/src/de/hsadmin/web/DatabaseModule.java new file mode 100644 index 0000000..3d69f04 --- /dev/null +++ b/hsarweb/src/de/hsadmin/web/DatabaseModule.java @@ -0,0 +1,161 @@ +package de.hsadmin.web; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import de.hsadmin.web.config.ModuleConfig; +import de.hsadmin.web.config.PropertyConfig; +import de.hsadmin.web.config.PropertyDefaultValue; +import de.hsadmin.web.config.PropertySelectValues; +import de.hsadmin.web.config.PropertyTableColumn; +import de.hsadmin.web.vaadin.SelectPropertyFieldFactory; + +public abstract class DatabaseModule extends GenericModule { + + private static final long serialVersionUID = 1L; + + private ModuleConfig moduleConfig; + + public abstract String getModuleIdent(); + + public abstract String getUserModuleIdent(); + + public abstract String[] getEncodings(); + + @Override + protected void initModule() { + MainApplication application = getApplication(); + moduleConfig = new ModuleConfig(getModuleIdent(), application.getLocale()); + String login = application.getLogin(); + final String pac = login.length() >= 5 ? login.substring(0, 5) : ""; + PropertyConfig idProp = new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY); + idProp.setReadOnly(true); + PropertyConfig nameProp = new PropertyConfig(moduleConfig, "name", String.class); + nameProp.setDefaultValue(new PropertyDefaultValue() { + @Override + public String getDefaultValue() { + if (pac.length() >= 5) { + return pac + "_"; + } + return ""; + } + }); + nameProp.setWriteOnce(true); + PropertyConfig pacProp = new PropertyConfig(moduleConfig, "pac", String.class, PropertyTableColumn.HIDDEN, new SelectPropertyFieldFactory()); + pacProp.setDefaultValue(new PropertyDefaultValue() { + @Override + public String getDefaultValue() { + return pac; + } + }); + pacProp.setSelectValues(new PropertySelectValues() { + @Override + public boolean newItemsAllowed() { + return false; + } + @Override + public boolean hasSelectList() { + return true; + } + @Override + public Map getSelectValues() { + List list = getPackets(); + TreeMap map = new TreeMap(); + for (String pac : list) { + map.put(pac, pac); + } + return map; + } + }); + pacProp.setWriteOnce(true); + PropertyConfig encodingProp = new PropertyConfig(moduleConfig, "encoding", String.class, new SelectPropertyFieldFactory()); + encodingProp.setDefaultValue(new PropertyDefaultValue() { + @Override + public String getDefaultValue() { + return "utf8"; + } + }); + encodingProp.setSelectValues(new PropertySelectValues() { + @Override + public boolean newItemsAllowed() { + return false; + } + @Override + public Map getSelectValues() { + String[] encodings = getEncodings(); + Map map = new TreeMap(); + for (String enc : encodings) { + map.put(enc, enc); + } + return map; + } + @Override + public boolean hasSelectList() { + return true; + } + }); + encodingProp.setWriteOnce(true); + PropertyConfig ownerProp = new PropertyConfig(moduleConfig, "owner", String.class, new SelectPropertyFieldFactory()); + ownerProp.setDefaultValue(new PropertyDefaultValue() { + @Override + public String getDefaultValue() { + return ""; + } + }); + ownerProp.setSelectValues(new PropertySelectValues() { + @Override + public boolean newItemsAllowed() { + return false; + } + @Override + public boolean hasSelectList() { + return true; + } + @Override + public Map getSelectValues() { + List list = getDatabaseUsers(); + TreeMap map = new TreeMap(); + for (String usr : list) { + map.put(usr, usr); + } + return map; + } + }); + ownerProp.setWriteOnce(true); + moduleConfig.addProperty(idProp); + moduleConfig.addProperty(pacProp); + moduleConfig.addProperty(nameProp); + moduleConfig.addProperty(encodingProp); + moduleConfig.addProperty(ownerProp); + } + + @Override + public ModuleConfig getModuleConfig() { + return moduleConfig; + } + + public List getDatabaseUsers() { + ArrayList list = new ArrayList(); + try { + Object callSearch = getApplication().getRemote().callSearch(getUserModuleIdent(), new HashMap()); + if (callSearch instanceof Object[]) { + for (Object row : ((Object[])callSearch)) { + if (row instanceof Map) { + Object object = ((Map) row).get("name"); + if (object instanceof String) { + list.add((String) object); + } + } + } + } + } catch (HsarwebException e) { + e.printStackTrace(); + getApplication().showSystemException(e); + } + return list; + } + +} diff --git a/hsarweb/src/de/hsadmin/web/DatabaseUserModule.java b/hsarweb/src/de/hsadmin/web/DatabaseUserModule.java new file mode 100644 index 0000000..8038a85 --- /dev/null +++ b/hsarweb/src/de/hsadmin/web/DatabaseUserModule.java @@ -0,0 +1,81 @@ +package de.hsadmin.web; + +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import de.hsadmin.web.config.ModuleConfig; +import de.hsadmin.web.config.PropertyConfig; +import de.hsadmin.web.config.PropertyDefaultValue; +import de.hsadmin.web.config.PropertySelectValues; +import de.hsadmin.web.config.PropertyTableColumn; +import de.hsadmin.web.vaadin.PasswordPropertyFieldFactory; +import de.hsadmin.web.vaadin.SelectPropertyFieldFactory; + +public abstract class DatabaseUserModule extends GenericModule { + + private static final long serialVersionUID = 1L; + + private ModuleConfig moduleConfig; + + public abstract String getModuleIdent(); + + @Override + protected void initModule() { + MainApplication application = getApplication(); + moduleConfig = new ModuleConfig(getModuleIdent(), application.getLocale()); + String login = application.getLogin(); + final String pac = login.length() >= 5 ? login.substring(0, 5) : ""; + PropertyConfig idProp = new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY); + idProp.setReadOnly(true); + PropertyConfig nameProp = new PropertyConfig(moduleConfig, "name", String.class); + nameProp.setDefaultValue(new PropertyDefaultValue() { + @Override + public String getDefaultValue() { + if (pac.length() >= 5) { + return pac + "_"; + } + return ""; + } + }); + nameProp.setWriteOnce(true); + PropertyConfig pacProp = new PropertyConfig(moduleConfig, "pac", String.class, PropertyTableColumn.HIDDEN, new SelectPropertyFieldFactory()); + pacProp.setDefaultValue(new PropertyDefaultValue() { + @Override + public String getDefaultValue() { + return pac; + } + }); + pacProp.setSelectValues(new PropertySelectValues() { + @Override + public boolean newItemsAllowed() { + return false; + } + @Override + public boolean hasSelectList() { + return true; + } + @Override + public Map getSelectValues() { + List list = getPackets(); + TreeMap map = new TreeMap(); + for (String pac : list) { + map.put(pac, pac); + } + return map; + } + }); + pacProp.setWriteOnce(true); + PropertyConfig passwordProp = new PropertyConfig(moduleConfig, "password", String.class, PropertyTableColumn.NONE, new PasswordPropertyFieldFactory(this)); + moduleConfig.addProperty(idProp); + moduleConfig.addProperty(pacProp); + moduleConfig.addProperty(nameProp); + moduleConfig.addProperty(passwordProp); + } + + @Override + public ModuleConfig getModuleConfig() { + return moduleConfig; + } + +} diff --git a/hsarweb/src/de/hsadmin/web/DomainModule.java b/hsarweb/src/de/hsadmin/web/DomainModule.java index 9361c76..02cc348 100644 --- a/hsarweb/src/de/hsadmin/web/DomainModule.java +++ b/hsarweb/src/de/hsadmin/web/DomainModule.java @@ -10,6 +10,7 @@ import de.hsadmin.web.config.PropertyConfig; import de.hsadmin.web.config.PropertyDefaultValue; import de.hsadmin.web.config.PropertySelectValues; import de.hsadmin.web.config.PropertyTableColumn; +import de.hsadmin.web.vaadin.DatePropertyFieldFactory; import de.hsadmin.web.vaadin.SelectPropertyFieldFactory; public class DomainModule extends GenericModule { @@ -65,7 +66,7 @@ public class DomainModule extends GenericModule { pacProp.setReadOnly(true); PropertyConfig hiveProp = new PropertyConfig(moduleConfig, "hive", String.class, PropertyTableColumn.HIDDEN); hiveProp.setReadOnly(true); - PropertyConfig sinceProp = new PropertyConfig(moduleConfig, "since", Date.class); + PropertyConfig sinceProp = new PropertyConfig(moduleConfig, "since", Date.class, new DatePropertyFieldFactory()); sinceProp.setReadOnly(true); moduleConfig.addProperty(idProp); moduleConfig.addProperty(nameProp); diff --git a/hsarweb/src/de/hsadmin/web/DomainReadonlyModule.java b/hsarweb/src/de/hsadmin/web/DomainReadonlyModule.java index f08f0cd..505cada 100644 --- a/hsarweb/src/de/hsadmin/web/DomainReadonlyModule.java +++ b/hsarweb/src/de/hsadmin/web/DomainReadonlyModule.java @@ -5,6 +5,7 @@ import java.util.Date; import de.hsadmin.web.config.ModuleConfig; import de.hsadmin.web.config.PropertyConfig; import de.hsadmin.web.config.PropertyTableColumn; +import de.hsadmin.web.vaadin.DatePropertyFieldFactory; public class DomainReadonlyModule extends AbstractModule { @@ -20,7 +21,7 @@ public class DomainReadonlyModule extends AbstractModule { moduleConfig.addProperty(new PropertyConfig(moduleConfig, "user", String.class)); moduleConfig.addProperty(new PropertyConfig(moduleConfig, "pac", String.class, PropertyTableColumn.HIDDEN)); moduleConfig.addProperty(new PropertyConfig(moduleConfig, "hive", String.class, PropertyTableColumn.HIDDEN)); - moduleConfig.addProperty(new PropertyConfig(moduleConfig, "since", Date.class)); + moduleConfig.addProperty(new PropertyConfig(moduleConfig, "since", Date.class, new DatePropertyFieldFactory())); } @Override diff --git a/hsarweb/src/de/hsadmin/web/MainApplication.java b/hsarweb/src/de/hsadmin/web/MainApplication.java index 60b89e0..0d22c72 100644 --- a/hsarweb/src/de/hsadmin/web/MainApplication.java +++ b/hsarweb/src/de/hsadmin/web/MainApplication.java @@ -22,7 +22,6 @@ import com.vaadin.ui.Component; import com.vaadin.ui.Embedded; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Link; -import com.vaadin.ui.Panel; import com.vaadin.ui.TabSheet; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; @@ -166,6 +165,7 @@ public class MainApplication extends Application implements HttpServletRequestLi try { module.reload(); } catch (HsarwebException e) { + e.printStackTrace(); showSystemException(e); } } diff --git a/hsarweb/src/de/hsadmin/web/MysqlDatabaseModule.java b/hsarweb/src/de/hsadmin/web/MysqlDatabaseModule.java new file mode 100644 index 0000000..7f855a1 --- /dev/null +++ b/hsarweb/src/de/hsadmin/web/MysqlDatabaseModule.java @@ -0,0 +1,22 @@ +package de.hsadmin.web; + +public class MysqlDatabaseModule extends DatabaseModule { + + private static final long serialVersionUID = 1L; + + @Override + public String[] getEncodings() { + return new String[] { "utf8", "latin1" }; + } + + @Override + public String getModuleIdent() { + return "mysqldb"; + } + + @Override + public String getUserModuleIdent() { + return "mysqluser"; + } + +} diff --git a/hsarweb/src/de/hsadmin/web/MysqlUserModule.java b/hsarweb/src/de/hsadmin/web/MysqlUserModule.java new file mode 100644 index 0000000..0965afb --- /dev/null +++ b/hsarweb/src/de/hsadmin/web/MysqlUserModule.java @@ -0,0 +1,12 @@ +package de.hsadmin.web; + +public class MysqlUserModule extends DatabaseUserModule { + + private static final long serialVersionUID = 1L; + + @Override + public String getModuleIdent() { + return "mysqluser"; + } + +} diff --git a/hsarweb/src/de/hsadmin/web/PacketReadonlyModule.java b/hsarweb/src/de/hsadmin/web/PacketReadonlyModule.java index 828837d..89aa727 100644 --- a/hsarweb/src/de/hsadmin/web/PacketReadonlyModule.java +++ b/hsarweb/src/de/hsadmin/web/PacketReadonlyModule.java @@ -5,6 +5,7 @@ import java.util.Date; import de.hsadmin.web.config.ModuleConfig; import de.hsadmin.web.config.PropertyConfig; import de.hsadmin.web.config.PropertyTableColumn; +import de.hsadmin.web.vaadin.DatePropertyFieldFactory; public class PacketReadonlyModule extends AbstractModule { @@ -21,7 +22,7 @@ public class PacketReadonlyModule extends AbstractModule { moduleConfig.addProperty(new PropertyConfig(moduleConfig, "components", String.class)); moduleConfig.addProperty(new PropertyConfig(moduleConfig, "hive", String.class)); moduleConfig.addProperty(new PropertyConfig(moduleConfig, "curinetaddr", String.class)); - moduleConfig.addProperty(new PropertyConfig(moduleConfig, "created", Date.class)); + moduleConfig.addProperty(new PropertyConfig(moduleConfig, "created", Date.class, new DatePropertyFieldFactory())); moduleConfig.addProperty(new PropertyConfig(moduleConfig, "customer", String.class, PropertyTableColumn.HIDDEN)); } diff --git a/hsarweb/src/de/hsadmin/web/PgsqlDatabaseModule.java b/hsarweb/src/de/hsadmin/web/PgsqlDatabaseModule.java new file mode 100644 index 0000000..116b061 --- /dev/null +++ b/hsarweb/src/de/hsadmin/web/PgsqlDatabaseModule.java @@ -0,0 +1,22 @@ +package de.hsadmin.web; + +public class PgsqlDatabaseModule extends DatabaseModule { + + private static final long serialVersionUID = 1L; + + @Override + public String[] getEncodings() { + return new String[] { "UTF-8", "LATIN1" }; + } + + @Override + public String getModuleIdent() { + return "postgresqldb"; + } + + @Override + public String getUserModuleIdent() { + return "postgresqluser"; + } + +} diff --git a/hsarweb/src/de/hsadmin/web/PgsqlUserModule.java b/hsarweb/src/de/hsadmin/web/PgsqlUserModule.java new file mode 100644 index 0000000..c43ca55 --- /dev/null +++ b/hsarweb/src/de/hsadmin/web/PgsqlUserModule.java @@ -0,0 +1,12 @@ +package de.hsadmin.web; + +public class PgsqlUserModule extends DatabaseUserModule { + + private static final long serialVersionUID = 1L; + + @Override + public String getModuleIdent() { + return "postgresqluser"; + } + +} diff --git a/hsarweb/src/de/hsadmin/web/QueueTaskModule.java b/hsarweb/src/de/hsadmin/web/QueueTaskModule.java index e393ee0..8bca559 100644 --- a/hsarweb/src/de/hsadmin/web/QueueTaskModule.java +++ b/hsarweb/src/de/hsadmin/web/QueueTaskModule.java @@ -5,6 +5,7 @@ import java.util.Date; import de.hsadmin.web.config.ModuleConfig; import de.hsadmin.web.config.PropertyConfig; import de.hsadmin.web.config.PropertyTableColumn; +import de.hsadmin.web.vaadin.DatePropertyFieldFactory; public class QueueTaskModule extends AbstractModule { @@ -18,8 +19,8 @@ public class QueueTaskModule extends AbstractModule { moduleConfig.addProperty(new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY)); moduleConfig.addProperty(new PropertyConfig(moduleConfig, "title", String.class)); moduleConfig.addProperty(new PropertyConfig(moduleConfig, "status", String.class)); - moduleConfig.addProperty(new PropertyConfig(moduleConfig, "started", Date.class)); - moduleConfig.addProperty(new PropertyConfig(moduleConfig, "finished", Date.class)); + moduleConfig.addProperty(new PropertyConfig(moduleConfig, "started", Date.class, new DatePropertyFieldFactory())); + moduleConfig.addProperty(new PropertyConfig(moduleConfig, "finished", Date.class, new DatePropertyFieldFactory())); moduleConfig.addProperty(new PropertyConfig(moduleConfig, "user", String.class, PropertyTableColumn.HIDDEN)); moduleConfig.addProperty(new PropertyConfig(moduleConfig, "details", String.class, PropertyTableColumn.HIDDEN)); moduleConfig.addProperty(new PropertyConfig(moduleConfig, "exception", String.class, PropertyTableColumn.HIDDEN)); diff --git a/hsarweb/src/de/hsadmin/web/vaadin/DatePropertyFieldFactory.java b/hsarweb/src/de/hsadmin/web/vaadin/DatePropertyFieldFactory.java new file mode 100644 index 0000000..c1dc066 --- /dev/null +++ b/hsarweb/src/de/hsadmin/web/vaadin/DatePropertyFieldFactory.java @@ -0,0 +1,70 @@ +package de.hsadmin.web.vaadin; + +import java.text.DateFormat; +import java.text.ParseException; +import java.util.Date; + +import com.vaadin.data.Property.ConversionException; +import com.vaadin.data.Property.ReadOnlyException; +import com.vaadin.terminal.Sizeable; +import com.vaadin.ui.DateField; +import com.vaadin.ui.PopupDateField; + +import de.hsadmin.web.config.PropertyConfig; +import de.hsadmin.web.config.PropertyFieldFactory; + +public class DatePropertyFieldFactory implements PropertyFieldFactory { + + public static final DateFormat serverDf = DateFormat.getDateInstance(DateFormat.SHORT); + + private boolean readOnly = false; + private boolean writeOnce; + + @Override + public Object createFieldComponent(PropertyConfig prop, Object value) { + DateField dateField = new PopupDateField(prop.getLabel()); + dateField.setDateFormat("dd.MM.yyyy"); + dateField.setData(prop.getId()); + dateField.setWidth(480.0f, Sizeable.UNITS_PIXELS); + try { + if (value != null) { + dateField.setValue(serverDf.parse((String) value)); + dateField.setReadOnly(isReadOnly()); + return dateField; + } + } catch (ReadOnlyException e) { + } catch (ConversionException e) { + } catch (ParseException e) { + } + dateField.setReadOnly(isReadOnly()); + return dateField; + } + + @Override + public String getValue(PropertyConfig prop, Object component) { + if (component instanceof DateField) { + return serverDf.format((Date) ((DateField) component).getValue()); + } + return null; + } + + @Override + public void setReadOnly(boolean readOnly) { + this.readOnly = readOnly; + } + + public boolean isReadOnly() { + return readOnly; + } + + @Override + public void setWriteOnce(boolean writeOnce) { + this.writeOnce = writeOnce; + } + + @Override + public boolean isWriteOnce() { + return writeOnce; + } + +} diff --git a/hsarweb/src/texts/main.properties b/hsarweb/src/texts/main.properties index 4995ccd..8b43bfa 100644 --- a/hsarweb/src/texts/main.properties +++ b/hsarweb/src/texts/main.properties @@ -11,6 +11,6 @@ logo.link=https://www.hostsharing.net/logo.png modules.NONE=de.hsadmin.web.HomeModule modules.USER=de.hsadmin.web.HomeModule modules.DOM_ADMIN=de.hsadmin.web.DomainReadonlyModule,de.hsadmin.web.EMailAddressModule,de.hsadmin.web.HomeModule -modules.PAC_ADMIN=de.hsadmin.web.UnixUserModule,de.hsadmin.web.DomainModule,de.hsadmin.web.EMailAddressModule,de.hsadmin.web.EMailAliasModule,de.hsadmin.web.QueueTaskModule -modules.CUSTOMER=de.hsadmin.web.PacketReadonlyModule,de.hsadmin.web.UnixUserModule,de.hsadmin.web.DomainModule,de.hsadmin.web.EMailAddressModule,de.hsadmin.web.EMailAliasModule,de.hsadmin.web.QueueTaskModule -modules.HOSTMASTER=de.hsadmin.web.PacketReadonlyModule,de.hsadmin.web.UnixUserModule,de.hsadmin.web.DomainModule,de.hsadmin.web.EMailAddressModule,de.hsadmin.web.EMailAliasModule,de.hsadmin.web.QueueTaskModule +modules.PAC_ADMIN=de.hsadmin.web.UnixUserModule,de.hsadmin.web.DomainModule,de.hsadmin.web.EMailAddressModule,de.hsadmin.web.EMailAliasModule,de.hsadmin.web.MysqlDatabaseModule,de.hsadmin.web.MysqlUserModule,de.hsadmin.web.PgsqlDatabaseModule,de.hsadmin.web.PgsqlUserModule,de.hsadmin.web.QueueTaskModule +modules.CUSTOMER=de.hsadmin.web.PacketReadonlyModule,de.hsadmin.web.UnixUserModule,de.hsadmin.web.DomainModule,de.hsadmin.web.EMailAddressModule,de.hsadmin.web.EMailAliasModule,de.hsadmin.web.MysqlDatabaseModule,de.hsadmin.web.MysqlUserModule,de.hsadmin.web.PgsqlDatabaseModule,de.hsadmin.web.PgsqlUserModule,de.hsadmin.web.QueueTaskModule +modules.HOSTMASTER=de.hsadmin.web.PacketReadonlyModule,de.hsadmin.web.UnixUserModule,de.hsadmin.web.DomainModule,de.hsadmin.web.EMailAddressModule,de.hsadmin.web.EMailAliasModule,de.hsadmin.web.MysqlDatabaseModule,de.hsadmin.web.MysqlUserModule,de.hsadmin.web.PgsqlDatabaseModule,de.hsadmin.web.PgsqlUserModule,de.hsadmin.web.QueueTaskModule diff --git a/hsarweb/src/texts/mysqldb.properties b/hsarweb/src/texts/mysqldb.properties new file mode 100644 index 0000000..4366f23 --- /dev/null +++ b/hsarweb/src/texts/mysqldb.properties @@ -0,0 +1,9 @@ +id=identifier +name=database +pac=packet +encoding=encoding +owner=owner +moduletitle=mysql db +new=create db +update=update db +moduleicon=../hs/icons/table.png \ No newline at end of file diff --git a/hsarweb/src/texts/mysqldb_de.properties b/hsarweb/src/texts/mysqldb_de.properties new file mode 100644 index 0000000..dcdf1dc --- /dev/null +++ b/hsarweb/src/texts/mysqldb_de.properties @@ -0,0 +1,9 @@ +id=Schlüssel +name=MySQL Datenbank +pac=Paket +encoding=Zeichensatz +owner=Verwalter +moduletitle=MySQL DB +new=Datenbank anlegen +update=Datenbank ändern +moduleicon=../hs/icons/table.png \ No newline at end of file diff --git a/hsarweb/src/texts/mysqluser.properties b/hsarweb/src/texts/mysqluser.properties new file mode 100644 index 0000000..434f936 --- /dev/null +++ b/hsarweb/src/texts/mysqluser.properties @@ -0,0 +1,10 @@ +id=identifier +name=database username +password=password +password1=new password +password2=repeat password +pac=packet +moduletitle=mysql user +new=create user +update=change password +moduleicon=../hs/icons/table_key.png \ No newline at end of file diff --git a/hsarweb/src/texts/mysqluser_de.properties b/hsarweb/src/texts/mysqluser_de.properties new file mode 100644 index 0000000..6c75274 --- /dev/null +++ b/hsarweb/src/texts/mysqluser_de.properties @@ -0,0 +1,10 @@ +id=Schlüssel +name=MySQL User +password=Passwort +password1=neues Passwort +password2=Passwort-Wiederholung +pac=Paket +moduletitle=MySQL User +new=User anlegen +update=Passwort ändern +moduleicon=../hs/icons/table_key.png \ No newline at end of file diff --git a/hsarweb/src/texts/pac.properties b/hsarweb/src/texts/pac.properties index 80c7eef..50959ab 100644 --- a/hsarweb/src/texts/pac.properties +++ b/hsarweb/src/texts/pac.properties @@ -1,7 +1,7 @@ id=identifier name=packet curinetaddr=inet address -created=created +created=created on basepac=packet type components=packet options hive=host diff --git a/hsarweb/src/texts/pac_de.properties b/hsarweb/src/texts/pac_de.properties index fdcc92e..5ef2da8 100644 --- a/hsarweb/src/texts/pac_de.properties +++ b/hsarweb/src/texts/pac_de.properties @@ -1,7 +1,7 @@ id=Schlüssel name=Paket curinetaddr=IP Adresse -created=angelegt +created=angelegt am basepac=Pakettyp components=Paket-Optionen hive=Server diff --git a/hsarweb/src/texts/postgresqldb.properties b/hsarweb/src/texts/postgresqldb.properties new file mode 100644 index 0000000..fe6c0a9 --- /dev/null +++ b/hsarweb/src/texts/postgresqldb.properties @@ -0,0 +1,9 @@ +id=identifier +name=database +pac=packet +encoding=encoding +owner=owner +moduletitle=postgresql db +new=create db +update=database +moduleicon=../hs/icons/database.png \ No newline at end of file diff --git a/hsarweb/src/texts/postgresqldb_de.properties b/hsarweb/src/texts/postgresqldb_de.properties new file mode 100644 index 0000000..439285c --- /dev/null +++ b/hsarweb/src/texts/postgresqldb_de.properties @@ -0,0 +1,9 @@ +id=Schlüssel +name=Datenbank +pac=Paket +encoding=Zeichensatz +owner=Verwalter +moduletitle=PostgreSQL DB +new=Datenbank anlegen +update=Datenbank +moduleicon=../hs/icons/database.png \ No newline at end of file diff --git a/hsarweb/src/texts/postgresqluser.properties b/hsarweb/src/texts/postgresqluser.properties new file mode 100644 index 0000000..2cef6f8 --- /dev/null +++ b/hsarweb/src/texts/postgresqluser.properties @@ -0,0 +1,10 @@ +id=identifier +name=postgres username +password=password +password1=new password +password2=repeat password +pac=packet +moduletitle=postgres user +new=create user +update=change password +moduleicon=../hs/icons/database_key.png \ No newline at end of file diff --git a/hsarweb/src/texts/postgresqluser_de.properties b/hsarweb/src/texts/postgresqluser_de.properties new file mode 100644 index 0000000..9bebc83 --- /dev/null +++ b/hsarweb/src/texts/postgresqluser_de.properties @@ -0,0 +1,10 @@ +id=Schlüssel +name=PostgreSQL User +password=Passwort +password1=neues Passwort +password2=Passwort-Wiederholung +pac=Paket +moduletitle=PostgreSQL User +new=User anlegen +update=Passwort ändern +moduleicon=../hs/icons/database_key.png \ No newline at end of file