2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 * ============LICENSE_START=======================================================
26 * ================================================================================
27 * Copyright © 2017 AT&T Intellectual Property.
28 * Copyright © 2017 Amdocs
29 * All rights reserved.
30 * ================================================================================
31 * Licensed under the Apache License, Version 2.0 (the "License");
32 * you may not use this file except in compliance with the License.
33 * You may obtain a copy of the License at
35 * http://www.apache.org/licenses/LICENSE-2.0
37 * Unless required by applicable law or agreed to in writing, software
38 * distributed under the License is distributed on an "AS IS" BASIS,
39 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40 * See the License for the specific language governing permissions and
41 * limitations under the License.
42 * ============LICENSE_END=========================================================
44 * ECOMP and OpenECOMP are trademarks
45 * and service marks of AT&T Intellectual Property.
48 package org.onap.aai.datarouter.entity;
50 import java.io.IOException;
51 import java.io.Serializable;
52 import java.security.MessageDigest;
53 import java.security.NoSuchAlgorithmException;
54 import java.sql.Timestamp;
55 import java.text.SimpleDateFormat;
56 import java.util.ArrayList;
57 import java.util.List;
59 import javax.json.Json;
60 import javax.json.JsonObject;
62 import org.openecomp.datarouter.util.NodeUtils;
65 * Note: AAIEventEntity is a port forward of IndexDocument Has been renamed here to move forward
66 * with abstraction of document store technology.
68 public class AaiEventEntity implements DocumentStoreDataEntity, Serializable {
70 private static final long serialVersionUID = -5188479658230319058L;
72 protected String entityType;
73 protected String entityPrimaryKeyName;
74 protected String entityPrimaryKeyValue;
75 protected ArrayList<String> searchTagCollection = new ArrayList<>();
76 protected ArrayList<String> searchTagIdCollection = new ArrayList<>();
77 protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<>();
78 protected String lastmodTimestamp;
79 protected String link;
81 private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
83 * Generated fields, leave the settings for junit overrides
86 // generated, SHA-256 digest
90 * generated based on searchTagCollection values
92 protected String searchTags;
93 protected String searchTagIds;
94 protected String crossReferenceEntityValues;
97 private static String convertBytesToHexString(byte[] bytesToConvert) {
98 StringBuilder hexString = new StringBuilder();
99 for (int i = 0; i < bytesToConvert.length; i++) {
100 hexString.append(Integer.toHexString(0xFF & bytesToConvert[i]));
102 return hexString.toString();
105 private static String concatArray(List<String> list, char delimiter) {
107 if (list == null || list.isEmpty()) {
111 StringBuilder result = new StringBuilder(64);
113 boolean firstValue = true;
115 for (String item : list) {
121 result.append(delimiter).append(item);
126 return result.toString();
130 public AaiEventEntity() {
131 SimpleDateFormat dateFormat = new SimpleDateFormat(TIMESTAMP_FORMAT);
132 Timestamp timestamp = new Timestamp(System.currentTimeMillis());
133 String currentFormattedTimeStamp = dateFormat.format(timestamp);
134 this.lastmodTimestamp = currentFormattedTimeStamp;
137 public void deriveFields() throws NoSuchAlgorithmException {
138 this.id = NodeUtils.generateUniqueShaDigest(link);
139 this.searchTags = concatArray(searchTagCollection, ';');
140 this.searchTagIds = concatArray(searchTagIdCollection, ';');
141 this.crossReferenceEntityValues = concatArray(crossEntityReferenceCollection, ';');
148 * @see org.onap.aai.datarouter.entity.AAIEventEntity#getAsJson()
151 public String getAsJson() throws IOException {
153 JsonObject obj = Json.createObjectBuilder().add("entityType", entityType)
154 .add("entityPrimaryKeyValue", entityPrimaryKeyValue).add("searchTagIDs", searchTagIds)
155 .add("searchTags", searchTags).add("crossEntityReferenceValues", crossReferenceEntityValues)
156 .add("lastmodTimestamp", lastmodTimestamp).add("link", link).build();
158 return obj.toString();
162 public void addSearchTagWithKey(String searchTag, String key) {
163 searchTagIdCollection.add(key);
164 searchTagCollection.add(searchTag);
167 public void addCrossEntityReferenceValue(String crossEntityReferenceValue) {
168 if (!crossEntityReferenceCollection.contains(crossEntityReferenceValue)) {
169 crossEntityReferenceCollection.add(crossEntityReferenceValue);
173 public String getEntityType() {
177 public String getEntityPrimaryKeyName() {
178 return entityPrimaryKeyName;
181 public String getEntityPrimaryKeyValue() {
182 return entityPrimaryKeyValue;
189 * @see org.onap.aai.datarouter.entity.AAIEventEntity#getId()
192 public String getId() {
196 public ArrayList<String> getSearchTagCollection() {
197 return searchTagCollection;
200 public String getSearchTags() {
204 public String getSearchTagIDs() {
208 public void setSearchTagIDs(String searchTagIDs) {
209 this.searchTagIds = searchTagIDs;
212 public void setEntityType(String entityType) {
213 this.entityType = entityType;
216 public void setId(String id) {
220 public void setSearchTagCollection(ArrayList<String> searchTagCollection) {
221 this.searchTagCollection = searchTagCollection;
224 public void setSearchTags(String searchTags) {
225 this.searchTags = searchTags;
228 public ArrayList<String> getSearchTagIdCollection() {
229 return searchTagIdCollection;
232 public void setSearchTagIdCollection(ArrayList<String> searchTagIdCollection) {
233 this.searchTagIdCollection = searchTagIdCollection;
236 public String getLastmodTimestamp() {
237 return lastmodTimestamp;
240 public void setLastmodTimestamp(String lastmodTimestamp) {
241 this.lastmodTimestamp = lastmodTimestamp;
244 public void setEntityPrimaryKeyName(String entityPrimaryKeyName) {
245 this.entityPrimaryKeyName = entityPrimaryKeyName;
248 public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) {
249 this.entityPrimaryKeyValue = entityPrimaryKeyValue;
252 public String getLink() {
256 public void setLink(String link) {
261 * public void mergeEntity(AAIEventEntity entityToMergeIn) {
263 * if ( entityToMergeIn == null ) { return; }
265 * if ( !entityToMergeIn.getEntityType().equals( entityType )) { entityType =
266 * entityToMergeIn.getEntityType(); }
268 * if ( !entityToMergeIn.getEntityType().equals( entityType )) { entityType =
269 * entityToMergeIn.getEntityType(); }
274 public String getCrossReferenceEntityValues() {
275 return crossReferenceEntityValues;
278 public void setCrossReferenceEntityValues(String crossReferenceEntityValues) {
279 this.crossReferenceEntityValues = crossReferenceEntityValues;
283 public String toString() {
284 return "AAIEventEntity [" + (entityType != null ? "entityType=" + entityType + ", " : "")
285 + (entityPrimaryKeyName != null ? "entityPrimaryKeyName=" + entityPrimaryKeyName + ", "
287 + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
289 + (searchTagCollection != null ? "searchTagCollection=" + searchTagCollection + ", " : "")
290 + (searchTagIdCollection != null ? "searchTagIDCollection=" + searchTagIdCollection + ", "
292 + (crossEntityReferenceCollection != null
293 ? "crossEntityReferenceCollection=" + crossEntityReferenceCollection + ", " : "")
294 + "lastmodTimestamp=" + lastmodTimestamp + ", " + (id != null ? "id=" + id + ", " : "")
295 + (searchTags != null ? "searchTags=" + searchTags + ", " : "")
296 + (searchTagIds != null ? "searchTagIDs=" + searchTagIds + ", " : "")
297 + (crossReferenceEntityValues != null
298 ? "crossReferenceEntityValues=" + crossReferenceEntityValues : "")