From 0b34dfecd6ee4e7f887fa47d2181edf097de788d Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Wed, 30 Aug 2017 05:56:17 -0700 Subject: Fix Sonar bugs In ModelElement.class Blocker issues fixed Change-Id: Ia03757ed3675d6af8a65b9ed862db25e703387d6 Issue-Id: CLAMP-43 Signed-off-by: Determe, Sebastien (sd378r) --- .../onap/clamp/clds/model/prop/ModelElement.java | 133 +++++++++++---------- 1 file changed, 67 insertions(+), 66 deletions(-) (limited to 'src/main/java') 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 42333559e..42d11f4b5 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 @@ -23,32 +23,32 @@ package org.onap.clamp.clds.model.prop; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.databind.JsonNode; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + /** * Provide base ModelElement functionality. */ public abstract class ModelElement { - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(ModelElement.class); + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(ModelElement.class); protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); - public static final String TYPE_POLICY = "policy"; - public static final String TYPE_TCA = "tca"; + public static final String TYPE_POLICY = "policy"; + public static final String TYPE_TCA = "tca"; - private final String type; - private final ModelBpmn modelBpmn; - private final String id; - protected String topicPublishes; - protected final JsonNode meNode; - private boolean isFound; + private final String type; + private final ModelBpmn modelBpmn; + private final String id; + protected String topicPublishes; + protected final JsonNode meNode; + private boolean isFound; - private final ModelProperties modelProp; + private final ModelProperties modelProp; /** * Perform base parsing of properties for a ModelElement (such as, @@ -122,57 +122,58 @@ 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 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 @@ -206,7 +207,7 @@ public abstract class ModelElement { } } } - if (values == null || values.size() == 0) { + if (values == null || values.isEmpty()) { logger.warn(name + "=" + values); } else { logger.debug(name + "=" + values); -- cgit 1.2.3-korg