From d9afe25155a68ee07c010e55a924aaa7a2e03457 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 18 Dec 2012 16:44:00 +0100 Subject: [PATCH] merged ArstractProperty, pac-prefix editor everywhere --- .../src/de/hsadmin/web/AbstractProperty.java | 4 ++- .../src/de/hsadmin/web/DatabaseModule.java | 28 +++-------------- .../de/hsadmin/web/DatabaseUserModule.java | 30 +++---------------- hsarweb/src/de/hsadmin/web/HomeModule.java | 12 ++++---- hsarweb/src/de/hsadmin/web/ItemsReader.java | 2 +- .../de/hsadmin/web/ListOfStringsProperty.java | 19 ++++++++++-- hsarweb/src/de/hsadmin/web/Remote.java | 29 ++++++++++++------ .../src/de/hsadmin/web/StringProperty.java | 6 ++++ .../src/de/hsadmin/web/UnixUserModule.java | 1 - .../de/hsadmin/web/vaadin/GenericForm.java | 4 +-- .../PacPrefixedNamePropertyFieldFactory.java | 6 ++-- hsarweb/src/texts/mysqldb.properties | 3 ++ hsarweb/src/texts/mysqldb_de.properties | 3 ++ hsarweb/src/texts/mysqluser.properties | 3 ++ hsarweb/src/texts/mysqluser_de.properties | 3 ++ hsarweb/src/texts/postgresqldb.properties | 3 ++ hsarweb/src/texts/postgresqldb_de.properties | 3 ++ hsarweb/src/texts/postgresqluser.properties | 3 ++ .../src/texts/postgresqluser_de.properties | 3 ++ 19 files changed, 90 insertions(+), 75 deletions(-) diff --git a/hsarweb/src/de/hsadmin/web/AbstractProperty.java b/hsarweb/src/de/hsadmin/web/AbstractProperty.java index 1527a0f..2c0455a 100644 --- a/hsarweb/src/de/hsadmin/web/AbstractProperty.java +++ b/hsarweb/src/de/hsadmin/web/AbstractProperty.java @@ -1,5 +1,7 @@ package de.hsadmin.web; -public class AbstractProperty { +public abstract class AbstractProperty { + + public abstract Object toXmlrpcParam(); } diff --git a/hsarweb/src/de/hsadmin/web/DatabaseModule.java b/hsarweb/src/de/hsadmin/web/DatabaseModule.java index 6b722ef..c62bba0 100644 --- a/hsarweb/src/de/hsadmin/web/DatabaseModule.java +++ b/hsarweb/src/de/hsadmin/web/DatabaseModule.java @@ -11,6 +11,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.PacPrefixedNamePropertyFieldFactory; import de.hsadmin.web.vaadin.SelectPropertyFieldFactory; public abstract class DatabaseModule extends GenericModule { @@ -29,29 +30,10 @@ public abstract class DatabaseModule extends GenericModule { protected void initModule() { MainApplication application = getApplication(); moduleConfig = new ModuleConfig(getModuleIdent(), application.getLocale()); - String login = application.getRunAs(); - 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() { + PropertyConfig nameProp = new PropertyConfig(moduleConfig, "name", String.class, new PacPrefixedNamePropertyFieldFactory(this)); + nameProp.setSelectValues(new PropertySelectValues() { @Override public boolean newItemsAllowed() { return false; @@ -70,7 +52,7 @@ public abstract class DatabaseModule extends GenericModule { return map; } }); - pacProp.setWriteOnce(true); + nameProp.setWriteOnce(true); PropertyConfig encodingProp = new PropertyConfig(moduleConfig, "encoding", String.class, new SelectPropertyFieldFactory()); encodingProp.setDefaultValue(new PropertyDefaultValue() { @Override @@ -125,10 +107,8 @@ public abstract class DatabaseModule extends GenericModule { } }); idProp.setShowInForm(false); - pacProp.setShowInForm(false); encodingProp.setShowInForm(false); moduleConfig.addProperty(idProp); - moduleConfig.addProperty(pacProp); moduleConfig.addProperty(nameProp); moduleConfig.addProperty(encodingProp); moduleConfig.addProperty(ownerProp); diff --git a/hsarweb/src/de/hsadmin/web/DatabaseUserModule.java b/hsarweb/src/de/hsadmin/web/DatabaseUserModule.java index 6f80135..097a99e 100644 --- a/hsarweb/src/de/hsadmin/web/DatabaseUserModule.java +++ b/hsarweb/src/de/hsadmin/web/DatabaseUserModule.java @@ -6,11 +6,10 @@ 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.PacPrefixedNamePropertyFieldFactory; import de.hsadmin.web.vaadin.PasswordPropertyFieldFactory; -import de.hsadmin.web.vaadin.SelectPropertyFieldFactory; public abstract class DatabaseUserModule extends GenericModule { @@ -24,29 +23,10 @@ public abstract class DatabaseUserModule extends GenericModule { protected void initModule() { MainApplication application = getApplication(); moduleConfig = new ModuleConfig(getModuleIdent(), application.getLocale()); - String login = application.getRunAs(); - 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() { + PropertyConfig nameProp = new PropertyConfig(moduleConfig, "name", String.class, new PacPrefixedNamePropertyFieldFactory(this)); + nameProp.setSelectValues(new PropertySelectValues() { @Override public boolean newItemsAllowed() { return false; @@ -65,12 +45,10 @@ public abstract class DatabaseUserModule extends GenericModule { return map; } }); - pacProp.setWriteOnce(true); + nameProp.setWriteOnce(true); PropertyConfig passwordProp = new PropertyConfig(moduleConfig, "password", String.class, PropertyTableColumn.NONE, new PasswordPropertyFieldFactory(this)); idProp.setShowInForm(false); - pacProp.setShowInForm(false); moduleConfig.addProperty(idProp); - moduleConfig.addProperty(pacProp); moduleConfig.addProperty(nameProp); moduleConfig.addProperty(passwordProp); } diff --git a/hsarweb/src/de/hsadmin/web/HomeModule.java b/hsarweb/src/de/hsadmin/web/HomeModule.java index e6bc473..65031d5 100644 --- a/hsarweb/src/de/hsadmin/web/HomeModule.java +++ b/hsarweb/src/de/hsadmin/web/HomeModule.java @@ -35,8 +35,8 @@ public class HomeModule extends AbstractModule implements ComponentFactory, Upda setComponentFactory(this); } - public void updateRow(Map paramHash) throws HsarwebException { - Map whereHash = new HashMap(); + public void updateRow(Map paramHash) throws HsarwebException { + Map whereHash = new HashMap(); String idKey = findIdKey(); whereHash.put(idKey, paramHash.get(idKey)); paramHash.remove(idKey); @@ -94,8 +94,8 @@ public class HomeModule extends AbstractModule implements ComponentFactory, Upda Button button = new Button(moduleConfig.getLabel("change_password")); ThemeResource icon = new ThemeResource(moduleConfig.getLabel("change_password_icon")); button.setIcon(icon); - Map whereHash = new HashMap(); - whereHash.put("name", application.getRunAs()); + Map whereHash = new HashMap(); + whereHash.put("name", new StringProperty(application.getRunAs())); Long key = -1L; try { Object object = application.getRemote().callSearch(moduleConfig.getRemoteName(), whereHash); @@ -130,8 +130,8 @@ public class HomeModule extends AbstractModule implements ComponentFactory, Upda public void buttonClick(ClickEvent event) { application.getMainWindow().removeWindow(childWindow); try { - Map map = new HashMap(); - map.put("id", ((Long) event.getButton().getData()).toString()); + Map map = new HashMap(); + map.put("id", new StringProperty(((Long) event.getButton().getData()).toString())); Iterator componentIterator = form.getLayout().getComponentIterator(); while (componentIterator.hasNext()) { Component component = (Component) componentIterator.next(); diff --git a/hsarweb/src/de/hsadmin/web/ItemsReader.java b/hsarweb/src/de/hsadmin/web/ItemsReader.java index 95e22f2..d1c22d5 100644 --- a/hsarweb/src/de/hsadmin/web/ItemsReader.java +++ b/hsarweb/src/de/hsadmin/web/ItemsReader.java @@ -9,7 +9,7 @@ public class ItemsReader { public static List readItemList(MainApplication app, String module, String property) throws HsarwebException { final List itemsList = new ArrayList(); - Object custListObj = app.getRemote().callSearch(module, new HashMap()); + Object custListObj = app.getRemote().callSearch(module, new HashMap()); if (custListObj instanceof Object[]) { Object[] custList = (Object[]) custListObj; for (Object custObj : custList) { diff --git a/hsarweb/src/de/hsadmin/web/ListOfStringsProperty.java b/hsarweb/src/de/hsadmin/web/ListOfStringsProperty.java index 92f111f..6a2366d 100644 --- a/hsarweb/src/de/hsadmin/web/ListOfStringsProperty.java +++ b/hsarweb/src/de/hsadmin/web/ListOfStringsProperty.java @@ -1,15 +1,28 @@ package de.hsadmin.web; +import java.util.ArrayList; import java.util.List; public class ListOfStringsProperty extends AbstractProperty { - public List properties; + + public final List properties; public ListOfStringsProperty(){ -// ?? this.properties = new List(); + this.properties = new ArrayList(); } - public boolean Add(String string){ + public boolean add(String string){ return properties.add(string); } + + @Override + public Object toXmlrpcParam() { + String[] result = new String[properties.size()]; + int idx = 0; + for (String prop : properties) { + result[idx] = prop; + idx++; + } + return result; + } } diff --git a/hsarweb/src/de/hsadmin/web/Remote.java b/hsarweb/src/de/hsadmin/web/Remote.java index ddb03f8..df819aa 100644 --- a/hsarweb/src/de/hsadmin/web/Remote.java +++ b/hsarweb/src/de/hsadmin/web/Remote.java @@ -19,35 +19,46 @@ public class Remote { } public Object callSearch(String module, Map where) throws HsarwebException { - return xmlrpcCall(module, "search", where); + return xmlrpcCall(module, "search", buildXmlrpcParam(where)); } public void callAdd(String module, Map set) throws HsarwebException { - xmlrpcCall(module, "add", set); + xmlrpcCall(module, "add", buildXmlrpcParam(set)); } public void callUpdate(String module, Map set, Map where) throws HsarwebException { - xmlrpcCall(module, "update", set, where); + xmlrpcCall(module, "update", buildXmlrpcParam(set), buildXmlrpcParam(where)); } public void callDelete(String module, Map where) throws HsarwebException { - xmlrpcCall(module, "delete", where); + xmlrpcCall(module, "delete", buildXmlrpcParam(where)); } - private Object xmlrpcCall(String module, String operation, Map param1) throws HsarwebException { + private Map buildXmlrpcParam(Map paramHash) { + Map resultMap = new HashMap(); + if (paramHash == null) { + return null; + } + for (String key : paramHash.keySet()) { + resultMap.put(key, paramHash.get(key).toXmlrpcParam()); + } + return resultMap; + } + + private Object xmlrpcCall(String module, String operation, Map param1) throws HsarwebException { Object[] params = new Object[3]; params[0] = app.getRunAs(); params[1] = app.getProxyTicket(); - params[2] = param1 != null ? param1 : new HashMap(); + params[2] = param1 != null ? param1 : new HashMap(); return xmlrpcCall(module + "." + operation, params); } - private Object xmlrpcCall(String module, String operation, Map param1, Map param2) throws HsarwebException { + private Object xmlrpcCall(String module, String operation, Map param1, Map param2) throws HsarwebException { Object[] params = new Object[4]; params[0] = app.getRunAs(); params[1] = app.getProxyTicket(); - params[2] = param1 != null ? param1 : new HashMap(); - params[3] = param2 != null ? param2 : new HashMap(); + params[2] = param1 != null ? param1 : new HashMap(); + params[3] = param2 != null ? param2 : new HashMap(); return xmlrpcCall(module + "." + operation, params); } diff --git a/hsarweb/src/de/hsadmin/web/StringProperty.java b/hsarweb/src/de/hsadmin/web/StringProperty.java index 4c3e9e2..daf67f6 100644 --- a/hsarweb/src/de/hsadmin/web/StringProperty.java +++ b/hsarweb/src/de/hsadmin/web/StringProperty.java @@ -1,10 +1,16 @@ package de.hsadmin.web; public class StringProperty extends AbstractProperty { + public String property ; public StringProperty(String property) { this.property = property; } + @Override + public Object toXmlrpcParam() { + return property; + } + } diff --git a/hsarweb/src/de/hsadmin/web/UnixUserModule.java b/hsarweb/src/de/hsadmin/web/UnixUserModule.java index 243c0c5..e4922d1 100644 --- a/hsarweb/src/de/hsadmin/web/UnixUserModule.java +++ b/hsarweb/src/de/hsadmin/web/UnixUserModule.java @@ -37,7 +37,6 @@ public class UnixUserModule extends GenericModule { public boolean hasSelectList() { return true; } - @Override public Map getSelectValues() { List list = getPackets(); diff --git a/hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java b/hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java index 78b9958..bc60ef1 100644 --- a/hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java +++ b/hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java @@ -81,8 +81,8 @@ public class GenericForm { try { MainApplication application = module.getApplication(); ModuleConfig config = module.getModuleConfig(); - Map where = new HashMap(); - where.put(findIdKey(), entityId.toString()); + Map where = new HashMap(); + where.put(findIdKey(), new StringProperty(entityId.toString())); Object searchResult = application.getRemote().callSearch(config.getRemoteName(), where); if (searchResult instanceof Object[]) { Map row = (Map) (((Object[]) searchResult)[0]); diff --git a/hsarweb/src/de/hsadmin/web/vaadin/PacPrefixedNamePropertyFieldFactory.java b/hsarweb/src/de/hsadmin/web/vaadin/PacPrefixedNamePropertyFieldFactory.java index 5fb268d..368f570 100644 --- a/hsarweb/src/de/hsadmin/web/vaadin/PacPrefixedNamePropertyFieldFactory.java +++ b/hsarweb/src/de/hsadmin/web/vaadin/PacPrefixedNamePropertyFieldFactory.java @@ -7,8 +7,10 @@ import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Select; import com.vaadin.ui.TextField; +import de.hsadmin.web.AbstractProperty; import de.hsadmin.web.HsarwebException; import de.hsadmin.web.Module; +import de.hsadmin.web.StringProperty; import de.hsadmin.web.config.ModuleConfig; import de.hsadmin.web.config.PropertyConfig; import de.hsadmin.web.config.PropertyFieldFactory; @@ -67,14 +69,14 @@ public class PacPrefixedNamePropertyFieldFactory implements PropertyFieldFactory } @Override - public String getValue(PropertyConfig prop, Object component) throws HsarwebException { + public AbstractProperty getValue(PropertyConfig prop, Object component) throws HsarwebException { ModuleConfig config = module.getModuleConfig(); HorizontalLayout layout = (HorizontalLayout) component; Select sel = (Select) layout.getComponent(0); TextField tf = (TextField) layout.getComponent(2); String pacPart = (String) sel.getValue(); String userPart = (String) tf.getValue(); - return pacPart + config.getLabel(prop.getId() + ".separator") + userPart; + return new StringProperty(pacPart + config.getLabel(prop.getId() + ".separator") + userPart); } @Override diff --git a/hsarweb/src/texts/mysqldb.properties b/hsarweb/src/texts/mysqldb.properties index b4bbda8..2879303 100644 --- a/hsarweb/src/texts/mysqldb.properties +++ b/hsarweb/src/texts/mysqldb.properties @@ -1,5 +1,8 @@ id=identifier name=database +name.pacprefix=packet +name.separator=_ +name.postfix=databasepart pac=packet encoding=encoding owner=owner diff --git a/hsarweb/src/texts/mysqldb_de.properties b/hsarweb/src/texts/mysqldb_de.properties index 09fdebd..58cddc9 100644 --- a/hsarweb/src/texts/mysqldb_de.properties +++ b/hsarweb/src/texts/mysqldb_de.properties @@ -1,5 +1,8 @@ id=Schlüssel name=MySQL Datenbank +name.pacprefix=Paket +name.separator=_ +name.postfix=Datenbank-Postfix pac=Paket encoding=Zeichensatz owner=Verwalter diff --git a/hsarweb/src/texts/mysqluser.properties b/hsarweb/src/texts/mysqluser.properties index cb622f8..1b915a7 100644 --- a/hsarweb/src/texts/mysqluser.properties +++ b/hsarweb/src/texts/mysqluser.properties @@ -1,5 +1,8 @@ id=identifier name=database username +name.pacprefix=packet +name.separator=_ +name.postfix=userpart password=password password1=new password password2=repeat password diff --git a/hsarweb/src/texts/mysqluser_de.properties b/hsarweb/src/texts/mysqluser_de.properties index df73d5c..2e15c6d 100644 --- a/hsarweb/src/texts/mysqluser_de.properties +++ b/hsarweb/src/texts/mysqluser_de.properties @@ -1,5 +1,8 @@ id=Schlüssel name=MySQL User +name.pacprefix=Paket +name.separator=_ +name.postfix=Benutzer-Postfix password=Passwort password1=neues Passwort password2=Passwort-Wiederholung diff --git a/hsarweb/src/texts/postgresqldb.properties b/hsarweb/src/texts/postgresqldb.properties index c8a1333..30eafff 100644 --- a/hsarweb/src/texts/postgresqldb.properties +++ b/hsarweb/src/texts/postgresqldb.properties @@ -1,5 +1,8 @@ id=identifier name=database +name.pacprefix=packet +name.separator=_ +name.postfix=databasepart pac=packet encoding=encoding owner=owner diff --git a/hsarweb/src/texts/postgresqldb_de.properties b/hsarweb/src/texts/postgresqldb_de.properties index 0651de5..dec80d7 100644 --- a/hsarweb/src/texts/postgresqldb_de.properties +++ b/hsarweb/src/texts/postgresqldb_de.properties @@ -1,5 +1,8 @@ id=Schlüssel name=Datenbank +name.pacprefix=Paket +name.separator=_ +name.postfix=Datenbank-Postfix pac=Paket encoding=Zeichensatz owner=Verwalter diff --git a/hsarweb/src/texts/postgresqluser.properties b/hsarweb/src/texts/postgresqluser.properties index b163a8d..007451b 100644 --- a/hsarweb/src/texts/postgresqluser.properties +++ b/hsarweb/src/texts/postgresqluser.properties @@ -1,5 +1,8 @@ id=identifier name=postgres username +name.pacprefix=packet +name.separator=_ +name.postfix=userpart password=password password1=new password password2=repeat password diff --git a/hsarweb/src/texts/postgresqluser_de.properties b/hsarweb/src/texts/postgresqluser_de.properties index 34dc4eb..95d7a36 100644 --- a/hsarweb/src/texts/postgresqluser_de.properties +++ b/hsarweb/src/texts/postgresqluser_de.properties @@ -1,5 +1,8 @@ id=Schlüssel name=PostgreSQL User +name.pacprefix=Paket +name.separator=_ +name.postfix=Benutzer-Postfix password=Passwort password1=neues Passwort password2=Passwort-Wiederholung