2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 * ============LICENSE_START=======================================================
28 * ================================================================================
29 * Copyright © 2017 AT&T Intellectual Property.
30 * Copyright © 2017 Amdocs
31 * All rights reserved.
32 * ================================================================================
33 * Licensed under the Apache License, Version 2.0 (the "License");
34 * you may not use this file except in compliance with the License.
35 * You may obtain a copy of the License at
37 * http://www.apache.org/licenses/LICENSE-2.0
39 * Unless required by applicable law or agreed to in writing, software
40 * distributed under the License is distributed on an "AS IS" BASIS,
41 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42 * See the License for the specific language governing permissions and
43 * limitations under the License.
44 * ============LICENSE_END=========================================================
46 * ECOMP and OpenECOMP are trademarks
47 * and service marks of AT&T Intellectual Property.
50 package org.openecomp.datarouter.entity;
52 import java.io.IOException;
53 import java.io.Serializable;
54 import java.security.MessageDigest;
55 import java.security.NoSuchAlgorithmException;
56 import java.sql.Timestamp;
57 import java.text.SimpleDateFormat;
58 import java.util.ArrayList;
59 import java.util.List;
61 import javax.json.Json;
62 import javax.json.JsonObject;
64 import org.openecomp.datarouter.util.NodeUtils;
67 * Note: AAIEventEntity is a port forward of IndexDocument Has been renamed here to move forward
68 * with abstraction of document store technology.
70 public class AaiEventEntity implements DocumentStoreDataEntity, Serializable {
72 private static final long serialVersionUID = -5188479658230319058L;
74 protected String entityType;
75 protected String entityPrimaryKeyName;
76 protected String entityPrimaryKeyValue;
77 protected ArrayList<String> searchTagCollection = new ArrayList<String>();
78 protected ArrayList<String> searchTagIdCollection = new ArrayList<String>();
79 protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<String>();
80 protected String lastmodTimestamp;
81 protected String link;
83 private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
85 * Generated fields, leave the settings for junit overrides
88 // generated, SHA-256 digest
92 * generated based on searchTagCollection values
94 protected String searchTags;
95 protected String searchTagIds;
96 protected String crossReferenceEntityValues;
99 private static String convertBytesToHexString(byte[] bytesToConvert) {
100 StringBuffer hexString = new StringBuffer();
101 for (int i = 0; i < bytesToConvert.length; i++) {
102 hexString.append(Integer.toHexString(0xFF & bytesToConvert[i]));
104 return hexString.toString();
107 private static String concatArray(List<String> list, char delimiter) {
109 if (list == null || list.size() == 0) {
113 StringBuilder result = new StringBuilder(64);
115 int listSize = list.size();
116 boolean firstValue = true;
118 for (String item : list) {
124 result.append(delimiter).append(item);
129 return result.toString();
133 public AaiEventEntity() {
134 SimpleDateFormat dateFormat = new SimpleDateFormat(TIMESTAMP_FORMAT);
135 Timestamp timestamp = new Timestamp(System.currentTimeMillis());
136 String currentFormattedTimeStamp = dateFormat.format(timestamp);
137 this.lastmodTimestamp = currentFormattedTimeStamp;
140 public void deriveFields() throws NoSuchAlgorithmException {
141 this.id = NodeUtils.generateUniqueShaDigest(this.getLink());
142 this.searchTags = concatArray(searchTagCollection, ';');
143 this.searchTagIds = concatArray(searchTagIdCollection, ';');
144 this.crossReferenceEntityValues = concatArray(crossEntityReferenceCollection, ';');
151 * @see org.openecomp.datarouter.entity.AAIEventEntity#getAsJson()
154 public String getAsJson() throws IOException {
156 JsonObject obj = Json.createObjectBuilder().add("entityType", entityType)
157 .add("entityPrimaryKeyValue", entityPrimaryKeyValue).add("searchTagIDs", searchTagIds)
158 .add("searchTags", searchTags).add("crossEntityReferenceValues", crossReferenceEntityValues)
159 .add("lastmodTimestamp", lastmodTimestamp).add("link", link).build();
161 return obj.toString();
165 public void addSearchTagWithKey(String searchTag, String key) {
166 searchTagIdCollection.add(key);
167 searchTagCollection.add(searchTag);
170 public void addCrossEntityReferenceValue(String crossEntityReferenceValue) {
171 if (!crossEntityReferenceCollection.contains(crossEntityReferenceValue)) {
172 crossEntityReferenceCollection.add(crossEntityReferenceValue);
176 public String getEntityType() {
180 public String getEntityPrimaryKeyName() {
181 return entityPrimaryKeyName;
184 public String getEntityPrimaryKeyValue() {
185 return entityPrimaryKeyValue;
192 * @see org.openecomp.datarouter.entity.AAIEventEntity#getId()
195 public String getId() {
199 public ArrayList<String> getSearchTagCollection() {
200 return searchTagCollection;
203 public String getSearchTags() {
207 public String getSearchTagIDs() {
211 public void setSearchTagIDs(String searchTagIDs) {
212 this.searchTagIds = searchTagIDs;
215 public void setEntityType(String entityType) {
216 this.entityType = entityType;
219 public void setId(String id) {
223 public void setSearchTagCollection(ArrayList<String> searchTagCollection) {
224 this.searchTagCollection = searchTagCollection;
227 public void setSearchTags(String searchTags) {
228 this.searchTags = searchTags;
231 public ArrayList<String> getSearchTagIdCollection() {
232 return searchTagIdCollection;
235 public void setSearchTagIdCollection(ArrayList<String> searchTagIdCollection) {
236 this.searchTagIdCollection = searchTagIdCollection;
239 public String getLastmodTimestamp() {
240 return lastmodTimestamp;
243 public void setLastmodTimestamp(String lastmodTimestamp) {
244 this.lastmodTimestamp = lastmodTimestamp;
247 public void setEntityPrimaryKeyName(String entityPrimaryKeyName) {
248 this.entityPrimaryKeyName = entityPrimaryKeyName;
251 public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) {
252 this.entityPrimaryKeyValue = entityPrimaryKeyValue;
255 public String getLink() {
259 public void setLink(String link) {
264 * public void mergeEntity(AAIEventEntity entityToMergeIn) {
266 * if ( entityToMergeIn == null ) { return; }
268 * if ( !entityToMergeIn.getEntityType().equals( entityType )) { entityType =
269 * entityToMergeIn.getEntityType(); }
271 * if ( !entityToMergeIn.getEntityType().equals( entityType )) { entityType =
272 * entityToMergeIn.getEntityType(); }
278 public String toString() {
279 return "AAIEventEntity [" + (entityType != null ? "entityType=" + entityType + ", " : "")
280 + (entityPrimaryKeyName != null ? "entityPrimaryKeyName=" + entityPrimaryKeyName + ", "
282 + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
284 + (searchTagCollection != null ? "searchTagCollection=" + searchTagCollection + ", " : "")
285 + (searchTagIdCollection != null ? "searchTagIDCollection=" + searchTagIdCollection + ", "
287 + (crossEntityReferenceCollection != null
288 ? "crossEntityReferenceCollection=" + crossEntityReferenceCollection + ", " : "")
289 + "lastmodTimestamp=" + lastmodTimestamp + ", " + (id != null ? "id=" + id + ", " : "")
290 + (searchTags != null ? "searchTags=" + searchTags + ", " : "")
291 + (searchTagIds != null ? "searchTagIDs=" + searchTagIds + ", " : "")
292 + (crossReferenceEntityValues != null
293 ? "crossReferenceEntityValues=" + crossReferenceEntityValues : "")