Initial commit for AAI-UI(sparky-backend)
[aai/sparky-be.git] / src / main / java / org / openecomp / sparky / synchronizer / entity / IndexableCrossEntityReference.java
1 /**
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25
26 package org.openecomp.sparky.synchronizer.entity;
27
28 import java.util.ArrayList;
29
30 import org.openecomp.sparky.config.oxm.OxmModelLoader;
31 import org.openecomp.sparky.util.NodeUtils;
32
33 import com.fasterxml.jackson.databind.ObjectMapper;
34 import com.fasterxml.jackson.databind.node.ObjectNode;
35
36
37 /**
38  * The Class IndexableCrossEntityReference.
39  */
40
41 public class IndexableCrossEntityReference extends IndexableEntity implements IndexDocument {
42
43   protected String crossReferenceEntityValues;
44   protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<String>();
45   protected ObjectMapper mapper = new ObjectMapper();
46
47   /**
48    * Instantiates a new indexable cross entity reference.
49    */
50   public IndexableCrossEntityReference() {
51     super();
52   }
53
54   /**
55    * Instantiates a new indexable cross entity reference.
56    *
57    * @param loader the loader
58    */
59   public IndexableCrossEntityReference(OxmModelLoader loader) {
60     super(loader);
61   }
62
63   /**
64    * Adds the cross entity reference value.
65    *
66    * @param crossEntityReferenceValue the cross entity reference value
67    */
68   public void addCrossEntityReferenceValue(String crossEntityReferenceValue) {
69     if (!crossEntityReferenceCollection.contains(crossEntityReferenceValue)) {
70       crossEntityReferenceCollection.add(crossEntityReferenceValue);
71     }
72   }
73
74   /* (non-Javadoc)
75    * @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
76    */
77   @Override
78   public void deriveFields() {
79     this.id = NodeUtils.generateUniqueShaDigest(link);
80     this.crossReferenceEntityValues = NodeUtils.concatArray(crossEntityReferenceCollection, ";");
81   }
82
83   @Override
84   public String getIndexDocumentJson() {
85     ObjectNode rootNode = mapper.createObjectNode();
86     rootNode.put("entityType", this.getEntityType());
87     rootNode.put("entityPrimaryKeyValue", this.getEntityPrimaryKeyValue());
88     rootNode.put("crossEntityReferenceValues", crossReferenceEntityValues);
89     rootNode.put("link", link);
90     rootNode.put("lastmodTimestamp", this.getEntityTimeStamp());
91     return rootNode.toString();
92   }
93
94   @Override
95   public ObjectNode getBulkImportEntity() {
96     // TODO Auto-generated method stub
97     return null;
98   }
99
100   /* (non-Javadoc)
101    * @see java.lang.Object#toString()
102    */
103   @Override
104   public String toString() {
105     return "IndexableCrossEntityReference ["
106         + (crossReferenceEntityValues != null
107             ? "crossReferenceEntityValues=" + crossReferenceEntityValues + ", " : "")
108         + (crossEntityReferenceCollection != null
109             ? "crossEntityReferenceCollection=" + crossEntityReferenceCollection + ", " : "")
110         + (mapper != null ? "mapper=" + mapper + ", " : "") + (id != null ? "id=" + id + ", " : "")
111         + (entityType != null ? "entityType=" + entityType + ", " : "")
112         + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
113             : "")
114         + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp + ", " : "")
115         + (link != null ? "link=" + link + ", " : "") + (loader != null ? "loader=" + loader : "")
116         + "]";
117   }
118
119 }