aboutsummaryrefslogtreecommitdiff
path: root/id/server/moa-id-commons/src/main/java
diff options
context:
space:
mode:
authorGerwin Gsenger <g.gsenger@datentechnik-innovation.at>2015-01-14 17:42:17 +0100
committerThomas Lenz <tlenz@iaik.tugraz.at>2015-06-19 11:07:50 +0200
commita7c3e354c481dcd0a0a59dbdae2e567ea57fa56d (patch)
treef9cf72674527854d6ac26f4a27e2efb77fef29b1 /id/server/moa-id-commons/src/main/java
parent22474d762e26931489593403774c1755601878be (diff)
downloadmoa-id-spss-a7c3e354c481dcd0a0a59dbdae2e567ea57fa56d.tar.gz
moa-id-spss-a7c3e354c481dcd0a0a59dbdae2e567ea57fa56d.tar.bz2
moa-id-spss-a7c3e354c481dcd0a0a59dbdae2e567ea57fa56d.zip
add initial getList implementation
Diffstat (limited to 'id/server/moa-id-commons/src/main/java')
-rw-r--r--id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java29
1 files changed, 24 insertions, 5 deletions
diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java
index da2c4b7e6..7a52d0c9d 100644
--- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java
+++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java
@@ -1,6 +1,7 @@
package com.datentechnik.moa.id.conf.persistence;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Required;
@@ -8,13 +9,16 @@ import org.springframework.stereotype.Component;
import com.datentechnik.moa.id.conf.persistence.dal.ConfigProperty;
import com.datentechnik.moa.id.conf.persistence.dal.ConfigPropertyDao;
-import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.type.CollectionType;
+import com.fasterxml.jackson.databind.type.TypeFactory;
/**
*
@@ -89,12 +93,26 @@ public class ConfigurationImpl implements Configuration {
}
}
+ @SuppressWarnings("unchecked")
@Override
public <T> List<T> getList(String key, Class<T> clazz) {
- // return empty list if key does not exist
- // TODO Auto-generated method stub
- return null;
+ CollectionType listType = TypeFactory.defaultInstance().constructCollectionType(List.class, clazz);
+ String json = configPropertyDao.getProperty(key).getValue();
+ ObjectMapper mapper = new ObjectMapper();
+
+ try {
+ return (List<T>) mapper.readValue(json, listType);
+ } catch (JsonMappingException e) {
+ ArrayList<T> tmp = new ArrayList<T>();
+ T value = get(key, clazz);
+ if(value != null){
+ tmp.add(value);
+ }
+ return tmp;
+ } catch (IOException e) {
+ return new ArrayList<T>();
+ }
}
private String getPropertyValue(String key) {
@@ -150,7 +168,8 @@ public class ConfigurationImpl implements Configuration {
ObjectMapper mapper = new ObjectMapper();
if (clazz != null) {
- return mapper.readValue(value, clazz);
+ JavaType javaType = TypeFactory.defaultInstance().constructType(clazz);
+ return mapper.readValue(value, javaType);
} else {
return mapper.readValue(value, Object.class);
}