summaryrefslogtreecommitdiffstats
path: root/sparkybe-onap-service/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'sparkybe-onap-service/src/main/java/org/onap')
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateSummaryProcessor.java138
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProvider.java2
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmConfigTranslator.java4
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java4
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/logging/util/ServletUtils.java2
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java7
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterProcessor.java44
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterQueryBuilder.java2
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilteredSearchHelper.java163
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersConfig.java27
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/searchservice/FileBasedFilters.java88
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/searchservice/FilterQueryAndResponseBuilder.java446
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/util/RestletUtils.java2
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java1
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/search/ViewInspectSearchProvider.java2
15 files changed, 682 insertions, 250 deletions
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateSummaryProcessor.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateSummaryProcessor.java
index 24ba725..7ba4f24 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateSummaryProcessor.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateSummaryProcessor.java
@@ -20,47 +20,42 @@
*/
package org.onap.aai.sparky.aggregatevnf.search;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.json.JsonObject;
import javax.servlet.http.HttpServletRequest;
import org.apache.camel.Exchange;
-import org.json.JSONArray;
-import org.json.JSONObject;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.logging.util.ServletUtils;
-import org.onap.aai.sparky.search.filters.FilterQueryBuilder;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.search.filters.config.FiltersConfig;
-import org.onap.aai.sparky.search.filters.entity.SearchFilter;
+import org.onap.aai.sparky.search.filters.searchservice.FilterQueryAndResponseBuilder;
import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+
public class AggregateSummaryProcessor {
- private static final Logger LOG =
- LoggerFactory.getInstance().getLogger(AggregateSummaryProcessor.class);
+ private static final Logger LOG = LoggerFactory.getInstance().getLogger(AggregateSummaryProcessor.class);
private static final String KEY_FILTERS = "filters";
- private static final String FILTER_ID_KEY = "filterId";
- private static final String FILTER_VALUE_KEY = "filterValue";
private static final String TOTAL = "total";
- private static final int DEFAULT_SHOULD_MATCH_SCORE = 1;
- private ElasticSearchAdapter elasticSearchAdapter = null;
+ private SearchServiceAdapter searchServiceAdapter = null;
private String vnfAggregationIndexName;
- private FiltersConfig filtersConfig;
- public AggregateSummaryProcessor(ElasticSearchAdapter elasticSearchAdapter,
+ private FilterQueryAndResponseBuilder filterQueryAndResponseBuilder;
+ private Gson converter;
+
+ public AggregateSummaryProcessor(SearchServiceAdapter searchServiceAdapter,
FiltersConfig filtersConfig) {
- this.elasticSearchAdapter = elasticSearchAdapter;
- this.filtersConfig = filtersConfig;
+ this.searchServiceAdapter = searchServiceAdapter;
+ this.filterQueryAndResponseBuilder = new FilterQueryAndResponseBuilder(filtersConfig);
+ this.converter = new Gson();
}
public void setVnfAggregationIndexName(String vnfAggregationIndexName) {
@@ -84,32 +79,11 @@ public class AggregateSummaryProcessor {
*/
} else {
+ JsonObject payloadObj = converter.fromJson(payload, JsonObject.class);
+ if (payloadObj.has(KEY_FILTERS)) {
- JSONObject parameters = new JSONObject(payload);
-
- JSONArray requestFilters = null;
- if (parameters.has(KEY_FILTERS)) {
- requestFilters = parameters.getJSONArray(KEY_FILTERS);
- } else {
-
- JSONObject zeroResponsePayload = new JSONObject();
- zeroResponsePayload.put("count", 0);
- exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 200);
- exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/json");
- exchange.getOut().setBody(zeroResponsePayload.toString());
-
- LOG.error(AaiUiMsgs.ERROR_FILTERS_NOT_FOUND);
- return;
- }
-
- if (requestFilters != null && requestFilters.length() > 0) {
- List<JSONObject> filtersToQuery = new ArrayList<>();
- for (int i = 0; i < requestFilters.length(); i++) {
- JSONObject filterEntry = requestFilters.getJSONObject(i);
- filtersToQuery.add(filterEntry);
- }
-
- String jsonResponsePayload = getVnfFilterAggregations(filtersToQuery);
+ String jsonResponsePayload = getVnfFilterAggregations(payload);
+
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 200);
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/json");
exchange.getOut().setBody(jsonResponsePayload);
@@ -125,84 +99,36 @@ public class AggregateSummaryProcessor {
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ERROR_GENERIC,
"AggregateSummaryProcessor failed to process request due to error = " + exc.getMessage());
-
}
}
private String getEmptyAggResponse() {
- JSONObject aggPayload = new JSONObject();
- aggPayload.put("totalChartHits", 0);
- aggPayload.put("buckets", new JSONArray());
- JSONObject payload = new JSONObject();
- payload.append("groupby_aggregation", aggPayload);
+ JsonObject aggPayload = new JsonObject();
+ aggPayload.addProperty("totalChartHits", 0);
+ aggPayload.add("buckets", new JsonArray());
+ JsonObject payload = new JsonObject();
+ payload.add("groupby_aggregation", aggPayload);
return payload.toString();
}
- private String getVnfFilterAggregations(List<JSONObject> filtersToQuery) {
-
- List<SearchFilter> searchFilters = new ArrayList<>();
- for (JSONObject filterEntry : filtersToQuery) {
-
- String filterId = filterEntry.getString(FILTER_ID_KEY);
- if (filterId != null) {
- SearchFilter filter = new SearchFilter();
- filter.setFilterId(filterId);
-
- if (filterEntry.has(FILTER_VALUE_KEY)) {
- String filterValue = filterEntry.getString(FILTER_VALUE_KEY);
- filter.addValue(filterValue);
- }
-
- searchFilters.add(filter);
- }
- }
-
- // Create query for summary by entity type
- JsonObject vnfSearch = FilterQueryBuilder.createCombinedBoolAndAggQuery(filtersConfig,
- searchFilters, DEFAULT_SHOULD_MATCH_SCORE);
-
+ private String getVnfFilterAggregations(String payload) {
+ String query = filterQueryAndResponseBuilder.createFileBasedFilterQuery(payload);
+
// Parse response for summary by entity type query
- OperationResult opResult = elasticSearchAdapter.doPost(
- elasticSearchAdapter.buildElasticSearchUrlForApi(vnfAggregationIndexName,
- SparkyConstants.ES_SEARCH_API),
- vnfSearch.toString(), javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE);
+ String searchUrl = searchServiceAdapter.buildSearchServiceUrlForApi(vnfAggregationIndexName, SparkyConstants.SS_QUERY_API);
+ OperationResult opResult = searchServiceAdapter.doPost(searchUrl, query);
if (opResult.wasSuccessful()) {
- return buildAggregateVnfResponseJson(opResult.getResult());
+ return filterQueryAndResponseBuilder.formatAggregationsResponse(opResult.getResult());
} else {
return buildEmptyAggregateVnfResponseJson();
}
}
private String buildEmptyAggregateVnfResponseJson() {
- JSONObject finalOutputToFe = new JSONObject();
- finalOutputToFe.put(TOTAL, 0);
- return finalOutputToFe.toString();
- }
-
- private String buildAggregateVnfResponseJson(String responseJsonStr) {
-
- JSONObject finalOutputToFe = new JSONObject();
- JSONObject responseJson = new JSONObject(responseJsonStr);
-
-
- JSONObject hits = responseJson.getJSONObject("hits");
- int totalHits = hits.getInt(TOTAL);
- finalOutputToFe.put(TOTAL, totalHits);
-
- JSONObject aggregations = responseJson.getJSONObject("aggregations");
- String[] aggKeys = JSONObject.getNames(aggregations);
- JSONObject aggregationsList = new JSONObject();
-
- for (String aggName : aggKeys) {
- JSONObject aggregation = aggregations.getJSONObject(aggName);
- JSONArray buckets = aggregation.getJSONArray("buckets");
- aggregationsList.put(aggName, buckets);
- }
-
- finalOutputToFe.put("aggregations", aggregationsList);
-
+ JsonObject finalOutputToFe = new JsonObject();
+ finalOutputToFe.addProperty(TOTAL, 0);
return finalOutputToFe.toString();
}
}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProvider.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProvider.java
index 91121c6..74cc940 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProvider.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProvider.java
@@ -85,7 +85,7 @@ public class AggregateVnfSearchProvider implements SearchProvider {
String.format(AUTO_SUGGEST_TEMPLATE, Integer.parseInt(queryRequest.getMaxResults()),
queryRequest.getQueryStr(), "entity_suggest");
OperationResult opResult =
- searchServiceAdapter.doPost(fullUrlStr, postBody, "application/json");
+ searchServiceAdapter.doPost(fullUrlStr, postBody);
if (opResult.getResultCode() == 200) {
returnList = generateSuggestionsForSearchResponse(opResult.getResult());
} else {
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmConfigTranslator.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmConfigTranslator.java
index 65181c1..4a46e22 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmConfigTranslator.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmConfigTranslator.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java
index fad6fdd..0c89dcb 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/logging/util/ServletUtils.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/logging/util/ServletUtils.java
index 2316679..1b077c3 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/logging/util/ServletUtils.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/logging/util/ServletUtils.java
@@ -84,7 +84,7 @@ public class ServletUtils {
public static OperationResult executePostQuery(Logger logger, SearchServiceAdapter search,
HttpServletResponse response, String requestUrl, String requestJsonPayload) throws Exception {
- OperationResult opResult = search.doPost(requestUrl, requestJsonPayload, "application/json");
+ OperationResult opResult = search.doPost(requestUrl, requestJsonPayload);
if (opResult.getResultCode() > 300) {
setServletResponse(logger, true, opResult.getResultCode(), response, opResult.getResult());
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java
index 614968e..cb3e5e4 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java
@@ -84,6 +84,13 @@ public class SearchServiceAdapter {
this.endpointConfig = endpointConfig;
}
+ public OperationResult doPost(String url, String jsonPayload) {
+ OperationResult or = client.post(url, jsonPayload, getTxnHeader(),
+ MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_JSON_TYPE);
+ return new OperationResult(or.getResultCode(), or.getResult());
+ }
+
+ @Deprecated
public OperationResult doPost(String url, String jsonPayload, String acceptContentType) {
OperationResult or = client.post(url, jsonPayload, getTxnHeader(),
MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_JSON_TYPE);
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterProcessor.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterProcessor.java
index 3cef322..77a435d 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterProcessor.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterProcessor.java
@@ -20,10 +20,6 @@
*/
package org.onap.aai.sparky.search.filters;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.json.JsonObject;
import javax.servlet.http.HttpServletRequest;
import org.apache.camel.Exchange;
@@ -31,12 +27,13 @@ import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.sparky.logging.AaiUiMsgs;
import org.onap.aai.sparky.logging.util.ServletUtils;
-import org.onap.aai.sparky.search.filters.entity.UiFilterEntity;
-import org.onap.aai.sparky.search.filters.entity.UiFiltersEntity;
import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
-import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
public class FilterProcessor {
@@ -44,9 +41,11 @@ public class FilterProcessor {
private ObjectMapper mapper;
private FilteredSearchHelper filteredSearchHelper;
+ private Gson converter;
public FilterProcessor() {
this.mapper = new ObjectMapper();
+ this.converter = new Gson();
}
public ObjectMapper getMapper() {
@@ -66,7 +65,7 @@ public class FilterProcessor {
HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
ServletUtils.setUpMdcContext(exchange, request);
- UiFiltersEntity viewFiltersList = null;
+ JsonArray viewFiltersQueries = null;
boolean wasErrorDuringFilterDiscovery = false;
try {
@@ -77,12 +76,20 @@ public class FilterProcessor {
LOG.error(AaiUiMsgs.SEARCH_SERVLET_ERROR, "Request Payload is empty");
wasErrorDuringFilterDiscovery = true;
} else {
- String viewName = mapper.readValue(payload, JsonNode.class).get(SparkyConstants.UI_FILTER_VIEW_NAME_PARAMETER).asText();
-
+ JsonObject payloadObj = converter.fromJson(payload, JsonObject.class);
+ String viewName = null;
+
+ if(payloadObj.has(SparkyConstants.UI_FILTER_VIEW_NAME_PARAMETER)) {
+ JsonElement viewNameElement = payloadObj.get(SparkyConstants.UI_FILTER_VIEW_NAME_PARAMETER);
+ if(!viewNameElement.isJsonNull()) {
+ viewName = viewNameElement.getAsString();
+ }
+ }
+
if (viewName == null || viewName.isEmpty()) {
wasErrorDuringFilterDiscovery = true;
} else {
- viewFiltersList = filteredSearchHelper.doFilterDiscovery(viewName);
+ viewFiltersQueries = filteredSearchHelper.createFilterValueQueries(payload);
}
}
} catch(Exception exc) {
@@ -100,18 +107,11 @@ public class FilterProcessor {
boolean wasErrorDuringValueSearch = false;
if(!wasErrorDuringFilterDiscovery) {
try {
- if(!viewFiltersList.getFilters().isEmpty()) {
- List<String> filterIds = new ArrayList<String>();
-
- for(UiFilterEntity filterEntity : viewFiltersList.getFilters()) {
- filterIds.add(filterEntity.getFilterId());
- }
-
- UiFiltersEntity responseFiltersList = filteredSearchHelper.doFilterEnumeration(filterIds);
-
- JsonObject finalResponse = UiFiltersEntityConverter.convertUiFiltersEntityToUnifiedFilterResponse(responseFiltersList);
+ if(viewFiltersQueries != null && viewFiltersQueries.size() > 0) {
+ String populatedFiltersList = filteredSearchHelper.doFilterEnumeration(viewFiltersQueries);
+
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 200);
- exchange.getOut().setBody(finalResponse.toString());
+ exchange.getOut().setBody(populatedFiltersList);
} else {
wasErrorDuringValueSearch = true;
}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterQueryBuilder.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterQueryBuilder.java
index 26e6997..3f7640f 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterQueryBuilder.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterQueryBuilder.java
@@ -126,7 +126,7 @@ public class FilterQueryBuilder {
List<String> fields = new ArrayList<String>();
JsonObject boolQuery = createFilteredBoolQueryObject(filtersConfig,searchFilters, minShouldMatch, fields);
JsonObject aggQuery = createAggregationQueryArray(filtersConfig, searchFilters);
-
+
if (boolQuery != null) {
wrappedQueryBuilder.add("size", 0);
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilteredSearchHelper.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilteredSearchHelper.java
index d3fd7fe..e908900 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilteredSearchHelper.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilteredSearchHelper.java
@@ -20,135 +20,78 @@
*/
package org.onap.aai.sparky.search.filters;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.sparky.logging.AaiUiMsgs;
+import org.onap.aai.sparky.search.SearchServiceAdapter;
import org.onap.aai.sparky.search.filters.config.FiltersConfig;
-import org.onap.aai.sparky.search.filters.config.FiltersDetailsConfig;
-import org.onap.aai.sparky.search.filters.config.UiFilterConfig;
-import org.onap.aai.sparky.search.filters.config.UiFilterDataSourceConfig;
-import org.onap.aai.sparky.search.filters.config.UiFilterListItemConfig;
-import org.onap.aai.sparky.search.filters.config.UiViewListItemConfig;
-import org.onap.aai.sparky.search.filters.entity.UiFilterEntity;
-import org.onap.aai.sparky.search.filters.entity.UiFilterValueEntity;
-import org.onap.aai.sparky.search.filters.entity.UiFiltersEntity;
+import org.onap.aai.sparky.search.filters.searchservice.FilterQueryAndResponseBuilder;
+import org.onap.aai.sparky.search.filters.searchservice.FilterQueryAndResponseBuilder.FileBasedFiltersConstants;
+import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
public class FilteredSearchHelper {
private static final Logger LOG = LoggerFactory.getInstance().getLogger(FilteredSearchHelper.class);
- private FiltersConfig filtersConfig;
- private Map<String, UiFilterConfig> filtersMap = null;
- private FilterElasticSearchAdapter filterSearchAdapter = null;
+ private SearchServiceAdapter searchServiceAdapter;
+ private FilterQueryAndResponseBuilder filterQueryAndResponseBuilder;
+ private Gson responseFormatter;
- public FilteredSearchHelper(FiltersConfig filterConfig,FilterElasticSearchAdapter filterElasticSearchAdapter) {
- this.filtersConfig = filterConfig;
- this.filterSearchAdapter = filterElasticSearchAdapter;
-
- if (filtersMap == null) {
- filtersMap = new HashMap<>();
-
- final FiltersDetailsConfig uiFiltersConfig = filterConfig.getFiltersConfig();
-
- if (uiFiltersConfig != null) {
- for (UiFilterConfig filter : uiFiltersConfig.getFilters()) {
- filtersMap.put(filter.getFilterId(), filter);
- }
- }
- }
-
+ public FilteredSearchHelper(FiltersConfig filterConfig, SearchServiceAdapter searchServiceAdapter) {
+ this.filterQueryAndResponseBuilder = new FilterQueryAndResponseBuilder(filterConfig);
+ this.searchServiceAdapter = searchServiceAdapter;
+ this.responseFormatter = new GsonBuilder().disableHtmlEscaping().create();
}
-
- public FiltersConfig getFiltersConfig() {
- return filtersConfig;
- }
-
- public void setFiltersConfig(FiltersConfig filterConfig) {
- this.filtersConfig = filterConfig;
+
+ public void setFiltersConfig(FiltersConfig filtersConfig) {
+ this.filterQueryAndResponseBuilder.setFiltersConfig(filtersConfig);
}
- public UiFiltersEntity doFilterDiscovery(String viewName) {
- List<UiViewListItemConfig> views = filtersConfig.getViewsConfig().getViews();
- List<UiFilterListItemConfig> filters = null;
- UiFiltersEntity viewFiltersList = new UiFiltersEntity();
-
- if(viewName != null) {
- for (UiViewListItemConfig view: views) {
- if (viewName.equalsIgnoreCase(view.getViewName())) {
- filters = view.getFilters();
- break;
- }
- }
-
- if (filters == null) {
- LOG.error(AaiUiMsgs.VIEW_NAME_NOT_SUPPORTED, viewName);
- } else {
- for (UiFilterListItemConfig filter : filters) {
- FiltersDetailsConfig filtersDetailsConfig = filtersConfig.getFiltersConfig();
-
- for (UiFilterConfig filterConfig: filtersDetailsConfig.getFilters()) {
- if (filterConfig.getFilterId().equals(filter.getFilterId())) {
- UiFilterEntity filterEntity = new UiFilterEntity(filterConfig);
- if(filter.getDefaultValue() != null) {
- filterEntity.setDefaultValue(filter.getDefaultValue());
- }
- viewFiltersList.addFilter(filterEntity);
- }
- }
- }
- }
- }
- return viewFiltersList;
+ public JsonArray createFilterValueQueries(String fePayload) {
+ return filterQueryAndResponseBuilder.createFileBasedFilterValueQueries(fePayload);
}
- public UiFiltersEntity doFilterEnumeration(List<String> requestedFilterIds) {
- UiFiltersEntity viewFiltersList = new UiFiltersEntity();
+ public String doFilterEnumeration(JsonArray filterQueries) {
+ String formattedResult = "";
+ JsonObject populatedFilters = new JsonObject();
+
+ for(JsonElement queryElement : filterQueries) {
+ JsonObject queryObj = queryElement.getAsJsonObject();
+ String filterId = queryObj.get(FileBasedFiltersConstants.FILTER_ID).getAsString();
+
+ if(queryObj.has(FileBasedFiltersConstants.FILTER_VALUE_QUERY)) {
+
+ JsonObject filterQuery = queryObj.get(FileBasedFiltersConstants.FILTER_VALUE_QUERY).getAsJsonObject();
+ String query = responseFormatter.toJson(filterQuery);
+
+ String index = queryObj.get(FileBasedFiltersConstants.INDEX).getAsString();
+ String searchUrl = searchServiceAdapter.buildSearchServiceUrlForApi(index, SparkyConstants.SS_QUERY_API);
- for (String requestedFilterId : requestedFilterIds) {
- if (null == filtersMap.get(requestedFilterId)) {
- String errorMessage = "Requested filter ID '" + requestedFilterId + "' does not exist.";
- LOG.error(AaiUiMsgs.SEARCH_SERVLET_ERROR, errorMessage);
+ OperationResult opResult = searchServiceAdapter.doPost(searchUrl, query);
+ if(opResult.wasSuccessful()) {
+ String result = opResult.getResult();
+ populatedFilters = filterQueryAndResponseBuilder.formatSingleFilterValueQueryResult(result, filterId, populatedFilters);
+ } else {
+ LOG.warn(AaiUiMsgs.WARN_GENERIC, "Filter values query failed with code " + opResult.getResultCode() + " for filter with ID " + filterId);
+ populatedFilters = filterQueryAndResponseBuilder.formatSingleFilterValueQueryResult(null, filterId, populatedFilters);
+ }
} else {
- UiFilterConfig sourceData = filtersMap.get(requestedFilterId);
- UiFilterEntity filterEntity = new UiFilterEntity(sourceData);
- this.getFilterEnumeration(filterEntity, sourceData);
- viewFiltersList.addFilter(filterEntity);
+ // If there is no query, then populate filter with data from file
+ populatedFilters = filterQueryAndResponseBuilder.formatSingleFilterValueQueryResult(null, filterId, populatedFilters);
}
}
-
- return viewFiltersList;
- }
-
- public void getFilterEnumeration(UiFilterEntity filter, UiFilterConfig sourceData) {
- List<String> filterValues = filterSearchAdapter.fetchValuesForFilter(filter, sourceData.getDataSource());
-
- for(String value : filterValues) {
- UiFilterValueEntity valueEntity = new UiFilterValueEntity();
- valueEntity.setDisplayName(value);
- valueEntity.setFilterValue(value);
- filter.addFilterValue(valueEntity);
- }
- }
-
- public Map<String, UiFilterConfig> getFiltersMap() {
- return filtersMap;
- }
-
- public void setFiltersMap(Map<String, UiFilterConfig> filtersMap) {
- this.filtersMap = filtersMap;
- }
-
- public UiFilterDataSourceConfig getFilterDataSource(String filterId) {
- UiFilterConfig filterConfig = filtersMap.get(filterId);
- UiFilterDataSourceConfig returnValue = null;
- if(filterConfig != null) {
- returnValue = filterConfig.getDataSource();
- }
+ JsonObject finalResponse = new JsonObject();
+ finalResponse.add(FileBasedFiltersConstants.FILTERS, populatedFilters);
+ formattedResult = responseFormatter.toJson(finalResponse);
+
- return returnValue;
+ return formattedResult;
}
}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersConfig.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersConfig.java
index 7d0a3ac..b507fa3 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersConfig.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersConfig.java
@@ -21,6 +21,7 @@
package org.onap.aai.sparky.search.filters.config;
import java.io.File;
+import java.io.IOException;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
@@ -109,7 +110,7 @@ public class FiltersConfig {
ObjectMapper mapper = new ObjectMapper();
FiltersDetailsConfig filtersConfig = null;
try{
- filtersConfig = mapper.readValue(resourceLoader.getResourceAsFile(this.getFiltersFileName(),true), FiltersDetailsConfig.class);
+ filtersConfig = mapper.readValue(resourceLoader.getResourceAsFile(this.getFiltersFileName(), true), FiltersDetailsConfig.class);
} catch (Exception e){
LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, this.getFiltersFileName());
}
@@ -122,7 +123,7 @@ public class FiltersConfig {
FiltersForViewsConfig viewsConfig = null;
try {
- viewsConfig = mapper.readValue(resourceLoader.getResourceAsFile(this.getViewsFileName(),true), FiltersForViewsConfig.class);
+ viewsConfig = mapper.readValue(resourceLoader.getResourceAsFile(this.getViewsFileName(), true), FiltersForViewsConfig.class);
} catch (Exception e){
LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, this.getViewsFileName());
}
@@ -147,8 +148,28 @@ public class FiltersConfig {
} catch (Exception e){
LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, viewsFile.getAbsolutePath());
}
+ }
+
+ public File getFiltersFile() {
+ File toReturn = null;
+ try {
+ toReturn = resourceLoader.getResourceAsFile(this.getFiltersFileName(), true);
+ } catch (IOException e) {
+ LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, this.getFiltersFileName());
+ }
+ return toReturn;
+ }
+
+ public File getViewsFile() {
+ File toReturn = null;
+
+ try {
+ toReturn = resourceLoader.getResourceAsFile(this.getViewsFileName(), true);
+ } catch (IOException e) {
+ LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, this.getViewsFileName());
+ }
+ return toReturn;
}
-
}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/searchservice/FileBasedFilters.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/searchservice/FileBasedFilters.java
new file mode 100644
index 0000000..69010b5
--- /dev/null
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/searchservice/FileBasedFilters.java
@@ -0,0 +1,88 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.sparky.search.filters.searchservice;
+
+import java.io.File;
+import java.io.FileReader;
+
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.sparky.logging.AaiUiMsgs;
+import org.onap.aai.sparky.search.filters.config.FiltersConfig;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.stream.JsonReader;
+
+public class FileBasedFilters {
+
+ private static final Logger LOG = LoggerFactory.getInstance().getLogger(FileBasedFilters.class);
+
+ private FiltersConfig filtersConfig;
+ private JsonObject filters;
+ private JsonObject views;
+ private Gson converter;
+
+ public FileBasedFilters(FiltersConfig filtersConfig) {
+ this.filtersConfig = filtersConfig;
+ this.converter = new Gson();
+ this.processFiltersAndViewsFromFile();
+ }
+
+ public JsonObject getFilters() {
+ return filters;
+ }
+
+ public JsonObject getViews() {
+ return views;
+ }
+
+ public void setFiltersConfig(FiltersConfig filtersConfig) {
+ this.filtersConfig = filtersConfig;
+ processFiltersAndViewsFromFile();
+ }
+
+ private void processFiltersAndViewsFromFile() {
+ String currentReadLocation = "_variable_not_set_check_filters_file_location_";
+
+ try {
+ File filtersFile = filtersConfig.getFiltersFile();
+ if (filtersFile != null) {
+ currentReadLocation = filtersConfig.getFiltersFileName();
+ JsonReader filtersFileReader = new JsonReader(new FileReader(filtersFile));
+ this.filters = converter.fromJson(filtersFileReader, JsonObject.class);
+ filtersFileReader.close();
+ }
+
+ File viewsFile = filtersConfig.getViewsFile();
+ if(viewsFile != null) {
+ currentReadLocation = filtersConfig.getViewsFileName();
+ JsonReader viewsFileReader = new JsonReader(new FileReader(viewsFile));
+ this.views = converter.fromJson(viewsFileReader, JsonObject.class);
+ viewsFileReader.close();
+ }
+
+ } catch (Exception exc) {
+ String errorMessage = "Exception " + exc.getClass() + " was caught while reading file " + currentReadLocation;
+ LOG.error(AaiUiMsgs.ERROR_GENERIC, errorMessage);
+ }
+ }
+}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/searchservice/FilterQueryAndResponseBuilder.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/searchservice/FilterQueryAndResponseBuilder.java
new file mode 100644
index 0000000..1373d59
--- /dev/null
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/searchservice/FilterQueryAndResponseBuilder.java
@@ -0,0 +1,446 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.sparky.search.filters.searchservice;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.sparky.logging.AaiUiMsgs;
+import org.onap.aai.sparky.search.filters.config.FiltersConfig;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+public class FilterQueryAndResponseBuilder {
+
+ public class FileBasedFiltersConstants {
+ public static final String FILTERS = "filters";
+ public static final String FILTER = "filter";
+ public static final String QUERIES = "queries";
+ public static final String AGGREGATIONS = "aggregations";
+
+ public static final String FILTER_ID = "filterId";
+ public static final String DATA_SOURCE = "dataSource";
+ public static final String FILTER_VALUE = "filterValue";
+ public static final String FIELD_NAME = "fieldName";
+
+ public static final String ALL = "all";
+ public static final String MATCH = "match";
+ public static final String FIELD = "field";
+ public static final String VALUE = "value";
+
+ public static final String NAME = "name";
+ public static final String AGGREGATION = "aggregation";
+ public static final String GROUP_BY = "group-by";
+
+ public static final String VIEWS = "views";
+ public static final String VIEW_NAME = "viewName";
+
+ public static final String AGGREGATION_RESULT = "aggregationResult";
+ public static final String BUCKETS = "buckets";
+ public static final String KEY = "key";
+
+ public static final String LABEL = "label";
+ public static final String DISPLAY_NAME = "displayName";
+ public static final String CONTROLS = "controls";
+ public static final String TYPE = "type";
+ public static final String DATA_TYPE = "dataType";
+ public static final String MULTISELECT = "multiSelect";
+ public static final String WATERMARK = "watermark";
+ public static final String OPTIONS_TYPE = "optionsType";
+ public static final String OPTIONS_VALUES = "optionsValues";
+ public static final String DEFAULT_VALUE = "defaultValue";
+ public static final String DECODE = "decode";
+ public static final String CODE = "code";
+ public static final String FILTER_NAME = "filterName";
+
+ public static final String TOTAL = "total";
+ public static final String DOC_COUNT = "doc_count";
+ public static final String COUNT = "count";
+ public static final String SEARCH_RESULT = "searchResult";
+ public static final String TOTAL_HITS = "totalHits";
+
+ public static final String FILTER_VALUE_QUERY = "filterQuery";
+ public static final String INDEX_NAME = "indexName";
+ public static final String INDEX = "index";
+
+ public static final int FILTER_VALUE_AGG_SIZE_LIMIT = 1;
+ public static final int FILTER_VALUE_AGG_FIRST_ELEMENT = 0;
+ }
+
+ private static final Logger LOG = LoggerFactory.getInstance().getLogger(FilterQueryAndResponseBuilder.class);
+
+ private FileBasedFilters fileBasedFilters;
+ private Gson converter;
+ private Gson responseFormatter;
+
+ public FilterQueryAndResponseBuilder(FiltersConfig filtersConfig) {
+ this.fileBasedFilters = new FileBasedFilters(filtersConfig);
+ this.converter = new Gson();
+ this.responseFormatter = new GsonBuilder().disableHtmlEscaping().create();
+ }
+
+ public void setFiltersConfig(FiltersConfig filtersConfig) {
+ this.fileBasedFilters.setFiltersConfig(filtersConfig);
+ }
+
+ public String createFileBasedFilterQuery(String request) {
+ String query = null;
+
+ JsonObject filtersOnFile = fileBasedFilters.getFilters();
+ JsonObject requestObj = converter.fromJson(request, JsonObject.class);
+
+ if (filtersOnFile != null && requestObj != null) {
+ JsonElement rawRequestFilters = requestObj.get(FileBasedFiltersConstants.FILTERS);
+ JsonArray requestFilters = null;
+
+ if (rawRequestFilters != null && rawRequestFilters.isJsonArray()) {
+ requestFilters = rawRequestFilters.getAsJsonArray();
+
+ Map<String, JsonObject> filtersOnFileMap = convertFiltersOnFileToMap(filtersOnFile);
+
+ JsonObject filterSubObject =
+ createFileBasedFilterQuerySubObject(requestFilters, filtersOnFileMap);
+ JsonArray queriesSubObject = createFileBasedQueriesQuerySubObject();
+ JsonArray aggregationsSubObject = createFileBasedAggregationQuerySubObject(requestFilters, filtersOnFileMap);
+
+ JsonObject finalQuery = new JsonObject();
+ finalQuery.add(FileBasedFiltersConstants.FILTER, filterSubObject);
+ finalQuery.add(FileBasedFiltersConstants.QUERIES, queriesSubObject);
+ finalQuery.add(FileBasedFiltersConstants.AGGREGATIONS, aggregationsSubObject);
+
+ query = responseFormatter.toJson(finalQuery);
+ }
+ }
+
+ return query;
+ }
+
+ public JsonArray createFileBasedFilterValueQueries(String request) {
+ JsonArray returnArray = new JsonArray();
+
+ JsonObject requestObj = converter.fromJson(request, JsonObject.class);
+
+ if (requestObj != null && requestObj.has(FileBasedFiltersConstants.VIEW_NAME)) {
+ JsonObject viewsOnFile = fileBasedFilters.getViews();
+ Map<String, JsonObject> viewsMap = convertViewsOnFileToMap(viewsOnFile);
+
+ String viewName = requestObj.get(FileBasedFiltersConstants.VIEW_NAME).getAsString();
+ JsonObject viewObj = viewsMap.get(viewName);
+
+ if (viewObj != null) {
+ JsonObject filtersOnFile = fileBasedFilters.getFilters();
+ Map<String, JsonObject> filtersOnFileMap = convertFiltersOnFileToMap(filtersOnFile);
+
+ JsonArray filtersForView = viewObj.get(FileBasedFiltersConstants.FILTERS).getAsJsonArray();
+
+ for (JsonElement filterForView : filtersForView) {
+ JsonObject idAndQuery = new JsonObject();
+
+ JsonObject filterIdObj = filterForView.getAsJsonObject();
+ String filterId = filterIdObj.get(FileBasedFiltersConstants.FILTER_ID).getAsString();
+ JsonObject filterOnFile = filtersOnFileMap.get(filterId);
+
+ if(filterOnFile != null) {
+ idAndQuery.addProperty(FileBasedFiltersConstants.FILTER_ID, filterId);
+
+ if (filterOnFile.has(FileBasedFiltersConstants.DATA_SOURCE)) {
+ JsonObject dataSource = filterOnFile.get(FileBasedFiltersConstants.DATA_SOURCE).getAsJsonObject();
+ String searchIndex = dataSource.get(FileBasedFiltersConstants.INDEX_NAME).getAsString();
+ idAndQuery.addProperty(FileBasedFiltersConstants.INDEX, searchIndex);
+
+ JsonObject filterQuery = new JsonObject();
+ filterQuery.add(FileBasedFiltersConstants.FILTER, new JsonObject());
+ filterQuery.add(FileBasedFiltersConstants.QUERIES, new JsonArray());
+ JsonObject filterAgg = createFileBasedAggregationQuerySubObject(filterForView, filtersOnFileMap);
+ JsonArray aggArray = new JsonArray();
+ aggArray.add(filterAgg);
+ filterQuery.add(FileBasedFiltersConstants.AGGREGATIONS, aggArray);
+ idAndQuery.add(FileBasedFiltersConstants.FILTER_VALUE_QUERY, filterQuery);
+ }
+
+ returnArray.add(idAndQuery);
+ } else {
+ LOG.error(AaiUiMsgs.ERROR_GENERIC, "Filter with ID " + filterId + " did not exist on the file system. Check filter configuration.");
+ }
+ }
+ }
+ }
+
+ return returnArray;
+ }
+
+ public JsonObject formatSingleFilterValueQueryResult(String result, String filterId, JsonObject existingFilters) {
+
+ List<String> filterValues = null;
+
+ if (result != null) {
+ JsonObject resultObj = converter.fromJson(result, JsonObject.class);
+ JsonObject aggsResult = resultObj.get(FileBasedFiltersConstants.AGGREGATION_RESULT).getAsJsonObject();
+ JsonArray aggs = aggsResult.get(FileBasedFiltersConstants.AGGREGATIONS).getAsJsonArray();
+
+ // If there are more than one aggregation array then previous steps are incorrect
+ if (aggs.size() == FileBasedFiltersConstants.FILTER_VALUE_AGG_SIZE_LIMIT) {
+ JsonObject aggObj = aggs.get(FileBasedFiltersConstants.FILTER_VALUE_AGG_FIRST_ELEMENT).getAsJsonObject();
+ JsonArray buckets = aggObj.get(FileBasedFiltersConstants.BUCKETS).getAsJsonArray();
+ filterValues = new ArrayList<String>();
+ for (JsonElement singleResult : buckets) {
+ JsonObject singleResultObj = singleResult.getAsJsonObject();
+ filterValues.add(singleResultObj.get(FileBasedFiltersConstants.KEY).getAsString());
+ }
+ }
+ }
+
+ JsonObject filtersOnFile = fileBasedFilters.getFilters();
+ Map<String, JsonObject> filtersOnFileMap = convertFiltersOnFileToMap(filtersOnFile);
+ JsonObject filterOnFile = filtersOnFileMap.get(filterId);
+
+ if(filterOnFile != null) {
+ JsonObject populatedFilter = createPopulatedFilterObjectForResponse(filterOnFile, filterValues);
+ existingFilters.add(filterId, populatedFilter);
+ }
+
+ return existingFilters;
+ }
+
+ public String formatAggregationsResponse(String result) {
+ String response = null;
+
+ JsonObject resultObj = converter.fromJson(result, JsonObject.class);
+ JsonObject searchResults =
+ resultObj.get(FileBasedFiltersConstants.SEARCH_RESULT).getAsJsonObject();
+ String total = searchResults.get(FileBasedFiltersConstants.TOTAL_HITS).getAsString();
+
+ JsonObject aggResult =
+ resultObj.get(FileBasedFiltersConstants.AGGREGATION_RESULT).getAsJsonObject();
+ JsonArray aggs = aggResult.get(FileBasedFiltersConstants.AGGREGATIONS).getAsJsonArray();
+
+ JsonObject responseAggs = new JsonObject();
+ for (JsonElement aggregation : aggs) {
+ JsonObject aggObj = aggregation.getAsJsonObject();
+
+ String aggName = aggObj.get(FileBasedFiltersConstants.NAME).getAsString();
+ JsonArray buckets = aggObj.get(FileBasedFiltersConstants.BUCKETS).getAsJsonArray();
+
+ JsonArray aggResponseSubArray = new JsonArray();
+ for (JsonElement singleResult : buckets) {
+ JsonObject singleResultObj = singleResult.getAsJsonObject();
+
+ JsonObject responseObj = new JsonObject();
+ responseObj.addProperty(FileBasedFiltersConstants.DOC_COUNT, singleResultObj.get(FileBasedFiltersConstants.COUNT).getAsInt());
+ responseObj.addProperty(FileBasedFiltersConstants.KEY, singleResultObj.get(FileBasedFiltersConstants.KEY).getAsString());
+
+ aggResponseSubArray.add(responseObj);
+ }
+
+ responseAggs.add(aggName, aggResponseSubArray);
+ }
+
+ JsonObject finalResponse = new JsonObject();
+ finalResponse.addProperty(FileBasedFiltersConstants.TOTAL, total);
+ finalResponse.add(FileBasedFiltersConstants.AGGREGATIONS, responseAggs);
+
+ response = responseFormatter.toJson(finalResponse);
+
+ return response;
+ }
+
+ private JsonObject createFileBasedFilterQuerySubObject(JsonArray requestFilters,
+ Map<String, JsonObject> filtersOnFile) {
+ JsonObject filter = new JsonObject();
+ JsonArray all = new JsonArray();
+
+ for (JsonElement requestElement : requestFilters) {
+ JsonObject requestObj = requestElement.getAsJsonObject();
+ // Only add filters to array if a filter value is present
+ if (requestObj != null && requestObj.has(FileBasedFiltersConstants.FILTER_VALUE)) {
+
+ String filterId = requestObj.get(FileBasedFiltersConstants.FILTER_ID).getAsString();
+ JsonObject filterObj = filtersOnFile.get(filterId);
+
+ JsonObject dataSource =
+ filterObj.get(FileBasedFiltersConstants.DATA_SOURCE).getAsJsonObject();
+ String field = dataSource.get(FileBasedFiltersConstants.FIELD_NAME).getAsString();
+ String value = requestObj.get(FileBasedFiltersConstants.FILTER_VALUE).getAsString();
+
+ JsonObject matchObj = new JsonObject();
+ matchObj.addProperty(FileBasedFiltersConstants.FIELD, field);
+ matchObj.addProperty(FileBasedFiltersConstants.VALUE, value);
+
+ JsonObject allEntry = new JsonObject();
+ allEntry.add(FileBasedFiltersConstants.MATCH, matchObj);
+
+ all.add(allEntry);
+ }
+ }
+
+ if (all.size() > 0) {
+ filter.add(FileBasedFiltersConstants.ALL, all);
+ }
+
+ return filter;
+ }
+
+ private JsonArray createFileBasedQueriesQuerySubObject() {
+ return new JsonArray();
+ }
+
+ private JsonArray createFileBasedAggregationQuerySubObject(JsonArray requestFilters,
+ Map<String, JsonObject> filtersOnFile) {
+ JsonArray aggregations = new JsonArray();
+
+ for (JsonElement requestElement : requestFilters) {
+ JsonObject requestObj = requestElement.getAsJsonObject();
+ String filterId = requestObj.get(FileBasedFiltersConstants.FILTER_ID).getAsString();
+ JsonObject filterObj = filtersOnFile.get(filterId);
+
+ if (filterObj != null && filterObj.has(FileBasedFiltersConstants.DATA_SOURCE)) {
+ JsonObject dataSource =
+ filterObj.get(FileBasedFiltersConstants.DATA_SOURCE).getAsJsonObject();
+ String field = dataSource.get(FileBasedFiltersConstants.FIELD_NAME).getAsString();
+
+ JsonObject groupBy = new JsonObject();
+ groupBy.addProperty(FileBasedFiltersConstants.FIELD, field);
+
+ JsonObject aggregation = new JsonObject();
+ aggregation.add(FileBasedFiltersConstants.GROUP_BY, groupBy);
+
+ JsonObject aggregationsEntry = new JsonObject();
+ aggregationsEntry.addProperty(FileBasedFiltersConstants.NAME, field);
+ aggregationsEntry.add(FileBasedFiltersConstants.AGGREGATION, aggregation);
+
+ aggregations.add(aggregationsEntry);
+ }
+ }
+
+ return aggregations;
+ }
+
+ private JsonObject createFileBasedAggregationQuerySubObject(JsonElement requestElement, Map<String, JsonObject> filtersOnFile) {
+ JsonObject requestObj = requestElement.getAsJsonObject();
+ String filterId = requestObj.get(FileBasedFiltersConstants.FILTER_ID).getAsString();
+ JsonObject filterObj = filtersOnFile.get(filterId);
+
+ JsonObject aggregationsEntry = new JsonObject();
+ // If there is no data source for a filter, then there is no query to generate ("should" contain predetermined values)
+ if (filterObj != null && filterObj.has(FileBasedFiltersConstants.DATA_SOURCE)) {
+ JsonObject dataSource = filterObj.get(FileBasedFiltersConstants.DATA_SOURCE).getAsJsonObject();
+ String field = dataSource.get(FileBasedFiltersConstants.FIELD_NAME).getAsString();
+
+ JsonObject groupBy = new JsonObject();
+ groupBy.addProperty(FileBasedFiltersConstants.FIELD, field);
+
+ JsonObject aggregation = new JsonObject();
+ aggregation.add(FileBasedFiltersConstants.GROUP_BY, groupBy);
+
+ aggregationsEntry.addProperty(FileBasedFiltersConstants.NAME, field);
+ aggregationsEntry.add(FileBasedFiltersConstants.AGGREGATION, aggregation);
+ }
+
+ return aggregationsEntry;
+ }
+
+ private Map<String, JsonObject> convertFiltersOnFileToMap(JsonObject filtersOnFile) {
+ Map<String, JsonObject> ninjaTurtle = new HashMap<String, JsonObject>();
+
+ if (filtersOnFile != null) {
+ JsonElement filtersElement = filtersOnFile.get(FileBasedFiltersConstants.FILTERS);
+ if (filtersElement != null && filtersElement.isJsonArray()) {
+ JsonArray filtersOnFileArray = filtersElement.getAsJsonArray();
+ for (JsonElement filterElement : filtersOnFileArray) {
+ if (filterElement.isJsonObject()) {
+ JsonObject filterObj = filterElement.getAsJsonObject();
+ String filterId = filterObj.get(FileBasedFiltersConstants.FILTER_ID).getAsString();
+ ninjaTurtle.put(filterId, filterObj);
+ }
+ }
+ }
+ }
+
+ return ninjaTurtle;
+ }
+
+ private Map<String, JsonObject> convertViewsOnFileToMap(JsonObject viewsOnFile) {
+ Map<String, JsonObject> viewsMap = new HashMap<String, JsonObject>();
+
+ if (viewsOnFile != null) {
+ JsonElement viewsElement = viewsOnFile.get(FileBasedFiltersConstants.VIEWS);
+ if (viewsElement != null && viewsElement.isJsonArray()) {
+ JsonArray viewsArray = viewsElement.getAsJsonArray();
+ for (JsonElement view : viewsArray) {
+ JsonObject viewObj = view.getAsJsonObject();
+ String viewName = viewObj.get(FileBasedFiltersConstants.VIEW_NAME).getAsString();
+ viewsMap.put(viewName, viewObj);
+ }
+ }
+ }
+
+ return viewsMap;
+ }
+
+ private JsonObject createPopulatedFilterObjectForResponse(JsonObject filterOnFile, List<String> filterValues) {
+
+ JsonObject filterNameObj = new JsonObject();
+ filterNameObj.addProperty(FileBasedFiltersConstants.TYPE, filterOnFile.get(FileBasedFiltersConstants.DATA_TYPE).getAsString());
+ filterNameObj.addProperty(FileBasedFiltersConstants.MULTISELECT, filterOnFile.get(FileBasedFiltersConstants.MULTISELECT).getAsString());
+ filterNameObj.addProperty(FileBasedFiltersConstants.WATERMARK, filterOnFile.get(FileBasedFiltersConstants.WATERMARK).getAsString());
+
+ if (filterOnFile.has(FileBasedFiltersConstants.DEFAULT_VALUE)) {
+ filterNameObj.add(FileBasedFiltersConstants.DEFAULT_VALUE, filterOnFile.get(FileBasedFiltersConstants.DEFAULT_VALUE));
+ }
+
+ JsonArray options = new JsonArray();
+
+ if (filterValues != null && !filterValues.isEmpty()) {
+ for (String value : filterValues) {
+ JsonObject optionValue = new JsonObject();
+ optionValue.addProperty(FileBasedFiltersConstants.DECODE, value);
+ optionValue.addProperty(FileBasedFiltersConstants.CODE, value);
+ options.add(optionValue);
+ }
+ }
+
+ if (filterOnFile.has(FileBasedFiltersConstants.OPTIONS_VALUES)) {
+ JsonElement optionsValuesElement = filterOnFile.get(FileBasedFiltersConstants.OPTIONS_VALUES);
+ if (optionsValuesElement.isJsonArray()) {
+ options.addAll(optionsValuesElement.getAsJsonArray());
+ }
+ }
+
+ filterNameObj.add(filterOnFile.get(FileBasedFiltersConstants.OPTIONS_TYPE).getAsString(), options);
+
+ JsonObject controlsObj = new JsonObject();
+ controlsObj.add(filterOnFile.get(FileBasedFiltersConstants.FILTER_NAME).getAsString(), filterNameObj);
+
+ JsonObject populatedFilter = new JsonObject();
+ populatedFilter.addProperty(FileBasedFiltersConstants.LABEL, filterOnFile.get(FileBasedFiltersConstants.DISPLAY_NAME).getAsString());
+ populatedFilter.add(FileBasedFiltersConstants.CONTROLS, controlsObj);
+
+ return populatedFilter;
+ }
+}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/util/RestletUtils.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/util/RestletUtils.java
index cd2d8fd..69812dc 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/util/RestletUtils.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/util/RestletUtils.java
@@ -54,7 +54,7 @@ public class RestletUtils {
public OperationResult executePostQuery(Logger logger, SearchServiceAdapter search,
Response response, String requestUrl, String requestJsonPayload) {
- OperationResult opResult = search.doPost(requestUrl, requestJsonPayload, "application/json");
+ OperationResult opResult = search.doPost(requestUrl, requestJsonPayload);
if (opResult.getResultCode() > 300) {
setRestletResponse(logger, true, opResult.getResultCode(), response, opResult.getResult());
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java
index b5f72bc..6dc8441 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java
@@ -65,6 +65,7 @@ public class SparkyConstants {
public static final String ES_SUGGEST_API = "_suggest";
public static final String ES_COUNT_API = "_count";
public static final String ES_SEARCH_API = "_search";
+ public static final String SS_QUERY_API = "query";
public static final String UI_FILTER_VIEW_NAME_PARAMETER = "viewName";
public static final String UI_FILTER_ID_LIST_PARAMETER = "filterIdList";
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/search/ViewInspectSearchProvider.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/search/ViewInspectSearchProvider.java
index 8bf8610..1937891 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/search/ViewInspectSearchProvider.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/search/ViewInspectSearchProvider.java
@@ -106,7 +106,7 @@ public class ViewInspectSearchProvider implements SearchProvider {
String postBody = String.format(VIUI_SEARCH_TEMPLATE, Integer.parseInt(queryRequest.getMaxResults()),
queryStringWithoutStopWords);
- OperationResult opResult = searchServiceAdapter.doPost(fullUrlStr, postBody, "application/json");
+ OperationResult opResult = searchServiceAdapter.doPost(fullUrlStr, postBody);
if (opResult.getResultCode() == 200) {
suggestionEntityList =
generateSuggestionsForSearchResponse(opResult.getResult(), queryRequest.getQueryStr());