Adding UI extensibility
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / sync / entity / AggregationEntity.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.sparky.sync.entity;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import org.onap.aai.sparky.util.NodeUtils;
29
30 import com.fasterxml.jackson.databind.ObjectMapper;
31 import com.fasterxml.jackson.databind.node.ObjectNode;
32
33 /**
34  * The Class AggregationEntity.
35  */
36 public class AggregationEntity extends IndexableEntity implements IndexDocument {
37   private Map<String, String> attributes = new HashMap<String, String>();
38   protected ObjectMapper mapper = new ObjectMapper();
39
40   /**
41    * Instantiates a new aggregation entity.
42    */
43   public AggregationEntity() {
44     super();
45   }
46
47   /*
48    * (non-Javadoc)
49    * 
50    * @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
51    */
52   @Override
53   public void deriveFields() {
54
55     /*
56      * We'll try and create a unique identity key that we can use for differencing the previously
57      * imported record sets as we won't have granular control of what is created/removed and when.
58      * The best we can hope for is identification of resources by generated Id until the
59      * Identity-Service UUID is tagged against all resources, then we can use that instead.
60      */
61     this.id = NodeUtils.generateUniqueShaDigest(link);
62   }
63
64   public void copyAttributeKeyValuePair(Map<String, Object> map) {
65     for (String key : map.keySet()) {
66       if (!key.equalsIgnoreCase("relationship-list")) { // ignore relationship data which is not
67                                                         // required in aggregation
68         this.attributes.put(key, map.get(key).toString()); // not sure if entity attribute can
69                                                            // contain an object as value
70       }
71     }
72   }
73
74   public void addAttributeKeyValuePair(String key, String value) {
75     this.attributes.put(key, value);
76   }
77
78   @Override
79   public String getAsJson() {
80     ObjectNode rootNode = mapper.createObjectNode();
81     rootNode.put("link", this.getLink());
82     rootNode.put("lastmodTimestamp", this.getEntityTimeStamp());
83     for (String key : this.attributes.keySet()) {
84       rootNode.put(key, this.attributes.get(key));
85     }
86     return rootNode.toString();
87   }
88
89   /*
90    * (non-Javadoc)
91    * 
92    * @see java.lang.Object#toString()
93    */
94   @Override
95   public String toString() {
96     return "IndexDocument [" + (entityType != null ? "entityType=" + entityType + ", " : "")
97         + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
98             : "")
99         + (mapper != null ? "mapper=" + mapper + ", " : "") + (id != null ? "id=" + id + ", " : "")
100         + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp + ", " : "") + "]";
101   }
102 }