diff options
author | 2021-11-19 14:46:00 +0100 | |
---|---|---|
committer | 2021-11-19 14:46:20 +0100 | |
commit | 3e739d832853e821472facb181aa972ecfb45b1c (patch) | |
tree | 35a79049048a506c03884e09d65c7a477c4cffd4 /sdnr/wt/common-yang/utils/src/main/java/org/onap | |
parent | 71031b0b238ee51affd8135fdd648d9a70a6970b (diff) |
Synchronize sdnr/wt artifacts
Synchronize sdnr/wt common, help, apigateway
Issue-ID: CCSDK-3528
Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com>
Change-Id: I4b5e5ce1b16adad80e670bdf08943e4a3eb658f1
Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/common-yang/utils/src/main/java/org/onap')
2 files changed, 59 insertions, 8 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 f443fd615..d468e075c 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 @@ -278,6 +278,12 @@ 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 @@ -290,6 +296,21 @@ 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 @@ -301,4 +322,13 @@ 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()); + } } diff --git a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/TypeObjectSerializer.java b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/TypeObjectSerializer.java index b43e6c100..4fb39415e 100644 --- a/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/TypeObjectSerializer.java +++ b/sdnr/wt/common-yang/utils/src/main/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/serialize/TypeObjectSerializer.java @@ -31,22 +31,43 @@ import org.opendaylight.yangtools.yang.binding.TypeObject; public class TypeObjectSerializer extends JsonSerializer<TypeObject> { + /** + * serialize typeobject values + * prefer stringValue() method over getValue() method + */ @Override public void serialize(TypeObject value, JsonGenerator gen, SerializerProvider serializers) throws IOException { - //stringValue Method[] methods = value.getClass().getDeclaredMethods(); String name; + Method getValueMethod = null; for (Method method : methods) { name = method.getName(); - if (method.getParameterCount()==0 && (name.equals("stringValue") || name.equals("getValue"))) { - try { - gen.writeString((String)method.invoke(value)); - break; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException - | IOException e) { - throw new IOException("No String getter method supported TypeObject for "+value.getClass(),e); + if (method.getParameterCount() == 0) { + if (name.equals("getValue")) { + getValueMethod = method; + } else if (name.equals("stringValue")) { + try { + gen.writeString((String) method.invoke(value)); + break; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException + | IOException e) { + throw new IOException("No String getter method supported TypeObject for " + value.getClass(), + e); + } } } } + if (getValueMethod != null) { + try { + if (String.class.equals(getValueMethod.getReturnType())) { + gen.writeString((String) getValueMethod.invoke(value)); + } else { + gen.writeObject(getValueMethod.invoke(value)); + } + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | IOException e) { + throw new IOException("No String getter method supported TypeObject for " + value.getClass(), e); + } + + } } } |