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.sync.entity;
25 import java.util.ArrayList;
26 import java.util.List;
28 import org.onap.aai.sparky.util.NodeUtils;
30 import com.fasterxml.jackson.annotation.JsonIgnore;
31 import com.fasterxml.jackson.annotation.JsonProperty;
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
36 * The Class SearchableEntity.
38 public class SearchableEntity extends IndexableEntity implements IndexDocument {
41 protected List<String> searchTagCollection = new ArrayList<String>();
44 protected List<String> searchTagIdCollection = new ArrayList<String>();
47 protected ObjectMapper mapper = new ObjectMapper();
50 * Instantiates a new searchable entity.
52 public SearchableEntity() {
57 * Generated fields, leave the settings for junit overrides
60 protected String searchTags; // generated based on searchTagCollection values
62 protected String searchTagIDs;
65 * Generates the sha based id.
67 public void generateId() {
68 this.id = NodeUtils.generateUniqueShaDigest(link);
74 * @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
77 public void deriveFields() {
80 * We'll try and create a unique identity key that we can use for differencing the previously
81 * imported record sets as we won't have granular control of what is created/removed and when.
82 * The best we can hope for is identification of resources by generated Id until the
83 * Identity-Service UUID is tagged against all resources, then we can use that instead.
86 this.searchTags = NodeUtils.concatArray(searchTagCollection, ";");
87 this.searchTagIDs = NodeUtils.concatArray(this.searchTagIdCollection, ";");
91 * Adds the search tag with key.
93 * @param searchTag the search tag
94 * @param searchTagKey the key associated with the search tag (key:value)
96 public void addSearchTagWithKey(String searchTag, String searchTagKey) {
97 searchTagIdCollection.add(searchTagKey);
98 searchTagCollection.add(searchTag);
101 public List<String> getSearchTagCollection() {
102 return searchTagCollection;
105 @JsonProperty("searchTags")
106 public String getSearchTags() {
110 @JsonProperty("searchTagIDs")
111 public String getSearchTagIDs() {
116 public List<String> getSearchTagIdCollection() {
117 return searchTagIdCollection;
122 public String getAsJson() throws JsonProcessingException {
123 return NodeUtils.convertObjectToJson(this, false);
129 * @see java.lang.Object#toString()
132 public String toString() {
133 return "IndexDocument [" + (entityType != null ? "entityType=" + entityType + ", " : "")
134 + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
136 + (searchTagCollection != null ? "searchTagCollection=" + searchTagCollection + ", " : "")
137 + (searchTagIdCollection != null ? "searchTagIDCollection=" + searchTagIdCollection + ", "
139 + (mapper != null ? "mapper=" + mapper + ", " : "") + (id != null ? "id=" + id + ", " : "")
140 + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp + ", " : "")
141 + (searchTags != null ? "searchTags=" + searchTags + ", " : "")
142 + (searchTagIDs != null ? "searchTagIDs=" + searchTagIDs : "") + "]";