From 5de9e7eceb39089c07a908d0b905287ce380a859 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Mon, 7 Sep 2015 16:29:30 +0200 Subject: [PATCH] implement compatible property module --- .../src/de/hsadmin/remote/PropertyRemote.java | 104 ++++++++++++++++++ .../xmlrpc/webserver/XmlRpcServlet.properties | 3 +- 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 hsarback/src/de/hsadmin/remote/PropertyRemote.java diff --git a/hsarback/src/de/hsadmin/remote/PropertyRemote.java b/hsarback/src/de/hsadmin/remote/PropertyRemote.java new file mode 100644 index 0000000..6d924aa --- /dev/null +++ b/hsarback/src/de/hsadmin/remote/PropertyRemote.java @@ -0,0 +1,104 @@ +package de.hsadmin.remote; + +import java.io.InputStream; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import de.hsadmin.core.model.AbstractEntity; +import de.hsadmin.core.model.AnnFieldIO; +import de.hsadmin.core.model.AuthenticationException; +import de.hsadmin.core.model.HSAdminException; +import de.hsadmin.core.model.ReadWriteAccess; +import de.hsadmin.core.model.Transaction; + +public class PropertyRemote implements IRemote { + + @Override + public List> search(String runAsUser, String ticket, + Map whereParams) throws HSAdminException { + String user = runAsUser; + List> result = new ArrayList>(); + Transaction transaction = new Transaction(user); + try { + if (transaction.login(user, ticket)) { + InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("org/apache/xmlrpc/webserver/XmlRpcServlet.properties"); + Properties properties = new Properties(); + properties.load(resourceAsStream); + for (Object moduleKey : properties.keySet()) { + Class remoteClass = Class.forName(properties.getProperty((String) moduleKey)); + Object newInstance = remoteClass.newInstance(); + if (newInstance instanceof AbstractRemote) { + AbstractRemote remote = (AbstractRemote) newInstance; + Class entityClass = remote.getEntityClass(); + for (Field f: entityClass.getDeclaredFields()) { + AnnFieldIO fieldIO = f.getAnnotation(AnnFieldIO.class); + if (fieldIO != null) { + HashMap propertyProperties = new HashMap(); + String fieldName = f.getName(); + propertyProperties.put("module", (String) moduleKey); + propertyProperties.put("name", fieldName); + propertyProperties.put("searchable", "equals"); + propertyProperties.put("readwriteable", "read"); + ReadWriteAccess rw = fieldIO.rw(); + if (ReadWriteAccess.READONLY.equals(rw)) { + propertyProperties.put("readwriteable", "read"); + } + if (ReadWriteAccess.READWRITE.equals(rw)) { + propertyProperties.put("readwriteable", "readwrite"); + } + if (ReadWriteAccess.WRITEONCE.equals(rw)) { + propertyProperties.put("readwriteable", "writeonce"); + } + if (ReadWriteAccess.WRITEONLY.equals(rw)) { + propertyProperties.put("readwriteable", "none"); + } + propertyProperties.put("type", "string"); + propertyProperties.put("displaySequence", "2"); + if ("name".equals(fieldName)) { + propertyProperties.put("displaySequence", "1"); + } + propertyProperties.put("displayVisible", "always"); + propertyProperties.put("minLength", "0"); + propertyProperties.put("maxLength", "999"); + String regExp = fieldIO.validation(); + propertyProperties.put("validationRegexp", regExp); + result.add(propertyProperties); + } + } + } + } + return result; + } else { + throw new AuthenticationException("authentication failed"); + } + } catch (Exception e) { + throw new HSAdminException(e); + } finally { + transaction.close(); + } + } + + @Override + public Map add(String runAsUser, String ticket, + Map setParams) throws HSAdminException { + throw new HSAdminException("read only module"); + } + + @Override + public void delete(String runAsUser, String ticket, + Map whereParams) throws HSAdminException { + throw new HSAdminException("read only module"); + } + + @Override + public List> update(String runAsUser, String ticket, + Map setParams, Map whereParams) + throws HSAdminException { + throw new HSAdminException("read only module"); + } + +} diff --git a/hsarback/src/org/apache/xmlrpc/webserver/XmlRpcServlet.properties b/hsarback/src/org/apache/xmlrpc/webserver/XmlRpcServlet.properties index ef98a27..d233600 100644 --- a/hsarback/src/org/apache/xmlrpc/webserver/XmlRpcServlet.properties +++ b/hsarback/src/org/apache/xmlrpc/webserver/XmlRpcServlet.properties @@ -9,4 +9,5 @@ mysqluser=de.hsadmin.remote.MysqlUserRemote postgresqluser=de.hsadmin.remote.PgsqlUserRemote mysqldb=de.hsadmin.remote.MysqlDbRemote postgresqldb=de.hsadmin.remote.PgsqlDbRemote -moduleprop=de.hsadmin.remote.ModulePropertiesRemote \ No newline at end of file +moduleprop=de.hsadmin.remote.ModulePropertiesRemote +property=de.hsadmin.remote.PropertyRemote \ No newline at end of file