aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2017-08-29 04:32:22 -0700
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2017-08-29 04:32:22 -0700
commitaf72cff2b9dfa1415e47dcd59e9a307913cab35d (patch)
treeb35db15c5e7c6fb05e0f302c55fc3bcfc1ff9a12 /src/main/java/org/onap
parentc55a0d2b6c8bbbc789c687f503cf64322e897305 (diff)
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) <sd378r@intl.att.com>
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/ModelElement.java51
1 files changed, 51 insertions, 0 deletions
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 ed038db66..42333559e 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<String> getNodeValuesByName(JsonNode nodeIn, String name) {
+ List<String> values = new ArrayList<String>();
+ if ( nodeIn != null ) {
+ Iterator<JsonNode> 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