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.sparky.sync.entity;
23 import java.util.HashMap;
26 import org.onap.aai.sparky.util.NodeUtils;
28 import com.fasterxml.jackson.databind.ObjectMapper;
29 import com.fasterxml.jackson.databind.node.ObjectNode;
32 * The Class AggregationEntity.
34 public class AggregationEntity extends IndexableEntity implements IndexDocument {
35 private Map<String, String> attributes = new HashMap<String, String>();
36 protected ObjectMapper mapper = new ObjectMapper();
39 * Instantiates a new aggregation entity.
41 public AggregationEntity() {
46 * @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
49 public void deriveFields() {
52 * We'll try and create a unique identity key that we can use for differencing the previously
53 * imported record sets as we won't have granular control of what is created/removed and when.
54 * The best we can hope for is identification of resources by generated Id until the
55 * Identity-Service UUID is tagged against all resources, then we can use that instead.
58 NodeUtils.generateUniqueShaDigest(link);
61 public void copyAttributeKeyValuePair(Map<String, Object> map){
62 for(String key: map.keySet()){
63 if (!key.equalsIgnoreCase("relationship-list")){ // ignore relationship data which is not required in aggregation
64 this.attributes.put(key, map.get(key).toString()); // not sure if entity attribute can contain an object as value
69 public void addAttributeKeyValuePair(String key, String value){
70 this.attributes.put(key, value);
74 public String getAsJson() {
75 ObjectNode rootNode = mapper.createObjectNode();
76 rootNode.put("link", this.getLink());
77 rootNode.put("lastmodTimestamp", this.getEntityTimeStamp());
78 for (String key: this.attributes.keySet()){
79 rootNode.put(key, this.attributes.get(key));
81 return rootNode.toString();
85 * @see java.lang.Object#toString()
88 public String toString() {
89 return "IndexDocument [" + (entityType != null ? "entityType=" + entityType + ", " : "")
90 + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
92 + (mapper != null ? "mapper=" + mapper + ", " : "") + (id != null ? "id=" + id + ", " : "")
93 + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp + ", " : "") + "]";