2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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=========================================================
22 package org.onap.aai.datarouter.entity;
24 import java.io.IOException;
25 import java.io.Serializable;
26 import java.security.NoSuchAlgorithmException;
27 import java.sql.Timestamp;
28 import java.text.SimpleDateFormat;
29 import java.util.ArrayList;
30 import java.util.List;
32 import javax.json.Json;
33 import javax.json.JsonObject;
35 import org.onap.aai.datarouter.util.NodeUtils;
38 * Note: SpikeEventEntity is a port forward of IndexDocument Has been renamed here to move forward
39 * with abstraction of document store technology.
41 public class SpikeEventEntity implements DocumentStoreDataEntity, Serializable {
43 private static final long serialVersionUID = -5188479658230319058L;
45 protected String entityType;
46 protected String entityPrimaryKeyName;
47 protected String entityPrimaryKeyValue;
48 protected ArrayList<String> searchTagCollection = new ArrayList<>();
49 protected ArrayList<String> searchTagIdCollection = new ArrayList<>();
50 protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<>();
51 protected String lastmodTimestamp;
52 protected String link;
54 private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
56 * Generated fields, leave the settings for junit overrides
59 // generated, SHA-256 digest
63 * generated based on searchTagCollection values
65 protected String searchTags;
66 protected String searchTagIds;
67 protected String crossReferenceEntityValues;
71 private static String concatArray(List<String> list, char delimiter) {
73 if (list == null || list.isEmpty()) {
77 StringBuilder result = new StringBuilder(64);
79 boolean firstValue = true;
81 for (String item : list) {
87 result.append(delimiter).append(item);
92 return result.toString();
96 public SpikeEventEntity() {
97 SimpleDateFormat dateFormat = new SimpleDateFormat(TIMESTAMP_FORMAT);
98 Timestamp timestamp = new Timestamp(System.currentTimeMillis());
99 String currentFormattedTimeStamp = dateFormat.format(timestamp);
100 this.lastmodTimestamp = currentFormattedTimeStamp;
103 public void deriveFields() throws NoSuchAlgorithmException {
104 this.id = NodeUtils.generateUniqueShaDigest(link);
105 this.searchTags = concatArray(searchTagCollection, ';');
106 this.searchTagIds = concatArray(searchTagIdCollection, ';');
107 this.crossReferenceEntityValues = concatArray(crossEntityReferenceCollection, ';');
114 * @see org.onap.aai.datarouter.entity.SpikeEventEntity#getAsJson()
117 public String getAsJson() throws IOException {
119 JsonObject obj = Json.createObjectBuilder().add("entityType", entityType)
120 .add("entityPrimaryKeyValue", entityPrimaryKeyValue).add("searchTagIDs", searchTagIds)
121 .add("searchTags", searchTags).add("crossEntityReferenceValues", crossReferenceEntityValues)
122 .add("lastmodTimestamp", lastmodTimestamp).add("link", link).build();
124 return obj.toString();
128 public void addSearchTagWithKey(String searchTag, String key) {
129 searchTagIdCollection.add(key);
130 searchTagCollection.add(searchTag);
133 public void addCrossEntityReferenceValue(String crossEntityReferenceValue) {
134 if (!crossEntityReferenceCollection.contains(crossEntityReferenceValue)) {
135 crossEntityReferenceCollection.add(crossEntityReferenceValue);
139 public String getEntityType() {
143 public String getEntityPrimaryKeyName() {
144 return entityPrimaryKeyName;
147 public String getEntityPrimaryKeyValue() {
148 return entityPrimaryKeyValue;
155 * @see org.onap.aai.datarouter.entity.SpikeEventEntity#getId()
158 public String getId() {
162 public ArrayList<String> getSearchTagCollection() {
163 return searchTagCollection;
166 public String getSearchTags() {
170 public String getSearchTagIDs() {
174 public void setSearchTagIDs(String searchTagIDs) {
175 this.searchTagIds = searchTagIDs;
178 public void setEntityType(String entityType) {
179 this.entityType = entityType;
182 public void setId(String id) {
186 public void setSearchTagCollection(ArrayList<String> searchTagCollection) {
187 this.searchTagCollection = searchTagCollection;
190 public void setSearchTags(String searchTags) {
191 this.searchTags = searchTags;
194 public ArrayList<String> getSearchTagIdCollection() {
195 return searchTagIdCollection;
198 public void setSearchTagIdCollection(ArrayList<String> searchTagIdCollection) {
199 this.searchTagIdCollection = searchTagIdCollection;
202 public String getLastmodTimestamp() {
203 return lastmodTimestamp;
206 public void setLastmodTimestamp(String lastmodTimestamp) {
207 this.lastmodTimestamp = lastmodTimestamp;
210 public void setEntityPrimaryKeyName(String entityPrimaryKeyName) {
211 this.entityPrimaryKeyName = entityPrimaryKeyName;
214 public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) {
215 this.entityPrimaryKeyValue = entityPrimaryKeyValue;
218 public String getLink() {
222 public void setLink(String link) {
228 public String getCrossReferenceEntityValues() {
229 return crossReferenceEntityValues;
232 public void setCrossReferenceEntityValues(String crossReferenceEntityValues) {
233 this.crossReferenceEntityValues = crossReferenceEntityValues;
237 public String toString() {
238 return "SpikeEventEntity [" + (entityType != null ? "entityType=" + entityType + ", " : "")
239 + (entityPrimaryKeyName != null ? "entityPrimaryKeyName=" + entityPrimaryKeyName + ", "
241 + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
243 + (searchTagCollection != null ? "searchTagCollection=" + searchTagCollection + ", " : "")
244 + (searchTagIdCollection != null ? "searchTagIDCollection=" + searchTagIdCollection + ", "
246 + (crossEntityReferenceCollection != null
247 ? "crossEntityReferenceCollection=" + crossEntityReferenceCollection + ", " : "")
248 + "lastmodTimestamp=" + lastmodTimestamp + ", " + (id != null ? "id=" + id + ", " : "")
249 + (searchTags != null ? "searchTags=" + searchTags + ", " : "")
250 + (searchTagIds != null ? "searchTagIDs=" + searchTagIds + ", " : "")
251 + (crossReferenceEntityValues != null
252 ? "crossReferenceEntityValues=" + crossReferenceEntityValues : "")