From bd2a2f21f9f23ea81f4fca74471e64cd4d33bbc6 Mon Sep 17 00:00:00 2001 From: Purodha Date: Thu, 7 Mar 2013 12:25:08 +0000 Subject: [PATCH] Names of domainproperties are pulled from server before used. HsarwebExeption got subclasses HsarwebUserExeption and HsarwebInternalException. --- .../src/de/hsadmin/web/AbstractModule.java | 2 +- hsarweb/src/de/hsadmin/web/DomainModule.java | 2 +- hsarweb/src/de/hsadmin/web/GenericModule.java | 38 ++++++ .../hsadmin/web/HsarwebInternalException.java | 19 +++ .../de/hsadmin/web/HsarwebUserException.java | 19 +++ .../DomainOptionsPropertyFieldFactory.java | 108 ++++++++++++------ 6 files changed, 148 insertions(+), 40 deletions(-) create mode 100644 hsarweb/src/de/hsadmin/web/HsarwebInternalException.java create mode 100644 hsarweb/src/de/hsadmin/web/HsarwebUserException.java diff --git a/hsarweb/src/de/hsadmin/web/AbstractModule.java b/hsarweb/src/de/hsadmin/web/AbstractModule.java index 8a12075..846fe83 100644 --- a/hsarweb/src/de/hsadmin/web/AbstractModule.java +++ b/hsarweb/src/de/hsadmin/web/AbstractModule.java @@ -167,7 +167,7 @@ public abstract class AbstractModule implements Module, Serializable { initLayout(); } - protected abstract void initModule(); + protected abstract void initModule() throws HsarwebException; public MainApplication getApplication() { return application; diff --git a/hsarweb/src/de/hsadmin/web/DomainModule.java b/hsarweb/src/de/hsadmin/web/DomainModule.java index e6f52cc..39e88cb 100644 --- a/hsarweb/src/de/hsadmin/web/DomainModule.java +++ b/hsarweb/src/de/hsadmin/web/DomainModule.java @@ -21,7 +21,7 @@ public class DomainModule extends GenericModule { private ModuleConfig moduleConfig; @Override - protected void initModule() { + protected void initModule() throws HsarwebException { MainApplication application = getApplication(); moduleConfig = new ModuleConfig("domain", application.getLocale()); String login = application.getRunAs(); diff --git a/hsarweb/src/de/hsadmin/web/GenericModule.java b/hsarweb/src/de/hsadmin/web/GenericModule.java index 0bd5a17..f200ea2 100644 --- a/hsarweb/src/de/hsadmin/web/GenericModule.java +++ b/hsarweb/src/de/hsadmin/web/GenericModule.java @@ -123,5 +123,43 @@ public abstract class GenericModule extends AbstractModule implements InsertAble } return list; } + + public Map> getModuleProps() { + Map> moduleList = new HashMap>(); + Object callSearch = null; + try { + callSearch = getApplication().getRemote().callSearch("moduleprop", new HashMap()); + if (!(callSearch instanceof Object[])) { + throw new HsarwebException("getModuleProps hat keine Liste bekommen."); + } + for (Object row : ((Object[])callSearch)) { + if (row instanceof Map) { + Map rowAsMap = (Map) row; + Object moduleName = rowAsMap.get("module"); + if (moduleName instanceof String) { + Object properties = rowAsMap.get("properties"); + if (properties instanceof Object[]) { + Map propertyList = new HashMap(); + moduleList.put((String) moduleName, propertyList ); + for (Object property : (Object[]) properties){ + if (property instanceof Map) { + Object propertyName = ((Map) property).get("property"); + if (propertyName instanceof String) { + propertyList.put((String) propertyName, property); +// propertyList.put((String) propertyName, (Map) property); + } + } + } + /* */ + } + } + } + } + } catch (HsarwebException e) { + e.printStackTrace(); + getApplication().showSystemException(e); + } + return moduleList; + } } diff --git a/hsarweb/src/de/hsadmin/web/HsarwebInternalException.java b/hsarweb/src/de/hsadmin/web/HsarwebInternalException.java new file mode 100644 index 0000000..09c4b1b --- /dev/null +++ b/hsarweb/src/de/hsadmin/web/HsarwebInternalException.java @@ -0,0 +1,19 @@ +package de.hsadmin.web; + +public class HsarwebInternalException extends HsarwebException { + + private static final long serialVersionUID = 1L; + + public HsarwebInternalException(String string, Throwable e) { + super(string, e); + } + + public HsarwebInternalException(Throwable e) { + super(e); + } + + public HsarwebInternalException(String string) { + super(string); + } + +} diff --git a/hsarweb/src/de/hsadmin/web/HsarwebUserException.java b/hsarweb/src/de/hsadmin/web/HsarwebUserException.java new file mode 100644 index 0000000..b323b4f --- /dev/null +++ b/hsarweb/src/de/hsadmin/web/HsarwebUserException.java @@ -0,0 +1,19 @@ +package de.hsadmin.web; + +public class HsarwebUserException extends HsarwebException { + + private static final long serialVersionUID = 1L; + + public HsarwebUserException(String string, Throwable e) { + super(string, e); + } + + public HsarwebUserException(Throwable e) { + super(e); + } + + public HsarwebUserException(String string) { + super(string); + } + +} diff --git a/hsarweb/src/de/hsadmin/web/vaadin/DomainOptionsPropertyFieldFactory.java b/hsarweb/src/de/hsadmin/web/vaadin/DomainOptionsPropertyFieldFactory.java index 1ea5e28..f41c761 100644 --- a/hsarweb/src/de/hsadmin/web/vaadin/DomainOptionsPropertyFieldFactory.java +++ b/hsarweb/src/de/hsadmin/web/vaadin/DomainOptionsPropertyFieldFactory.java @@ -2,6 +2,7 @@ package de.hsadmin.web.vaadin; import java.util.ArrayList; import java.util.List; +import java.util.Map; import com.vaadin.terminal.Sizeable; import com.vaadin.ui.Component; @@ -10,7 +11,8 @@ import com.vaadin.ui.Label; import com.vaadin.ui.Select; import com.vaadin.ui.VerticalLayout; -import de.hsadmin.web.HsarwebException; +import de.hsadmin.web.DomainModule; +import de.hsadmin.web.HsarwebInternalException; import de.hsadmin.web.ListOfStringsProperty; import de.hsadmin.web.Module; import de.hsadmin.web.XmlrpcProperty; @@ -20,60 +22,89 @@ import de.hsadmin.web.config.PropertyFieldFactory; /** * @author Purodha Blissenbach - * + * */ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory { private final Module module; - private final ModuleConfig config ; - // TODO: besorge Options und ihre Typen aus der DB - private static final String[] OPTION_NAMES = new String[] { "backupmxforexternalmx", "greylisting", "htdocsfallback", "includes", "indexes", "multiviews", "php"}; -// private final Map optionTypes ; // TODO: auf Vorrat hier - // TODO: besorge Options .... Ende + private final ModuleConfig config; + private static String[] OPTION_NAMES; // {"backupmxforexternalmx", "php", ...}; + // private final Map optionTypes ; // TODO: auf Vorrat hier private boolean readOnly = false; private boolean writeOnce = false; private VerticalLayout layout; - private final List optionLayout ; + private final List optionLayout; - public DomainOptionsPropertyFieldFactory(Module module) { + public DomainOptionsPropertyFieldFactory(Module module) throws HsarwebInternalException { this.module = module; - this.config = module.getModuleConfig(); - optionLayout = new ArrayList() ; + this.config = this.module.getModuleConfig(); + // Liste der Namen der Domainoptions besorgen + DomainModule domainModule = (DomainModule) module; + Map> moduleProps = domainModule.getModuleProps(); + Object p1 = moduleProps.get("domain").get("domainoptions"); + Map p2 = (Map) p1; + Object p3 = p2.get("selectableValues"); + if (p3 instanceof Map) { + Map p4 = (Map) p3; + if (p4.get("kind").equals("DOMAINOPTIONS")) { + Object p5 = p4.get("values"); + if (p5 instanceof Object[]) { + Object[] p6 = (Object[]) p5; + OPTION_NAMES = new String[p6.length]; + int i = 0; + for (Object p7 : p6) { + if (p7 instanceof Map) { + Map p8 = (Map) p7; + OPTION_NAMES[i++] = p8.keySet().iterator().next(); + } else { + throw new HsarwebInternalException("p7"); + } + } + } else { + throw new HsarwebInternalException("p5"); + } + } else { + throw new HsarwebInternalException("p4"); + } + } else { + throw new HsarwebInternalException("p3"); + } + optionLayout = new ArrayList(); } - + private void repaint() { layout.removeAllComponents(); - for (int idx=0 ; idx