Names of domainproperties are pulled from server before used.

HsarwebExeption got subclasses HsarwebUserExeption and
HsarwebInternalException.
This commit is contained in:
Purodha 2013-03-07 12:25:08 +00:00
parent 16134613b4
commit bd2a2f21f9
6 changed files with 148 additions and 40 deletions

View File

@ -167,7 +167,7 @@ public abstract class AbstractModule implements Module, Serializable {
initLayout(); initLayout();
} }
protected abstract void initModule(); protected abstract void initModule() throws HsarwebException;
public MainApplication getApplication() { public MainApplication getApplication() {
return application; return application;

View File

@ -21,7 +21,7 @@ public class DomainModule extends GenericModule {
private ModuleConfig moduleConfig; private ModuleConfig moduleConfig;
@Override @Override
protected void initModule() { protected void initModule() throws HsarwebException {
MainApplication application = getApplication(); MainApplication application = getApplication();
moduleConfig = new ModuleConfig("domain", application.getLocale()); moduleConfig = new ModuleConfig("domain", application.getLocale());
String login = application.getRunAs(); String login = application.getRunAs();

View File

@ -124,4 +124,42 @@ 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

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -2,6 +2,7 @@ package de.hsadmin.web.vaadin;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import com.vaadin.terminal.Sizeable; import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Component; import com.vaadin.ui.Component;
@ -10,7 +11,8 @@ import com.vaadin.ui.Label;
import com.vaadin.ui.Select; import com.vaadin.ui.Select;
import com.vaadin.ui.VerticalLayout; 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.ListOfStringsProperty;
import de.hsadmin.web.Module; import de.hsadmin.web.Module;
import de.hsadmin.web.XmlrpcProperty; import de.hsadmin.web.XmlrpcProperty;
@ -24,56 +26,85 @@ import de.hsadmin.web.config.PropertyFieldFactory;
*/ */
public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory { public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
private final Module module; private final Module module;
private final ModuleConfig config ; private final ModuleConfig config;
// TODO: besorge Options und ihre Typen aus der DB private static String[] OPTION_NAMES; // {"backupmxforexternalmx", "php", ...};
private static final String[] OPTION_NAMES = new String[] { "backupmxforexternalmx", "greylisting", "htdocsfallback", "includes", "indexes", "multiviews", "php"}; // private final Map<String,AbstractProperty> optionTypes ; // TODO: auf Vorrat hier
// private final Map<String,AbstractProperty> optionTypes ; // TODO: auf Vorrat hier
// TODO: besorge Options .... Ende
private boolean readOnly = false; private boolean readOnly = false;
private boolean writeOnce = false; private boolean writeOnce = false;
private VerticalLayout layout; private VerticalLayout layout;
private final List<SingleDomainOption> optionLayout ; private final List<SingleDomainOption> optionLayout;
public DomainOptionsPropertyFieldFactory(Module module) { public DomainOptionsPropertyFieldFactory(Module module) throws HsarwebInternalException {
this.module = module; this.module = module;
this.config = module.getModuleConfig(); this.config = this.module.getModuleConfig();
optionLayout = new ArrayList<SingleDomainOption>() ; // 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");
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")) {
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<String, ?> p8 = (Map<String, ?>) 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<SingleDomainOption>();
} }
private void repaint() { private void repaint() {
layout.removeAllComponents(); layout.removeAllComponents();
for (int idx=0 ; idx<OPTION_NAMES.length ; ++idx ) { for (int idx = 0; idx < OPTION_NAMES.length; ++idx) {
layout.addComponent(optionLayout.get(idx).getComponent()); layout.addComponent(optionLayout.get(idx).getComponent());
} }
} }
@Override @Override
public Object createFieldComponent(PropertyConfig prop, XmlrpcProperty value) throws HsarwebException { public Object createFieldComponent(PropertyConfig prop, XmlrpcProperty value)
throws HsarwebInternalException {
layout = new VerticalLayout(); layout = new VerticalLayout();
layout.setCaption(prop.getLabel()); layout.setCaption(prop.getLabel());
layout.setData(prop.getId()); layout.setData(prop.getId());
optionLayout.clear(); optionLayout.clear();
if (value instanceof ListOfStringsProperty) { if (value instanceof ListOfStringsProperty) {
ListOfStringsProperty list = (ListOfStringsProperty) value; ListOfStringsProperty list = (ListOfStringsProperty) value;
for (int idx=0 ; idx<OPTION_NAMES.length ; ++idx ) { for (int idx = 0; idx < OPTION_NAMES.length; ++idx) {
optionLayout.add(new SingleDomainOption(this, OPTION_NAMES[idx], list.contains(OPTION_NAMES[idx]) )); optionLayout.add(new SingleDomainOption(this,
OPTION_NAMES[idx], list.contains(OPTION_NAMES[idx])));
} }
} } else {
else
{
// Eine leere Liste von Domainoptionen wird angezeigt werden. // Eine leere Liste von Domainoptionen wird angezeigt werden.
throw new HsarwebException("Keine Liste: ListOfStringsProperty"); throw new HsarwebInternalException(
"Keine Liste: ListOfStringsProperty");
} }
repaint(); repaint();
return layout; return layout;
} }
@Override @Override
public XmlrpcProperty getValue(PropertyConfig prop, Object component) throws HsarwebException { public XmlrpcProperty getValue(PropertyConfig prop, Object component) {
ListOfStringsProperty setOptions = new ListOfStringsProperty() ; ListOfStringsProperty setOptions = new ListOfStringsProperty();
for (int idx=0 ; idx<OPTION_NAMES.length ; ++idx ) { for (int idx = 0; idx < OPTION_NAMES.length; ++idx) {
if(Boolean.TRUE.equals(optionLayout.get(idx).getValue())) if (Boolean.TRUE.equals(optionLayout.get(idx).getValue())) {
{
setOptions.add(OPTION_NAMES[idx]); setOptions.add(OPTION_NAMES[idx]);
} }
} }
@ -104,17 +135,19 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
private final DomainOptionsPropertyFieldFactory owner; private final DomainOptionsPropertyFieldFactory owner;
private final String optionName; private final String optionName;
private HorizontalLayout targetLine; private HorizontalLayout targetLine;
private Select select ; private Select select;
protected SingleDomainOption(DomainOptionsPropertyFieldFactory owner, String optionName, boolean optionValue) { protected SingleDomainOption(DomainOptionsPropertyFieldFactory owner,
String optionName, boolean optionValue) {
this.owner = owner; this.owner = owner;
this.optionName = optionName; this.optionName = optionName;
targetLine = new HorizontalLayout(); targetLine = new HorizontalLayout();
targetLine.setWidth(500.0f, Sizeable.UNITS_PIXELS); targetLine.setWidth(500.0f, Sizeable.UNITS_PIXELS);
HorizontalLayout leftPart = new HorizontalLayout(); HorizontalLayout leftPart = new HorizontalLayout();
leftPart.setWidth(220.0f, Sizeable.UNITS_PIXELS); leftPart.setWidth(220.0f, Sizeable.UNITS_PIXELS);
Label label = new Label(owner.config.getLabel("domainoption."+optionName),Label.CONTENT_RAW); Label label = new Label(owner.config.getLabel("domainoption."
leftPart.addComponent( label); // setCaption(owner.config.getLabel("domainoption."+optionName)); + optionName), Label.CONTENT_RAW);
leftPart.addComponent(label); // setCaption(owner.config.getLabel("domainoption."+optionName));
HorizontalLayout rightPart = new HorizontalLayout(); HorizontalLayout rightPart = new HorizontalLayout();
// ToDO: Fallunterscheidungen nach Optionsart. Z.Z. nur Boolean: // ToDO: Fallunterscheidungen nach Optionsart. Z.Z. nur Boolean:
{ {
@ -124,9 +157,9 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
this.select.setNewItemsAllowed(false); this.select.setNewItemsAllowed(false);
this.select.setNullSelectionAllowed(false); this.select.setNullSelectionAllowed(false);
this.select.addItem("y"); this.select.addItem("y");
this.select.setItemCaption("y" , owner.config.getLabel("yes")); this.select.setItemCaption("y", owner.config.getLabel("yes"));
this.select.addItem("n"); this.select.addItem("n");
this.select.setItemCaption("n" , owner.config.getLabel("no")); this.select.setItemCaption("n", owner.config.getLabel("no"));
this.select.setValue(optionValue ? "y" : "n"); this.select.setValue(optionValue ? "y" : "n");
rightPart.addComponent(this.select); rightPart.addComponent(this.select);
} }
@ -141,8 +174,7 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
public Boolean getValue() { public Boolean getValue() {
Boolean value = null; Boolean value = null;
String val = (String) this.select.getValue(); String val = (String) this.select.getValue();
if( val.equals("y") || val.equals("n") ) if (val.equals("y") || val.equals("n")) {
{
value = (val.equals("y")); value = (val.equals("y"));
} }
return value; return value;