diff options
author | Gerwin Gsenger <g.gsenger@datentechnik-innovation.at> | 2015-01-13 16:35:33 +0100 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2015-06-19 11:07:46 +0200 |
commit | 7d3a585005e9907b043770891206eb591e064ebe (patch) | |
tree | 55456c0cdc851fb0ee7243f4a1c615d226a0209a /id/server/idserverlib/src | |
parent | c20d8f3da0b112864130031d39800e60289380d4 (diff) | |
download | moa-id-spss-7d3a585005e9907b043770891206eb591e064ebe.tar.gz moa-id-spss-7d3a585005e9907b043770891206eb591e064ebe.tar.bz2 moa-id-spss-7d3a585005e9907b043770891206eb591e064ebe.zip |
moved path to property file to runtime argument, small code cleanup
Diffstat (limited to 'id/server/idserverlib/src')
-rw-r--r-- | id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/ConfigurationToJSONConverter.java | 100 |
1 files changed, 18 insertions, 82 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 index 321cb150c..b47ba0e27 100644 --- 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 @@ -18,13 +18,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class ConfigurationToJSONConverter { - AuthConfigurationProvider config; - Configuration configuration; + AuthConfigurationProvider configProvider; + Configuration configDataBase; public static void main(String[] args) { try { - ConfigurationToJSONConverter converter = new ConfigurationToJSONConverter(); + ConfigurationToJSONConverter converter = new ConfigurationToJSONConverter(args[0]); converter.writeConfigToJSONDB(); System.out.println("====================================="); System.out.println("====================================="); @@ -38,31 +38,15 @@ public class ConfigurationToJSONConverter { } - public ConfigurationToJSONConverter() throws ConfigurationException { - config = AuthConfigurationProvider.getInstance(); - - System.getProperties().setProperty("location", "file:" + "c:\\Users\\cwagner\\dev\\temp\\moaid_test_db.properties"); + public ConfigurationToJSONConverter(String pathToDBConfigPropertiesFile) throws ConfigurationException { + configProvider = AuthConfigurationProvider.getInstance(); + System.getProperties().setProperty("location", "file:" + pathToDBConfigPropertiesFile); ApplicationContext context = new ClassPathXmlApplicationContext("configuration.beans.xml"); - configuration = (ConfigurationImpl) context.getBean(ConfigurationImpl.class); + configDataBase = (ConfigurationImpl) context.getBean(ConfigurationImpl.class); } - // public void writeConfigToJSONFile(String jsonFileName, boolean isPrettyPrint) throws FileNotFoundException, - // IOException, ConfigurationException { - // File out = new File(jsonFileName); - // try (PrintWriter outStream = new PrintWriter(out)) { - // // get pretty printed JSON - // ConfigurationToJSONConverter converter = new ConfigurationToJSONConverter(); - // Map<String, String> jsonResults = converter.convertConfigToJSONStrings(isPrettyPrint); - // for (String name : jsonResults.keySet()) { - // outStream.println(name); - // outStream.println(jsonResults.get(name)); - // } - // } - // - // } - public void writeConfigToJSONDB() { try { @@ -75,14 +59,10 @@ public class ConfigurationToJSONConverter { // get result of get method Object tmp; try { - tmp = pd.getReadMethod().invoke(config); - + tmp = pd.getReadMethod().invoke(configProvider); // convert result to JSON - if (name != null) { - - - configuration.set(name.value(), tmp); + configDataBase.set(name.value(), tmp); } else { System.out.println("CHECK if '" + pd.getDisplayName() + "' is NOT ANNOTATED"); } @@ -90,7 +70,6 @@ public class ConfigurationToJSONConverter { // TODO Auto-generated catch block e.printStackTrace(); } - } } @@ -99,8 +78,7 @@ public class ConfigurationToJSONConverter { } catch (IllegalArgumentException e) { System.out.println("Problems while using reflection to get all getter methods."); } catch (IntrospectionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + System.out.println("Problems while using reflection to get all getter methods."); } } @@ -108,69 +86,27 @@ public class ConfigurationToJSONConverter { public void readConfigFromDB() { try { // find all getter methods - for (PropertyDescriptor pd : Introspector.getBeanInfo(AuthConfigurationProvider.class).getPropertyDescriptors()) { + for (PropertyDescriptor pd : Introspector.getBeanInfo(AuthConfigurationProvider.class) + .getPropertyDescriptors()) { // check if correct methods, and not annotated with @JsonIgnore - if ((pd.getReadMethod() != null) && (!"class".equals(pd.getName())) && (pd.getReadMethod().getAnnotation(JsonIgnore.class) == null)) { + if ((pd.getReadMethod() != null) + && (!"class".equals(pd.getName())) + && (pd.getReadMethod().getAnnotation(JsonIgnore.class) == null)) { JsonProperty name = pd.getReadMethod().getAnnotation(JsonProperty.class); // get result of get method - Object tmp; if (name != null) { - - Object o = configuration.get(name.value()); - - System.out.println(">>> OBJECT: " + o ); - + System.out.println(">>> OBJECT: " + configDataBase.get(name.value())); } else { System.out.println("CHECK if '" + pd.getDisplayName() + "' is NOT ANNOTATED"); } - } } - - // no static method handling needed - } catch (IllegalArgumentException e) { System.out.println("Problems while using reflection to get all getter methods."); } catch (IntrospectionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + System.out.println("Problems while using reflection to get all getter methods."); + } } - // ============================================================================= - // private class JsonMapper { - // - // private ObjectMapper mapper = new ObjectMapper(); - // - // public JsonMapper(){ - // this(false); - // } - // - // public JsonMapper(boolean prettyPrint) { - // mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE); - // mapper.setVisibility(PropertyAccessor.GETTER, Visibility.PUBLIC_ONLY); - // mapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.PUBLIC_ONLY); - // if (prettyPrint) { - // mapper.enable(SerializationFeature.INDENT_OUTPUT); - // } - // } - // - // public String serialize(Object value) throws JsonProcessingException { - // return mapper.writeValueAsString(value); - // } - // - // public Object deserialize(String value, Class type) throws JsonParseException, JsonMappingException, - // IOException { - // - // ObjectMapper mapper = new ObjectMapper(); - // if (type != null) { - // return mapper.readValue(value, type); - // } else { - // return mapper.readValue(value, Object.class); - // } - // - // } - // - // } } |