Fix Spike Event Processing with Common Format
[aai/data-router.git] / src / main / java / org / onap / aai / datarouter / entity / SpikeAggregationEntity.java
index cb620d8..bb52802 100644 (file)
@@ -2,8 +2,8 @@
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 Amdocs
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  */
 package org.onap.aai.datarouter.entity;
 
@@ -30,6 +28,7 @@ import java.util.Map.Entry;
 
 import org.onap.aai.datarouter.util.NodeUtils;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -38,6 +37,13 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
  * The Class SpikeAggregationEntity. Mimics functionality of SPIKEUI's AggregationEntity
  */
 public class SpikeAggregationEntity implements DocumentStoreDataEntity, Serializable {
+  
+  private Map<String, String> attributes = new HashMap<>();
+  
+  @JsonIgnore
+  private ObjectMapper mapper = new ObjectMapper();
+  
+  
   private String id;
   private String link;
   private String lastmodTimestamp;
@@ -70,28 +76,23 @@ public class SpikeAggregationEntity implements DocumentStoreDataEntity, Serializ
   }
 
 
-  Map<String, String> attributes = new HashMap<>();
-  ObjectMapper mapper = new ObjectMapper();
 
   /**
    * Instantiates a new aggregation entity.
    */
   public SpikeAggregationEntity() {}
 
-  public void deriveFields(JsonNode uebPayload) {
+  public void deriveFields(JsonNode entityProperties) {
 
     this.setId(NodeUtils.generateUniqueShaDigest(link));
     this.setLastmodTimestamp(Long.toString(System.currentTimeMillis()));
-    JsonNode entityNode = uebPayload.get("vertex").get("properties");
-    Iterator<Entry<String, JsonNode>> nodes = entityNode.fields();
+    Iterator<Entry<String, JsonNode>> nodes = entityProperties.fields();
     while (nodes.hasNext()) {
       Map.Entry<String, JsonNode> entry = (Map.Entry<String, JsonNode>) nodes.next();
       attributes.put(entry.getKey(), entry.getValue().asText());
     }
   }
 
-
   @Override
   public String getAsJson() {
     ObjectNode rootNode = mapper.createObjectNode();
@@ -107,7 +108,12 @@ public class SpikeAggregationEntity implements DocumentStoreDataEntity, Serializ
 
   @Override
   public String toString() {
-    return "AggregationEntity [id=" + id + ", link=" + link + ", attributes=" + attributes
-        + ", mapper=" + mapper + "]";
+    return "SpikeAggregationEntity ["
+        + (attributes != null ? "attributes=" + attributes + ", " : "")
+        + (id != null ? "id=" + id + ", " : "") + (link != null ? "link=" + link + ", " : "")
+        + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp : "") + "]";
   }
+  
+  
+
 }