From af72cff2b9dfa1415e47dcd59e9a307913cab35d Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Tue, 29 Aug 2017 04:32:22 -0700 Subject: [PATCH] Add 2 new methods getNodeValueByName Add those new methods for new coming features Change-Id: I2dbdd8ea524b2eb93841642318a682950f5b7038 Issue-Id: CLAMP-43 Signed-off-by: Determe, Sebastien (sd378r) --- .../onap/clamp/clds/model/prop/ModelElement.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/main/java/org/onap/clamp/clds/model/prop/ModelElement.java b/src/main/java/org/onap/clamp/clds/model/prop/ModelElement.java index ed038db6..42333559 100644 --- a/src/main/java/org/onap/clamp/clds/model/prop/ModelElement.java +++ b/src/main/java/org/onap/clamp/clds/model/prop/ModelElement.java @@ -122,6 +122,57 @@ public abstract class ModelElement { } return value; } + + /** + * Return the value field of the json node element that has a name field that equals the given name. + * + * @param nodeIn + * @param name + * @return + */ + public static String getNodeValueByName(JsonNode nodeIn, String name) { + String value = null; + if ( nodeIn != null ) { + value = nodeIn.path(name).asText(); + } + if ( value == null || value.length() == 0 ) { + logger.warn(name + "=" + value); + } else { + logger.debug(name + "=" + value); + } + return value; + } + + + /** + * Return the value field of the json node element that has a name field that equals the given name. + * + * @param nodeIn + * @param name + * @return + */ + public static List getNodeValuesByName(JsonNode nodeIn, String name) { + List values = new ArrayList(); + if ( nodeIn != null ) { + Iterator i = nodeIn.iterator(); + while (i.hasNext()) { + JsonNode node = i.next(); + if ( node.path("name").asText().equals(name) ) { + String value = ""; + JsonNode vnode = node.path("value"); + if ( vnode.isArray() ) { + // if array, assume value is in first element + value = vnode.path(0).asText(); + } else { + // otherwise, just return text + value = vnode.asText(); + } + values.add(value); + } + } + } + return values; + } /** * Return the int value field of the json node element that has a name field -- 2.16.6