|
@@ -5,8 +5,8 @@ package cz.senslog.connector.model.config;
|
|
|
|
|
|
|
|
import cz.senslog.connector.tools.exception.PropertyNotFoundException;
|
|
import cz.senslog.connector.tools.exception.PropertyNotFoundException;
|
|
|
import cz.senslog.connector.tools.util.ClassUtils;
|
|
import cz.senslog.connector.tools.util.ClassUtils;
|
|
|
-import cz.senslog.connector.tools.util.LocalDateTimeUtils;
|
|
|
|
|
|
|
|
|
|
|
|
+import java.lang.reflect.Array;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
import java.time.LocalTime;
|
|
@@ -15,6 +15,8 @@ import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
import static java.lang.String.format;
|
|
import static java.lang.String.format;
|
|
|
|
|
+import static java.lang.String.valueOf;
|
|
|
|
|
+import static java.util.Collections.emptyList;
|
|
|
import static java.util.Collections.emptySet;
|
|
import static java.util.Collections.emptySet;
|
|
|
import static java.util.Optional.ofNullable;
|
|
import static java.util.Optional.ofNullable;
|
|
|
|
|
|
|
@@ -116,6 +118,15 @@ public class PropertyConfig {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * Returns property as a Double object.
|
|
|
|
|
+ * @param name - name of property.
|
|
|
|
|
+ * @return double value.
|
|
|
|
|
+ */
|
|
|
|
|
+ public Double getDoubleProperty(String name) {
|
|
|
|
|
+ return ClassUtils.cast(getProperty(name), Double.class);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* Returns property as a LocalDateTime.
|
|
* Returns property as a LocalDateTime.
|
|
|
* @param name - name of property.
|
|
* @param name - name of property.
|
|
|
* @return localDateTime value.
|
|
* @return localDateTime value.
|
|
@@ -202,22 +213,54 @@ public class PropertyConfig {
|
|
|
*/
|
|
*/
|
|
|
public <T> Set<T> getSetProperty(String name, Class<T> type) {
|
|
public <T> Set<T> getSetProperty(String name, Class<T> type) {
|
|
|
Object value = properties.get(name);
|
|
Object value = properties.get(name);
|
|
|
-
|
|
|
|
|
- if (value instanceof List) {
|
|
|
|
|
- List<Object> list = (List<Object>) value;
|
|
|
|
|
|
|
+ if (value instanceof Collection) {
|
|
|
|
|
+ Collection<?> list = (Collection<?>) value;
|
|
|
Set<T> res = new HashSet<>(list.size());
|
|
Set<T> res = new HashSet<>(list.size());
|
|
|
for (Object o : list) {
|
|
for (Object o : list) {
|
|
|
res.add(ClassUtils.cast(o, type));
|
|
res.add(ClassUtils.cast(o, type));
|
|
|
}
|
|
}
|
|
|
return res;
|
|
return res;
|
|
|
- } else if (value instanceof Set) {
|
|
|
|
|
- Set<?> set = (Set<?>) value;
|
|
|
|
|
- Set<T> res = new HashSet<>(set.size());
|
|
|
|
|
- for (Object o : set) {
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return emptySet();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public <T> List<T> getListProperty(String name, Class<T> type) {
|
|
|
|
|
+ Object object = getProperty(name);
|
|
|
|
|
+ if (object instanceof Collection) {
|
|
|
|
|
+ Collection<?> list = (Collection<?>) object;
|
|
|
|
|
+ List<T> res = new ArrayList<>(list.size());
|
|
|
|
|
+ for (Object o : list) {
|
|
|
res.add(ClassUtils.cast(o, type));
|
|
res.add(ClassUtils.cast(o, type));
|
|
|
}
|
|
}
|
|
|
return res;
|
|
return res;
|
|
|
}
|
|
}
|
|
|
|
|
+ return emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static PropertyConfig mapMapObjectoToPropertyConfig(String id, Object mapObject) {
|
|
|
|
|
+ PropertyConfig config = new PropertyConfig(id);
|
|
|
|
|
+ if (mapObject instanceof Map) {
|
|
|
|
|
+ Map<?, ?> properties = (Map<?, ?>) mapObject;
|
|
|
|
|
+ for (Map.Entry<?, ?> propertyEntry : properties.entrySet()) {
|
|
|
|
|
+ config.setProperty(propertyEntry.getKey().toString(), propertyEntry.getValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return config;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Set<PropertyConfig> getSetProperty(String name) {
|
|
|
|
|
+ Object value = properties.get(name);
|
|
|
|
|
+ if (value instanceof Collection) {
|
|
|
|
|
+ Collection<?> collection = (Collection<?>) value;
|
|
|
|
|
+ Iterator<?> iter = collection.iterator();
|
|
|
|
|
+ Set<PropertyConfig> res = new HashSet<>(collection.size());
|
|
|
|
|
+ int index = 0;
|
|
|
|
|
+ while (iter.hasNext()) {
|
|
|
|
|
+ res.add(mapMapObjectoToPropertyConfig(getNewPropertyId(name, index++), iter.next()));
|
|
|
|
|
+ }
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return emptySet();
|
|
return emptySet();
|
|
|
}
|
|
}
|
|
@@ -229,16 +272,7 @@ public class PropertyConfig {
|
|
|
*/
|
|
*/
|
|
|
public PropertyConfig getPropertyConfig(String name) {
|
|
public PropertyConfig getPropertyConfig(String name) {
|
|
|
Object property = getProperty(name);
|
|
Object property = getProperty(name);
|
|
|
- PropertyConfig config = new PropertyConfig(getNewPropertyId(name));
|
|
|
|
|
-
|
|
|
|
|
- if (property instanceof Map) {
|
|
|
|
|
- Map<String, Object> properties = (Map<String, Object>) property;
|
|
|
|
|
- for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) {
|
|
|
|
|
- config.setProperty(propertyEntry.getKey(), propertyEntry.getValue());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return config;
|
|
|
|
|
|
|
+ return mapMapObjectoToPropertyConfig(getNewPropertyId(name), property);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Set<String> getAttributes() {
|
|
public Set<String> getAttributes() {
|
|
@@ -249,6 +283,10 @@ public class PropertyConfig {
|
|
|
return id + PATH_DELIMITER + name;
|
|
return id + PATH_DELIMITER + name;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private String getNewPropertyId(String name, int index) {
|
|
|
|
|
+ return getNewPropertyId(name) + PATH_DELIMITER + index;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public String getId() {
|
|
public String getId() {
|
|
|
return id;
|
|
return id;
|
|
|
}
|
|
}
|