From 1c32c7e969ba8d94d46e371d3dd119e74a6eeec0 Mon Sep 17 00:00:00 2001
From: Purodha <bli00@hostsharing.net>
Date: Thu, 07 Mar 2013 18:16:52 +0100
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.

---
 hsarweb/src/de/hsadmin/web/vaadin/DomainOptionsPropertyFieldFactory.java |   17 ++++-
 hsarweb/src/de/hsadmin/web/AbstractModule.java                           |    8 ++
 hsarweb/src/de/hsadmin/web/MainApplication.java                          |   83 +++++++++++++++++++++++----
 hsarweb/src/de/hsadmin/web/GenericModule.java                            |   41 -------------
 hsarweb/src/de/hsadmin/web/Module.java                                   |    4 +
 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 @@
 	private Component component;
 	private ComponentFactory componentFactory;
 	private Select selRunAs;
+	private Map<String,Map<String, Object>> moduleProps = null;
 
 	public Component getComponent() {
 		return layout;
@@ -180,4 +181,11 @@
 	@Override
 	public abstract ModuleConfig getModuleConfig();
 
+	@Override
+	public Map<String,Map<String,Object>> getModuleProps() {
+		if (this.moduleProps == null) {
+			this.moduleProps = (Map<String,Map<String,Object>>) 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 @@
 			getApplication().showSystemException(e);
 		}
 		return list;
-	}
-
-	public Map<String,Map<String,Object>> getModuleProps() {
-		Map<String,Map<String,Object>> moduleList = new HashMap<String,Map<String,Object>>();
-		Object callSearch = null;
-		try {
-			callSearch = getApplication().getRemote().callSearch("moduleprop", new HashMap<String, XmlrpcProperty>());
-			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<String,Object> propertyList = new HashMap<String,Object>();
-							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<String,Object>) 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 @@
 
 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 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 @@
 		Object loginURL = config.getProperty("loginURL", LOGIN_URL);
 		isTestEnvironment = "TestUmgebung".equals(loginURL);
 	}
-	
+
 	private HttpSession httpSession;
 	private ServletContext servletContext;
 	private AttributePrincipal userPrincipal;
@@ -53,7 +56,7 @@
 	private TabSheet tabSheet;
 	private Window mainWindow;
 	private List<Object> runAsList = null;
-
+	private Map<String, Map<String, Map<String, Object>>> moduleProps = null;
 
 	@Override
 	public void init() {
@@ -69,6 +72,7 @@
 		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 @@
 	private Module initTabSheet() {
 		tabSheet = new TabSheet();
 		tabSheet.setSizeFull();
-		String modulesParamString = localeConfig.getText("modules." + readUserRole());
+		String modulesParamString = localeConfig.getText("modules."
+				+ readUserRole());
 		modules = new HashMap<String, Module>();
 		Module firstModule = null;
 		for (String className : modulesParamString.split(",")) {
@@ -112,7 +117,8 @@
 				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 @@
 		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 @@
 		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 @@
 				}
 			};
 		} 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 @@
 			showUserException(e);
 		} else {
 			showSystemException(e);
-		}		
+		}
 	}
 
 	public void showUserException(Exception e) {
-		getMainWindow().showNotification("Anwendungs-Fehler", "<br />" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE);			
+		getMainWindow().showNotification("Anwendungs-Fehler",
+				"<br />" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
 	}
 
 	public void showSystemException(Exception e) {
-		getMainWindow().showNotification("System-Fehler", "<br />Bitte informieren Sie den Support<br/ >" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE);			
+		getMainWindow().showNotification(
+				"System-Fehler",
+				"<br />Bitte informieren Sie den Support<br/ >"
+						+ e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
 	}
 
 	public String getRunAs() {
@@ -239,7 +255,8 @@
 		if (runAsList == null) {
 			runAsList = new ArrayList<Object>();
 			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 @@
 		return runAsList;
 	}
 
+	public Map<String, Map<String, Map<String, Object>>> getModuleProps() {
+		if (this.moduleProps == null) {
+			Object callSearch = null;
+			try {
+				callSearch = getRemote().callSearch("moduleprop", new HashMap<String, XmlrpcProperty>());
+				if (!(callSearch instanceof Object[])) {
+					throw new HsarwebInternalException("getModuleProps hat keine Liste bekommen.");
+				}
+				moduleProps = new HashMap<String, Map<String, Map<String, Object>>>();
+				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<String, Map<String, Object>> propertyList = new HashMap<String, Map<String, Object>>();
+								moduleProps.put((String) moduleName, propertyList);
+								for (Object property : (Object[]) properties) {
+									if (property instanceof Map<?, ?>) {
+										Map<String, Object> propertyAsMap = (Map<String, Object>) 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 abstract Object getComponent();
 
+	public abstract Map<String,Map<String,Object>> 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 @@
 	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<String,AbstractProperty> optionTypes ; // TODO: auf Vorrat hier
 	private boolean readOnly = false;
 	private boolean writeOnce = false;
@@ -37,12 +38,19 @@
 	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<String, Map<String, Object>> 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<String, Map<String, Object>> moduleProps = domainModule.getModuleProps();
+		Map<String, Map<String, Object>> 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<String, Object> p2 = (Map<String, Object>) p1;
 		Object p3 = p2.get("selectableValues");
+		
 		if (p3 instanceof Map<?, ?>) {
 			Map<String, Object> p4 = (Map<String, Object>) p3;
 			if (p4.get("kind").equals("DOMAINOPTIONS")) {
@@ -68,6 +76,7 @@
 		} else {
 			throw new HsarwebInternalException("p3");
 		}
+	/* */
 		optionLayout = new ArrayList<SingleDomainOption>();
 	}
 

--
Gitblit v1.9.0-SNAPSHOT