From: Determe, Sebastien (sd378r) Date: Tue, 29 Aug 2017 11:32:22 +0000 (-0700) Subject: Add 2 new methods getNodeValueByName X-Git-Tag: v1.1.0~124^2~4 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=clamp.git;a=commitdiff_plain;h=af72cff2b9dfa1415e47dcd59e9a307913cab35d 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) --- 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