generisches Delete, Fehlerbehandlung

This commit is contained in:
Peter Hormanns 2010-12-17 17:39:53 +00:00
parent 93db501810
commit e62f1fdd50
11 changed files with 190 additions and 67 deletions

View File

@ -157,11 +157,13 @@ public class EMailAddress extends AbstractEntity implements Serializable {
} }
public String toString() { public String toString() {
if (localpart != null && target != null) if (localpart != null && target != null && domain != null) {
return super.toString() + "{ id=" + id + "; address=" + localpart String local = super.toString() + "{ id=" + id + "; address=" + localpart + "@";
+ subdomain + "; target=" + target + " }"; if (subdomain != null) { local += "." + subdomain; }
else return local + domain + "; target=" + target + " }";
} else {
return super.toString(); return super.toString();
}
} }
@Override @Override

View File

@ -202,9 +202,11 @@ public abstract class AbstractRemote implements IRemote {
String value = whereParams.get(field).replaceAll("'", "\'"); String value = whereParams.get(field).replaceAll("'", "\'");
cond.append("obj."); cond.append("obj.");
cond.append(field); cond.append(field);
cond.append(" = '"); cond.append(" = ");
boolean numeric = "id".equals(field);
if (!numeric) cond.append("'");
cond.append(value); cond.append(value);
cond.append("'"); if (!numeric) cond.append("'");
} }
return cond.toString(); return cond.toString();
} }

View File

