HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2010-12-17 e62f1fdd50708039943d3fdffa8e6639e706dd88
generisches Delete, Fehlerbehandlung
1 files added
10 files modified
257 ■■■■ changed files
hsarback/src/de/hsadmin/mods/email/EMailAddress.java 10 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/remote/AbstractRemote.java 6 ●●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/EMailAddressTest.java 20 ●●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/EMailAliasTest.java 2 ●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/UnixUserTest.java 2 ●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/GenericModule.java 131 ●●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/HsarwebException.java 8 ●●●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/MainApplication.java 53 ●●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/Remote.java 16 ●●●● patch | view | raw | blame | history
hsarweb/src/texts/main.properties 5 ●●●● patch | view | raw | blame | history
hsarweb/src/texts/main_de.properties 4 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/email/EMailAddress.java
@@ -157,11 +157,13 @@
    }
    public String toString() {
        if (localpart != null && target != null)
            return super.toString() + "{ id=" + id + "; address=" + localpart
                    + subdomain + "; target=" + target + " }";
        else
        if (localpart != null && target != null && domain != null) {
            String local = super.toString() + "{ id=" + id + "; address=" + localpart + "@";
            if (subdomain != null) { local += "." + subdomain; }
            return local + domain + "; target=" + target + " }";
        } else {
            return super.toString();
        }
    }
    @Override
hsarback/src/de/hsadmin/remote/AbstractRemote.java
@@ -202,9 +202,11 @@
            String value = whereParams.get(field).replaceAll("'", "\'");
            cond.append("obj.");
            cond.append(field);
            cond.append(" = '");
            cond.append(" = ");
            boolean numeric = "id".equals(field);
            if (!numeric) cond.append("'");
            cond.append(value);
            cond.append("'");
            if (!numeric) cond.append("'");
        }
        return cond.toString();
    }
