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 ComponentFactory componentFactory;
private Select selRunAs;
private Map<String,Map<String, Object>> 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<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;
}
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.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";
@ -53,7 +56,7 @@ public class MainApplication extends Application implements HttpServletRequestLi
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 @@ 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<String, Module>();
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);
}
@ -127,7 +133,8 @@ public class MainApplication extends Application implements HttpServletRequestLi
}
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,7 +184,9 @@ 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();
}
}
@ -207,11 +219,15 @@ public class MainApplication extends Application implements HttpServletRequestLi
}
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 @@ public class MainApplication extends Application implements HttpServletRequestLi
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 @@ public class MainApplication extends Application implements HttpServletRequestLi
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;
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<String,Map<String,Object>> getModuleProps();
}

View File

@ -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<String,AbstractProperty> 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<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 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
} else {
throw new HsarwebInternalException("p3");
}
/* */
optionLayout = new ArrayList<SingleDomainOption>();
}