@ -44,7 +44,7 @@ public class EMailAddressTest {
try { try {
Object execute = client.execute(MODULE + ".search", params); Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute; Object[] result = (Object[]) execute;
assertEquals(262, result.length); assertEquals(253, result.length);
for (Object o : result) { for (Object o : result) {
if (o instanceof Map<?, ?>) { if (o instanceof Map<?, ?>) {
Map<?, ?> row = (Map<?, ?>) o; Map<?, ?> row = (Map<?, ?>) o;
@ -191,13 +191,29 @@ public class EMailAddressTest {
} }
assertEquals(count + 1, getObjectCount()); assertEquals(count + 1, getObjectCount());
count = getObjectCount(); count = getObjectCount();
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, Object> whereParams = new HashMap<String, Object>();
whereParams.put("localpart", "f6n"); whereParams.put("localpart", "f6n");
whereParams.put("domain", "jalin.de"); whereParams.put("domain", "jalin.de");
params = new Object[] { user, params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams }; whereParams };
try { try {
Object execute = client.execute(MODULE + ".search", params);
assertTrue(execute instanceof Object[]);
whereParams = new HashMap<String, Object>();
Object[] resArray = (Object[]) execute;
assertEquals(1, resArray.length);
Object res = resArray[0];
Map<String, Object> map = (Map<String, Object>) res;
Object idVal = map.get("id");
whereParams.put("id", idVal);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
try {
params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
Object execute = client.execute(MODULE + ".delete", params); Object execute = client.execute(MODULE + ".delete", params);
assertNull(execute); assertNull(execute);
} catch (XmlRpcException e) { } catch (XmlRpcException e) {

View File

@ -44,7 +44,7 @@ public class EMailAliasTest {
try { try {
Object execute = client.execute(MODULE + ".search", params); Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute; Object[] result = (Object[]) execute;
assertEquals(262, result.length); assertEquals(3, result.length);
for (Object o : result) { for (Object o : result) {
if (o instanceof Map<?, ?>) { if (o instanceof Map<?, ?>) {
Map<?, ?> row = (Map<?, ?>) o; Map<?, ?> row = (Map<?, ?>) o;

View File

@ -43,7 +43,7 @@ public class UnixUserTest {
try { try {
Object execute = client.execute(MODULE + ".search", params); Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute; Object[] result = (Object[]) execute;
assertEquals(23, result.length); assertEquals(22, result.length);
for (Object o : result) { for (Object o : result) {
if (o instanceof Map<?, ?>) { if (o instanceof Map<?, ?>) {
Map<?, ?> row = (Map<?, ?>) o; Map<?, ?> row = (Map<?, ?>) o;

View File

@ -14,10 +14,15 @@ import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.ThemeResource; import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Button; import com.vaadin.ui.Button;
import com.vaadin.ui.Component; import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Table; import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.themes.BaseTheme; import com.vaadin.ui.themes.BaseTheme;
import de.hsadmin.web.config.LocaleConfig;
import de.hsadmin.web.config.ModuleConfig; import de.hsadmin.web.config.ModuleConfig;
import de.hsadmin.web.config.PropertyConfig; import de.hsadmin.web.config.PropertyConfig;
@ -27,16 +32,11 @@ public abstract class GenericModule implements Serializable {
private static final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); private static final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
private Table table; private Table table;
private Remote remote; private MainApplication application;
public void setRemote(Remote remote) { public void setApplication(MainApplication app) throws HsarwebException {
this.remote = remote; this.application = app;
try { initTable();
initTable();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
public abstract ModuleConfig getModuleConfig(); public abstract ModuleConfig getModuleConfig();
@ -45,11 +45,11 @@ public abstract class GenericModule implements Serializable {
return table; return table;
} }
public void reload() { public void reload() throws HsarwebException {
loadTable(); loadTable();
} }
private void initTable() throws IllegalAccessException { private void initTable() throws HsarwebException {
table = new Table() { table = new Table() {
private static final long serialVersionUID = 35127658139420917L; private static final long serialVersionUID = 35127658139420917L;
@Override @Override
@ -65,31 +65,35 @@ public abstract class GenericModule implements Serializable {
return super.formatPropertyValue(rowId, colId, property); return super.formatPropertyValue(rowId, colId, property);
} }
}; };
table.setWidth(100.0f, Sizeable.UNITS_PERCENTAGE); try {
table.setHeight(100.0f, Sizeable.UNITS_PERCENTAGE); table.setWidth(100.0f, Sizeable.UNITS_PERCENTAGE);
table.setSelectable(true); table.setHeight(100.0f, Sizeable.UNITS_PERCENTAGE);
table.setImmediate(true); table.setSelectable(true);
table.setColumnCollapsingAllowed(true); table.setImmediate(true);
table.setColumnReorderingAllowed(true); table.setColumnCollapsingAllowed(true);
for (PropertyConfig prop : getModuleConfig().getPropertyList()) { table.setColumnReorderingAllowed(true);
table.addContainerProperty(prop.getId(), prop.getType(), prop.getDefaultValue()); for (PropertyConfig prop : getModuleConfig().getPropertyList()) {
table.setColumnHeader(prop.getId(), prop.getLabel()); table.addContainerProperty(prop.getId(), prop.getType(), prop.getDefaultValue());
if (prop.isHidden()) { table.setColumnHeader(prop.getId(), prop.getLabel());
table.setColumnCollapsed(prop.getId(), true); if (prop.isHidden()) {
table.setColumnCollapsed(prop.getId(), true);
}
} }
table.addContainerProperty("edit", Button.class, null);
table.setColumnWidth("edit", 16);
table.setColumnHeader("edit", "");
table.addContainerProperty("del", Button.class, null);
table.setColumnWidth("del", 16);
table.setColumnHeader("del", "");
} catch (Exception e) {
throw new HsarwebException(e);
} }
table.addContainerProperty("edit", Button.class, null);
table.setColumnWidth("edit", 16);
table.setColumnHeader("edit", "");
table.addContainerProperty("del", Button.class, null);
table.setColumnWidth("del", 16);
table.setColumnHeader("del", "");
} }
private void loadTable() { private void loadTable() throws HsarwebException {
table.removeAllItems(); table.removeAllItems();
try { try {
Object callSearch = remote.callSearch(getModuleConfig().getName(), new HashMap<String, String>()); Object callSearch = application.getRemote().callSearch(getModuleConfig().getName(), new HashMap<String, String>());
List<PropertyConfig> propertyList = getModuleConfig().getPropertyList(); List<PropertyConfig> propertyList = getModuleConfig().getPropertyList();
if (callSearch instanceof Object[]) { if (callSearch instanceof Object[]) {
for (Object row : ((Object[])callSearch)) { for (Object row : ((Object[])callSearch)) {
@ -133,14 +137,29 @@ public abstract class GenericModule implements Serializable {
table.sort(); table.sort();
} }
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
// TODO Auto-generated catch block throw new HsarwebException(e);
e.printStackTrace();
} catch (HsarwebException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
} }
private void deleteRow(long id) throws HsarwebException {
Map<String, String> paramHash = new HashMap<String, String>();
paramHash.put(findIdKey(), Long.toString(id));
application.getRemote().callDelete(getModuleConfig().getName(), paramHash);
loadTable();
}
private String findIdKey() {
List<PropertyConfig> propertyList = getModuleConfig().getPropertyList();
String idKey = null;
for (PropertyConfig propConf : propertyList) {
if (propConf.isIdent()) {
idKey = propConf.getId();
return idKey;
}
}
return idKey;
}
private Button createEditButton(long id) { private Button createEditButton(long id) {
ThemeResource icon = new ThemeResource("../runo/icons/16/document-txt.png"); ThemeResource icon = new ThemeResource("../runo/icons/16/document-txt.png");
Button button = new Button(); Button button = new Button();
@ -151,7 +170,7 @@ public abstract class GenericModule implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
public void buttonClick(ClickEvent event) { public void buttonClick(ClickEvent event) {
loadTable(); // loadTable();
System.out.println("Data: " + event.getButton().getData()); System.out.println("Data: " + event.getButton().getData());
} }
}); });
@ -160,16 +179,50 @@ public abstract class GenericModule implements Serializable {
private Button createDeleteButton(long id) { private Button createDeleteButton(long id) {
ThemeResource icon = new ThemeResource("../runo/icons/16/document-delete.png"); ThemeResource icon = new ThemeResource("../runo/icons/16/document-delete.png");
Button button = new Button(); final Button button = new Button();
button.setIcon(icon); button.setIcon(icon);
button.setData(id); button.setData(id);
button.setStyleName(BaseTheme.BUTTON_LINK); button.setStyleName(BaseTheme.BUTTON_LINK);
button.addListener(new Button.ClickListener() { button.addListener(new Button.ClickListener() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Window childWindow;
@Override @Override
public void buttonClick(ClickEvent event) { public void buttonClick(ClickEvent event) {
loadTable(); LocaleConfig localeConfig = application.getLocaleConfig();
System.out.println("Data: " + event.getButton().getData()); childWindow = new Window(getModuleConfig().getLabel("moduletitle") + " " + localeConfig.getText("delete"));
childWindow.setWidth(320.0f, Sizeable.UNITS_PIXELS);
VerticalLayout vLayout = new VerticalLayout();
vLayout.setMargin(true);
vLayout.setSpacing(true);
vLayout.addComponent(new Label(localeConfig.getText("confirmdelete")));
HorizontalLayout hLayout = new HorizontalLayout();
Button btDeleteRow = new Button(localeConfig.getText("delete"));
btDeleteRow.addListener(new Button.ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
application.getMainWindow().removeWindow(childWindow);
try {
deleteRow((Long) button.getData());
} catch (HsarwebException e) {
application.showUserException(e);
}
}
});
Button btAbort = new Button(localeConfig.getText("abort"));
btAbort.addListener(new Button.ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
application.getMainWindow().removeWindow(childWindow);
}
});
hLayout.addComponent(btDeleteRow);
hLayout.addComponent(btAbort);
vLayout.addComponent(hLayout);
childWindow.setContent(vLayout);
childWindow.setModal(true);
application.getMainWindow().addWindow(childWindow);
} }
}); });
return button; return button;

View File

@ -9,4 +9,12 @@ public class HsarwebException extends Exception {
super(string, e); super(string, e);
} }
public HsarwebException(Throwable e) {
super(e);
}
public HsarwebException(String string) {
super(string);
}
} }

View File

@ -15,6 +15,7 @@ import org.jasig.cas.client.validation.Assertion;
import com.vaadin.Application; import com.vaadin.Application;
import com.vaadin.terminal.Sizeable; import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.Terminal;
import com.vaadin.terminal.ThemeResource; import com.vaadin.terminal.ThemeResource;
import com.vaadin.terminal.gwt.server.HttpServletRequestListener; import com.vaadin.terminal.gwt.server.HttpServletRequestListener;
import com.vaadin.ui.Component; import com.vaadin.ui.Component;
@ -22,6 +23,7 @@ import com.vaadin.ui.TabSheet;
import com.vaadin.ui.Window; import com.vaadin.ui.Window;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent; import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.Tab; import com.vaadin.ui.TabSheet.Tab;
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;
@ -37,6 +39,7 @@ public class MainApplication extends Application implements HttpServletRequestLi
private Remote remote; private Remote remote;
private Map<String, GenericModule> modules; private Map<String, GenericModule> modules;
@Override @Override
public void init() { public void init() {
localeConfig = new LocaleConfig(Locale.getDefault(), "main"); localeConfig = new LocaleConfig(Locale.getDefault(), "main");
@ -44,14 +47,14 @@ public class MainApplication extends Application implements HttpServletRequestLi
Window mainWindow = new Window(localeConfig.getText("applicationtitle")); Window mainWindow = new Window(localeConfig.getText("applicationtitle"));
TabSheet tabs = new TabSheet(); TabSheet tabs = new TabSheet();
tabs.setWidth(100.0f, Sizeable.UNITS_PERCENTAGE); tabs.setWidth(100.0f, Sizeable.UNITS_PERCENTAGE);
tabs.setHeight(680.0f, Sizeable.UNITS_PIXELS); tabs.setHeight(200.0f, Sizeable.UNITS_PERCENTAGE);
String modulesParamString = getContextParam("hsarmodules"); String modulesParamString = getContextParam("hsarmodules");
modules = new HashMap<String, GenericModule>(); modules = new HashMap<String, GenericModule>();
GenericModule firstModule = null; GenericModule firstModule = null;
for (String className : modulesParamString.split(",")) { for (String className : modulesParamString.split(",")) {
try { try {
GenericModule module = (GenericModule) Class.forName(className).newInstance(); GenericModule module = (GenericModule) Class.forName(className).newInstance();
module.setRemote(remote); module.setApplication(this);
if (firstModule == null) { if (firstModule == null) {
firstModule = module; firstModule = module;
} }
@ -59,21 +62,25 @@ public class MainApplication extends Application implements HttpServletRequestLi
String label = moduleConfig.getLabel("moduletitle"); String label = moduleConfig.getLabel("moduletitle");
modules.put(label, module); modules.put(label, module);
tabs.addTab(module.getComponent(), label, new ThemeResource(moduleConfig.getLabel("moduleicon"))); tabs.addTab(module.getComponent(), label, new ThemeResource(moduleConfig.getLabel("moduleicon")));
} catch (InstantiationException e) { } catch (Exception e) {
// TODO Auto-generated catch block showSystemException(e);
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
} }
tabs.addListener(this); tabs.addListener(this);
mainWindow.addComponent(tabs); mainWindow.addComponent(tabs);
setMainWindow(mainWindow); setMainWindow(mainWindow);
firstModule.reload(); setErrorHandler(new Terminal.ErrorListener() {
private static final long serialVersionUID = 1L;
@Override
public void terminalError(Terminal.ErrorEvent event) {
event.getThrowable().printStackTrace();
}
});
try {
firstModule.reload();
} catch (HsarwebException e) {
showSystemException(e);
}
} }
public String getProxyTicket() { public String getProxyTicket() {
@ -88,6 +95,14 @@ public class MainApplication extends Application implements HttpServletRequestLi
return userPrincipal.getName(); return userPrincipal.getName();
} }
public Remote getRemote() {
return remote;
}
public LocaleConfig getLocaleConfig() {
return localeConfig;
}
@Override @Override
public void onRequestStart(HttpServletRequest request, public void onRequestStart(HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
@ -108,7 +123,19 @@ public class MainApplication extends Application implements HttpServletRequestLi
Component selectedTab = tabSheet.getSelectedTab(); Component selectedTab = tabSheet.getSelectedTab();
Tab tab = tabSheet.getTab(selectedTab); Tab tab = tabSheet.getTab(selectedTab);
GenericModule module = modules.get(tab.getCaption()); GenericModule module = modules.get(tab.getCaption());
module.reload(); try {
module.reload();
} catch (HsarwebException e) {
showSystemException(e);
}
}
public void showUserException(Exception e) {
getMainWindow().showNotification("Anwendungs-Fehler", "<br/ >" + e.getMessage(), Notification.TYPE_WARNING_MESSAGE);
}
public void showSystemException(Exception e) {
getMainWindow().showNotification("System-Fehler", "<br />Bitte informieren Sie den Support<br/ >" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
} }
} }

View File

@ -18,26 +18,34 @@ public class Remote {
} }
public Object callSearch(String module, Map<String, String> where) throws HsarwebException { public Object callSearch(String module, Map<String, String> where) throws HsarwebException {
return xmlrpcCall(module, "search", where);
}
public void callDelete(String module, Map<String, String> where) throws HsarwebException {
xmlrpcCall(module, "delete", where);
}
private Object xmlrpcCall(String module, String operation, Map<String, String> where) throws HsarwebException {
Object[] params = new Object[3]; Object[] params = new Object[3];
params[0] = app.getLogin(); params[0] = app.getLogin();
params[1] = app.getProxyTicket(); params[1] = app.getProxyTicket();
params[2] = where; params[2] = where;
Object res; Object res;
try { try {
res = getClient().execute(module + ".search", params); res = getClient().execute(module + "." + operation, params);
} catch (XmlRpcException e) { } catch (XmlRpcException e) {
throw new HsarwebException("error in remote server call", e); throw new HsarwebException("error in remote server call", e);
} }
return res; return res;
} }
private XmlRpcClient getClient() throws HsarwebException { private XmlRpcClient getClient() throws HsarwebException {
if (client == null) { if (client == null) {
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
try { try {
String xmlrpcURL = app.getContextParam("xmlrpcURL"); String xmlrpcURL = app.getContextParam("xmlrpcURL");
config.setServerURL(new URL(xmlrpcURL)); config.setServerURL(new URL(xmlrpcURL));
config.setEnabledForExceptions(true); config.setEnabledForExtensions(true);
client = new XmlRpcClient(); client = new XmlRpcClient();
client.setConfig(config); client.setConfig(config);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {

View File

@ -1 +1,4 @@
applicationtitle=HSAdmin Web Application applicationtitle=HSAdmin Web Application
delete=delete
confirmdelete=confirm delete
abort=abort

View File

@ -0,0 +1,4 @@
applicationtitle=HSAdmin Web Application
delete=löschen
confirmdelete=Diese Zeile löschen?
abort=abbrechen