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