summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common-yang/utils/src
diff options
context:
space:
mode:
authorRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2023-03-02 12:06:07 +0530
committerRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2023-03-10 10:46:55 +0530
commit6b8e4f12fc66a64fa5c5498d06891f1f5f1189ac (patch)
tree6414988944a78393509923a5ace70d66db0b29bd /sdnr/wt/common-yang/utils/src
parentd944abfab1a53a462868ae805ab5372935f854ef (diff)
Upgrade parents to 2.5.4-SNAPSHOT
Code changes as a result of changes induced by ODL Chlorine SR1 Issue-ID: CCSDK-3856 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> Change-Id: Ic08786f050e58bdb8371c8f8c25fb0db9f258cd4 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/common-yang/utils/src')
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapper.java2
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapper2.java1
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapperHelper.java46
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsDeserializerModifier.java8
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsModule.java9
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/BaseIdentityDeserializer.java32
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/BaseIdentitySerializer.java21
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/TypeObjectDeserializer.java3
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/HostBuilder.java25
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressBuilder.java25
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressNoZoneBuilder.java25
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpPrefixBuilder.java25
-rw-r--r--sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangToolsMapper.java30
-rw-r--r--sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/HostBuilder.java25
-rw-r--r--sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressBuilder.java25
-rw-r--r--sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressNoZoneBuilder.java25
-rw-r--r--sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpPrefixBuilder.java25
-rw-r--r--sdnr/wt/common-yang/utils/src/test/yang/test-yang-utils.yang35
18 files changed, 131 insertions, 256 deletions
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 0d9045658..dbc233016 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
@@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.KeyDeserializer;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
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;
@@ -58,6 +59,7 @@ public class YangToolsMapper extends ObjectMapper {
this.annotationIntrospector = yangToolsBuilderAnnotationIntrospector;
this.module = new YangToolsModule();
this.registerModule(this.module);
+ this.registerModule(new JavaTimeModule());
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
setPropertyNamingStrategy(PropertyNamingStrategies.KEBAB_CASE);
setSerializationInclusion(Include.NON_NULL);
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapper2.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapper2.java
index 6b5704078..1c7d58b48 100644
--- a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapper2.java
+++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/YangToolsMapper2.java
@@ -27,7 +27,6 @@ import java.lang.reflect.Method;
import javax.annotation.Nullable;
import org.eclipse.jdt.annotation.NonNull;
import org.onap.ccsdk.features.sdnr.wt.yang.mapper.mapperextensions.YangToolsBuilderAnnotationIntrospector;
-import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 e72e962bb..9ca07fe59 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
@@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.DeserializationContext;
import com.google.common.collect.Maps;
import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.Instant;
@@ -38,14 +39,11 @@ import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
+
import org.opendaylight.mdsal.dom.api.DOMEvent;
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.opendaylight.yangtools.yang.binding.*;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
@@ -131,12 +129,12 @@ public class YangToolsMapperHelper {
}
@SuppressWarnings("unchecked")
- public static <B extends Builder<?>> Class<B> findBuilderClass(DeserializationContext ctxt, Class<?> clazz)
+ public static Class<?> findBuilderClass(DeserializationContext ctxt, Class<?> clazz)
throws ClassNotFoundException {
- return (Class<B>) findClass(getBuilderClassName(clazz));
+ return findClass(getBuilderClassName(clazz));
}
- public static <B extends Builder<?>> Optional<Class<B>> findBuilderClassOptional(DeserializationContext ctxt,
+ public static Optional<Class<?>> findBuilderClassOptional(DeserializationContext ctxt,
Class<?> clazz) {
try {
return Optional.of(findBuilderClass(ctxt, clazz));
@@ -145,6 +143,15 @@ public class YangToolsMapperHelper {
}
}
+ public static <T extends BaseIdentity, S extends T> S getIdentityValueFromClass(Class<S> clazz) {
+ try {
+ Field valueField = clazz.getDeclaredField("VALUE");
+ return (S) valueField.get(clazz);
+ } catch (NoSuchFieldException | IllegalAccessException ignore) {
+ }
+ return null;
+ }
+
public static boolean hasClassDeclaredMethod(Class<?> clazz, String name) {
Method[] methods = clazz.getDeclaredMethods();
for (Method m : methods) {
@@ -238,7 +245,8 @@ public class YangToolsMapperHelper {
* @param name with attribute name, not null or empty
* @return converted string or null if name was empty or null
*/
- public @Nullable static String toCamelCaseAttributeName(final String name) {
+ public @Nullable
+ static String toCamelCaseAttributeName(final String name) {
if (name == null || name.isEmpty())
return null;
@@ -306,15 +314,17 @@ public class YangToolsMapperHelper {
}
return DateAndTime.getDefaultInstance(ZonedDateTime.ofInstant(time, ZoneOffset.UTC).format(formatterOutput));
}
-
-
- 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);
+
+
+ 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);
}
-
+
@SuppressWarnings("unchecked")
- public static <S,T> T callBuild(S builder) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- Method method = builder.getClass().getMethod("build");
- return (T) method.invoke(builder);
- }
+ public static <S, T> T callBuild(S builder)
+ throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
+ InvocationTargetException {
+ Method method = builder.getClass().getMethod("build");
+ return (T) method.invoke(builder);
+ }
}
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 b7f1782b6..b2fb31385 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
@@ -35,16 +35,14 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.NoSuchElementException;
import java.util.Optional;
-import java.util.Set;
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.SetDeserializer;
import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.TypeObjectDeserializer;
+import org.opendaylight.yangtools.concepts.Identifier;
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;
@@ -67,7 +65,7 @@ public class YangToolsDeserializerModifier extends BeanDeserializerModifier {
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| NoSuchElementException | SecurityException e) {
Method method = clazz.getDeclaredMethod(getEnumMethodName2, String.class);
- Optional<Enum<?>> result = (Optional<Enum<?>>) method.invoke(null, value);
+ Optional<Enum<?>> result = Optional.ofNullable((Enum<?>) method.invoke(null, value));
LOG.debug("Deserialize '{}' with class '{}' to '{}'", value, clazz.getName(), result);
return result.orElseThrow();
}
@@ -109,6 +107,8 @@ public class YangToolsDeserializerModifier extends BeanDeserializerModifier {
deser = new TypeObjectDeserializer<ScalarTypeObject<?>>(type, deser);
} else if (YangToolsMapperHelper.implementsInterface(rawClass, BaseIdentity.class)) {
deser = new BaseIdentityDeserializer<BaseIdentity>(deser);
+ } else if (YangToolsMapperHelper.implementsInterface(rawClass, Identifier.class)) {
+ deser = new BaseIdentityDeserializer<Identifier>(deser);
} else if (rawClass.equals(Class.class)) {
deser = new ClassDeserializer(rawClass);
}
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsModule.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsModule.java
index 02628dc16..8091a6042 100644
--- a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsModule.java
+++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsModule.java
@@ -23,11 +23,10 @@ package org.onap.ccsdk.features.sdnr.wt.yang.mapper.mapperextensions;
import com.fasterxml.jackson.databind.module.SimpleModule;
import java.util.Map;
-import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.DateAndTimeSerializer;
-import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.EnumSerializer;
-import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.MapSerializer;
-import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.TypeObjectSerializer;
+
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.*;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
import org.opendaylight.yangtools.yang.binding.ScalarTypeObject;
import org.opendaylight.yangtools.yang.binding.TypeObject;
@@ -44,7 +43,7 @@ public class YangToolsModule extends SimpleModule {
addSerializer(ScalarTypeObject.class, new TypeObjectSerializer());
addSerializer(Enum.class, new EnumSerializer());
addSerializer(Map.class, new MapSerializer());
-
+ addSerializer(BaseIdentity.class, new BaseIdentitySerializer());
}
}
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/BaseIdentityDeserializer.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/BaseIdentityDeserializer.java
index f85f80e2c..1c4226322 100644
--- a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/BaseIdentityDeserializer.java
+++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/BaseIdentityDeserializer.java
@@ -25,8 +25,16 @@ 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 java.io.IOException;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import com.google.common.reflect.ClassPath;
+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.BaseIdentity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,25 +47,35 @@ public class BaseIdentityDeserializer<T> extends JsonDeserializer<T> {
this.deser = deser;
}
+ private static List<Class<? extends BaseIdentity>> getTypesInNamespace(String packageName) throws IOException {
+ return ClassPath.from(Thread.currentThread().getContextClassLoader()).getTopLevelClasses(packageName).
+ stream().map(e -> (Class<? extends BaseIdentity>)e.load()).collect(Collectors.toList());
+ }
+
@SuppressWarnings("unchecked")
@Override
public T deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
- LOG.debug("BaseIdentityDeserializer class for '{}'",parser.getValueAsString());
+ LOG.debug("BaseIdentityDeserializer class for '{}'", parser.getValueAsString());
String clazzToSearch = parser.getValueAsString();
+ String simpleName;
+ Class<? extends BaseIdentity> clazz;
// clazz from Elasticsearch is full qualified
int lastDot = clazzToSearch.lastIndexOf(".");
if (lastDot > -1) {
- clazzToSearch = clazzToSearch.substring(lastDot+1);
+ simpleName = clazzToSearch.substring(lastDot + 1);
+ clazz = getTypesInNamespace(clazzToSearch.substring(0, lastDot)).stream()
+ .filter(e -> e.getSimpleName().equals(simpleName)).findFirst().orElse(null);
+ if (clazz != null)
+ return (T) YangToolsMapperHelper.getIdentityValueFromClass(clazz);
} else {
- clazzToSearch = clazzToSearch.substring(0, 1).toUpperCase() + clazzToSearch.substring(1);
+ simpleName = clazzToSearch.substring(0, 1).toUpperCase() + clazzToSearch.substring(1);
}
- Class<?> clazz;
try {
- clazz = YangToolsMapperHelper.findClass(clazzToSearch);
+ clazz = (Class<? extends BaseIdentity>) YangToolsMapperHelper.findClass(simpleName);
if (clazz != null)
- return (T)clazz;
+ return (T) YangToolsMapperHelper.getIdentityValueFromClass(clazz);
} catch (ClassNotFoundException e) {
- LOG.warn("BaseIdentityDeserializer class not found for '"+parser.getValueAsString()+"'",e);
+ LOG.warn("BaseIdentityDeserializer class not found for '" + parser.getValueAsString() + "'", e);
}
return (T) deser.deserialize(parser, ctxt);
}
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/BaseIdentitySerializer.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/BaseIdentitySerializer.java
new file mode 100644
index 000000000..29d4fc049
--- /dev/null
+++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/BaseIdentitySerializer.java
@@ -0,0 +1,21 @@
+package org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+
+import java.io.IOException;
+
+public class BaseIdentitySerializer extends JsonSerializer<BaseIdentity> {
+
+ @Override
+ public void serialize(BaseIdentity value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
+ String clsName = value.getClass().getName();
+ int idx = clsName.indexOf("$");
+ if(idx>0){
+ clsName = clsName.substring(0,idx);
+ }
+ gen.writeString(clsName);
+ }
+} \ No newline at end of file
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/TypeObjectDeserializer.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/TypeObjectDeserializer.java
index b857a2ffb..5e3fe13bb 100644
--- a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/TypeObjectDeserializer.java
+++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/TypeObjectDeserializer.java
@@ -31,7 +31,6 @@ import java.lang.reflect.InvocationTargetException;
import java.util.NoSuchElementException;
import java.util.Optional;
import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper;
-import org.opendaylight.yangtools.concepts.Builder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,7 +58,7 @@ public class TypeObjectDeserializer<T> extends JsonDeserializer<T> {
//try get method for default instance
if ((oRes = YangToolsMapperHelper.getDefaultInstance(clazz, arg)).isEmpty()) {
//try to find builder with getDefaultInstance method
- Optional<Class<Builder<?>>> oBuilderClazz = YangToolsMapperHelper.findBuilderClassOptional(ctxt, clazz);
+ Optional<Class<?>> oBuilderClazz = YangToolsMapperHelper.findBuilderClassOptional(ctxt, clazz);
LOG.debug("Try builder class present:{}",oBuilderClazz.isPresent());
if (oBuilderClazz.isEmpty()
|| ((oRes = YangToolsMapperHelper.getDefaultInstance(oBuilderClazz.get(), arg)).isEmpty())) {
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/HostBuilder.java b/sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/HostBuilder.java
deleted file mode 100644
index 3d859e8b5..000000000
--- a/sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/HostBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-import java.lang.String;
-import java.lang.UnsupportedOperationException;
-import javax.annotation.processing.Generated;
-
-/**
- * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
- * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-@Generated("mdsal-binding-generator")
-public class HostBuilder {
- private HostBuilder() {
- //Exists only to defeat instantiation.
- }
-
- public static Host getDefaultInstance(String defaultValue) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
-}
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressBuilder.java b/sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressBuilder.java
deleted file mode 100644
index 62771f669..000000000
--- a/sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-import java.lang.String;
-import java.lang.UnsupportedOperationException;
-import javax.annotation.processing.Generated;
-
-/**
- * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
- * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-@Generated("mdsal-binding-generator")
-public class IpAddressBuilder {
- private IpAddressBuilder() {
- //Exists only to defeat instantiation.
- }
-
- public static IpAddress getDefaultInstance(String defaultValue) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
-}
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressNoZoneBuilder.java b/sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressNoZoneBuilder.java
deleted file mode 100644
index d7b295263..000000000
--- a/sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressNoZoneBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-import java.lang.String;
-import java.lang.UnsupportedOperationException;
-import javax.annotation.processing.Generated;
-
-/**
- * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
- * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-@Generated("mdsal-binding-generator")
-public class IpAddressNoZoneBuilder {
- private IpAddressNoZoneBuilder() {
- //Exists only to defeat instantiation.
- }
-
- public static IpAddressNoZone getDefaultInstance(String defaultValue) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
-}
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpPrefixBuilder.java b/sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpPrefixBuilder.java
deleted file mode 100644
index d5fff3db4..000000000
--- a/sdnr/wt/common-yang/utils/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpPrefixBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-import java.lang.String;
-import java.lang.UnsupportedOperationException;
-import javax.annotation.processing.Generated;
-
-/**
- * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
- * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-@Generated("mdsal-binding-generator")
-public class IpPrefixBuilder {
- private IpPrefixBuilder() {
- //Exists only to defeat instantiation.
- }
-
- public static IpPrefix getDefaultInstance(String defaultValue) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
-}
diff --git a/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangToolsMapper.java b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangToolsMapper.java
index 2e51e8404..81df00789 100644
--- a/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangToolsMapper.java
+++ b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangToolsMapper.java
@@ -34,7 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.
import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.AddressLocation;
import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.AddressLocationBuilder;
import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.AddressType;
-import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.ItemCode;
+import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.ItemCodeIdentity;
import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.address.location.entity.ItemList;
import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.address.location.entity.ItemListBuilder;
import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.address.location.entity.ItemListKey;
@@ -47,7 +47,29 @@ public class TestYangToolsMapper {
public void init() {
MAPPER.addKeyDeserializer(ItemListKey.class, new IdentifierDeserializer());
}
+ @Test
+ public void testYangMapperDeser2() {
+ AddressLocation al = null;
+ try {
+ al = MAPPER.readValue(
+ "{\n"
+ + " \"address-type\": \"OFFICE\",\n"
+ + " \"delivery-date-time\": \"2022-03-15T11:12:13.890Z\",\n"
+ + " \"delivery-url\": \"delivery.uri\",\n"
+ + " \"test-id\": \"org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.ItemCodeIdentity\""
+ + "}",
+ AddressLocation.class);
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
+ assertEquals(AddressType.OFFICE, al.getAddressType());
+ assertEquals("2022-03-15T11:12:13.890Z", al.getDeliveryDateTime().getValue());
+ assertEquals(ItemCodeIdentity.VALUE, al.getTestId());
+ System.out.println("Delivery Date = " + al.getDeliveryDateTime().getValue());
+ System.out.println(al.getItemList());
+ System.out.println(al.getDeliveryUrl().getValue());
+ }
@Test
public void testYangMapperDeser() {
AddressLocation al = null;
@@ -60,7 +82,7 @@ public class TestYangToolsMapper {
+ " \"delivery-url\": \"delivery.uri\",\n"
+ " \"item-list\": [\n"
+ " {\n"
- + " \"item-key\": \"org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.ItemCode\"\n"
+ + " \"item-key\": \"org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.ItemCodeIdentity\"\n"
+ " }\n"
+ " ]\n"
+ "}",
@@ -78,8 +100,8 @@ public class TestYangToolsMapper {
@Test
public void testYangMapperSer() {
Map<ItemListKey, ItemList> items = new HashMap<ItemListKey, ItemList>();
- ItemList il = new ItemListBuilder().setItemKey(ItemCode.class).build();
- items.put(new ItemListKey(ItemCode.class), il);
+ ItemList il = new ItemListBuilder().setItemKey(ItemCodeIdentity.VALUE).build();
+ items.put(new ItemListKey(ItemCodeIdentity.VALUE), il);
Uri uri = new Uri("delivery.uri");
diff --git a/sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/HostBuilder.java b/sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/HostBuilder.java
deleted file mode 100644
index 3d859e8b5..000000000
--- a/sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/HostBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-import java.lang.String;
-import java.lang.UnsupportedOperationException;
-import javax.annotation.processing.Generated;
-
-/**
- * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
- * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-@Generated("mdsal-binding-generator")
-public class HostBuilder {
- private HostBuilder() {
- //Exists only to defeat instantiation.
- }
-
- public static Host getDefaultInstance(String defaultValue) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
-}
diff --git a/sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressBuilder.java b/sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressBuilder.java
deleted file mode 100644
index 62771f669..000000000
--- a/sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-import java.lang.String;
-import java.lang.UnsupportedOperationException;
-import javax.annotation.processing.Generated;
-
-/**
- * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
- * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-@Generated("mdsal-binding-generator")
-public class IpAddressBuilder {
- private IpAddressBuilder() {
- //Exists only to defeat instantiation.
- }
-
- public static IpAddress getDefaultInstance(String defaultValue) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
-}
diff --git a/sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressNoZoneBuilder.java b/sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressNoZoneBuilder.java
deleted file mode 100644
index d7b295263..000000000
--- a/sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressNoZoneBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-import java.lang.String;
-import java.lang.UnsupportedOperationException;
-import javax.annotation.processing.Generated;
-
-/**
- * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
- * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-@Generated("mdsal-binding-generator")
-public class IpAddressNoZoneBuilder {
- private IpAddressNoZoneBuilder() {
- //Exists only to defeat instantiation.
- }
-
- public static IpAddressNoZone getDefaultInstance(String defaultValue) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
-}
diff --git a/sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpPrefixBuilder.java b/sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpPrefixBuilder.java
deleted file mode 100644
index d5fff3db4..000000000
--- a/sdnr/wt/common-yang/utils/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpPrefixBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-import java.lang.String;
-import java.lang.UnsupportedOperationException;
-import javax.annotation.processing.Generated;
-
-/**
- * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
- * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-@Generated("mdsal-binding-generator")
-public class IpPrefixBuilder {
- private IpPrefixBuilder() {
- //Exists only to defeat instantiation.
- }
-
- public static IpPrefix getDefaultInstance(String defaultValue) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
-}
diff --git a/sdnr/wt/common-yang/utils/src/test/yang/test-yang-utils.yang b/sdnr/wt/common-yang/utils/src/test/yang/test-yang-utils.yang
index eb62a859a..a43a151e1 100644
--- a/sdnr/wt/common-yang/utils/src/test/yang/test-yang-utils.yang
+++ b/sdnr/wt/common-yang/utils/src/test/yang/test-yang-utils.yang
@@ -3,52 +3,52 @@ module test-yang-utils {
yang-version 1.1;
namespace "urn:test:yang:utils";
prefix tesyangutils;
-
+
import ietf-yang-types {
prefix yang;
reference
"RFC 6991: Common YANG Data Types.";
}
-
+
import ietf-inet-types {
prefix inet;
}
-
+
typedef AddressType {
type enumeration {
enum OFFICE {
- description
+ description
"Office Address";
}
enum HOME {
- description
+ description
"Home Address";
}
}
}
-
- identity item-code {
+
+ identity item-code-identity {
description
"Base identity";
}
typedef item-code {
type identityref {
- base item-code;
+ base item-code-identity;
}
description
"Item code - Could be bar code, QR code or any other code to uniquely identify an item";
}
-
+
grouping address-location-entity {
leaf id {
type string;
- description
+ description
"Unique ID of the address";
}
leaf address-type {
type AddressType;
- description
+ description
"Type of Address";
}
leaf delivery-date-time {
@@ -58,7 +58,7 @@ module test-yang-utils {
}
leaf delivery-url {
type inet:uri;
- description
+ description
"Delivery URL";
}
list item-list {
@@ -66,13 +66,18 @@ module test-yang-utils {
leaf item-key {
type item-code;
}
- description
+ description
"Unique code of the ordered item";
}
+ leaf test-id {
+ type item-code;
+ description "test identity leaf";
+ }
+
}
-
+
container address-location {
- description
+ description
"builder";
uses address-location-entity;
}