Fix potential null pointer places
[aai/sparky-be.git] / sparkybe-onap-service / src / main / java / org / onap / aai / sparky / viewandinspect / services / BaseVisualizationContext.java
index 21f7fdd..5dd5aca 100644 (file)
@@ -538,38 +538,15 @@ public class BaseVisualizationContext implements VisualizationContext {
 
         JsonNode nodeValue = field.getValue();
 
-        if (nodeValue != null && nodeValue.isValueNode()) {
-
-          if (oxmEntityLookup.getEntityDescriptors().get(fieldName) == null) {
-
-            /*
-             * entity property name is not an entity, thus we can add this property name and value
-             * to our property set
-             */
-
-            ain.addProperty(fieldName, nodeValue.asText());
-
-          }
-
-        } else {
-
-          if (nodeValue.isArray()) {
-
-            if (oxmEntityLookup.getEntityDescriptors().get(fieldName) == null) {
-
-              /*
-               * entity property name is not an entity, thus we can add this property name and value
-               * to our property set
-               */
-
-              ain.addProperty(field.getKey(), nodeValue.toString());
-
-            }
-
+        if(nodeValue!=null) {
+          if (nodeValue.isValueNode()) {
+            String key = fieldName;
+            handleNodeValue(ain, fieldName, key, nodeValue.asText());
+          } else if (nodeValue.isArray()) {
+            String key = field.getKey();
+            handleNodeValue(ain, fieldName, key, nodeValue.toString());
           } else {
-
-            ain.addComplexGroup(nodeValue);
-
+              ain.addComplexGroup(nodeValue);
           }
 
         }
@@ -628,6 +605,19 @@ public class BaseVisualizationContext implements VisualizationContext {
 
   }
 
+  private void handleNodeValue(ActiveInventoryNode ain, String fieldName, String key, String value) {
+    if (oxmEntityLookup.getEntityDescriptors().get(fieldName) == null) {
+
+      /*
+       * entity property name is not an entity, thus we can add this property name and value
+       * to our property set
+       */
+
+      ain.addProperty(key, value);
+
+    }
+  }
+
   /**
    * Perform self link resolve.
    *
@@ -826,7 +816,6 @@ public class BaseVisualizationContext implements VisualizationContext {
   /**
    * Process current node states.
    *
-   * @param rootNodeDiscovered the root node discovered
    */
   private void processCurrentNodeStates(QueryParams queryParams) {
     /*