From 1c32c7e969ba8d94d46e371d3dd119e74a6eeec0 Mon Sep 17 00:00:00 2001 From: Purodha Date: Thu, 7 Mar 2013 17:16:52 +0000 Subject: [PATCH] All modules got a method getModuleProps returning their own part of all properties as returned from the server; the data is requested only once and kept inside MainApplication. --- .../src/de/hsadmin/web/AbstractModule.java | 8 ++ hsarweb/src/de/hsadmin/web/GenericModule.java | 41 +-------- .../src/de/hsadmin/web/MainApplication.java | 83 ++++++++++++++++--- hsarweb/src/de/hsadmin/web/Module.java | 4 + .../DomainOptionsPropertyFieldFactory.java | 17 +++- 5 files changed, 96 insertions(+), 57 deletions(-) diff --git a/hsarweb/src/de/hsadmin/web/AbstractModule.java b/hsarweb/src/de/hsadmin/web/AbstractModule.java index 9e69384..502b852 100644 --- a/hsarweb/src/de/hsadmin/web/AbstractModule.java +++ b/hsarweb/src/de/hsadmin/web/AbstractModule.java @@ -35,6 +35,7 @@ public abstract class AbstractModule implements Module, Serializable { private Component component; private ComponentFactory componentFactory; private Select selRunAs; + private Map> moduleProps = null; public Component getComponent() { return layout; @@ -180,4 +181,11 @@ public abstract class AbstractModule implements Module, Serializable { @Override public abstract ModuleConfig getModuleConfig(); + @Override + public Map> getModuleProps() { + if (this.moduleProps == null) { + this.moduleProps = (Map>) getApplication().getModuleProps().get(getModuleConfig().getName()); + } + return moduleProps; + } } diff --git a/hsarweb/src/de/hsadmin/web/GenericModule.java b/hsarweb/src/de/hsadmin/web/GenericModule.java index f200ea2..8ca843b 100644 --- a/hsarweb/src/de/hsadmin/web/GenericModule.java +++ b/hsarweb/src/de/hsadmin/web/GenericModule.java @@ -122,44 +122,5 @@ public abstract class GenericModule extends AbstractModule implements InsertAble getApplication().showSystemException(e); } 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/MainApplication.java b/hsarweb/src/de/hsadmin/web/MainApplication.java index 40b4864..9d7ba26 100644 --- a/hsarweb/src/de/hsadmin/web/MainApplication.java +++ b/hsarweb/src/de/hsadmin/web/MainApplication.java @@ -2,9 +2,11 @@ package de.hsadmin.web; import java.util.ArrayList; import java.util.HashMap; +import java.util.Hashtable; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.TreeMap; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -29,7 +31,8 @@ import com.vaadin.ui.Window.Notification; import de.hsadmin.web.config.LocaleConfig; import de.hsadmin.web.config.ModuleConfig; -public class MainApplication extends Application implements HttpServletRequestListener, TabSheet.SelectedTabChangeListener { +public class MainApplication extends Application implements + HttpServletRequestListener, TabSheet.SelectedTabChangeListener { private static final long serialVersionUID = 1L; private static final String LOGIN_URL = "https://login.hostsharing.net:443/cas/v1/tickets"; @@ -40,7 +43,7 @@ public class MainApplication extends Application implements HttpServletRequestLi Object loginURL = config.getProperty("loginURL", LOGIN_URL); isTestEnvironment = "TestUmgebung".equals(loginURL); } - + private HttpSession httpSession; private ServletContext servletContext; private AttributePrincipal userPrincipal; @@ -53,7 +56,7 @@ public class MainApplication extends Application implements HttpServletRequestLi private TabSheet tabSheet; private Window mainWindow; private List runAsList = null; - + private Map>> moduleProps = null; @Override public void init() { @@ -69,6 +72,7 @@ public class MainApplication extends Application implements HttpServletRequestLi setMainWindow(mainWindow); setErrorHandler(new Terminal.ErrorListener() { private static final long serialVersionUID = 1L; + @Override public void terminalError(Terminal.ErrorEvent event) { event.getThrowable().printStackTrace(); @@ -99,7 +103,8 @@ public class MainApplication extends Application implements HttpServletRequestLi private Module initTabSheet() { tabSheet = new TabSheet(); tabSheet.setSizeFull(); - String modulesParamString = localeConfig.getText("modules." + readUserRole()); + String modulesParamString = localeConfig.getText("modules." + + readUserRole()); modules = new HashMap(); Module firstModule = null; for (String className : modulesParamString.split(",")) { @@ -112,7 +117,8 @@ public class MainApplication extends Application implements HttpServletRequestLi ModuleConfig moduleConfig = module.getModuleConfig(); String label = moduleConfig.getLabel("moduletitle"); modules.put(label, module); - tabSheet.addTab((Component) module.getComponent(), label, new ThemeResource(moduleConfig.getLabel("moduleicon"))); + tabSheet.addTab((Component) module.getComponent(), label, + new ThemeResource(moduleConfig.getLabel("moduleicon"))); } catch (Exception e) { showSystemException(e); } @@ -121,13 +127,14 @@ public class MainApplication extends Application implements HttpServletRequestLi mainWindow.setContent(tabSheet); return firstModule; } - + public String getLoginUserRole() { return loginUserRole; } public String getProxyTicket() { - return userPrincipal.getProxyTicketFor(servletContext.getInitParameter("backendURL")); + return userPrincipal.getProxyTicketFor(servletContext + .getInitParameter("backendURL")); } public String getContextParam(String string) { @@ -159,14 +166,17 @@ public class MainApplication extends Application implements HttpServletRequestLi if (isTestEnvironment) { userPrincipal = new AttributePrincipal() { private static final long serialVersionUID = 1L; + @Override public String getName() { return "ad"; } + @Override public String getProxyTicketFor(String arg0) { return "user:ad"; } + @SuppressWarnings("rawtypes") @Override public Map getAttributes() { @@ -174,14 +184,16 @@ public class MainApplication extends Application implements HttpServletRequestLi } }; } else { - userPrincipal = ((Assertion) httpSession.getAttribute(AuthenticationFilter.CONST_CAS_ASSERTION)).getPrincipal(); + userPrincipal = ((Assertion) httpSession + .getAttribute(AuthenticationFilter.CONST_CAS_ASSERTION)) + .getPrincipal(); } } @Override public void onRequestEnd(HttpServletRequest request, HttpServletResponse response) { - + } @Override @@ -203,15 +215,19 @@ public class MainApplication extends Application implements HttpServletRequestLi showUserException(e); } else { showSystemException(e); - } + } } public void showUserException(Exception e) { - getMainWindow().showNotification("Anwendungs-Fehler", "
" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE); + getMainWindow().showNotification("Anwendungs-Fehler", + "
" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE); } public void showSystemException(Exception e) { - getMainWindow().showNotification("System-Fehler", "
Bitte informieren Sie den Support
" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE); + getMainWindow().showNotification( + "System-Fehler", + "
Bitte informieren Sie den Support
" + + e.getMessage(), Notification.TYPE_ERROR_MESSAGE); } public String getRunAs() { @@ -239,7 +255,8 @@ public class MainApplication extends Application implements HttpServletRequestLi if (runAsList == null) { runAsList = new ArrayList(); if ("HOSTMASTER".equals(loginUserRole)) { - runAsList = ItemsReader.readItemList(this, "member", "membercode"); + runAsList = ItemsReader.readItemList(this, "member", + "membercode"); } if ("CUSTOMER".equals(loginUserRole)) { runAsList = ItemsReader.readItemList(this, "pac", "name"); @@ -251,4 +268,44 @@ public class MainApplication extends Application implements HttpServletRequestLi return runAsList; } + public Map>> getModuleProps() { + if (this.moduleProps == null) { + Object callSearch = null; + try { + callSearch = getRemote().callSearch("moduleprop", new HashMap()); + if (!(callSearch instanceof Object[])) { + throw new HsarwebInternalException("getModuleProps hat keine Liste bekommen."); + } + moduleProps = new HashMap>>(); + 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>(); + moduleProps.put((String) moduleName, propertyList); + for (Object property : (Object[]) properties) { + if (property instanceof Map) { + Map propertyAsMap = (Map) property; + Object propertyName = propertyAsMap.get("property"); + if (propertyName instanceof String) { + propertyList.put( (String) propertyName, propertyAsMap); + } + } + } + + } + } + } + } + } catch (HsarwebException e) { + e.printStackTrace(); + showSystemException(e); + } + } + return moduleProps; + } + } diff --git a/hsarweb/src/de/hsadmin/web/Module.java b/hsarweb/src/de/hsadmin/web/Module.java index 7c4d4b2..7d71cb7 100644 --- a/hsarweb/src/de/hsadmin/web/Module.java +++ b/hsarweb/src/de/hsadmin/web/Module.java @@ -1,5 +1,7 @@ package de.hsadmin.web; +import java.util.Map; + import de.hsadmin.web.config.ModuleConfig; public interface Module { @@ -14,4 +16,6 @@ public interface Module { public abstract Object getComponent(); + public abstract Map> getModuleProps(); + } \ No newline at end of file diff --git a/hsarweb/src/de/hsadmin/web/vaadin/DomainOptionsPropertyFieldFactory.java b/hsarweb/src/de/hsadmin/web/vaadin/DomainOptionsPropertyFieldFactory.java index f41c761..11da68e 100644 --- a/hsarweb/src/de/hsadmin/web/vaadin/DomainOptionsPropertyFieldFactory.java +++ b/hsarweb/src/de/hsadmin/web/vaadin/DomainOptionsPropertyFieldFactory.java @@ -28,6 +28,7 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory { private final Module module; private final ModuleConfig config; private static String[] OPTION_NAMES; // {"backupmxforexternalmx", "php", ...}; +// private static String[] OPTION_NAMES = {"backupmxforexternalmx", "php"}; // private final Map optionTypes ; // TODO: auf Vorrat hier private boolean readOnly = false; private boolean writeOnce = false; @@ -37,12 +38,19 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory { public DomainOptionsPropertyFieldFactory(Module module) throws HsarwebInternalException { this.module = module; 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"); + // Liste der Namen der Domainoptions besorgen. TODO: mögliche Werte. +//if(true) +// throw new HsarwebInternalException("p9"); + // DomainModule domainModule = (DomainModule) module; + // Map> moduleProps = domainModule.getModuleProps(); + Map> moduleProps = module.getModuleProps(); + if (moduleProps == null)OPTION_NAMES[1] ="XXXXX"+module.getModuleConfig().getName(); +// Object p0 = moduleProps.get("domain"); +// Object p1 = moduleProps.get("domain").get("domainoptions"); + Object p1 = moduleProps.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")) { @@ -68,6 +76,7 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory { } else { throw new HsarwebInternalException("p3"); } + /* */ optionLayout = new ArrayList(); }