Fix potential null pointer places
[aai/sparky-be.git] / sparkybe-onap-service / src / main / java / org / onap / aai / sparky / aggregation / sync / AggregationSynchronizer.java
index e0b6955..b4c254a 100644 (file)
@@ -118,7 +118,6 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
   /**
    * Instantiates a new entity aggregation synchronizer.
    *
-   * @param indexName the index name
    * @throws Exception the exception
    */
   public AggregationSynchronizer(String entityType, ElasticSearchSchemaConfig schemaConfig,
@@ -613,7 +612,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
     Map<String, Object> map = mapper.convertValue(entityNode, Map.class);
     doc.copyAttributeKeyValuePair(map);
   }
-  
+
   /**
    * Process entity type self links.
    *
@@ -621,10 +620,8 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
    */
   private void processEntityTypeSelfLinks(OperationResult operationResult) {
 
-    JsonNode rootNode = null;
-    
-    if ( operationResult == null ) {
-       return;
+    if (operationResult == null) {
+      return;
     }
 
     final String jsonResult = operationResult.getResult();
@@ -632,46 +629,41 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
     if (jsonResult != null && jsonResult.length() > 0 && operationResult.wasSuccessful()) {
 
       try {
-        rootNode = mapper.readTree(jsonResult);
-      } catch (IOException exc) {
-        String message =
-            "Could not deserialize JSON (representing operation result) as node tree. " +
-            "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
-        LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
-      }
+        JsonNode rootNode = mapper.readTree(jsonResult);
 
-      JsonNode resultData = rootNode.get("result-data");
-      ArrayNode resultDataArrayNode = null;
+        JsonNode resultData = rootNode.get("result-data");
 
-      if (resultData.isArray()) {
-        resultDataArrayNode = (ArrayNode) resultData;
+        if (resultData.isArray()) {
+          ArrayNode resultDataArrayNode = (ArrayNode) resultData;
 
-        Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
-        JsonNode element = null;
+          Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
 
-        while (elementIterator.hasNext()) {
-          element = elementIterator.next();
+          while (elementIterator.hasNext()) {
+            JsonNode element = elementIterator.next();
 
-          final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
-          final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
+            final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
+            final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
 
-          OxmEntityDescriptor descriptor = null;
+            if (resourceType != null && resourceLink != null) {
 
-          if (resourceType != null && resourceLink != null) {
+              OxmEntityDescriptor descriptor = oxmEntityLookup.getEntityDescriptors().get(resourceType);
 
-            descriptor = oxmEntityLookup.getEntityDescriptors().get(resourceType);
-
-            if (descriptor == null) {
-              LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
-              // go to next element in iterator
-              continue;
-            }
+              if (descriptor == null) {
+                LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
+                // go to next element in iterator
+                continue;
+              }
 
-            selflinks.add(new SelfLinkDescriptor(resourceLink, SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
-            
+              selflinks.add(new SelfLinkDescriptor(resourceLink, SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
 
+            }
           }
         }
+      } catch (IOException exc) {
+        String message =
+                "Could not deserialize JSON (representing operation result) as node tree. " +
+                        "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
+        LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
       }
     }