summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common-yang/utils/src
diff options
context:
space:
mode:
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/YangToolsMapperHelper.java17
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsBuilderAnnotationIntrospector.java12
-rw-r--r--sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsDeserializerModifier.java26
3 files changed, 44 insertions, 11 deletions
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 3086167bf..c50e3210e 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
@@ -35,6 +35,8 @@ import java.util.List;
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;
@@ -264,6 +266,9 @@ public class YangToolsMapperHelper {
public static boolean hasTime(Notification notification) {
return notification instanceof EventInstantAware;
}
+ public static boolean hasTime(DOMNotification notification) {
+ return notification instanceof DOMEvent;
+ }
public static DateAndTime getTime(Notification notification, Instant defaultValue) {
Instant time;
if (hasTime(notification)) { // If notification class extends/implements the EventInstantAware
@@ -275,4 +280,16 @@ public class YangToolsMapperHelper {
}
return DateAndTime.getDefaultInstance(ZonedDateTime.ofInstant(time, ZoneOffset.UTC).format(formatterOutput));
}
+
+ public static DateAndTime getTime(DOMNotification notification, Instant defaultValue) {
+ Instant time;
+ if (hasTime(notification)) { // If notification class extends/implements the EventInstantAware
+ time = ((DOMEvent) notification).getEventInstant();
+ LOG.debug("Event time {}", time);
+ } else {
+ time = defaultValue;
+ LOG.debug("Defaulting to actual time of processing the notification - {}", time);
+ }
+ return DateAndTime.getDefaultInstance(ZonedDateTime.ofInstant(time, ZoneOffset.UTC).format(formatterOutput));
+ }
}
diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsBuilderAnnotationIntrospector.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsBuilderAnnotationIntrospector.java
index 46c966076..7dde2ef7f 100644
--- a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsBuilderAnnotationIntrospector.java
+++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/mapperextensions/YangToolsBuilderAnnotationIntrospector.java
@@ -99,15 +99,15 @@ public class YangToolsBuilderAnnotationIntrospector extends JacksonAnnotationInt
Class<?> p2 = setter2.getRawParameterType(0);
AnnotatedMethod res = null;
- if (this.isAssignable(p1, p2, Map.class, List.class)) {
+ if (isAssignable(p1, p2, Map.class, List.class)) {
res = p1.isAssignableFrom(List.class) ? setter1 : setter2; //prefer List setter
- } else if (this.isAssignable(p1, p2, Uint64.class, BigInteger.class)) {
+ } else if (isAssignable(p1, p2, Uint64.class, BigInteger.class)) {
res = setter1;
- } else if (this.isAssignable(p1, p2, Uint32.class, Long.class)) {
+ } else if (isAssignable(p1, p2, Uint32.class, Long.class)) {
res = setter1;
- } else if (this.isAssignable(p1, p2, Uint16.class, Integer.class)) {
+ } else if (isAssignable(p1, p2, Uint16.class, Integer.class)) {
res = setter1;
- } else if (this.isAssignable(p1, p2, Uint8.class, Short.class)) {
+ } else if (isAssignable(p1, p2, Uint8.class, Short.class)) {
res = setter1;
}
if (res == null) {
@@ -123,7 +123,7 @@ public class YangToolsBuilderAnnotationIntrospector extends JacksonAnnotationInt
return res;
}
- private boolean isAssignable(Class<?> p1, Class<?> p2, Class<?> c1, Class<?> c2) {
+ public static boolean isAssignable(Class<?> p1, Class<?> p2, Class<?> c1, Class<?> c2) {
return ((p1.isAssignableFrom(c1) && p2.isAssignableFrom(c2))
|| (p2.isAssignableFrom(c1) && p1.isAssignableFrom(c2)));
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 c12d17e74..58e75bde5 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
@@ -33,6 +33,7 @@ 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;
@@ -48,7 +49,25 @@ 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 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,
@@ -60,10 +79,7 @@ public class YangToolsDeserializerModifier extends BeanDeserializerModifier {
Class<?> clazz = type.getRawClass();
try {
- Method method = clazz.getDeclaredMethod(getEnumMethodName, String.class);
- Enum<?> result = (Enum<?>) method.invoke(null, jp.getValueAsString());
- LOG.debug("Deserialize '{}' with class '{}' to '{}'", jp.getValueAsString(), clazz.getName(), result);
- return result;
+ return parseEnum(jp.getValueAsString(), clazz);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | NoSuchElementException | SecurityException e) {
LOG.warn("problem deserializing enum for {} with value {}: {}", clazz.getName(),