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.openecomp.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<String>();
76 protected ArrayList<String> searchTagIdCollection = new ArrayList<String>();
77 protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<String>();
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 StringBuffer hexString = new StringBuffer();
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.size() == 0) {
111 StringBuilder result = new StringBuilder(64);
113 int listSize = list.size();
114 boolean firstValue = true;
116 for (String item : list) {
122 result.append(delimiter).append(item);
127 return result.toString();
131 public AaiEventEntity() {
132 SimpleDateFormat dateFormat = new SimpleDateFormat(TIMESTAMP_FORMAT);
133 Timestamp timestamp = new Timestamp(System.currentTimeMillis());
134 String currentFormattedTimeStamp = dateFormat.format(timestamp);
135 this.lastmodTimestamp = currentFormattedTimeStamp;
138 public void deriveFields() throws NoSuchAlgorithmException {
139 this.id = NodeUtils.generateUniqueShaDigest(link);
140 this.searchTags = concatArray(searchTagCollection, ';');
141 this.searchTagIds = concatArray(searchTagIdCollection, ';');
142 this.crossReferenceEntityValues = concatArray(crossEntityReferenceCollection, ';');
149 * @see org.openecomp.datarouter.entity.AAIEventEntity#getAsJson()
152 public String getAsJson() throws IOException {
154 JsonObject obj = Json.createObjectBuilder().add("entityType", entityType)
155 .add("entityPrimaryKeyValue", entityPrimaryKeyValue).add("searchTagIDs", searchTagIds)
156 .add("searchTags", searchTags).add("crossEntityReferenceValues", crossReferenceEntityValues)
157 .add("lastmodTimestamp", lastmodTimestamp).add("link", link).build();
159 return obj.toString();
163 public void addSearchTagWithKey(String searchTag, String key) {
164 searchTagIdCollection.add(key);
165 searchTagCollection.add(searchTag);
168 public void addCrossEntityReferenceValue(String crossEntityReferenceValue) {
169 if (!crossEntityReferenceCollection.contains(crossEntityReferenceValue)) {
170 crossEntityReferenceCollection.add(crossEntityReferenceValue);
174 public String getEntityType() {
178 public String getEntityPrimaryKeyName() {
179 return entityPrimaryKeyName;
182 public String getEntityPrimaryKeyValue() {
183 return entityPrimaryKeyValue;
190 * @see org.openecomp.datarouter.entity.AAIEventEntity#getId()
193 public String getId() {
197 public ArrayList<String> getSearchTagCollection() {
198 return searchTagCollection;
201 public String getSearchTags() {
205 public String getSearchTagIDs() {
209 public void setSearchTagIDs(String searchTagIDs) {
210 this.searchTagIds = searchTagIDs;
213 public void setEntityType(String entityType) {
214 this.entityType = entityType;
217 public void setId(String id) {
221 public void setSearchTagCollection(ArrayList<String> searchTagCollection) {
222 this.searchTagCollection = searchTagCollection;
225 public void setSearchTags(String searchTags) {
226 this.searchTags = searchTags;
229 public ArrayList<String> getSearchTagIdCollection() {
230 return searchTagIdCollection;
233 public void setSearchTagIdCollection(ArrayList<String> searchTagIdCollection) {
234 this.searchTagIdCollection = searchTagIdCollection;
237 public String getLastmodTimestamp() {
238 return lastmodTimestamp;
241 public void setLastmodTimestamp(String lastmodTimestamp) {
242 this.lastmodTimestamp = lastmodTimestamp;
245 public void setEntityPrimaryKeyName(String entityPrimaryKeyName) {
246 this.entityPrimaryKeyName = entityPrimaryKeyName;
249 public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) {
250 this.entityPrimaryKeyValue = entityPrimaryKeyValue;
253 public String getLink() {
257 public void setLink(String link) {
262 * public void mergeEntity(AAIEventEntity entityToMergeIn) {
264 * if ( entityToMergeIn == null ) { return; }
266 * if ( !entityToMergeIn.getEntityType().equals( entityType )) { entityType =
267 * entityToMergeIn.getEntityType(); }
269 * if ( !entityToMergeIn.getEntityType().equals( entityType )) { entityType =
270 * entityToMergeIn.getEntityType(); }
275 public String getCrossReferenceEntityValues() {
276 return crossReferenceEntityValues;
279 public void setCrossReferenceEntityValues(String crossReferenceEntityValues) {
280 this.crossReferenceEntityValues = crossReferenceEntityValues;
284 public String toString() {
285 return "AAIEventEntity [" + (entityType != null ? "entityType=" + entityType + ", " : "")
286 + (entityPrimaryKeyName != null ? "entityPrimaryKeyName=" + entityPrimaryKeyName + ", "
288 + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
290 + (searchTagCollection != null ? "searchTagCollection=" + searchTagCollection + ", " : "")
291 + (searchTagIdCollection != null ? "searchTagIDCollection=" + searchTagIdCollection + ", "
293 + (crossEntityReferenceCollection != null
294 ? "crossEntityReferenceCollection=" + crossEntityReferenceCollection + ", " : "")
295 + "lastmodTimestamp=" + lastmodTimestamp + ", " + (id != null ? "id=" + id + ", " : "")
296 + (searchTags != null ? "searchTags=" + searchTags + ", " : "")
297 + (searchTagIds != null ? "searchTagIDs=" + searchTagIds + ", " : "")
298 + (crossReferenceEntityValues != null
299 ? "crossReferenceEntityValues=" + crossReferenceEntityValues : "")