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.
25 package org.onap.aai.sparky.sync.entity;
27 import java.util.ArrayList;
28 import java.util.List;
30 import org.json.JSONArray;
31 import org.json.JSONObject;
32 import org.onap.aai.sparky.search.filters.config.FiltersConfig;
33 import org.onap.aai.sparky.search.filters.config.UiFilterListItemConfig;
34 import org.onap.aai.sparky.search.filters.config.UiViewListItemConfig;
35 import org.onap.aai.sparky.util.NodeUtils;
37 import com.fasterxml.jackson.annotation.JsonIgnore;
38 import com.fasterxml.jackson.databind.ObjectMapper;
40 public class AggregationSuggestionEntity extends IndexableEntity implements IndexDocument {
42 private static final String FILTER_ID = "filterId";
43 private static final String FILTER_LIST = "filterList";
45 private List<String> inputs = new ArrayList<>();
46 private final String outputString = "VNFs";
47 protected ObjectMapper mapper = new ObjectMapper();
48 List<String> filterIds = new ArrayList<>();
51 private FiltersConfig filtersConfig;
53 public AggregationSuggestionEntity(FiltersConfig filtersConfig) {
55 this.filtersConfig = filtersConfig;
57 inputs.add("generic-vnfs");
61 public void deriveFields() {
62 this.id = NodeUtils.generateUniqueShaDigest(this.outputString);
66 public String getAsJson() {
67 JSONArray inputArray = new JSONArray();
68 for (String input: inputs) {
69 input = input.replace(",","" );
70 input = input.replace("[","" );
71 input = input.replace("]","" );
72 inputArray.put(input);
75 JSONObject entitySuggest = new JSONObject();
76 entitySuggest.put("input", inputArray);
77 entitySuggest.put("output", this.outputString);
78 entitySuggest.put("weight", 100);
80 JSONArray payloadFilters = new JSONArray();
82 for (String filterId : filterIds) {
83 JSONObject filterPayload = new JSONObject();
84 filterPayload.put(FILTER_ID, filterId);
85 payloadFilters.put(filterPayload);
88 JSONObject payloadNode = new JSONObject();
89 payloadNode.put(FILTER_LIST, payloadFilters);
90 entitySuggest.put("payload", payloadNode);
92 JSONObject rootNode = new JSONObject();
93 rootNode.put("entity_suggest", entitySuggest);
95 return rootNode.toString();
98 public void initializeFilters() {
99 for (UiViewListItemConfig view : filtersConfig.getViewsConfig().getViews()) {
100 if (view.getViewName().equals("vnfSearch")) {
101 for (UiFilterListItemConfig currentViewFilter : view.getFilters()) {
102 filterIds.add(currentViewFilter.getFilterId());
108 public void setFilterIds(List<String> filterIds) {
109 this.filterIds = filterIds;