Update the dependencies to use project version
[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
42   /**
43    * @return the crossReferenceEntityValues
44    */
45   public String getCrossReferenceEntityValues() {
46     return crossReferenceEntityValues;
47   }
48
49   /**
50    * @param crossReferenceEntityValues the crossReferenceEntityValues to set
51    */
52   public void setCrossReferenceEntityValues(String crossReferenceEntityValues) {
53     this.crossReferenceEntityValues = crossReferenceEntityValues;
54   }
55
56   /**
57    * @return the crossEntityReferenceCollection
58    */
59   public ArrayList<String> getCrossEntityReferenceCollection() {
60     return crossEntityReferenceCollection;
61   }
62
63   /**
64    * @param crossEntityReferenceCollection the crossEntityReferenceCollection to set
65    */
66   public void setCrossEntityReferenceCollection(ArrayList<String> crossEntityReferenceCollection) {
67     this.crossEntityReferenceCollection = crossEntityReferenceCollection;
68   }
69
70   /**
71    * @return the mapper
72    */
73   public ObjectMapper getMapper() {
74     return mapper;
75   }
76
77   /**
78    * @param mapper the mapper to set
79    */
80   public void setMapper(ObjectMapper mapper) {
81     this.mapper = mapper;
82   }
83
84   protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<String>();
85   protected ObjectMapper mapper = new ObjectMapper();
86
87   /**
88    * Instantiates a new indexable cross entity reference.
89    */
90   public IndexableCrossEntityReference() {
91     super();
92   }
93
94   /**
95    * Instantiates a new indexable cross entity reference.
96    *
97    * @param loader the loader
98    */
99   public IndexableCrossEntityReference(OxmModelLoader loader) {
100     super(loader);
101   }
102
103   /**
104    * Adds the cross entity reference value.
105    *
106    * @param crossEntityReferenceValue the cross entity reference value
107    */
108   public void addCrossEntityReferenceValue(String crossEntityReferenceValue) {
109     if (!crossEntityReferenceCollection.contains(crossEntityReferenceValue)) {
110       crossEntityReferenceCollection.add(crossEntityReferenceValue);
111     }
112   }
113
114   /*
115    * (non-Javadoc)
116    * 
117    * @see org.onap.aai.sparky.synchronizer.entity.IndexDocument#deriveFields()
118    */
119   @Override
120   public void deriveFields() {
121     this.id = NodeUtils.generateUniqueShaDigest(link);
122     this.crossReferenceEntityValues = NodeUtils.concatArray(crossEntityReferenceCollection, ";");
123   }
124
125   @Override
126   public String getIndexDocumentJson() {
127     ObjectNode rootNode = mapper.createObjectNode();
128     rootNode.put("entityType", this.getEntityType());
129     rootNode.put("entityPrimaryKeyValue", this.getEntityPrimaryKeyValue());
130     rootNode.put("crossEntityReferenceValues", crossReferenceEntityValues);
131     rootNode.put("link", link);
132     rootNode.put("lastmodTimestamp", this.getEntityTimeStamp());
133     return rootNode.toString();
134   }
135
136   @Override
137   public ObjectNode getBulkImportEntity() {
138     // TODO Auto-generated method stub
139     return null;
140   }
141
142   /*
143    * (non-Javadoc)
144    * 
145    * @see java.lang.Object#toString()
146    */
147   @Override
148   public String toString() {
149     return "IndexableCrossEntityReference ["
150         + (crossReferenceEntityValues != null
151             ? "crossReferenceEntityValues=" + crossReferenceEntityValues + ", " : "")
152         + (crossEntityReferenceCollection != null
153             ? "crossEntityReferenceCollection=" + crossEntityReferenceCollection + ", " : "")
154         + (mapper != null ? "mapper=" + mapper + ", " : "") + (id != null ? "id=" + id + ", " : "")
155         + (entityType != null ? "entityType=" + entityType + ", " : "")
156         + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
157             : "")
158         + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp + ", " : "")
159         + (link != null ? "link=" + link + ", " : "") + (loader != null ? "loader=" + loader : "")
160         + "]";
161   }
162
163 }