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.json.JSONArray;
29 import org.json.JSONObject;
30 import org.onap.aai.sparky.search.filters.config.FiltersConfig;
31 import org.onap.aai.sparky.search.filters.config.UiFilterListItemConfig;
32 import org.onap.aai.sparky.search.filters.config.UiViewListItemConfig;
33 import org.onap.aai.sparky.util.NodeUtils;
35 import com.fasterxml.jackson.databind.ObjectMapper;
37 public class AggregationSuggestionEntity extends IndexableEntity implements IndexDocument {
39 private static final String FILTER_ID = "filterId";
40 private static final String FILTER_LIST = "filterList";
42 private List<String> inputs = new ArrayList<>();
43 private final String outputString = "VNFs";
44 protected ObjectMapper mapper = new ObjectMapper();
45 List<String> filterIds = new ArrayList<>();
47 public AggregationSuggestionEntity() {
50 inputs.add("generic-vnfs");
54 public void deriveFields() {
55 this.id = NodeUtils.generateUniqueShaDigest(this.outputString);
59 public String getAsJson() {
60 JSONArray inputArray = new JSONArray();
61 for (String input : inputs) {
62 input = input.replace(",", "");
63 input = input.replace("[", "");
64 input = input.replace("]", "");
65 inputArray.put(input);
68 JSONObject entitySuggest = new JSONObject();
69 entitySuggest.put("input", inputArray);
70 entitySuggest.put("output", this.outputString);
71 entitySuggest.put("weight", 100);
73 JSONArray payloadFilters = new JSONArray();
75 for (String filterId : filterIds) {
76 JSONObject filterPayload = new JSONObject();
77 filterPayload.put(FILTER_ID, filterId);
78 payloadFilters.put(filterPayload);
81 JSONObject payloadNode = new JSONObject();
82 payloadNode.put(FILTER_LIST, payloadFilters);
83 entitySuggest.put("payload", payloadNode);
85 JSONObject rootNode = new JSONObject();
86 rootNode.put("entity_suggest", entitySuggest);
88 return rootNode.toString();
91 public void initializeFilters() {
92 for (UiViewListItemConfig view : FiltersConfig.getInstance().getViewsConfig().getViews()) {
93 if (view.getViewName().equals("vnfSearch")) {
94 for (UiFilterListItemConfig currentViewFilter : view.getFilters()) {
95 filterIds.add(currentViewFilter.getFilterId());
101 public void setFilterIds(List<String> filterIds) {
102 this.filterIds = filterIds;