2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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 package org.onap.aai.sparky.sync.entity;
23 import java.util.ArrayList;
24 import java.util.List;
26 import org.json.JSONArray;
27 import org.json.JSONObject;
28 import org.onap.aai.sparky.search.filters.config.FiltersConfig;
29 import org.onap.aai.sparky.search.filters.config.UiFilterListItemConfig;
30 import org.onap.aai.sparky.search.filters.config.UiViewListItemConfig;
31 import org.onap.aai.sparky.util.NodeUtils;
33 import com.fasterxml.jackson.annotation.JsonIgnore;
34 import com.fasterxml.jackson.databind.ObjectMapper;
36 public class AggregationSuggestionEntity extends IndexableEntity implements IndexDocument {
38 private static final String FILTER_ID = "filterId";
39 private static final String FILTER_LIST = "filterList";
41 private List<String> inputs = new ArrayList<>();
42 private final String outputString = "VNFs";
43 protected ObjectMapper mapper = new ObjectMapper();
44 List<String> filterIds = new ArrayList<>();
47 private FiltersConfig filtersConfig;
49 public AggregationSuggestionEntity(FiltersConfig filtersConfig) {
51 this.filtersConfig = filtersConfig;
53 inputs.add("generic-vnfs");
57 public void deriveFields() {
58 this.id = NodeUtils.generateUniqueShaDigest(this.outputString);
62 public String getAsJson() {
63 JSONArray inputArray = new JSONArray();
64 for (String input: inputs) {
65 input = input.replace(",","" );
66 input = input.replace("[","" );
67 input = input.replace("]","" );
68 inputArray.put(input);
71 JSONObject entitySuggest = new JSONObject();
72 entitySuggest.put("input", inputArray);
73 entitySuggest.put("output", this.outputString);
74 entitySuggest.put("weight", 100);
76 JSONArray payloadFilters = new JSONArray();
78 for (String filterId : filterIds) {
79 JSONObject filterPayload = new JSONObject();
80 filterPayload.put(FILTER_ID, filterId);
81 payloadFilters.put(filterPayload);
84 JSONObject payloadNode = new JSONObject();
85 payloadNode.put(FILTER_LIST, payloadFilters);
86 entitySuggest.put("payload", payloadNode);
88 JSONObject rootNode = new JSONObject();
89 rootNode.put("entity_suggest", entitySuggest);
91 return rootNode.toString();
94 public void initializeFilters() {
95 for (UiViewListItemConfig view : filtersConfig.getViewsConfig().getViews()) {
96 if (view.getViewName().equals("vnfSearch")) {
97 for (UiFilterListItemConfig currentViewFilter : view.getFilters()) {
98 filterIds.add(currentViewFilter.getFilterId());
104 public void setFilterIds(List<String> filterIds) {
105 this.filterIds = filterIds;