2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.datarouter.entity;
25 import java.io.Serializable;
26 import java.util.Arrays;
27 import java.util.HashMap;
28 import java.util.Iterator;
30 import java.util.Map.Entry;
32 import org.openecomp.datarouter.util.NodeUtils;
34 import com.fasterxml.jackson.databind.JsonNode;
35 import com.fasterxml.jackson.databind.ObjectMapper;
36 import com.fasterxml.jackson.databind.node.ObjectNode;
39 * The Class AggregationEntity. Mimics functionality of AAIUI's AggregationEntity
41 public class AggregationEntity implements DocumentStoreDataEntity, Serializable {
44 private String lastmodTimestamp;
46 public String getLink() {
49 public void setLink(String link) {
52 public String getId() {
53 // make sure that deliveFields() is called before getting the id
56 public void setId(String id) {
61 public String getLastmodTimestamp() {
62 return lastmodTimestamp;
64 public void setLastmodTimestamp(String lastmodTimestamp) {
65 this.lastmodTimestamp = lastmodTimestamp;
69 Map<String, String> attributes = new HashMap<String, String>();
70 ObjectMapper mapper = new ObjectMapper();
73 * Instantiates a new aggregation entity.
75 public AggregationEntity() { }
77 public void deriveFields(JsonNode uebPayload) {
79 this.setId(NodeUtils.generateUniqueShaDigest(link));
81 this.setLastmodTimestamp(Long.toString(System.currentTimeMillis()));
83 JsonNode entityNode = uebPayload.get("entity");
85 Iterator<Entry<String, JsonNode>> nodes = entityNode.fields();
87 while (nodes.hasNext()) {
88 Map.Entry<String, JsonNode> entry = (Map.Entry<String, JsonNode>) nodes.next();
89 if (!entry.getKey().equalsIgnoreCase("relationship-list")){
90 attributes.put(entry.getKey(), entry.getValue().asText());
95 public void copyAttributeKeyValuePair(Map<String, Object> map){
96 for(String key: map.keySet()){
97 if (!key.equalsIgnoreCase("relationship-list")){ // ignore relationship data which is not required in aggregation
98 this.attributes.put(key, map.get(key).toString()); // not sure if entity attribute can contain an object as value
103 public void addAttributeKeyValuePair(String key, String value){
104 this.attributes.put(key, value);
107 public String getAsJson() {
108 ObjectNode rootNode = mapper.createObjectNode();
109 rootNode.put("link", this.getLink());
110 rootNode.put("lastmodTimestamp", lastmodTimestamp);
111 for (String key: this.attributes.keySet()){
112 rootNode.put(key, this.attributes.get(key));
114 return rootNode.toString();
118 public String toString() {
119 return "AggregationEntity [id=" + id + ", link=" + link + ", attributes=" + attributes
120 + ", mapper=" + mapper + "]";