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.
This commit is contained in:
Purodha 2013-03-07 17:16:52 +00:00
parent a9543dddc6
commit 1c32c7e969
5 changed files with 96 additions and 57 deletions

View File

@ -35,6 +35,7 @@ public abstract class AbstractModule implements Module, Serializable {
private Component component; private Component component;
private ComponentFactory componentFactory; private ComponentFactory componentFactory;
private Select selRunAs; private Select selRunAs;
private Map<String,Map<String, Object>> moduleProps = null;
public Component getComponent() { public Component getComponent() {
return layout; return layout;
@ -180,4 +181,11 @@ public abstract class AbstractModule implements Module, Serializable {
@Override @Override
public abstract ModuleConfig getModuleConfig(); 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;
}
} }

View File

@ -123,43 +123,4 @@ public abstract class GenericModule extends AbstractModule implements InsertAble
} }
return list; 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;
}
} }

View File

@ -2,9 +2,11 @@ package de.hsadmin.web;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.TreeMap;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest; 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.LocaleConfig;
import de.hsadmin.web.config.ModuleConfig; 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 long serialVersionUID = 1L;
private static final String LOGIN_URL = "https://login.hostsharing.net:443/cas/v1/tickets"; private static final String LOGIN_URL = "https://login.hostsharing.net:443/cas/v1/tickets";
@ -53,7 +56,7 @@ public class MainApplication extends Application implements HttpServletRequestLi
private TabSheet tabSheet; private TabSheet tabSheet;
private Window mainWindow; private Window mainWindow;
private List<Object> runAsList = null; private List<Object> runAsList = null;
private Map<String, Map<String, Map<String, Object>>> moduleProps = null;
@Override @Override
public void init() { public void init() {
@ -69,6 +72,7 @@ public class MainApplication extends Application implements HttpServletRequestLi
setMainWindow(mainWindow); setMainWindow(mainWindow);
setErrorHandler(new Terminal.ErrorListener() { setErrorHandler(new Terminal.ErrorListener() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
public void terminalError(Terminal.ErrorEvent event) { public void terminalError(Terminal.ErrorEvent event) {
event.getThrowable().printStackTrace(); event.getThrowable().printStackTrace();
@ -99,7 +103,8 @@ public class MainApplication extends Application implements HttpServletRequestLi
private Module initTabSheet() { private Module initTabSheet() {
tabSheet = new TabSheet(); tabSheet = new TabSheet();
tabSheet.setSizeFull(); tabSheet.setSizeFull();
String modulesParamString = localeConfig.getText("modules." + readUserRole()); String modulesParamString = localeConfig.getText("modules."
+ readUserRole());
modules = new HashMap<String, Module>(); modules = new HashMap<String, Module>();
Module firstModule = null; Module firstModule = null;
for (String className : modulesParamString.split(",")) { for (String className : modulesParamString.split(",")) {
@ -112,7 +117,8 @@ public class MainApplication extends Application implements HttpServletRequestLi
ModuleConfig moduleConfig = module.getModuleConfig(); ModuleConfig moduleConfig = module.getModuleConfig();
String label = moduleConfig.getLabel("moduletitle"); String label = moduleConfig.getLabel("moduletitle");
modules.put(label, module); 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) { } catch (Exception e) {
showSystemException(e); showSystemException(e);
} }
@ -127,7 +133,8 @@ public class MainApplication extends Application implements HttpServletRequestLi
} }
public String getProxyTicket() { public String getProxyTicket() {
return userPrincipal.getProxyTicketFor(servletContext.getInitParameter("backendURL")); return userPrincipal.getProxyTicketFor(servletContext
.getInitParameter("backendURL"));
} }
public String getContextParam(String string) { public String getContextParam(String string) {
@ -159,14 +166,17 @@ public class MainApplication extends Application implements HttpServletRequestLi
if (isTestEnvironment) { if (isTestEnvironment) {
userPrincipal = new AttributePrincipal() { userPrincipal = new AttributePrincipal() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
public String getName() { public String getName() {
return "ad"; return "ad";
} }
@Override @Override
public String getProxyTicketFor(String arg0) { public String getProxyTicketFor(String arg0) {
return "user:ad"; return "user:ad";
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public Map getAttributes() { public Map getAttributes() {
@ -174,7 +184,9 @@ public class MainApplication extends Application implements HttpServletRequestLi
} }
}; };
} else { } else {
userPrincipal = ((Assertion) httpSession.getAttribute(AuthenticationFilter.CONST_CAS_ASSERTION)).getPrincipal(); userPrincipal = ((Assertion) httpSession
.getAttribute(AuthenticationFilter.CONST_CAS_ASSERTION))
.getPrincipal();
} }
} }
@ -207,11 +219,15 @@ public class MainApplication extends Application implements HttpServletRequestLi
} }
public void showUserException(Exception 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) { 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() { public String getRunAs() {
@ -239,7 +255,8 @@ public class MainApplication extends Application implements HttpServletRequestLi
if (runAsList == null) { if (runAsList == null) {
runAsList = new ArrayList<Object>(); runAsList = new ArrayList<Object>();
if ("HOSTMASTER".equals(loginUserRole)) { if ("HOSTMASTER".equals(loginUserRole)) {
runAsList = ItemsReader.readItemList(this, "member", "membercode"); runAsList = ItemsReader.readItemList(this, "member",
"membercode");
} }
if ("CUSTOMER".equals(loginUserRole)) { if ("CUSTOMER".equals(loginUserRole)) {
runAsList = ItemsReader.readItemList(this, "pac", "name"); runAsList = ItemsReader.readItemList(this, "pac", "name");
@ -251,4 +268,44 @@ public class MainApplication extends Application implements HttpServletRequestLi
return runAsList; 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;
}
} }

View File

@ -1,5 +1,7 @@
package de.hsadmin.web; package de.hsadmin.web;
import java.util.Map;
import de.hsadmin.web.config.ModuleConfig; import de.hsadmin.web.config.ModuleConfig;
public interface Module { public interface Module {
@ -14,4 +16,6 @@ public interface Module {
public abstract Object getComponent(); public abstract Object getComponent();
public abstract Map<String,Map<String,Object>> getModuleProps();
} }

View File

@ -28,6 +28,7 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
private final Module module; private final Module module;
private final ModuleConfig config; private final ModuleConfig config;
private static String[] OPTION_NAMES; // {"backupmxforexternalmx", "php", ...}; 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 final Map<String,AbstractProperty> optionTypes ; // TODO: auf Vorrat hier
private boolean readOnly = false; private boolean readOnly = false;
private boolean writeOnce = false; private boolean writeOnce = false;
@ -37,12 +38,19 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
public DomainOptionsPropertyFieldFactory(Module module) throws HsarwebInternalException { public DomainOptionsPropertyFieldFactory(Module module) throws HsarwebInternalException {
this.module = module; this.module = module;
this.config = this.module.getModuleConfig(); this.config = this.module.getModuleConfig();
// Liste der Namen der Domainoptions besorgen // Liste der Namen der Domainoptions besorgen. TODO: mögliche Werte.
DomainModule domainModule = (DomainModule) module; //if(true)
Map<String, Map<String, Object>> moduleProps = domainModule.getModuleProps(); // throw new HsarwebInternalException("p9");
Object p1 = moduleProps.get("domain").get("domainoptions"); // 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; Map<String, Object> p2 = (Map<String, Object>) p1;
Object p3 = p2.get("selectableValues"); Object p3 = p2.get("selectableValues");
if (p3 instanceof Map<?, ?>) { if (p3 instanceof Map<?, ?>) {
Map<String, Object> p4 = (Map<String, Object>) p3; Map<String, Object> p4 = (Map<String, Object>) p3;
if (p4.get("kind").equals("DOMAINOPTIONS")) { if (p4.get("kind").equals("DOMAINOPTIONS")) {
@ -68,6 +76,7 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
} else { } else {
throw new HsarwebInternalException("p3"); throw new HsarwebInternalException("p3");
} }
/* */
optionLayout = new ArrayList<SingleDomainOption>(); optionLayout = new ArrayList<SingleDomainOption>();
} }