2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
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.openecomp.sparky.synchronizer.entity;
28 import com.fasterxml.jackson.databind.ObjectMapper;
29 import com.fasterxml.jackson.databind.node.ObjectNode;
31 import java.util.ArrayList;
32 import java.util.List;
34 import org.openecomp.sparky.config.oxm.OxmModelLoader;
35 import org.openecomp.sparky.util.NodeUtils;
38 * The Class SearchableEntity.
40 public class SearchableEntity extends IndexableEntity implements IndexDocument {
41 protected List<String> searchTagCollection = new ArrayList<String>();
42 protected List<String> searchTagIdCollection = new ArrayList<String>();
43 protected ObjectMapper mapper = new ObjectMapper();
46 * Instantiates a new searchable entity.
48 public SearchableEntity() {
53 * Instantiates a new searchable entity.
55 * @param loader the loader
57 public SearchableEntity(OxmModelLoader loader) {
62 * Generated fields, leave the settings for junit overrides
64 protected String searchTags; // generated based on searchTagCollection values
65 protected String searchTagIDs;
68 * Generates the sha based id.
70 public void generateId() {
71 this.id = NodeUtils.generateUniqueShaDigest(link);
75 * @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
78 public void deriveFields() {
81 * We'll try and create a unique identity key that we can use for differencing the previously
82 * imported record sets as we won't have granular control of what is created/removed and when.
83 * The best we can hope for is identification of resources by generated Id until the
84 * Identity-Service UUID is tagged against all resources, then we can use that instead.
87 this.searchTags = NodeUtils.concatArray(searchTagCollection, ";");
88 this.searchTagIDs = NodeUtils.concatArray(this.searchTagIdCollection, ";");
92 * Adds the search tag with key.
94 * @param searchTag the search tag
95 * @param searchTagKey the key associated with the search tag (key:value)
97 public void addSearchTagWithKey(String searchTag, String searchTagKey) {
98 searchTagIdCollection.add(searchTagKey);
99 searchTagCollection.add(searchTag);
102 public List<String> getSearchTagCollection() {
103 return searchTagCollection;
106 public String getSearchTags() {
110 public String getSearchTagIDs() {
114 public List<String> getSearchTagIdCollection() {
115 return searchTagIdCollection;
119 public String getIndexDocumentJson() {
120 ObjectNode rootNode = mapper.createObjectNode();
121 rootNode.put("entityType", this.getEntityType());
122 rootNode.put("entityPrimaryKeyValue", this.getEntityPrimaryKeyValue());
123 rootNode.put("searchTagIDs", this.getSearchTagIDs());
124 rootNode.put("searchTags", this.getSearchTags());
125 rootNode.put("link", this.getLink());
126 rootNode.put("lastmodTimestamp", this.getEntityTimeStamp());
127 return rootNode.toString();
131 public ObjectNode getBulkImportEntity() {
132 // TODO Auto-generated method stub
137 * @see java.lang.Object#toString()
140 public String toString() {
141 return "IndexDocument [" + (entityType != null ? "entityType=" + entityType + ", " : "")
142 + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
144 + (searchTagCollection != null ? "searchTagCollection=" + searchTagCollection + ", " : "")
145 + (searchTagIdCollection != null ? "searchTagIDCollection=" + searchTagIdCollection + ", "
147 + (mapper != null ? "mapper=" + mapper + ", " : "") + (id != null ? "id=" + id + ", " : "")
148 + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp + ", " : "")
149 + (searchTags != null ? "searchTags=" + searchTags + ", " : "")
150 + (searchTagIDs != null ? "searchTagIDs=" + searchTagIDs : "") + "]";