aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/utils
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/utils')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt10
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/utils/Logging.java4
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/utils/Multival.java54
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/utils/Streams.java11
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/utils/TimeUtils.java21
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt44
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java23
7 files changed, 165 insertions, 2 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt b/vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt
new file mode 100644
index 000000000..7ccdd1bc4
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt
@@ -0,0 +1,10 @@
+package org.onap.vid.utils
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
+
+inline fun <reified E: Enum<E>> getEnumFromMapOfStrings(map: Map<String, Any>, key:String, defaultValue:E): E {
+ return java.lang.Enum.valueOf(E::class.java, (map.getOrDefault(key, defaultValue.name) as String))
+}
+
+val JACKSON_OBJECT_MAPPER: ObjectMapper = jacksonObjectMapper() \ No newline at end of file
diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java b/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java
index 3ac905884..f02497b05 100644
--- a/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java
+++ b/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java
@@ -28,12 +28,14 @@ import static org.onap.vid.utils.Streams.not;
public class Logging {
- Logging() {
+ private Logging() {
}
public static final String HTTP_REQUESTS_OUTGOING = "http.requests.outgoing.";
public static final String REQUEST_ID_HEADER_KEY = SystemProperties.ECOMP_REQUEST_ID;
+ public static final String ONAP_REQUEST_ID_HEADER_KEY = "X-ONAP-RequestID";
+
private static ObjectMapper objectMapper = new ObjectMapper();
diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Multival.java b/vid-app-common/src/main/java/org/onap/vid/utils/Multival.java
new file mode 100644
index 000000000..3a9b518d1
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/utils/Multival.java
@@ -0,0 +1,54 @@
+package org.onap.vid.utils;
+
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+import java.util.Collection;
+import java.util.function.Function;
+
+import static java.util.stream.Collectors.toSet;
+
+@JsonPropertyOrder({"keyType", "valuesType"})
+public class Multival<K, V> {
+ private final String keyType;
+ private final String valuesType;
+ private final K key;
+ private final Collection<V> values;
+
+ private Multival(String keyType, K key, String valuesType, Collection<V> values) {
+ this.keyType = keyType;
+ this.key = key;
+ this.valuesType = valuesType;
+ this.values = values;
+ }
+
+ public static <K, V> Multival<K, V> of(String keyType, K key, String valuesType, Collection<V> values) {
+ return new Multival<>(keyType, key, valuesType, values);
+ }
+
+ public String getKeyType() {
+ return keyType;
+ }
+
+ public String getValuesType() {
+ return valuesType;
+ }
+
+ public K getKey() {
+ return key;
+ }
+
+ public Collection<V> getValues() {
+ return values;
+ }
+
+ public <W> Multival<K, W> mapEachVal(Function<V, W> mapper) {
+ return Multival.of(
+ this.getKeyType(),
+ this.getKey(),
+ this.getValuesType(),
+ this.getValues().stream()
+ .map(mapper)
+ .collect(toSet())
+ );
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Streams.java b/vid-app-common/src/main/java/org/onap/vid/utils/Streams.java
index 7f81b225a..9c836912d 100644
--- a/vid-app-common/src/main/java/org/onap/vid/utils/Streams.java
+++ b/vid-app-common/src/main/java/org/onap/vid/utils/Streams.java
@@ -9,13 +9,22 @@ import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class Streams {
+
+ private Streams() {
+ // hide the implicit public constructor
+ }
+
public static <R> Predicate<R> not(Predicate<R> predicate) {
return predicate.negate();
}
public static <T> Stream<T> fromIterator(final Iterator<T> iterator) {
Iterable<T> iterable = () -> iterator;
- return StreamSupport.<T>stream(iterable.spliterator(), false);
+ return StreamSupport.stream(iterable.spliterator(), false);
+ }
+
+ public static <T> Stream<T> fromIterable(final Iterable<T> iterable) {
+ return StreamSupport.stream(iterable.spliterator(), false);
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/TimeUtils.java b/vid-app-common/src/main/java/org/onap/vid/utils/TimeUtils.java
new file mode 100644
index 000000000..7d281454e
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/utils/TimeUtils.java
@@ -0,0 +1,21 @@
+package org.onap.vid.utils;
+
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+
+public class TimeUtils {
+ private static DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME;
+
+ private TimeUtils() {
+ // explicit private constructor, to hide the implicit public constructor
+ }
+
+ public static ZonedDateTime parseZonedDateTime(String time) {
+
+ return ZonedDateTime.from(formatter.parse(time));
+ }
+
+ public static String zonedDateTimeToString(ZonedDateTime time) {
+ return formatter.format(time);
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt b/vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt
new file mode 100644
index 000000000..28f989bb3
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt
@@ -0,0 +1,44 @@
+package org.onap.vid.utils
+
+data class Node<T>(val value:T, val children:MutableMap<T, Node<T>> = hashMapOf())
+
+data class Tree<T>(private val root:Node<T>) {
+
+ constructor(value: T) : this(Node(value))
+
+ fun getRootValue():T {
+ return root.value;
+ }
+
+ fun addPath(vararg path: T) {
+ addPath(path.asList())
+ }
+
+ fun addPath(path:Collection<T>) {
+ var currentNode = root
+ path.forEach {
+ currentNode = currentNode.children.getOrPut(it) {Node(it)}
+ }
+ }
+
+ fun getSubTree(vararg path: T): Tree<T>? {
+ return getSubTree(path.asList())
+ }
+
+ fun getSubTree(path:Collection<T>): Tree<T>? {
+ var currentNode:Node<T> = root
+ path.forEach {
+ currentNode = currentNode.children[it] ?: return null
+ }
+ return Tree(currentNode)
+ }
+
+ fun isPathExist(vararg path: T): Boolean {
+ return isPathExist(path.asList())
+ }
+
+ fun isPathExist(path:Collection<T>): Boolean {
+ return getSubTree(path)!=null
+ }
+}
+
diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java b/vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java
new file mode 100644
index 000000000..25bf0efd2
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java
@@ -0,0 +1,23 @@
+package org.onap.vid.utils;
+
+import org.onap.vid.exceptions.GenericUncheckedException;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+public class Unchecked {
+ private Unchecked() {
+ // explicit private constructor, to hide the implicit public constructor
+ }
+
+ public static URI toURI(String uri) {
+ try {
+ // Indulge spaces in the URI by the replcement
+ return new URI(uri.replace(" ", "%20"));
+ } catch (URISyntaxException e) {
+ throw new GenericUncheckedException(e);
+ }
+ }
+
+
+}