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.
23 package org.onap.aai.sparky.synchronizer.entity;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.fasterxml.jackson.databind.node.ObjectNode;
28 import java.util.ArrayList;
29 import java.util.List;
31 import org.onap.aai.sparky.config.oxm.OxmModelLoader;
32 import org.onap.aai.sparky.util.NodeUtils;
35 * The Class SearchableEntity.
37 public class SearchableEntity extends IndexableEntity implements IndexDocument {
38 protected List<String> searchTagCollection = new ArrayList<String>();
43 public ObjectMapper getMapper() {
48 * @param mapper the mapper to set
50 public void setMapper(ObjectMapper mapper) {
55 * @param searchTagCollection the searchTagCollection to set
57 public void setSearchTagCollection(List<String> searchTagCollection) {
58 this.searchTagCollection = searchTagCollection;
62 * @param searchTagIdCollection the searchTagIdCollection to set
64 public void setSearchTagIdCollection(List<String> searchTagIdCollection) {
65 this.searchTagIdCollection = searchTagIdCollection;
69 * @param searchTags the searchTags to set
71 public void setSearchTags(String searchTags) {
72 this.searchTags = searchTags;
76 * @param searchTagIDs the searchTagIDs to set
78 public void setSearchTagIDs(String searchTagIDs) {
79 this.searchTagIDs = searchTagIDs;
82 protected List<String> searchTagIdCollection = new ArrayList<String>();
83 protected ObjectMapper mapper = new ObjectMapper();
86 * Instantiates a new searchable entity.
88 public SearchableEntity() {
93 * Instantiates a new searchable entity.
95 * @param loader the loader
97 public SearchableEntity(OxmModelLoader loader) {
102 * Generated fields, leave the settings for junit overrides
104 protected String searchTags; // generated based on searchTagCollection values
105 protected String searchTagIDs;
108 * Generates the sha based id.
110 public void generateId() {
111 this.id = NodeUtils.generateUniqueShaDigest(link);
117 * @see org.onap.aai.sparky.synchronizer.entity.IndexDocument#deriveFields()
120 public void deriveFields() {
123 * We'll try and create a unique identity key that we can use for differencing the previously
124 * imported record sets as we won't have granular control of what is created/removed and when.
125 * The best we can hope for is identification of resources by generated Id until the
126 * Identity-Service UUID is tagged against all resources, then we can use that instead.
129 this.searchTags = NodeUtils.concatArray(searchTagCollection, ";");
130 this.searchTagIDs = NodeUtils.concatArray(this.searchTagIdCollection, ";");
134 * Adds the search tag with key.
136 * @param searchTag the search tag
137 * @param searchTagKey the key associated with the search tag (key:value)
139 public void addSearchTagWithKey(String searchTag, String searchTagKey) {
140 searchTagIdCollection.add(searchTagKey);
141 searchTagCollection.add(searchTag);
144 public List<String> getSearchTagCollection() {
145 return searchTagCollection;
148 public String getSearchTags() {
152 public String getSearchTagIDs() {
156 public List<String> getSearchTagIdCollection() {
157 return searchTagIdCollection;
161 public String getIndexDocumentJson() {
162 ObjectNode rootNode = mapper.createObjectNode();
163 rootNode.put("entityType", this.getEntityType());
164 rootNode.put("entityPrimaryKeyValue", this.getEntityPrimaryKeyValue());
165 rootNode.put("searchTagIDs", this.getSearchTagIDs());
166 rootNode.put("searchTags", this.getSearchTags());
167 rootNode.put("link", this.getLink());
168 rootNode.put("lastmodTimestamp", this.getEntityTimeStamp());
169 return rootNode.toString();
173 public ObjectNode getBulkImportEntity() {
174 // TODO Auto-generated method stub
181 * @see java.lang.Object#toString()
184 public String toString() {
185 return "IndexDocument [" + (entityType != null ? "entityType=" + entityType + ", " : "")
186 + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
188 + (searchTagCollection != null ? "searchTagCollection=" + searchTagCollection + ", " : "")
189 + (searchTagIdCollection != null ? "searchTagIDCollection=" + searchTagIdCollection + ", "
191 + (mapper != null ? "mapper=" + mapper + ", " : "") + (id != null ? "id=" + id + ", " : "")
192 + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp + ", " : "")
193 + (searchTags != null ? "searchTags=" + searchTags + ", " : "")
194 + (searchTagIDs != null ? "searchTagIDs=" + searchTagIDs : "") + "]";