Update license and poms
[aai/sparky-be.git] / sparkybe-onap-service / src / main / java / org / onap / aai / sparky / sync / entity / AggregationEntity.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
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 package org.onap.aai.sparky.sync.entity;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.onap.aai.sparky.util.NodeUtils;
27
28 import com.fasterxml.jackson.databind.ObjectMapper;
29 import com.fasterxml.jackson.databind.node.ObjectNode;
30
31 /**
32  * The Class AggregationEntity.
33  */
34 public class AggregationEntity extends IndexableEntity implements IndexDocument {
35   private Map<String, String> attributes = new HashMap<String, String>();
36   protected ObjectMapper mapper = new ObjectMapper();
37   
38   /**
39    * Instantiates a new aggregation entity.
40    */
41   public AggregationEntity() {
42     super();
43   }
44
45   /* (non-Javadoc)
46    * @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
47    */
48   @Override
49   public void deriveFields() {
50
51     /*
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.
56      */
57     this.id =
58         NodeUtils.generateUniqueShaDigest(link);
59   }
60
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
65       }
66     }
67   }
68   
69   public void addAttributeKeyValuePair(String key, String value){
70     this.attributes.put(key, value);
71   }
72
73   @Override
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));
80     }
81     return rootNode.toString();
82   }
83
84   /* (non-Javadoc)
85    * @see java.lang.Object#toString()
86    */
87   @Override
88   public String toString() {
89     return "IndexDocument [" + (entityType != null ? "entityType=" + entityType + ", " : "")
90         + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
91             : "")
92         + (mapper != null ? "mapper=" + mapper + ", " : "") + (id != null ? "id=" + id + ", " : "")
93         + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp + ", " : "") + "]";
94   }
95 }