Renaming openecomp to onap
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / synchronizer / entity / IndexableCrossEntityReference.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.ArrayList;
26
27 import org.onap.aai.sparky.config.oxm.OxmModelLoader;
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 /**
35  * The Class IndexableCrossEntityReference.
36  */
37
38 public class IndexableCrossEntityReference extends IndexableEntity implements IndexDocument {
39
40   protected String crossReferenceEntityValues;
41   protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<String>();
42   protected ObjectMapper mapper = new ObjectMapper();
43
44   /**
45    * Instantiates a new indexable cross entity reference.
46    */
47   public IndexableCrossEntityReference() {
48     super();
49   }
50
51   /**
52    * Instantiates a new indexable cross entity reference.
53    *
54    * @param loader the loader
55    */
56   public IndexableCrossEntityReference(OxmModelLoader loader) {
57     super(loader);
58   }
59
60   /**
61    * Adds the cross entity reference value.
62    *
63    * @param crossEntityReferenceValue the cross entity reference value
64    */
65   public void addCrossEntityReferenceValue(String crossEntityReferenceValue) {
66     if (!crossEntityReferenceCollection.contains(crossEntityReferenceValue)) {
67       crossEntityReferenceCollection.add(crossEntityReferenceValue);
68     }
69   }
70
71   /* (non-Javadoc)
72    * @see org.onap.aai.sparky.synchronizer.entity.IndexDocument#deriveFields()
73    */
74   @Override
75   public void deriveFields() {
76     this.id = NodeUtils.generateUniqueShaDigest(link);
77     this.crossReferenceEntityValues = NodeUtils.concatArray(crossEntityReferenceCollection, ";");
78   }
79
80   @Override
81   public String getIndexDocumentJson() {
82     ObjectNode rootNode = mapper.createObjectNode();
83     rootNode.put("entityType", this.getEntityType());
84     rootNode.put("entityPrimaryKeyValue", this.getEntityPrimaryKeyValue());
85     rootNode.put("crossEntityReferenceValues", crossReferenceEntityValues);
86     rootNode.put("link", link);
87     rootNode.put("lastmodTimestamp", this.getEntityTimeStamp());
88     return rootNode.toString();
89   }
90
91   @Override
92   public ObjectNode getBulkImportEntity() {
93     // TODO Auto-generated method stub
94     return null;
95   }
96
97   /* (non-Javadoc)
98    * @see java.lang.Object#toString()
99    */
100   @Override
101   public String toString() {
102     return "IndexableCrossEntityReference ["
103         + (crossReferenceEntityValues != null
104             ? "crossReferenceEntityValues=" + crossReferenceEntityValues + ", " : "")
105         + (crossEntityReferenceCollection != null
106             ? "crossEntityReferenceCollection=" + crossEntityReferenceCollection + ", " : "")
107         + (mapper != null ? "mapper=" + mapper + ", " : "") + (id != null ? "id=" + id + ", " : "")
108         + (entityType != null ? "entityType=" + entityType + ", " : "")
109         + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
110             : "")
111         + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp + ", " : "")
112         + (link != null ? "link=" + link + ", " : "") + (loader != null ? "loader=" + loader : "")
113         + "]";
114   }
115
116 }