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 package org.onap.aai.datarouter.entity;
28 import java.io.IOException;
29 import java.io.Serializable;
30 import java.security.NoSuchAlgorithmException;
31 import java.sql.Timestamp;
32 import java.text.SimpleDateFormat;
33 import java.util.ArrayList;
34 import java.util.List;
36 import javax.json.Json;
37 import javax.json.JsonObject;
39 import org.onap.aai.datarouter.util.NodeUtils;
42 * Note: SpikeEventEntity is a port forward of IndexDocument Has been renamed here to move forward
43 * with abstraction of document store technology.
45 public class SpikeEventEntity implements DocumentStoreDataEntity, Serializable {
47 private static final long serialVersionUID = -5188479658230319058L;
49 protected String entityType;
50 protected String entityPrimaryKeyName;
51 protected String entityPrimaryKeyValue;
52 protected ArrayList<String> searchTagCollection = new ArrayList<>();
53 protected ArrayList<String> searchTagIdCollection = new ArrayList<>();
54 protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<>();
55 protected String lastmodTimestamp;
56 protected String link;
58 private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
60 * Generated fields, leave the settings for junit overrides
63 // generated, SHA-256 digest
67 * generated based on searchTagCollection values
69 protected String searchTags;
70 protected String searchTagIds;
71 protected String crossReferenceEntityValues;
75 private static String concatArray(List<String> list, char delimiter) {
77 if (list == null || list.isEmpty()) {
81 StringBuilder result = new StringBuilder(64);
83 boolean firstValue = true;
85 for (String item : list) {
91 result.append(delimiter).append(item);
96 return result.toString();
100 public SpikeEventEntity() {
101 SimpleDateFormat dateFormat = new SimpleDateFormat(TIMESTAMP_FORMAT);
102 Timestamp timestamp = new Timestamp(System.currentTimeMillis());
103 String currentFormattedTimeStamp = dateFormat.format(timestamp);
104 this.lastmodTimestamp = currentFormattedTimeStamp;
107 public void deriveFields() throws NoSuchAlgorithmException {
108 this.id = NodeUtils.generateUniqueShaDigest(link);
109 this.searchTags = concatArray(searchTagCollection, ';');
110 this.searchTagIds = concatArray(searchTagIdCollection, ';');
111 this.crossReferenceEntityValues = concatArray(crossEntityReferenceCollection, ';');
118 * @see org.onap.aai.datarouter.entity.SpikeEventEntity#getAsJson()
121 public String getAsJson() throws IOException {
123 JsonObject obj = Json.createObjectBuilder().add("entityType", entityType)
124 .add("entityPrimaryKeyValue", entityPrimaryKeyValue).add("searchTagIDs", searchTagIds)
125 .add("searchTags", searchTags).add("crossEntityReferenceValues", crossReferenceEntityValues)
126 .add("lastmodTimestamp", lastmodTimestamp).add("link", link).build();
128 return obj.toString();
132 public void addSearchTagWithKey(String searchTag, String key) {
133 searchTagIdCollection.add(key);
134 searchTagCollection.add(searchTag);
137 public void addCrossEntityReferenceValue(String crossEntityReferenceValue) {
138 if (!crossEntityReferenceCollection.contains(crossEntityReferenceValue)) {
139 crossEntityReferenceCollection.add(crossEntityReferenceValue);
143 public String getEntityType() {
147 public String getEntityPrimaryKeyName() {
148 return entityPrimaryKeyName;
151 public String getEntityPrimaryKeyValue() {
152 return entityPrimaryKeyValue;
159 * @see org.onap.aai.datarouter.entity.SpikeEventEntity#getId()
162 public String getId() {
166 public ArrayList<String> getSearchTagCollection() {
167 return searchTagCollection;
170 public String getSearchTags() {
174 public String getSearchTagIDs() {
178 public void setSearchTagIDs(String searchTagIDs) {
179 this.searchTagIds = searchTagIDs;
182 public void setEntityType(String entityType) {
183 this.entityType = entityType;
186 public void setId(String id) {
190 public void setSearchTagCollection(ArrayList<String> searchTagCollection) {
191 this.searchTagCollection = searchTagCollection;
194 public void setSearchTags(String searchTags) {
195 this.searchTags = searchTags;
198 public ArrayList<String> getSearchTagIdCollection() {
199 return searchTagIdCollection;
202 public void setSearchTagIdCollection(ArrayList<String> searchTagIdCollection) {
203 this.searchTagIdCollection = searchTagIdCollection;
206 public String getLastmodTimestamp() {
207 return lastmodTimestamp;
210 public void setLastmodTimestamp(String lastmodTimestamp) {
211 this.lastmodTimestamp = lastmodTimestamp;
214 public void setEntityPrimaryKeyName(String entityPrimaryKeyName) {
215 this.entityPrimaryKeyName = entityPrimaryKeyName;
218 public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) {
219 this.entityPrimaryKeyValue = entityPrimaryKeyValue;
222 public String getLink() {
226 public void setLink(String link) {
232 public String getCrossReferenceEntityValues() {
233 return crossReferenceEntityValues;
236 public void setCrossReferenceEntityValues(String crossReferenceEntityValues) {
237 this.crossReferenceEntityValues = crossReferenceEntityValues;
241 public String toString() {
242 return "SpikeEventEntity [" + (entityType != null ? "entityType=" + entityType + ", " : "")
243 + (entityPrimaryKeyName != null ? "entityPrimaryKeyName=" + entityPrimaryKeyName + ", "
245 + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
247 + (searchTagCollection != null ? "searchTagCollection=" + searchTagCollection + ", " : "")
248 + (searchTagIdCollection != null ? "searchTagIDCollection=" + searchTagIdCollection + ", "
250 + (crossEntityReferenceCollection != null
251 ? "crossEntityReferenceCollection=" + crossEntityReferenceCollection + ", " : "")
252 + "lastmodTimestamp=" + lastmodTimestamp + ", " + (id != null ? "id=" + id + ", " : "")
253 + (searchTags != null ? "searchTags=" + searchTags + ", " : "")
254 + (searchTagIds != null ? "searchTagIDs=" + searchTagIds + ", " : "")
255 + (crossReferenceEntityValues != null
256 ? "crossReferenceEntityValues=" + crossReferenceEntityValues : "")