aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common-yang/utils
diff options
context:
space:
mode:
authorRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2021-07-26 12:42:00 +0530
committerKAPIL SINGAL <ks220y@att.com>2021-07-28 16:08:00 +0000
commit016536791b95df23811dabd063010f0561526163 (patch)
treedc9af75cdad070fa803b6ea8799cfa38244a17f0 /sdnr/wt/common-yang/utils
parentd70d7624795a9305eef1f0a6d3842d47ecd27160 (diff)
Support for MariaDB
Support for MariaDB Issue-ID: CCSDK-3384 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> Change-Id: Ic93ad33257a091f2cd208cdf02d1d7400c256bf0 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/common-yang/utils')
-rw-r--r--sdnr/wt/common-yang/utils/pom.xml5
-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
4 files changed, 49 insertions, 11 deletions
diff --git a/sdnr/wt/common-yang/utils/pom.xml b/sdnr/wt/common-yang/utils/pom.xml
index ef3c22b4c..2fa1021db 100644
--- a/sdnr/wt/common-yang/utils/pom.xml
+++ b/sdnr/wt/common-yang/utils/pom.xml
@@ -69,6 +69,11 @@
<artifactId>rfc6991-ietf-yang-types</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-dom-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
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(),