From 6ad41e3ccd398a2721f41ad61c80b7bb03f7d127 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Mon, 31 Dec 2018 17:21:27 +0200 Subject: Merge from ECOMP's repository Main Features -------------- - Async-Instantiation jobs mechanism major update; still WIP (package `org.onap.vid.job`) - New features in View/Edit: Activate fabric configuration; show related networks; soft delete - Support AAI service-tree traversal (`AAIServiceTree`) - In-memory cache for SDC models and certain A&AI queries (`CacheProviderWithLoadingCache`) - Upgrade TOSCA Parser and add parsing options; fix malformed TOSCA models - Resolve Cloud-Owner values for MSO - Pass X-ONAP headers to MSO Infrastructure -------------- - Remove codehaus' jackson mapper; use soley fasterxml 2.9.7 - Surefire invokes both TestNG and JUnit tests - Support Kotlin source files - AaiController2 which handles errors in a "Spring manner" - Inline generated-sources and remove jsonschema2pojo Quality -------- - Cumulative bug fixes (A&AI API, UI timeouts, and many more) - Many Sonar issues cleaned-up - Some unused classes removed - Minor changes in vid-automation project, allowing some API verification to run Hard Merges ------------ - HTTP Clients (MSO, A&AI, WebConfig, OutgoingRequestHeadersTest) - Moved `package org.onap.vid.controllers` to `controller`, without plural -- just to keep semantic sync with ECOMP. Reference commit in ECOMP: 3d1141625 Issue-ID: VID-378 Change-Id: I9c8d1e74caa41815891d441fc0760bb5f29c5788 Signed-off-by: Ittay Stern --- .../main/java/org/onap/vid/utils/KotlinUtils.kt | 10 ++++ .../src/main/java/org/onap/vid/utils/Logging.java | 4 +- .../src/main/java/org/onap/vid/utils/Multival.java | 54 ++++++++++++++++++++++ .../src/main/java/org/onap/vid/utils/Streams.java | 11 ++++- .../main/java/org/onap/vid/utils/TimeUtils.java | 21 +++++++++ .../src/main/java/org/onap/vid/utils/Tree.kt | 44 ++++++++++++++++++ .../main/java/org/onap/vid/utils/Unchecked.java | 23 +++++++++ 7 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/utils/Multival.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/utils/TimeUtils.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java (limited to 'vid-app-common/src/main/java/org/onap/vid/utils') 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 > getEnumFromMapOfStrings(map: Map, 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 { + private final String keyType; + private final String valuesType; + private final K key; + private final Collection values; + + private Multival(String keyType, K key, String valuesType, Collection values) { + this.keyType = keyType; + this.key = key; + this.valuesType = valuesType; + this.values = values; + } + + public static Multival of(String keyType, K key, String valuesType, Collection 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 getValues() { + return values; + } + + public Multival mapEachVal(Function 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 Predicate not(Predicate predicate) { return predicate.negate(); } public static Stream fromIterator(final Iterator iterator) { Iterable iterable = () -> iterator; - return StreamSupport.stream(iterable.spliterator(), false); + return StreamSupport.stream(iterable.spliterator(), false); + } + + public static Stream fromIterable(final Iterable 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(val value:T, val children:MutableMap> = hashMapOf()) + +data class Tree(private val root:Node) { + + constructor(value: T) : this(Node(value)) + + fun getRootValue():T { + return root.value; + } + + fun addPath(vararg path: T) { + addPath(path.asList()) + } + + fun addPath(path:Collection) { + var currentNode = root + path.forEach { + currentNode = currentNode.children.getOrPut(it) {Node(it)} + } + } + + fun getSubTree(vararg path: T): Tree? { + return getSubTree(path.asList()) + } + + fun getSubTree(path:Collection): Tree? { + var currentNode:Node = 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): 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); + } + } + + +} -- cgit 1.2.3-korg