diff options
author | Gerwin Gsenger <g.gsenger@datentechnik-innovation.at> | 2015-01-09 15:40:59 +0100 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2015-06-19 11:01:57 +0200 |
commit | 3221a6d123d7f6e30220d7f86081927deeb23f22 (patch) | |
tree | 86804befa7c03812fbd2174d3bf39264d76519f1 /id/server | |
parent | 4707d0408674020f3c0f82ab08c605cef3e4932e (diff) | |
download | moa-id-spss-3221a6d123d7f6e30220d7f86081927deeb23f22.tar.gz moa-id-spss-3221a6d123d7f6e30220d7f86081927deeb23f22.tar.bz2 moa-id-spss-3221a6d123d7f6e30220d7f86081927deeb23f22.zip |
initial commit for mapping the configuration to JSON
Diffstat (limited to 'id/server')
-rw-r--r-- | id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/ConfigurationToJSONConverter.java | 99 | ||||
-rw-r--r-- | id/server/moa-id-commons/pom.xml | 5 |
2 files changed, 104 insertions, 0 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/ConfigurationToJSONConverter.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/ConfigurationToJSONConverter.java new file mode 100644 index 000000000..36063ca2c --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/ConfigurationToJSONConverter.java @@ -0,0 +1,99 @@ +package at.gv.egovernment.moa.id.config.auth; + +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility; +import org.codehaus.jackson.annotate.JsonMethod; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; + +import at.gv.egovernment.moa.id.config.ConfigurationException; +import at.gv.egovernment.moa.id.config.ConfigurationProvider; + +public class ConfigurationToJSONConverter { + + AuthConfigurationProvider config; + + public static void main(String[] args) { + + try { + ConfigurationToJSONConverter converter = new ConfigurationToJSONConverter(); + + List<String> jsonResults = converter.convertConfigToJSONStrings(); + System.out.println(jsonResults); + + } catch (ConfigurationException e) { + e.printStackTrace(); + System.out.println("Problems reading the configuration file in: " + + System.getProperty(ConfigurationProvider.CONFIG_PROPERTY_NAME)); + System.exit(1); + } + } + + public ConfigurationToJSONConverter() throws ConfigurationException { + config = AuthConfigurationProvider.getInstance(); + } + + public void writeConfigToJSONFile(String jsonFileName) { + // get JSON + // prettyprint and write to file + + } + + public void writeConfigToJSONDB() throws ConfigurationException { + ConfigurationToJSONConverter converter = new ConfigurationToJSONConverter(); + List<String> jsonResults = converter.convertConfigToJSONStrings(); + // TODO: write to db + } + + public List<String> convertConfigToJSONStrings() { + + List<String> result = new ArrayList<String>(); + ObjectMapper mapper = new ObjectMapper(); + mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY); + + int numberOfCalledGetterMethods = 0; + try { + System.out.println("=== Start ==="); + // find all getter methods + for (PropertyDescriptor pd : Introspector.getBeanInfo(AuthConfigurationProvider.class) + .getPropertyDescriptors()) { + if (pd.getReadMethod() != null && !"class".equals(pd.getName())) { + + try { + // get result of get method + Object tmp = pd.getReadMethod().invoke(config); + // result to JSON + String show = mapper.writeValueAsString(tmp); + System.out.println(show); + result.add(show); + numberOfCalledGetterMethods++; + } catch (JsonGenerationException | JsonMappingException e) { + e.printStackTrace(); + // System.out.println("Problems while writing JSON as String"); + // return new ArrayList<String>(); + } + } + } + + // TODO: handle static methods + + } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + System.out.println("Problems while using reflection to get all getter methods."); + } catch (IOException e) { + System.out.println("Problems while writing JSON as String"); + return new ArrayList<String>(); + } + + System.out.println("=== END called:'" + numberOfCalledGetterMethods + "' getter-methods ==="); + return result; + } + +} diff --git a/id/server/moa-id-commons/pom.xml b/id/server/moa-id-commons/pom.xml index 27beeaaf3..6d499f42a 100644 --- a/id/server/moa-id-commons/pom.xml +++ b/id/server/moa-id-commons/pom.xml @@ -123,6 +123,11 @@ <artifactId>mysql-connector-java</artifactId> <version>${mysql-connector.java}</version> </dependency> + <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-mapper-asl</artifactId> + <version>1.9.13</version> + </dependency> </dependencies> <build> |