From a7c3e354c481dcd0a0a59dbdae2e567ea57fa56d Mon Sep 17 00:00:00 2001 From: Gerwin Gsenger Date: Wed, 14 Jan 2015 17:42:17 +0100 Subject: add initial getList implementation --- .../moa/id/conf/persistence/ConfigurationImpl.java | 29 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'id/server/moa-id-commons/src/main/java/com/datentechnik') 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 List getList(String key, Class 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) mapper.readValue(json, listType); + } catch (JsonMappingException e) { + ArrayList tmp = new ArrayList(); + T value = get(key, clazz); + if(value != null){ + tmp.add(value); + } + return tmp; + } catch (IOException e) { + return new ArrayList(); + } } 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); } -- cgit v1.2.3