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();
}
protected abstract void initModule();
protected abstract void initModule() throws HsarwebException;
public MainApplication getApplication() {
return application;

View File

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

View File

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

@ -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.List;
import java.util.Map;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Component;
@ -10,7 +11,8 @@ import com.vaadin.ui.Label;
import com.vaadin.ui.Select;
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.Module;
import de.hsadmin.web.XmlrpcProperty;
@ -25,18 +27,47 @@ import de.hsadmin.web.config.PropertyFieldFactory;
public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
private final Module module;
private final ModuleConfig config;
// TODO: besorge Options und ihre Typen aus der DB
private static final String[] OPTION_NAMES = new String[] { "backupmxforexternalmx", "greylisting", "htdocsfallback", "includes", "indexes", "multiviews", "php"};
private static String[] OPTION_NAMES; // {"backupmxforexternalmx", "php", ...};
// private final Map<String,AbstractProperty> optionTypes ; // TODO: auf Vorrat hier
// TODO: besorge Options .... Ende
private boolean readOnly = false;
private boolean writeOnce = false;
private VerticalLayout layout;
private final List<SingleDomainOption> optionLayout;
public DomainOptionsPropertyFieldFactory(Module module) {
public DomainOptionsPropertyFieldFactory(Module module) throws HsarwebInternalException {
this.module = module;
this.config = module.getModuleConfig();
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");
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>();
}
@ -48,7 +79,8 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
}
@Override
public Object createFieldComponent(PropertyConfig prop, XmlrpcProperty value) throws HsarwebException {
public Object createFieldComponent(PropertyConfig prop, XmlrpcProperty value)
throws HsarwebInternalException {
layout = new VerticalLayout();
layout.setCaption(prop.getLabel());
layout.setData(prop.getId());
@ -56,24 +88,23 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
if (value instanceof ListOfStringsProperty) {
ListOfStringsProperty list = (ListOfStringsProperty) value;
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.
throw new HsarwebException("Keine Liste: ListOfStringsProperty");
throw new HsarwebInternalException(
"Keine Liste: ListOfStringsProperty");
}
repaint();
return layout;
}
@Override
public XmlrpcProperty getValue(PropertyConfig prop, Object component) throws HsarwebException {
public XmlrpcProperty getValue(PropertyConfig prop, Object component) {
ListOfStringsProperty setOptions = new ListOfStringsProperty();
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]);
}
}
@ -106,14 +137,16 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
private HorizontalLayout targetLine;
private Select select;
protected SingleDomainOption(DomainOptionsPropertyFieldFactory owner, String optionName, boolean optionValue) {
protected SingleDomainOption(DomainOptionsPropertyFieldFactory owner,
String optionName, boolean optionValue) {
this.owner = owner;
this.optionName = optionName;
targetLine = new HorizontalLayout();
targetLine.setWidth(500.0f, Sizeable.UNITS_PIXELS);
HorizontalLayout leftPart = new HorizontalLayout();
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."
+ optionName), Label.CONTENT_RAW);
leftPart.addComponent(label); // setCaption(owner.config.getLabel("domainoption."+optionName));
HorizontalLayout rightPart = new HorizontalLayout();
// ToDO: Fallunterscheidungen nach Optionsart. Z.Z. nur Boolean:
@ -141,8 +174,7 @@ public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
public Boolean getValue() {
Boolean value = null;
String val = (String) this.select.getValue();
if( val.equals("y") || val.equals("n") )
{
if (val.equals("y") || val.equals("n")) {
value = (val.equals("y"));
}
return value;