Update the dependencies to use project version
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / synchronizer / 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.synchronizer.entity;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import org.onap.aai.sparky.config.oxm.OxmModelLoader;
29 import org.onap.aai.sparky.util.NodeUtils;
30
31 import com.fasterxml.jackson.databind.ObjectMapper;
32 import com.fasterxml.jackson.databind.node.ObjectNode;
33
34 /**
35  * The Class AggregationEntity.
36  */
37 public class AggregationEntity extends IndexableEntity implements IndexDocument {
38   private Map<String, String> attributes = new HashMap<String, String>();
39   protected ObjectMapper mapper = new ObjectMapper();
40
41   /**
42    * Instantiates a new aggregation entity.
43    */
44   public AggregationEntity() {
45     super();
46   }
47
48   /**
49    * Instantiates a new aggregation entity.
50    *
51    * @param loader the loader
52    */
53   public AggregationEntity(OxmModelLoader loader) {
54     super(loader);
55   }
56
57   /*
58    * (non-Javadoc)
59    * 
60    * @see org.onap.aai.sparky.synchronizer.entity.IndexDocument#deriveFields()
61    */
62   @Override
63   public void deriveFields() {
64
65     /*
66      * We'll try and create a unique identity key that we can use for differencing the previously
67      * imported record sets as we won't have granular control of what is created/removed and when.
68      * The best we can hope for is identification of resources by generated Id until the
69      * Identity-Service UUID is tagged against all resources, then we can use that instead.
70      */
71     this.id = NodeUtils.generateUniqueShaDigest(link);
72   }
73
74   public void copyAttributeKeyValuePair(Map<String, Object> map) {
75     for (String key : map.keySet()) {
76       if (!key.equalsIgnoreCase("relationship-list")) { // ignore relationship data which is not
77                                                         // required in aggregation
78         this.attributes.put(key, map.get(key).toString()); // not sure if entity attribute can
79                                                            // contain an object as value
80       }
81     }
82   }
83
84   public void addAttributeKeyValuePair(String key, String value) {
85     this.attributes.put(key, value);
86   }
87
88   @Override
89   public String getIndexDocumentJson() {
90     ObjectNode rootNode = mapper.createObjectNode();
91     rootNode.put("link", this.getLink());
92     rootNode.put("lastmodTimestamp", this.getEntityTimeStamp());
93     for (String key : this.attributes.keySet()) {
94       rootNode.put(key, this.attributes.get(key));
95     }
96     return rootNode.toString();
97   }
98
99   /**
100    * @return the attributes
101    */
102   public Map<String, String> getAttributes() {
103     return attributes;
104   }
105
106   /**
107    * @param attributes the attributes to set
108    */
109   public void setAttributes(Map<String, String> attributes) {
110     this.attributes = attributes;
111   }
112
113   /**
114    * @return the mapper
115    */
116   public ObjectMapper getMapper() {
117     return mapper;
118   }
119
120   /**
121    * @param mapper the mapper to set
122    */
123   public void setMapper(ObjectMapper mapper) {
124     this.mapper = mapper;
125   }
126
127   @Override
128   public ObjectNode getBulkImportEntity() {
129     // TODO Auto-generated method stub
130     return null;
131   }
132
133   /*
134    * (non-Javadoc)
135    * 
136    * @see java.lang.Object#toString()
137    */
138   @Override
139   public String toString() {
140     return "IndexDocument [" + (entityType != null ? "entityType=" + entityType + ", " : "")
141         + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
142             : "")
143         + (mapper != null ? "mapper=" + mapper + ", " : "") + (id != null ? "id=" + id + ", " : "")
144         + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp + ", " : "") + "]";
145   }
146 }