2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.datarouter.entity;
23 import java.io.Serializable;
24 import java.util.HashMap;
25 import java.util.Iterator;
27 import java.util.Map.Entry;
29 import org.onap.aai.datarouter.util.NodeUtils;
31 import com.fasterxml.jackson.databind.JsonNode;
32 import com.fasterxml.jackson.databind.ObjectMapper;
33 import com.fasterxml.jackson.databind.node.ObjectNode;
36 * The Class SpikeAggregationEntity. Mimics functionality of SPIKEUI's AggregationEntity
38 public class SpikeAggregationEntity implements DocumentStoreDataEntity, Serializable {
41 private String lastmodTimestamp;
43 public String getLink() {
47 public void setLink(String link) {
52 public String getId() {
53 // make sure that deliveFields() is called before getting the id
57 public void setId(String id) {
62 public String getLastmodTimestamp() {
63 return lastmodTimestamp;
66 public void setLastmodTimestamp(String lastmodTimestamp) {
67 this.lastmodTimestamp = lastmodTimestamp;
71 Map<String, String> attributes = new HashMap<>();
72 ObjectMapper mapper = new ObjectMapper();
75 * Instantiates a new aggregation entity.
77 public SpikeAggregationEntity() {}
79 public void deriveFields(JsonNode uebPayload) {
81 this.setId(NodeUtils.generateUniqueShaDigest(link));
82 this.setLastmodTimestamp(Long.toString(System.currentTimeMillis()));
83 JsonNode entityNode = uebPayload.get("vertex").get("properties");
84 Iterator<Entry<String, JsonNode>> nodes = entityNode.fields();
85 while (nodes.hasNext()) {
86 Map.Entry<String, JsonNode> entry = (Map.Entry<String, JsonNode>) nodes.next();
87 attributes.put(entry.getKey(), entry.getValue().asText());
94 public String getAsJson() {
95 ObjectNode rootNode = mapper.createObjectNode();
96 rootNode.put("link", this.getLink());
97 rootNode.put("lastmodTimestamp", lastmodTimestamp);
98 for (Map.Entry<String, String> entry : this.attributes.entrySet()) {
99 String key = entry.getKey();
100 String value = entry.getValue();
101 rootNode.put(key, value);
103 return rootNode.toString();
107 public String toString() {
108 return "AggregationEntity [id=" + id + ", link=" + link + ", attributes=" + attributes
109 + ", mapper=" + mapper + "]";