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.onap.aai.sparky.synchronizer.entity;
25 import java.util.HashMap;
28 import org.onap.aai.sparky.config.oxm.OxmModelLoader;
29 import org.onap.aai.sparky.util.NodeUtils;
31 import com.fasterxml.jackson.databind.ObjectMapper;
32 import com.fasterxml.jackson.databind.node.ObjectNode;
35 * The Class AggregationEntity.
37 public class AggregationEntity extends IndexableEntity implements IndexDocument {
38 private Map<String, String> attributes = new HashMap<String, String>();
39 protected ObjectMapper mapper = new ObjectMapper();
42 * Instantiates a new aggregation entity.
44 public AggregationEntity() {
49 * Instantiates a new aggregation entity.
51 * @param loader the loader
53 public AggregationEntity(OxmModelLoader loader) {
58 * @see org.onap.aai.sparky.synchronizer.entity.IndexDocument#deriveFields()
61 public void deriveFields() {
64 * We'll try and create a unique identity key that we can use for differencing the previously
65 * imported record sets as we won't have granular control of what is created/removed and when.
66 * The best we can hope for is identification of resources by generated Id until the
67 * Identity-Service UUID is tagged against all resources, then we can use that instead.
70 NodeUtils.generateUniqueShaDigest(link);
73 public void copyAttributeKeyValuePair(Map<String, Object> map){
74 for(String key: map.keySet()){
75 if (!key.equalsIgnoreCase("relationship-list")){ // ignore relationship data which is not required in aggregation
76 this.attributes.put(key, map.get(key).toString()); // not sure if entity attribute can contain an object as value
81 public void addAttributeKeyValuePair(String key, String value){
82 this.attributes.put(key, value);
86 public String getIndexDocumentJson() {
87 ObjectNode rootNode = mapper.createObjectNode();
88 rootNode.put("link", this.getLink());
89 rootNode.put("lastmodTimestamp", this.getEntityTimeStamp());
90 for (String key: this.attributes.keySet()){
91 rootNode.put(key, this.attributes.get(key));
93 return rootNode.toString();
97 * @return the attributes
99 public Map<String, String> getAttributes() {
104 * @param attributes the attributes to set
106 public void setAttributes(Map<String, String> attributes) {
107 this.attributes = attributes;
113 public ObjectMapper getMapper() {
118 * @param mapper the mapper to set
120 public void setMapper(ObjectMapper mapper) {
121 this.mapper = mapper;
125 public ObjectNode getBulkImportEntity() {
126 // TODO Auto-generated method stub
131 * @see java.lang.Object#toString()
134 public String toString() {
135 return "IndexDocument [" + (entityType != null ? "entityType=" + entityType + ", " : "")
136 + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
138 + (mapper != null ? "mapper=" + mapper + ", " : "") + (id != null ? "id=" + id + ", " : "")
139 + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp + ", " : "") + "]";