aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common-yang
diff options
context:
space:
mode:
authorMichael DÜrre <michael.duerre@highstreet-technologies.com>2022-03-10 10:39:16 +0100
committerDan Timoney <dtimoney@att.com>2022-03-23 15:08:48 -0400
commiteb2a7c97c0007b013bd1784ac17d57be02b63d03 (patch)
treeb0861438532727219216cfd426e21ae053abb31a /sdnr/wt/common-yang
parent3c74361514bb920ed441d105f66ca978bd074ced (diff)
migrate sdnr features to phosphorus
fix mapper and switch to dom api Updated to use phosphorus version of parent poms Issue-ID: CCSDK-3566 Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com> Change-Id: I98c5bef9286622e0d66b53db687557d798cd53f5 Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/common-yang')
-rwxr-xr-xsdnr/wt/common-yang/iana-crypt-hash/pom.xml2
-rwxr-xr-xsdnr/wt/common-yang/ietf-alarms/pom.xml2
-rwxr-xr-xsdnr/wt/common-yang/onap/pom.xml2
-rwxr-xr-xsdnr/wt/common-yang/openroadm-pm-types/pom.xml2
-rwxr-xr-xsdnr/wt/common-yang/pom.xml2
-rwxr-xr-xsdnr/wt/common-yang/rfc7317-ietf-system/pom.xml2
-rwxr-xr-xsdnr/wt/common-yang/rfc8341/pom.xml2
-rw-r--r--sdnr/wt/common-yang/utils/pom.xml9
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapper.java27
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapperHelper.java38
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsDeserializerModifier.java144
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsDeserializerModifier2.java135
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangtoolsMapDesirializer.java44
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangtoolsMapDesirializer2.java36
-rw-r--r--sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestDataMappings.java99
-rw-r--r--sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestHashMap.java80
-rw-r--r--sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestMapper.java92
-rw-r--r--sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangGenSalMapping.java286
18 files changed, 411 insertions, 593 deletions
diff --git a/sdnr/wt/common-yang/iana-crypt-hash/pom.xml b/sdnr/wt/common-yang/iana-crypt-hash/pom.xml
index a6aaa8f76..6bd1b3e8b 100755
--- a/sdnr/wt/common-yang/iana-crypt-hash/pom.xml
+++ b/sdnr/wt/common-yang/iana-crypt-hash/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>2.3.2</version>
+ <version>2.3.3-SNAPSHOT</version>
<relativePath/>
</parent>
diff --git a/sdnr/wt/common-yang/ietf-alarms/pom.xml b/sdnr/wt/common-yang/ietf-alarms/pom.xml
index fb181a67b..eb24462bb 100755
--- a/sdnr/wt/common-yang/ietf-alarms/pom.xml
+++ b/sdnr/wt/common-yang/ietf-alarms/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>2.3.2</version>
+ <version>2.3.3-SNAPSHOT</version>
<relativePath/>
</parent>
diff --git a/sdnr/wt/common-yang/onap/pom.xml b/sdnr/wt/common-yang/onap/pom.xml
index d3960ed91..102b12f4f 100755
--- a/sdnr/wt/common-yang/onap/pom.xml
+++ b/sdnr/wt/common-yang/onap/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>2.3.2</version>
+ <version>2.3.3-SNAPSHOT</version>
<relativePath/>
</parent>
diff --git a/sdnr/wt/common-yang/openroadm-pm-types/pom.xml b/sdnr/wt/common-yang/openroadm-pm-types/pom.xml
index 384d8d786..7fe125893 100755
--- a/sdnr/wt/common-yang/openroadm-pm-types/pom.xml
+++ b/sdnr/wt/common-yang/openroadm-pm-types/pom.xml
@@ -28,7 +28,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>2.3.2</version>
+ <version>2.3.3-SNAPSHOT</version>
<relativePath/>
</parent>
diff --git a/sdnr/wt/common-yang/pom.xml b/sdnr/wt/common-yang/pom.xml
index 76f0aa125..15cfd1da8 100755
--- a/sdnr/wt/common-yang/pom.xml
+++ b/sdnr/wt/common-yang/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>2.3.2</version>
+ <version>2.3.3-SNAPSHOT</version>
<relativePath/>
</parent>
diff --git a/sdnr/wt/common-yang/rfc7317-ietf-system/pom.xml b/sdnr/wt/common-yang/rfc7317-ietf-system/pom.xml
index 4b6cc612e..ae8a7b7e7 100755
--- a/sdnr/wt/common-yang/rfc7317-ietf-system/pom.xml
+++ b/sdnr/wt/common-yang/rfc7317-ietf-system/pom.xml
@@ -28,7 +28,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>2.3.2</version>
+ <version>2.3.3-SNAPSHOT</version>
<relativePath/>
</parent>
diff --git a/sdnr/wt/common-yang/rfc8341/pom.xml b/sdnr/wt/common-yang/rfc8341/pom.xml
index d2bdbeaea..b7180e020 100755
--- a/sdnr/wt/common-yang/rfc8341/pom.xml
+++ b/sdnr/wt/common-yang/rfc8341/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>2.3.2</version>
+ <version>2.3.3-SNAPSHOT</version>
<relativePath/>
</parent>
diff --git a/sdnr/wt/common-yang/utils/pom.xml b/sdnr/wt/common-yang/utils/pom.xml
index dd844815a..3708d0470 100644
--- a/sdnr/wt/common-yang/utils/pom.xml
+++ b/sdnr/wt/common-yang/utils/pom.xml
@@ -28,7 +28,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>2.3.2</version>
+ <version>2.3.3-SNAPSHOT</version>
<relativePath/>
</parent>
@@ -74,16 +74,9 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>sdnr-wt-data-provider-model</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.opendaylight.netconf</groupId>
<artifactId>sal-netconf-connector</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
-
</project>
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapper.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapper.java
index f406ea97d..7d73afae0 100644
--- a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapper.java
+++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapper.java
@@ -22,11 +22,13 @@
package org.onap.ccsdk.features.sdnr.wt.yang.mapper;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.KeyDeserializer;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.PropertyNamingStrategy;
+import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import org.onap.ccsdk.features.sdnr.wt.yang.mapper.mapperextensions.YangToolsBuilderAnnotationIntrospector;
import org.onap.ccsdk.features.sdnr.wt.yang.mapper.mapperextensions.YangToolsModule;
import org.slf4j.Logger;
@@ -44,7 +46,7 @@ public class YangToolsMapper extends ObjectMapper {
private final YangToolsBuilderAnnotationIntrospector annotationIntrospector;
private final YangToolsModule module;
private static final long serialVersionUID = 1L;
-
+ private boolean isModuleRegistered=false;
public YangToolsMapper() {
this(new YangToolsBuilderAnnotationIntrospector());
}
@@ -54,13 +56,12 @@ public class YangToolsMapper extends ObjectMapper {
this.annotationIntrospector = yangToolsBuilderAnnotationIntrospector;
this.module = new YangToolsModule();
+ this.registerModule(this.module);
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
+ setPropertyNamingStrategy(PropertyNamingStrategies.KEBAB_CASE);
setSerializationInclusion(Include.NON_NULL);
enable(MapperFeature.USE_GETTERS_AS_SETTERS);
setAnnotationIntrospector(yangToolsBuilderAnnotationIntrospector);
- registerModule(this.module);
-
}
public void addDeserializer(Class<?> clsToDeserialize, String builderClassName) {
this.annotationIntrospector.addDeserializer(clsToDeserialize, builderClassName);
@@ -69,5 +70,21 @@ public class YangToolsMapper extends ObjectMapper {
public void addKeyDeserializer(Class<?> type, KeyDeserializer deserializer) {
this.module.addKeyDeserializer(type, deserializer);
}
+ @Override
+ public <T> T readValue(String content, Class<T> valueType) throws JsonProcessingException, JsonMappingException {
+ if(!this.isModuleRegistered) {
+ this.registerModule(this.module);
+ this.isModuleRegistered=true;
+ }
+ return super.readValue(content, valueType);
+ }
+ @Override
+ public String writeValueAsString(Object value) throws JsonProcessingException {
+ if(!this.isModuleRegistered) {
+ this.registerModule(this.module);
+ this.isModuleRegistered=true;
+ }
+ return super.writeValueAsString(value);
+ }
}
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapperHelper.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapperHelper.java
index d468e075c..fe7631a6d 100644
--- a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapperHelper.java
+++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapperHelper.java
@@ -22,6 +22,8 @@
package org.onap.ccsdk.features.sdnr.wt.yang.mapper;
import com.fasterxml.jackson.databind.DeserializationContext;
+import com.google.common.collect.Maps;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -32,6 +34,7 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
@@ -40,6 +43,8 @@ import org.opendaylight.mdsal.dom.api.DOMNotification;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.EventInstantAware;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -278,12 +283,6 @@ public class YangToolsMapperHelper {
return notification instanceof DOMEvent;
}
- /**
- * Get time instant from notification if available or default
- * @param notification
- * @param defaultValue
- * @return DateAndTime
- */
public static DateAndTime getTime(Notification notification, Instant defaultValue) {
Instant time;
if (hasTime(notification)) { // If notification class extends/implements the EventInstantAware
@@ -296,21 +295,6 @@ public class YangToolsMapperHelper {
return DateAndTime.getDefaultInstance(ZonedDateTime.ofInstant(time, ZoneOffset.UTC).format(formatterOutput));
}
- /**
- * Get time instant from notification if available or actual time
- * @param notification
- * @return DateAndTime
- */
- public static DateAndTime getTime(Notification notification) {
- return getTime(notification, Instant.now());
- }
-
- /**
- * Get time instant from DOM notification if available or default
- * @param DOM notification
- * @param defaultValue
- * @return DateAndTime
- */
public static DateAndTime getTime(DOMNotification notification, Instant defaultValue) {
Instant time;
if (hasTime(notification)) { // If notification class extends/implements the EventInstantAware
@@ -322,13 +306,9 @@ public class YangToolsMapperHelper {
}
return DateAndTime.getDefaultInstance(ZonedDateTime.ofInstant(time, ZoneOffset.UTC).format(formatterOutput));
}
-
- /**
- * Get time instant from notification if available or actual time
- * @param DOM notification
- * @return DateAndTime
- */
- public static DateAndTime getTime(DOMNotification notification) {
- return getTime(notification, Instant.now());
+
+
+ public static <K extends Identifier<V>, V extends Identifiable<K>> Map<K,V> toMap(List<V> list) {
+ return list == null || list.isEmpty() ? null : Maps.uniqueIndex(list, Identifiable::key);
}
}
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsDeserializerModifier.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsDeserializerModifier.java
index 58e75bde5..0fe8ab9d7 100644
--- a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsDeserializerModifier.java
+++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsDeserializerModifier.java
@@ -29,6 +29,9 @@ import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.KeyDeserializer;
import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;
+import com.fasterxml.jackson.databind.type.ArrayType;
+import com.fasterxml.jackson.databind.type.MapType;
+
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -48,80 +51,87 @@ import org.slf4j.LoggerFactory;
public class YangToolsDeserializerModifier extends BeanDeserializerModifier {
- private static final Logger LOG = LoggerFactory.getLogger(YangToolsDeserializerModifier.class);
- private static final String getEnumMethodName = "valueOf";
- private static final String getEnumMethodName2 = "forName";
+ private static final Logger LOG = LoggerFactory.getLogger(YangToolsDeserializerModifier.class);
+ private static final String getEnumMethodName = "valueOf";
+ private static final String getEnumMethodName2 = "forName";
+
+ @SuppressWarnings("unchecked")
+ public static Enum<?> parseEnum(String value, Class<?> clazz) throws IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
+ try {
+ Method method = clazz.getDeclaredMethod(getEnumMethodName, String.class);
+ Enum<?> result = (Enum<?>) method.invoke(null, value);
+ LOG.debug("Deserialize '{}' with class '{}' to '{}'", value, clazz.getName(), result);
+ return result;
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
+ | NoSuchElementException | SecurityException e) {
+ Method method = clazz.getDeclaredMethod(getEnumMethodName2, String.class);
+ Optional<Enum<?>> result = (Optional<Enum<?>>) method.invoke(null, value);
+ LOG.debug("Deserialize '{}' with class '{}' to '{}'", value, clazz.getName(), result);
+ return result.orElseThrow();
+ }
+ }
- @SuppressWarnings("unchecked")
- public static Enum<?> parseEnum(String value, Class<?> clazz) throws IllegalAccessException,
- IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
- try {
- Method method = clazz.getDeclaredMethod(getEnumMethodName, String.class);
- Enum<?> result = (Enum<?>) method.invoke(null, value);
- LOG.debug("Deserialize '{}' with class '{}' to '{}'", value, clazz.getName(), result);
- return result;
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
- | NoSuchElementException | SecurityException e) {
- Method method = clazz.getDeclaredMethod(getEnumMethodName2, String.class);
- Optional<Enum<?>> result = (Optional<Enum<?>>) method.invoke(null, value);
- LOG.debug("Deserialize '{}' with class '{}' to '{}'", value, clazz.getName(), result);
- return result.orElseThrow();
- }
- }
+ @Override
+ public JsonDeserializer<Enum<?>> modifyEnumDeserializer(DeserializationConfig config, final JavaType type,
+ BeanDescription beanDesc, final JsonDeserializer<?> deserializer) {
+ return new JsonDeserializer<Enum<?>>() {
- @Override
- public JsonDeserializer<Enum<?>> modifyEnumDeserializer(DeserializationConfig config, final JavaType type,
- BeanDescription beanDesc, final JsonDeserializer<?> deserializer) {
- return new JsonDeserializer<Enum<?>>() {
+ @Override
+ public Enum<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
+ Class<?> clazz = type.getRawClass();
- @Override
- public Enum<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
- Class<?> clazz = type.getRawClass();
+ try {
+ return parseEnum(jp.getValueAsString(), clazz);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | NoSuchMethodException | NoSuchElementException | SecurityException e) {
+ LOG.warn("problem deserializing enum for {} with value {}: {}", clazz.getName(),
+ jp.getValueAsString(), e);
+ }
+ throw new IOException(
+ "unable to parse enum (" + type.getRawClass() + ")for value " + jp.getValueAsString());
+ }
+ };
+ }
- try {
- return parseEnum(jp.getValueAsString(), clazz);
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | NoSuchMethodException | NoSuchElementException | SecurityException e) {
- LOG.warn("problem deserializing enum for {} with value {}: {}", clazz.getName(),
- jp.getValueAsString(), e);
- }
- throw new IOException(
- "unable to parse enum (" + type.getRawClass() + ")for value " + jp.getValueAsString());
- }
- };
- }
+ @Override
+ public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc,
+ JsonDeserializer<?> deserializer) {
+ final JavaType type = beanDesc.getType();
+ final Class<?> rawClass = type.getRawClass();
- @Override
- public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc,
- JsonDeserializer<?> deserializer) {
- final JavaType type = beanDesc.getType();
- final Class<?> rawClass = type.getRawClass();
+ JsonDeserializer<?> deser = super.modifyDeserializer(config, beanDesc, deserializer);
- JsonDeserializer<?> deser = super.modifyDeserializer(config, beanDesc, deserializer);
+ if (YangToolsMapperHelper.implementsInterface(rawClass, TypeObject.class)) {
+ deser = new TypeObjectDeserializer<TypeObject>(type, deser);
+ } else if (YangToolsMapperHelper.implementsInterface(rawClass, ScalarTypeObject.class)) {
+ deser = new TypeObjectDeserializer<ScalarTypeObject<?>>(type, deser);
+ } else if (YangToolsMapperHelper.implementsInterface(rawClass, BaseIdentity.class)) {
+ deser = new BaseIdentityDeserializer<BaseIdentity>(deser);
+ } else if (rawClass.equals(Class.class)) {
+ deser = new ClassDeserializer(rawClass);
+ }
- if (YangToolsMapperHelper.implementsInterface(rawClass, TypeObject.class)) {
- deser = new TypeObjectDeserializer<TypeObject>(type, deser);
- } else if (YangToolsMapperHelper.implementsInterface(rawClass, ScalarTypeObject.class)) {
- deser = new TypeObjectDeserializer<ScalarTypeObject<?>>(type, deser);
- } else if (YangToolsMapperHelper.implementsInterface(rawClass, BaseIdentity.class)) {
- deser = new BaseIdentityDeserializer<BaseIdentity>(deser);
- } else if (rawClass.equals(Class.class)) {
- deser = new ClassDeserializer(rawClass);
- }
+ LOG.debug("Deserialize '{}' with deserializer '{}'", rawClass.getName(), deser.getClass().getName());
+ return deser;
+ }
- LOG.debug("Deserialize '{}' with deserializer '{}'", rawClass.getName(), deser.getClass().getName());
- return deser;
- }
+ @Override
+ public JsonDeserializer<?> modifyMapDeserializer(DeserializationConfig config, MapType type,
+ BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
+ final Class<?> rawClass = type.getBindings().getBoundType(1).getRawClass();
+ return new YangtoolsMapDesirializer(rawClass);
+ }
- @Override
- public KeyDeserializer modifyKeyDeserializer(DeserializationConfig config, JavaType type, KeyDeserializer deser) {
- KeyDeserializer res;
- if (YangToolsMapperHelper.implementsInterface(type.getRawClass(), Identifier.class)) {
- res = new IdentifierDeserializer();
- } else {
- res = super.modifyKeyDeserializer(config, type, deser);
- }
- LOG.debug("Keydeserialize '{}' with deserializer '{}'", type.getRawClass().getName(), res.getClass().getName());
- return res;
- }
+ @Override
+ public KeyDeserializer modifyKeyDeserializer(DeserializationConfig config, JavaType type, KeyDeserializer deser) {
+ KeyDeserializer res;
+ if (YangToolsMapperHelper.implementsInterface(type.getRawClass(), Identifier.class)) {
+ res = new IdentifierDeserializer();
+ } else {
+ res = super.modifyKeyDeserializer(config, type, deser);
+ }
+ LOG.debug("Keydeserialize '{}' with deserializer '{}'", type.getRawClass().getName(), res.getClass().getName());
+ return res;
+ }
}
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsDeserializerModifier2.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsDeserializerModifier2.java
new file mode 100644
index 000000000..0697f5f2e
--- /dev/null
+++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsDeserializerModifier2.java
@@ -0,0 +1,135 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.yang.mapper.mapperextensions;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.BeanDescription;
+import com.fasterxml.jackson.databind.DeserializationConfig;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.KeyDeserializer;
+import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;
+import com.fasterxml.jackson.databind.type.MapType;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.NoSuchElementException;
+import java.util.Optional;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.BaseIdentityDeserializer;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.ClassDeserializer;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.IdentifierDeserializer;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.TypeObjectDeserializer;
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.ScalarTypeObject;
+import org.opendaylight.yangtools.yang.binding.TypeObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class YangToolsDeserializerModifier2 extends BeanDeserializerModifier {
+
+ private static final Logger LOG = LoggerFactory.getLogger(YangToolsDeserializerModifier2.class);
+ private static final String getEnumMethodName = "valueOf";
+ private static final String getEnumMethodName2 = "forName";
+
+ @SuppressWarnings("unchecked")
+ public static Enum<?> parseEnum(String value, Class<?> clazz) throws IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
+ try {
+ Method method = clazz.getDeclaredMethod(getEnumMethodName, String.class);
+ Enum<?> result = (Enum<?>) method.invoke(null, value);
+ LOG.debug("Deserialize '{}' with class '{}' to '{}'", value, clazz.getName(), result);
+ return result;
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
+ | NoSuchElementException | SecurityException e) {
+ Method method = clazz.getDeclaredMethod(getEnumMethodName2, String.class);
+ Optional<Enum<?>> result = (Optional<Enum<?>>) method.invoke(null, value);
+ LOG.debug("Deserialize '{}' with class '{}' to '{}'", value, clazz.getName(), result);
+ return result.orElseThrow();
+ }
+ }
+
+ @Override
+ public JsonDeserializer<Enum<?>> modifyEnumDeserializer(DeserializationConfig config, final JavaType type,
+ BeanDescription beanDesc, final JsonDeserializer<?> deserializer) {
+ return new JsonDeserializer<Enum<?>>() {
+
+ @Override
+ public Enum<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
+ Class<?> clazz = type.getRawClass();
+
+ try {
+ return parseEnum(jp.getValueAsString(), clazz);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | NoSuchMethodException | NoSuchElementException | SecurityException e) {
+ LOG.warn("problem deserializing enum for {} with value {}: {}", clazz.getName(),
+ jp.getValueAsString(), e);
+ }
+ throw new IOException(
+ "unable to parse enum (" + type.getRawClass() + ")for value " + jp.getValueAsString());
+ }
+ };
+ }
+
+ @Override
+ public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc,
+ JsonDeserializer<?> deserializer) {
+ final JavaType type = beanDesc.getType();
+ final Class<?> rawClass = type.getRawClass();
+
+ JsonDeserializer<?> deser = super.modifyDeserializer(config, beanDesc, deserializer);
+
+ if (YangToolsMapperHelper.implementsInterface(rawClass, TypeObject.class)) {
+ deser = new TypeObjectDeserializer<TypeObject>(type, deser);
+ } else if (YangToolsMapperHelper.implementsInterface(rawClass, ScalarTypeObject.class)) {
+ deser = new TypeObjectDeserializer<ScalarTypeObject<?>>(type, deser);
+ } else if (YangToolsMapperHelper.implementsInterface(rawClass, BaseIdentity.class)) {
+ deser = new BaseIdentityDeserializer<BaseIdentity>(deser);
+ } else if (rawClass.equals(Class.class)) {
+ deser = new ClassDeserializer(rawClass);
+ }
+
+ LOG.debug("Deserialize '{}' with deserializer '{}'", rawClass.getName(), deser.getClass().getName());
+ return deser;
+ }
+
+ @Override
+ public JsonDeserializer<?> modifyMapDeserializer(DeserializationConfig config, MapType type,
+ BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
+ final Class<?> rawClass = type.getBindings().getBoundType(1).getRawClass();
+ return new YangtoolsMapDesirializer(rawClass);
+ }
+
+ @Override
+ public KeyDeserializer modifyKeyDeserializer(DeserializationConfig config, JavaType type, KeyDeserializer deser) {
+ KeyDeserializer res;
+ if (YangToolsMapperHelper.implementsInterface(type.getRawClass(), Identifier.class)) {
+ res = new IdentifierDeserializer();
+ } else {
+ res = super.modifyKeyDeserializer(config, type, deser);
+ }
+ LOG.debug("Keydeserialize '{}' with deserializer '{}'", type.getRawClass().getName(), res.getClass().getName());
+ return res;
+ }
+}
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangtoolsMapDesirializer.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangtoolsMapDesirializer.java
new file mode 100644
index 000000000..2fe7fa11f
--- /dev/null
+++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangtoolsMapDesirializer.java
@@ -0,0 +1,44 @@
+package org.onap.ccsdk.features.sdnr.wt.yang.mapper.mapperextensions;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.core.TreeNode;
+import com.fasterxml.jackson.databind.BeanDescription;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.type.CollectionLikeType;
+import com.fasterxml.jackson.databind.type.TypeFactory;
+import com.google.common.collect.Maps;
+
+public class YangtoolsMapDesirializer<K extends Identifier<V>, V extends Identifiable<K>>
+ extends JsonDeserializer<Map<K, V>> {
+
+ private final Class<V> clazz;
+ private final YangToolsMapper mapper;
+
+ public YangtoolsMapDesirializer(Class<V> clazz) {
+ super();
+ this.clazz = clazz;
+ this.mapper = new YangToolsMapper();
+ }
+
+ @Override
+ public Map<K, V> deserialize(JsonParser p, DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+ CollectionLikeType type = ctxt.getTypeFactory().constructCollectionType(List.class, clazz);
+ List<V> list = mapper.readValue(p,type);
+ return YangToolsMapperHelper.toMap(list);
+ }
+
+}
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangtoolsMapDesirializer2.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangtoolsMapDesirializer2.java
new file mode 100644
index 000000000..6a419eee1
--- /dev/null
+++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangtoolsMapDesirializer2.java
@@ -0,0 +1,36 @@
+package org.onap.ccsdk.features.sdnr.wt.yang.mapper.mapperextensions;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.type.CollectionLikeType;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+
+public class YangtoolsMapDesirializer2<K extends Identifier<V>, V extends Identifiable<K>>
+ extends JsonDeserializer<Map<K, V>> {
+
+ private final Class<V> clazz;
+ private final YangToolsMapper mapper;
+
+ public YangtoolsMapDesirializer2(Class<V> clazz) {
+ super();
+ this.clazz = clazz;
+ this.mapper = new YangToolsMapper();
+ }
+
+ @Override
+ public Map<K, V> deserialize(JsonParser p, DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+ CollectionLikeType type = ctxt.getTypeFactory().constructCollectionType(List.class, clazz);
+ List<V> list = mapper.readValue(p,type);
+ return YangToolsMapperHelper.toMap(list);
+ }
+
+}
diff --git a/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestDataMappings.java b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestDataMappings.java
deleted file mode 100644
index 584b4b044..000000000
--- a/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestDataMappings.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : ccsdk features
- * ================================================================================
- * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- */
-package org.onap.ccsdk.features.sdnr.wt.yang.mapper;
-
-import static org.junit.Assert.fail;
-import java.io.IOException;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data;
-
-public class TestDataMappings {
-
- // @formatter:off
- private static final String PMDATA15M_SERVERDB_JSON = "{\n"
- + "\"node-name\": \"sim2\",\n"
- + "\"uuid-interface\": \"LP-MWPS-TTP-01\",\n"
- + "\"layer-protocol-name\": \"MWPS\",\n"
- + "\"radio-signal-id\": \"Test11\",\n"
- + "\"time-stamp\": \"2017-07-04T14:00:00.0Z\",\n"
- + "\"granularity-period\": \"Period15Min\",\n"
- + "\"scanner-id\": \"PM_RADIO_15M_9\",\n"
- + "\"performance-data\": {\n"
- + "\"es\": 0,\n"
- + "\"rx-level-avg\": -41,\n"
- + "\"time2-states\": -1,\n"
- + "\"time4-states-s\": 0,\n"
- + "\"time4-states\": 0,\n"
- + "\"time8-states\": 0,\n"
- + "\"time16-states-s\": -1,\n"
- + "\"time16-states\": 0,\n"
- + "\"time32-states\": 0,\n"
- + "\"time64-states\": 0,\n"
- + "\"time128-states\": 0,\n"
- + "\"time256-states\": 900,\n"
- + "\"time512-states\": -1,\n"
- + "\"time512-states-l\": -1,\n"
- + "\"time1024-states\": -1,\n"
- + "\"time1024-states-l\": -1,\n"
- + "\"time2048-states\": -1,\n"
- + "\"time2048-states-l\": -1,\n"
- + "\"time4096-states\": -1,\n"
- + "\"time4096-states-l\": -1,\n"
- + "\"time8192-states\": -1,\n"
- + "\"time8192-states-l\": -1,\n"
- + "\"snir-min\": -99,\n"
- + "\"snir-max\": -99,\n"
- + "\"snir-avg\": -99,\n"
- + "\"xpd-min\": -99,\n"
- + "\"xpd-max\": -99,\n"
- + "\"xpd-avg\": -99,\n"
- + "\"rf-temp-min\": -99,\n"
- + "\"rf-temp-max\": -99,\n"
- + "\"rf-temp-avg\": -99,\n"
- + "\"defect-blocks-sum\": -1,\n"
- + "\"time-period\": 900,\n"
- + "\"tx-level-min\": 25,\n"
- + "\"tx-level-max\": 25,\n"
- + "\"tx-level-avg\": 25,\n"
- + "\"rx-level-min\": -41,\n"
- + "\"rx-level-max\": -41,\n"
- + "\"unavailability\": 0,\n"
- + "\"ses\": 0,\n"
- + "\"cses\": 0\n"
- + "},\n"
- + "\"suspect-interval-flag\": false\n"
- + "}";
- // @formatter:on
- @Test
- public void testPmData15m() throws ClassNotFoundException {
-
- YangToolsMapper2<Data> mapper = new YangToolsMapper2<Data>(Data.class, null);
- try {
- Data data = mapper.readValue(PMDATA15M_SERVERDB_JSON.getBytes(), Data.class);
- System.out.println(data);
- } catch (IOException e) {
- e.printStackTrace();
- fail("Can not parse data");
- }
- }
-
-}
diff --git a/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestHashMap.java b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestHashMap.java
new file mode 100644
index 000000000..9aacd2e49
--- /dev/null
+++ b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestHashMap.java
@@ -0,0 +1,80 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.yang.mapper;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import org.junit.Test;
+
+public class TestHashMap {
+
+ String mapDataString = "[\n"
+ + " {\n"
+ + " \"Name\": \"System Idle Process\",\n"
+ + " \"CreationDate\": \"20160409121836.675345+330\"\n"
+ + " },\n"
+ + " {\n"
+ + " \"Name\": \"System\",\n"
+ + " \"CreationDate\": \"20160409121836.675345+330\"\n"
+ + " },\n"
+ + " {\n"
+ + " \"Name\": \"smss.exe\",\n"
+ + " \"CreationDate\": \"20160409121836.684966+330\"\n"
+ + " }\n"
+ + "]";
+
+
+ @Test
+ public void test() throws JsonParseException, JsonMappingException, IOException {
+ byte[] mapData = mapDataString.getBytes();
+ List<Map<String, Object>> myMap;
+ ObjectMapper objectMapper=new ObjectMapper();
+ objectMapper.registerModule(new YangToolsModule());
+
+
+ myMap = objectMapper.readValue(mapData, new TypeReference<List<Map<String, Object>>>(){});
+ System.out.println("Type1: "+myMap.getClass().getSimpleName());
+ System.out.println("Type2: "+myMap.get(0).getClass().getSimpleName());
+ System.out.println("Map is: "+myMap); }
+
+ private class YangToolsModule extends SimpleModule {
+
+ private static final long serialVersionUID = 1L;
+
+ public YangToolsModule() {
+ super();
+ setDeserializerModifier(new YangToolsDeserializerModifier());
+ }
+ }
+
+ private class YangToolsDeserializerModifier extends BeanDeserializerModifier {
+ }
+
+
+}
diff --git a/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestMapper.java b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestMapper.java
deleted file mode 100644
index 2d2e0114c..000000000
--- a/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestMapper.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : ccsdk features
- * ================================================================================
- * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- */
-package org.onap.ccsdk.features.sdnr.wt.yang.mapper;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import org.json.JSONObject;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnection;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
-
-public class TestMapper {
-
- private static final YangToolsMapper MAPPER = new YangToolsMapper();
-
- @Test
- public void testYangGenEnumMapperDeser() {
- NetworkElementConnection con = null;
- try {
- con = MAPPER.readValue("{\"device-type\":\"O-RAN\"}", NetworkElementConnection.class);
- } catch (JsonProcessingException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- assertEquals(NetworkElementDeviceType.ORAN, con.getDeviceType());
- try {
- con = MAPPER.readValue("{\"device-type\":\"ORAN\"}", NetworkElementConnection.class);
- } catch (JsonProcessingException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- assertEquals(NetworkElementDeviceType.ORAN, con.getDeviceType());
- try {
- con = MAPPER.readValue("{\"device-type\":\"O-ROADM\"}", NetworkElementConnection.class);
- } catch (JsonProcessingException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- assertEquals(NetworkElementDeviceType.OROADM, con.getDeviceType());
- try {
- con = MAPPER.readValue("{\"device-type\":\"O-ROADM\"}", NetworkElementConnection.class);
- } catch (JsonProcessingException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- assertEquals(NetworkElementDeviceType.OROADM, con.getDeviceType());
- }
-
- @Test
- public void testYangGenEnumMapperSer() {
- NetworkElementConnection con =
- new NetworkElementConnectionBuilder().setDeviceType(NetworkElementDeviceType.ORAN).build();
- String str = null;
- try {
- str = MAPPER.writeValueAsString(con);
- } catch (JsonProcessingException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- assertEquals("O-RAN", new JSONObject(str).getString("device-type"));
- con = new NetworkElementConnectionBuilder().setDeviceType(NetworkElementDeviceType.OROADM).build();
- str = null;
- try {
- str = MAPPER.writeValueAsString(con);
- } catch (JsonProcessingException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- assertEquals("O-ROADM", new JSONObject(str).getString("device-type"));
- }
-}
diff --git a/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangGenSalMapping.java b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangGenSalMapping.java
deleted file mode 100644
index f46729c98..000000000
--- a/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangGenSalMapping.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : ccsdk features
- * ================================================================================
- * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- */
-package org.onap.ccsdk.features.sdnr.wt.yang.mapper;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.json.JSONObject;
-import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.IdentifierDeserializer;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.OdlHelloMessageCapabilitiesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.DefectSeconds;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.Measurement;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.MeasurementBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.MeasurementKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata15m.entity.PerformanceDataBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.DataBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.KHz;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class TestYangGenSalMapping {
-
- // Create mapper for serialization and deserialization
- DataProviderYangToolsMapper mapper = new DataProviderYangToolsMapper();
-
- @Test
- public void test1() throws IOException {
-
- // Create test object
- NetconfNodeBuilder netconfNodeBuilder = new NetconfNodeBuilder();
- netconfNodeBuilder.setConnectedMessage("ConnMessage");
-
- LoginPasswordBuilder loginPasswordBuilder = new LoginPasswordBuilder();
- loginPasswordBuilder.setUsername("myTestUsername");
- loginPasswordBuilder.setPassword("myTestPassword");
- netconfNodeBuilder.setCredentials(loginPasswordBuilder.build());
-
- OdlHelloMessageCapabilitiesBuilder odlHelloMessageCapabilitiesBuilder =
- new OdlHelloMessageCapabilitiesBuilder();
- List<Uri> uriList = new ArrayList<>();
- uriList.add(new Uri("test.uri"));
- odlHelloMessageCapabilitiesBuilder.setCapability(uriList);
- netconfNodeBuilder.setOdlHelloMessageCapabilities(odlHelloMessageCapabilitiesBuilder.build());
-
- NetconfNode netconfNode = netconfNodeBuilder.build();
- out(netconfNode.toString());
-
- // Map Object to JSON String
- String res = mapper.writeValueAsString(netconfNode);
- JSONObject json = new JSONObject(res); // Convert text to object
- out(json.toString(4)); // Print it with specified indentation
-
- // Map to JSON String to Object
- NetconfNode generatedNode = mapper.readValue(res.getBytes(), NetconfNode.class);
- out(generatedNode.toString()); // Print it with specified indentation
- // Compare result
- //TODO - Guilin
- //out("Equal? "+netconfNode.equals(generatedNode));
- }
-
- @Test
- public void test3() throws IOException {
-
- PerformanceDataBuilder performanceBuilder = new PerformanceDataBuilder();
- performanceBuilder.setEs(99);
- Map<MeasurementKey, Measurement> values = new HashMap<>();
-
- Measurement m = new MeasurementBuilder().setPmKey(DefectSeconds.class).setPmUnit(KHz.class)
- .setPmValue(new PmDataType(1L)).build();
- values.put(m.key(), m);
- performanceBuilder.setMeasurement(values);
- DataBuilder pmData15MinutesBuilder = new DataBuilder();
- pmData15MinutesBuilder.setLayerProtocolName("fdsaf");
- pmData15MinutesBuilder.setTimeStamp(new DateAndTime("2017-03-01T09:15:00.0Z"));
- pmData15MinutesBuilder.setPerformanceData(performanceBuilder.build());
-
- // Map Object to JSON String
- String res = mapper.writeValueAsString(pmData15MinutesBuilder.build());
- JSONObject json = new JSONObject(res); // Convert text to object
- out(json.toString(4)); // Print it with specified indentation
-
- // Map to JSON String to Object
- Data generatedNode = mapper.readValue(res.getBytes(), Data.class);
- out(generatedNode.toString()); // Print it with specified indentation
- }
-
- @Test
- public void test4() throws IOException {
- // @formatter:off
- String jsonString = "{\n"
- + "\"node-name\": \"Sim2230\",\n"
- + "\"uuid-interface\": \"LP-MWPS-TTP-RADIO\",\n"
- + "\"layer-protocol-name\": \"MWPS\",\n"
- + "\"radio-signal-id\": \"Test8\",\n"
- + "\"time-stamp\": \"2017-03-01T09:15:00.0Z\",\n"
- + "\"granularity-period\": \"Period15Min\",\n"
- + "\"scanner-id\": \"PM_RADIO_15M_4\",\n"
- + "\"performance-data\": {\n"
- + "\"unavailability\": 0,\n"
- + "\"tx-level-max\": 3,\n"
- + "\"tx-level-avg\": 3,\n"
- + "\"rx-level-min\": -44,\n"
- + "\"rx-level-max\": -45,\n"
- + "\"rx-level-avg\": -44,\n"
- + "\"time2-states\": 0,\n"
- + "\"time4-states-s\": 0,\n"
- + "\"time4-states\": 0,\n"
- + "\"time8-states\": -1,\n"
- + "\"time16-states-s\": -1,\n"
- + "\"time16-states\": 0,\n"
- + "\"time32-states\": -1,\n"
- + "\"time64-states\": 900,\n"
- + "\"time128-states\": -1,\n"
- + "\"time256-states\": -1,\n"
- + "\"time512-states\": -1,\n"
- + "\"time512-states-l\": -1,\n"
- + "\"time1024-states\": -1,\n"
- + "\"time1024-states-l\": -1,\n"
- + "\"time8192-states-l\": -1,\n"
- + "\"time8192-states\": -1,\n"
- + "\"time2048-states\": -1,\n"
- + "\"snir-min\": -99,\n"
- + "\"snir-max\": -99,\n"
- + "\"snir-avg\": -99,\n"
- + "\"xpd-min\": -99,\n"
- + "\"xpd-max\": -99,\n"
- + "\"xpd-avg\": -99,\n"
- + "\"rf-temp-min\": -99,\n"
- + "\"rf-temp-max\": -99,\n"
- + "\"rf-temp-avg\": -99,\n"
- + "\"defect-blocks-sum\": -1,\n"
- + "\"time-period\": 900,\n"
- + "\"cses\": 0,\n"
- + "\"time4096-states-l\": -1,\n"
- + "\"tx-level-min\": 3,\n"
- + "\"es\": 0,\n"
- + "\"time2048-states-l\": -1,\n"
- + "\"time4096-states\": -1,\n"
- + "\"ses\": 0\n"
- + "},\n"
- + "\"suspect-interval-flag\": false\n"
- + "}\n"
- + "}";
- // @formatter:on
- // Map to JSON String to Object
- Data generatedNode = mapper.readValue(jsonString.getBytes(), Data.class);
- out(generatedNode.toString()); // Print it with specified indentation
- }
-
- @Test
- public void test5() throws IOException {
- // @formatter:off
- String jsonString = "{\n"
- + " \"time-stamp\": \"2017-03-01T06:45:00.0Z\",\n"
- + " \"node-name\": \"Sim2230\",\n"
- + " \"uuid-interface\": \"LP-MWPS-TTP-RADIO\",\n"
- + " \"scanner-id\": \"PM_RADIO_15M_14\",\n"
- + " \"layer-protocol-name\": \"MWPS\",\n"
- + " \"granularity-period\": \"Period15Min\",\n"
- + " \"radio-signal-id\": \"Test8\",\n"
- + " \"suspect-interval-flag\": false,\n"
- + " \"performance-data\": {\n"
- + " \"time4096-states-l\": -1,\n"
- + " \"time16-states-s\": -1,\n"
- + " \"tx-level-max\": 3,\n"
- + " \"snir-max\": -99,\n"
- + " \"time16-states\": 0,\n"
- + " \"time64-states\": 900,\n"
- + " \"unavailability\": 0,\n"
- + " \"time8192-states-l\": -1,\n"
- + " \"time512-states\": -1,\n"
- + " \"xpd-min\": -99,\n"
- + " \"xpd-avg\": -99,\n"
- + " \"tx-level-avg\": 3,\n"
- + " \"tx-level-min\": 3,\n"
- + " \"rf-temp-min\": -99,\n"
- + " \"rf-temp-avg\": -99,\n"
- + " \"snir-avg\": -99,\n"
- + " \"snir-min\": -99,\n"
- + " \"time-period\": 900,\n"
- + " \"time2-states\": 0,\n"
- + " \"time4-states\": 0,\n"
- + " \"time8-states\": -1,\n"
- + " \"ses\": 0,\n"
- + " \"time2048-states-l\": -1,\n"
- + " \"time2048-states\": -1,\n"
- + " \"xpd-max\": -99,\n"
- + " \"rf-temp-max\": -99,\n"
- + " \"time8192-states\": -1,\n"
- + " \"time128-states\": -1,\n"
- + " \"time256-states\": -1,\n"
- + " \"rx-level-min\": -44,\n"
- + " \"rx-level-avg\": -44,\n"
- + " \"time1024-states-l\": -1,\n"
- + " \"es\": 0,\n"
- + " \"cses\": 0,\n"
- + " \"time4-states-s\": 0,\n"
- + " \"time1024-states\": -1,\n"
- + " \"time512-states-l\": -1,\n"
- + " \"time4096-states\": -1,\n"
- + " \"rx-level-max\": -45,\n"
- + " \"defect-blocks-sum\": -1,\n"
- + " \"time32-states\": -1\n"
- + " }\n"
- + "}";
- // @formatter:on
- // Map to JSON String to Object
- Data generatedNode = mapper.readValue(jsonString.getBytes(), Data.class);
- out(generatedNode.toString()); // Print it with specified indentation
- }
-
- @Test
- public void test8() throws IOException {
- out(method());
- String input;
- input = "id-dd-dd";
- System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
- input = "idDdGg";
- System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
- input = "_idDdGg";
- System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
- input = "--ff--gfg";
- System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
- input = "";
- System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
- }
-
- /* ---------------------------------
- * Private
- */
- private static String method() {
- String nameofCurrMethod = new Throwable().getStackTrace()[1].getMethodName();
- return nameofCurrMethod;
- }
-
- private static void out(String text) {
- System.out.println("----------------------");
- System.out.println(text);
- }
-
- private static class DataProviderYangToolsMapper extends YangToolsMapper {
-
- @SuppressWarnings("unused")
- private final Logger LOG = LoggerFactory.getLogger(DataProviderYangToolsMapper.class);
- private static final long serialVersionUID = 1L;
-
- public DataProviderYangToolsMapper() {
- super();
- this.addDeserializer(Credentials.class, LoginPasswordBuilder.class.getName());
- this.addKeyDeserializer(MeasurementKey.class, new IdentifierDeserializer());
- }
-
-
- }
-
-}