hsarback/test/de/hsadmin/remote/EMailAddressTest.java
@@ -44,7 +44,7 @@
        try {
            Object execute = client.execute(MODULE + ".search", params);
            Object[] result = (Object[]) execute;
            assertEquals(262, result.length);
            assertEquals(253, result.length);
            for (Object o : result) {
                if (o instanceof Map<?, ?>) {
                    Map<?, ?> row = (Map<?, ?>) o;
@@ -191,13 +191,29 @@
        }
        assertEquals(count + 1, 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("domain", "jalin.de");
        params = new Object[] { user, 
                cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), 
                whereParams };
        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);
            assertNull(execute);
        } catch (XmlRpcException e) {
hsarback/test/de/hsadmin/remote/EMailAliasTest.java
@@ -44,7 +44,7 @@
        try {
            Object execute = client.execute(MODULE + ".search", params);
            Object[] result = (Object[]) execute;
            assertEquals(262, result.length);
            assertEquals(3, result.length);
            for (Object o : result) {
                if (o instanceof Map<?, ?>) {
                    Map<?, ?> row = (Map<?, ?>) o;
hsarback/test/de/hsadmin/remote/UnixUserTest.java
@@ -43,7 +43,7 @@
        try {
            Object execute = client.execute(MODULE + ".search", params);
            Object[] result = (Object[]) execute;
            assertEquals(23, result.length);
            assertEquals(22, result.length);
            for (Object o : result) {
                if (o instanceof Map<?, ?>) {
                    Map<?, ?> row = (Map<?, ?>) o;
hsarweb/src/de/hsadmin/web/GenericModule.java
@@ -14,10 +14,15 @@
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
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.themes.BaseTheme;
import de.hsadmin.web.config.LocaleConfig;
import de.hsadmin.web.config.ModuleConfig;
import de.hsadmin.web.config.PropertyConfig;
@@ -27,16 +32,11 @@
    private static final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
    private Table table;
    private Remote remote;
    private MainApplication application;
    public void setRemote(Remote remote) {
        this.remote = remote;
        try {
            initTable();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    public void setApplication(MainApplication app) throws HsarwebException {
        this.application = app;
        initTable();
    }
    
    public abstract ModuleConfig getModuleConfig();
@@ -45,11 +45,11 @@
        return table;
    }
    public void reload() {
    public void reload() throws HsarwebException {
        loadTable();
    }
    private void initTable() throws IllegalAccessException {
    private void initTable() throws HsarwebException {
        table = new Table() {
            private static final long serialVersionUID = 35127658139420917L;
            @Override
@@ -65,31 +65,35 @@
                return super.formatPropertyValue(rowId, colId, property);
            }
        };
        table.setWidth(100.0f, Sizeable.UNITS_PERCENTAGE);
        table.setHeight(100.0f, Sizeable.UNITS_PERCENTAGE);
        table.setSelectable(true);
        table.setImmediate(true);
        table.setColumnCollapsingAllowed(true);
        table.setColumnReorderingAllowed(true);
        for (PropertyConfig prop : getModuleConfig().getPropertyList()) {
            table.addContainerProperty(prop.getId(), prop.getType(), prop.getDefaultValue());
            table.setColumnHeader(prop.getId(), prop.getLabel());
            if (prop.isHidden()) {
                table.setColumnCollapsed(prop.getId(), true);
        try {
            table.setWidth(100.0f, Sizeable.UNITS_PERCENTAGE);
            table.setHeight(100.0f, Sizeable.UNITS_PERCENTAGE);
            table.setSelectable(true);
            table.setImmediate(true);
            table.setColumnCollapsingAllowed(true);
            table.setColumnReorderingAllowed(true);
            for (PropertyConfig prop : getModuleConfig().getPropertyList()) {
                table.addContainerProperty(prop.getId(), prop.getType(), prop.getDefaultValue());
                table.setColumnHeader(prop.getId(), prop.getLabel());
                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();
        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();
            if (callSearch instanceof Object[]) {
                for (Object row : ((Object[])callSearch)) {
@@ -133,14 +137,29 @@
                table.sort();
            }
        } catch (UnsupportedOperationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (HsarwebException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new HsarwebException(e);
        }
    }
    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) {
        ThemeResource icon = new ThemeResource("../runo/icons/16/document-txt.png");
        Button button = new Button();
@@ -151,7 +170,7 @@
            private static final long serialVersionUID = 1L;
            @Override
            public void buttonClick(ClickEvent event) {
                loadTable();
//                loadTable();
                System.out.println("Data: " + event.getButton().getData());
            }
        });
@@ -160,16 +179,50 @@
    private Button createDeleteButton(long id) {
        ThemeResource icon = new ThemeResource("../runo/icons/16/document-delete.png");
        Button button = new Button();
        final Button button = new Button();
        button.setIcon(icon);
        button.setData(id);
        button.setStyleName(BaseTheme.BUTTON_LINK);
        button.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 1L;
            private Window childWindow;
            @Override
            public void buttonClick(ClickEvent event) {
                loadTable();
                System.out.println("Data: " + event.getButton().getData());
                LocaleConfig localeConfig = application.getLocaleConfig();
                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;
hsarweb/src/de/hsadmin/web/HsarwebException.java
@@ -9,4 +9,12 @@
        super(string, e);
    }
    public HsarwebException(Throwable e) {
        super(e);
    }
    public HsarwebException(String string) {
        super(string);
    }
}
hsarweb/src/de/hsadmin/web/MainApplication.java
@@ -15,6 +15,7 @@
import com.vaadin.Application;
import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.Terminal;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.terminal.gwt.server.HttpServletRequestListener;
import com.vaadin.ui.Component;
@@ -22,6 +23,7 @@
import com.vaadin.ui.Window;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.Tab;
import com.vaadin.ui.Window.Notification;
import de.hsadmin.web.config.LocaleConfig;
import de.hsadmin.web.config.ModuleConfig;
@@ -37,6 +39,7 @@
    private Remote remote;
    private Map<String, GenericModule> modules;
    @Override
    public void init() {
        localeConfig = new LocaleConfig(Locale.getDefault(), "main");
@@ -44,14 +47,14 @@
        Window mainWindow = new Window(localeConfig.getText("applicationtitle"));
        TabSheet tabs = new TabSheet();
        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");
        modules = new HashMap<String, GenericModule>();
        GenericModule firstModule = null;
        for (String className : modulesParamString.split(",")) {
            try {
                GenericModule module = (GenericModule) Class.forName(className).newInstance();
                module.setRemote(remote);
                module.setApplication(this);
                if (firstModule == null) {
                    firstModule = module;
                }
@@ -59,21 +62,25 @@
                String label = moduleConfig.getLabel("moduletitle");
                modules.put(label, module);
                tabs.addTab(module.getComponent(), label, new ThemeResource(moduleConfig.getLabel("moduleicon")));
            } catch (InstantiationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (Exception e) {
                showSystemException(e);
            }
        }
        tabs.addListener(this);
        mainWindow.addComponent(tabs);
        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() {
@@ -86,6 +93,14 @@
    public Object getLogin() {
        return userPrincipal.getName();
    }
    public Remote getRemote() {
        return remote;
    }
    public LocaleConfig getLocaleConfig() {
        return localeConfig;
    }
    @Override
@@ -108,7 +123,19 @@
        Component selectedTab = tabSheet.getSelectedTab();
        Tab tab = tabSheet.getTab(selectedTab);
        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);
    }
}
hsarweb/src/de/hsadmin/web/Remote.java
@@ -18,26 +18,34 @@
    }
    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];
        params[0] = app.getLogin();
        params[1] = app.getProxyTicket();
        params[2] = where;
        Object res;
        try {
            res = getClient().execute(module + ".search", params);
            res = getClient().execute(module + "." + operation, params);
        } catch (XmlRpcException e) {
            throw new HsarwebException("error in remote server call", e);
        }
        return res;
        return res;
    }
    private XmlRpcClient getClient() throws HsarwebException {
        if (client == null) {
            XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
            try {
                String xmlrpcURL = app.getContextParam("xmlrpcURL");
                config.setServerURL(new URL(xmlrpcURL));
                config.setEnabledForExceptions(true);
                config.setEnabledForExtensions(true);
                client = new XmlRpcClient();
                client.setConfig(config);
            } catch (MalformedURLException e) {
hsarweb/src/texts/main.properties
@@ -1 +1,4 @@
applicationtitle=HSAdmin Web Application
applicationtitle=HSAdmin Web Application
delete=delete
confirmdelete=confirm delete
abort=abort
hsarweb/src/texts/main_de.properties
New file
@@ -0,0 +1,4 @@
applicationtitle=HSAdmin Web Application
delete=löschen
confirmdelete=Diese Zeile löschen?
abort=abbrechen