summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sparkybe-onap-application/config/application.properties5
-rw-r--r--sparkybe-onap-application/config/spring-beans/sparky-aggregate-vnf-search-provider.xml2
-rw-r--r--sparkybe-onap-application/config/spring-beans/sparky-filters.xml7
-rw-r--r--sparkybe-onap-application/pom.xml2
-rw-r--r--sparkybe-onap-service/pom.xml2
-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
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProviderTest.java3
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/SearchServiceAdapterTest.java3
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/filters/FilterProcessorTest.java98
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/SparkyTestConstants.java4
-rw-r--r--sparkybe-onap-service/src/test/resources/filters/aaiui_filters.json107
-rw-r--r--sparkybe-onap-service/src/test/resources/filters/aaiui_views.json51
26 files changed, 779 insertions, 437 deletions
diff --git a/sparkybe-onap-application/config/application.properties b/sparkybe-onap-application/config/application.properties
index 54f4f40..f3ba9a9 100644
--- a/sparkybe-onap-application/config/application.properties
+++ b/sparkybe-onap-application/config/application.properties
@@ -3,8 +3,9 @@
#
spring.mvc.favicon.enabled=false
-#possible values: camel,http,ssl,portal,fe-dev,fe-prod,oxm-default,oxm-override,[resources|gizmo],sync,oxm-schema-prod
-spring.profiles.active=camel,ssl,fe-dev,oxm-schema-dev,resources,sync
+#possible values: camel,http,ssl,portal,fe-dev,fe-prod,oxm-default,oxm-override,[resources|gizmo],sync,oxm-schema-dev,oxm-schema-prod
+#For oxm loading there needs to be a combo of [oxm-default OR oxm-override] AND [oxm-schema-dev OR oxm-schema-prod]
+spring.profiles.active=camel,ssl,fe-dev,oxm-schema-dev,resources,sync,oxm-override
elasticsearch.hostname=127.0.0.1
elasticsearch.port=9200
diff --git a/sparkybe-onap-application/config/spring-beans/sparky-aggregate-vnf-search-provider.xml b/sparkybe-onap-application/config/spring-beans/sparky-aggregate-vnf-search-provider.xml
index 25da171..03218d1 100644
--- a/sparkybe-onap-application/config/spring-beans/sparky-aggregate-vnf-search-provider.xml
+++ b/sparkybe-onap-application/config/spring-beans/sparky-aggregate-vnf-search-provider.xml
@@ -14,7 +14,7 @@
<bean id="aggregateSummaryProcessor"
class="org.onap.aai.sparky.aggregatevnf.search.AggregateSummaryProcessor">
- <constructor-arg ref="elasticSearchAdapter" />
+ <constructor-arg ref="searchServiceAdapter" />
<constructor-arg ref="filtersConfig" />
<property name="vnfAggregationIndexName" value="aggregate_generic-vnf_index" />
</bean>
diff --git a/sparkybe-onap-application/config/spring-beans/sparky-filters.xml b/sparkybe-onap-application/config/spring-beans/sparky-filters.xml
index 2dc4936..6cd9b06 100644
--- a/sparkybe-onap-application/config/spring-beans/sparky-filters.xml
+++ b/sparkybe-onap-application/config/spring-beans/sparky-filters.xml
@@ -10,14 +10,9 @@
<constructor-arg name="resourceLoader" ref="sparkyResourceLoader" />
</bean>
- <bean id="filterElasticSearchAdapter"
- class="org.onap.aai.sparky.search.filters.FilterElasticSearchAdapter">
- <constructor-arg ref="elasticSearchAdapter" />
- </bean>
-
<bean id="filteredSearchHelper" class="org.onap.aai.sparky.search.filters.FilteredSearchHelper">
<constructor-arg ref="filtersConfig" />
- <constructor-arg ref="filterElasticSearchAdapter" />
+ <constructor-arg ref="searchServiceAdapter" />
</bean>
<bean id="filterProcessor" class="org.onap.aai.sparky.search.filters.FilterProcessor">
diff --git a/sparkybe-onap-application/pom.xml b/sparkybe-onap-application/pom.xml
index e8ec642..0f81a17 100644
--- a/sparkybe-onap-application/pom.xml
+++ b/sparkybe-onap-application/pom.xml
@@ -225,7 +225,7 @@
<dependency>
<groupId>org.onap.aai.aai-common</groupId>
<artifactId>aai-schema</artifactId>
- <version>1.3.0-SNAPSHOT</version>
+ <version>${version.aai-schema}</version>
</dependency>
<dependency>
diff --git a/sparkybe-onap-service/pom.xml b/sparkybe-onap-service/pom.xml
index 370f9f0..5527f71 100644
--- a/sparkybe-onap-service/pom.xml
+++ b/sparkybe-onap-service/pom.xml
@@ -24,7 +24,7 @@
<camel-spring-boot.version>2.20.0</camel-spring-boot.version>
<config-home>${basedir}/</config-home>
<version.aai.aai-schema-ingest>1.2.4</version.aai.aai-schema-ingest>
- <version.aai-schema>1.3.0-SNAPSHOT</version.aai-schema>
+ <version.aai-schema>1.2.4</version.aai-schema>
<sitePath>/content/sites/site/org/onap/aai/sparky-be/${project.artifactId}/${project.version}</sitePath>
<onap.nexus.url>https://nexus.onap.org</onap.nexus.url>
</properties>
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());
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProviderTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProviderTest.java
index 06ebafa..2a8e503 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProviderTest.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProviderTest.java
@@ -50,8 +50,7 @@ public class AggregateVnfSearchProviderTest {
@Test
public void testProxyMessage_Success() {
- Mockito.when(searchserviceAdapter.doPost(Mockito.eq(goodDrTargetUrl), Mockito.anyString(),
- Mockito.eq(MediaType.APPLICATION_JSON_TYPE.toString()))).thenReturn(successResult);
+ Mockito.when(searchserviceAdapter.doPost(Mockito.eq(goodDrTargetUrl), Mockito.anyString())).thenReturn(successResult);
Mockito.when(resultValue.getResultCode()).thenReturn(200);
aggregateVnfSearchProvider.search(querySearchEntity);
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/SearchServiceAdapterTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/SearchServiceAdapterTest.java
index ca7eab9..59db5c2 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/SearchServiceAdapterTest.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/SearchServiceAdapterTest.java
@@ -33,8 +33,7 @@ public class SearchServiceAdapterTest {
assertNotNull(searchServiceAdapter.getServiceApiVersion());
searchServiceAdapter.setEndpointConfig(endpointConfig);
assertNotNull(searchServiceAdapter.getEndpointConfig());
- assertNotNull(searchServiceAdapter.doPost("https://aai.search.service:8000",
- "{maxResults:10, queryStr: f}", "application/json"));
+ assertNotNull(searchServiceAdapter.doPost("https://aai.search.service:8000", "{maxResults:10, queryStr: f}"));
assertNotNull(searchServiceAdapter.doGet("https://aai.search.service:8000", "application/json"));
assertNotNull(searchServiceAdapter.doPut("https://aai.search.service:8000",
"{maxResults:10, queryStr: f}", "application/json"));
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/filters/FilterProcessorTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/filters/FilterProcessorTest.java
index 0644a53..f313a3a 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/filters/FilterProcessorTest.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/filters/FilterProcessorTest.java
@@ -35,7 +35,6 @@ import java.util.ArrayList;
import java.util.List;
import javax.json.Json;
-import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.json.stream.JsonParsingException;
@@ -44,25 +43,22 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
-import org.apache.camel.component.restlet.RestletConstants;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.DefaultExchange;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.onap.aai.restclient.enums.RestAuthenticationMode;
import org.onap.aai.sparky.config.SparkyResourceLoader;
-import org.onap.aai.sparky.dal.ElasticSearchAdapter;
import org.onap.aai.sparky.dal.rest.RestClientConstructionException;
import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
-import org.onap.aai.sparky.search.filters.FilterProcessor;
-import org.onap.aai.sparky.search.filters.FilteredSearchHelper;
+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.FiltersForViewsConfig;
import org.onap.aai.sparky.search.filters.config.UiFilterConfig;
import org.onap.aai.sparky.search.filters.config.UiFilterListItemConfig;
import org.onap.aai.sparky.search.filters.config.UiFilterOptionsValuesConfig;
-import org.onap.aai.sparky.search.filters.config.FiltersDetailsConfig;
-import org.onap.aai.sparky.search.filters.config.FiltersConfig;
import org.onap.aai.sparky.search.filters.config.UiViewListItemConfig;
import org.onap.aai.sparky.search.filters.entity.DiscoverFiltersRequest;
import org.onap.aai.sparky.search.filters.entity.ViewConfiguration;
@@ -70,10 +66,6 @@ import org.onap.aai.sparky.search.filters.entity.ViewFilter;
import org.onap.aai.sparky.util.HttpServletHelper;
import org.onap.aai.sparky.util.NodeUtils;
import org.onap.aai.sparky.util.SparkyTestConstants;
-import org.onap.aai.sparky.search.filters.config.FiltersForViewsConfig;
-import org.restlet.Request;
-import org.restlet.Response;
-import org.restlet.data.MediaType;
import org.restlet.data.Status;
import org.springframework.core.io.DefaultResourceLoader;
@@ -130,14 +122,6 @@ public class FilterProcessorTest {
ViewConfiguration viewInspectConfig = new ViewConfiguration("viewInspect");
views.add(generateViewConfig(viewInspectConfig));
- // Data Integrity - 4 Filters
- ViewConfiguration dataIntegrityConfig = new ViewConfiguration("dataIntegrity");
- dataIntegrityConfig.addViewFilter(new ViewFilter("3", null));
- dataIntegrityConfig.addViewFilter(new ViewFilter("4", null));
- dataIntegrityConfig.addViewFilter(new ViewFilter("5", defaultValue));
- dataIntegrityConfig.addViewFilter(new ViewFilter("6", null));
- views.add(generateViewConfig(dataIntegrityConfig));
-
uiViewsConfig.setViews(views);
viewFilterConfig.setViewsConfig(uiViewsConfig);
@@ -156,10 +140,7 @@ public class FilterProcessorTest {
List<UiFilterConfig> uiFilterConfig = new ArrayList<UiFilterConfig>();
uiFilterConfig.add(new UiFilterConfig("1", "filterName1", "Display Name 1", "dropDown", "false", "Any 1", null, "options", null, null));
uiFilterConfig.add(new UiFilterConfig("2", "filterName2", "Display Name 2", "dropDown", "false", "Any 2", null, "options", null, null));
- uiFilterConfig.add(new UiFilterConfig("3", "filterName3", "Display Name 3", "dropDown", "false", "Any 3", null, "options", null, null));
- uiFilterConfig.add(new UiFilterConfig("4", "filterName4", "Display Name 4", "dropDown", "false", "Any 4", null, "options", null, null));
uiFilterConfig.add(new UiFilterConfig("5", "filterName5", "Display Name 5", "date", "false", "Any 5", defaultValue, "dynamicOptions", optionsValues, null));
- uiFilterConfig.add(new UiFilterConfig("6", "filterName6", "Display Name 6", "dropDown", "false", "Any 6", null, "options", null, null));
uiFilterConfig.add(new UiFilterConfig("7", "filterName7", "Display Name 7", "dropDown", "false", "Any 7", null, "options", null, null));
uiFilterConfig.add(new UiFilterConfig("8", "filterName8", "Display Name 8", "dropDown", "false", "Any 8", null, "options", null, null));
@@ -171,7 +152,7 @@ public class FilterProcessorTest {
}
@Before
- public void init()throws RestClientConstructionException {
+ public void init() throws Exception {
camelContext = new DefaultCamelContext();
exchange = new DefaultExchange(camelContext);
@@ -183,8 +164,12 @@ public class FilterProcessorTest {
//TODO-> edit the following:FilteredSearchHelper & FilterProcessor to pass in the correct parameters
restEndpointConfig = new RestEndpointConfig();
restEndpointConfig.setRestAuthenticationMode(RestAuthenticationMode.SSL_BASIC);
- filteredSearchHelper = new FilteredSearchHelper(new FiltersConfig(),
- new FilterElasticSearchAdapter(new ElasticSearchAdapter(restEndpointConfig)));
+
+ SparkyResourceLoader resourceLoader = new SparkyResourceLoader();
+ resourceLoader.setResourceLoader(new DefaultResourceLoader());
+ FiltersConfig filtersConfig = new FiltersConfig(SparkyTestConstants.FILTERS_JSON_FILE, SparkyTestConstants.VIEWS_JSON_FILE, resourceLoader);
+
+ filteredSearchHelper = new FilteredSearchHelper(filtersConfig, new SearchServiceAdapter(restEndpointConfig, "1.0"));
filterProcessor = new FilterProcessor();
mapper = new ObjectMapper();
@@ -227,14 +212,9 @@ public class FilterProcessorTest {
SparkyResourceLoader resourceLoader = new SparkyResourceLoader();
resourceLoader.setResourceLoader(new DefaultResourceLoader());
- filterProcessor.setFilteredSearchHelper(filteredSearchHelper);
-
- FiltersConfig filtersConfig = new FiltersConfig();
- filtersConfig.initializeFiltersDetailsConfig(resourceLoader.getResourceAsFile(SparkyTestConstants.FILTERS_JSON_FILE, false));
- filtersConfig.initializeFiltersForViewsConfig(resourceLoader.getResourceAsFile(SparkyTestConstants.VIEWS_JSON_FILE, false));
-
+ FiltersConfig filtersConfig = new FiltersConfig(SparkyTestConstants.FILTERS_JSON_FILE, SparkyTestConstants.VIEWS_JSON_FILE, resourceLoader);
filteredSearchHelper.setFiltersConfig(filtersConfig);
-
+ filterProcessor.setFilteredSearchHelper(filteredSearchHelper);
}
@@ -260,57 +240,7 @@ public class FilterProcessorTest {
JsonObject vnfFilters = vnfResponsePayload.getJsonObject("filters");
assertNotNull(vnfFilters);
- assertEquals(0, vnfFilters.size());
-
- //JsonObject filterOne = vnfFilters.getJsonObject("1");
- //assertNotNull(filterOne);
- //assertEquals("Display Name 1", filterOne.getString("label"));
-
- JsonObject filterEight = vnfFilters.getJsonObject("8");
- //assertNotNull(filterEight);
- // JsonObject eightInnerControl = filterEight.getJsonObject("controls").getJsonObject("filterName8");
- // assertEquals(4, eightInnerControl.size());
- //assertEquals("dropDown", eightInnerControl.getString("type"));
- //assertEquals("false", eightInnerControl.getString("multiSelect"));
- //assertEquals("Any 8", eightInnerControl.getString("watermark"));
- //assertEquals(0, eightInnerControl.getJsonArray("options").size());
-
- // Initialize for call against 'dataIntegrity'
- DiscoverFiltersRequest dataIntegrityRequest = new DiscoverFiltersRequest();
- dataIntegrityRequest.setViewName("dataIntegrity");
-
- initializeMocks(NodeUtils.convertObjectToJson(dataIntegrityRequest, false));
-
- // Test call against 'dataIntegrity'
- filterProcessor.getFiltersWithValues(exchange);
-
- assertEquals(200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
-
- entityPayload = exchange.getOut().getBody(String.class);
- assertNotNull(entityPayload);
-
- JsonReader dIJsonReader = Json.createReader(new StringReader(entityPayload));
- JsonObject dIResponsePayload = dIJsonReader.readObject();
-
- JsonObject dIFilters = dIResponsePayload.getJsonObject("filters");
- assertNotNull(dIFilters);
- // assertEquals(4, dIFilters.size());
-
- //JsonObject filterFour = dIFilters.getJsonObject("4");
- //// assertNotNull(filterFour);
- // assertEquals("Display Name 4", filterFour.getString("label"));
-
- JsonObject filterFive = dIFilters.getJsonObject("5");
- //assertNotNull(filterFive);
- //JsonObject fiveInnerControl = filterFive.getJsonObject("controls").getJsonObject("filterName5");
- //assertEquals(5, fiveInnerControl.size());
- //assertEquals("date", fiveInnerControl.getString("type"));
- // assertEquals("false", fiveInnerControl.getString("multiSelect"));
- //assertEquals("Any 5", fiveInnerControl.getString("watermark"));
- // JsonArray dynamicOptions = fiveInnerControl.getJsonArray("dynamicOptions");
- //assertEquals(5, dynamicOptions.size());
- //JsonObject today = dynamicOptions.getJsonObject(0);
- //assertEquals("Today", today.getString("decode"));
+ assertEquals(4, vnfFilters.size());
}
@Test
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/SparkyTestConstants.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/SparkyTestConstants.java
index ffb27fa..b5ff1fd 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/SparkyTestConstants.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/SparkyTestConstants.java
@@ -14,6 +14,6 @@ public class SparkyTestConstants {
+ FILESEP + "src" + FILESEP + "test" + FILESEP + "resources";
public static final String PATH_TO_FILTERS_CONFIG = PATH_TO_TEST_RESOURCES + FILESEP + "filters";
- public static final String FILTERS_JSON_FILE = PATH_TO_FILTERS_CONFIG + FILESEP + "aaiui_filters.json";
- public static final String VIEWS_JSON_FILE = PATH_TO_FILTERS_CONFIG + FILESEP + "aaiui_views.json";
+ public static final String FILTERS_JSON_FILE = "file:" + PATH_TO_FILTERS_CONFIG + FILESEP + "aaiui_filters.json";
+ public static final String VIEWS_JSON_FILE = "file:" + PATH_TO_FILTERS_CONFIG + FILESEP + "aaiui_views.json";
}
diff --git a/sparkybe-onap-service/src/test/resources/filters/aaiui_filters.json b/sparkybe-onap-service/src/test/resources/filters/aaiui_filters.json
index 31716ed..e053442 100644
--- a/sparkybe-onap-service/src/test/resources/filters/aaiui_filters.json
+++ b/sparkybe-onap-service/src/test/resources/filters/aaiui_filters.json
@@ -1,10 +1,12 @@
{
- "filters": [
- {
+ "filters": [{
"filterId": "1",
"filterName": "Orchestration-Status",
"displayName": "Orchestration Status",
- "dataType": "list",
+ "dataType": "dropDown",
+ "multiSelect": "false",
+ "watermark": "Any Orchestration Status",
+ "optionsType": "options",
"dataSource": {
"indexName": "aggregate_generic-vnf_index",
"docType": "default",
@@ -15,7 +17,10 @@
"filterId": "2",
"filterName": "Prov-Status",
"displayName": "Provisioning Status",
- "dataType": "list",
+ "dataType": "dropDown",
+ "multiSelect": "false",
+ "watermark": "Any Provisioning Status",
+ "optionsType": "options",
"dataSource": {
"indexName": "aggregate_generic-vnf_index",
"docType": "default",
@@ -23,66 +28,68 @@
}
},
{
- "filterId": "3",
- "filterName": "Severity",
- "displayName": "Severity",
- "dataType": "list",
- "dataSource": {
- "indexName": "di-violations",
- "docType": "default",
- "fieldName": "severity"
- }
- },
- {
- "filterId": "4",
- "filterName": "Category",
- "displayName": "Category",
- "dataType": "list",
- "dataSource": {
- "indexName": "di-violations",
- "docType": "default",
- "fieldName": "category"
- }
- },
- {
"filterId": "5",
"filterName": "Date",
"displayName": "Date",
- "dataType": "date"
+ "dataType": "date",
+ "multiSelect": "false",
+ "watermark": "Choose Date Range",
+ "defaultValue": {
+ "decode": "Today",
+ "code": "last_0_hours"
+ },
+ "optionsType": "dynamicOptions",
+ "optionsValues": [{
+ "decode": "Today",
+ "code": "last_0_hours"
+ },
+ {
+ "decode": "Since Yesterday",
+ "code": "last_1_days"
+ },
+ {
+ "decode": "Since Last Week",
+ "code": "last_1_weeks"
+ },
+ {
+ "decode": "Since Last Month",
+ "code": "last_1_months"
+ },
+ {
+ "decode": "Since Last Year",
+ "code": "last_1_years"
+ },
+ {
+ "decode": "Custom Range",
+ "code": "custom_range"
+ }]
},
{
- "filterId": "6",
- "filterName": "EntityType",
- "displayName": "Object Type",
- "dataType": "list",
- "dataSource": {
- "indexName": "di-violations",
- "docType": "default",
- "fieldName": "entityType"
- }
- },
- {
- "filterId": "7",
- "filterName": "NF-Type",
+ "filterId": "7",
+ "filterName": "nf-type",
"displayName": "Network Function Type",
- "dataType": "list",
+ "dataType": "dropDown",
+ "multiSelect": "false",
+ "watermark": "Any Network Function Type",
+ "optionsType": "options",
"dataSource": {
"indexName": "aggregate_generic-vnf_index",
"docType": "default",
"fieldName": "nf-type"
- }
+ }
},
- {
- "filterId": "8",
- "filterName": "NF-Role",
+ {
+ "filterId": "8",
+ "filterName": "nf-role",
"displayName": "Network Function Role",
- "dataType": "list",
+ "dataType": "dropDown",
+ "multiSelect": "false",
+ "watermark": "Any Network Function Role",
+ "optionsType": "options",
"dataSource": {
"indexName": "aggregate_generic-vnf_index",
"docType": "default",
"fieldName": "nf-role"
- }
- }
-
- ]
+ }
+ }]
} \ No newline at end of file
diff --git a/sparkybe-onap-service/src/test/resources/filters/aaiui_views.json b/sparkybe-onap-service/src/test/resources/filters/aaiui_views.json
index e6ece9f..dce8926 100644
--- a/sparkybe-onap-service/src/test/resources/filters/aaiui_views.json
+++ b/sparkybe-onap-service/src/test/resources/filters/aaiui_views.json
@@ -1,38 +1,17 @@
{
- "views": [
- {
- "viewName" : "vnfSearch",
- "filters" : [
- {
- "filterId": "1"
- },
- {
- "filterId": "2"
- },
- {
- "filterId": "7"
- },
- {
- "filterId": "8"
- }
- ]
- },
- {
- "viewName" : "dataIntegrity",
- "filters" : [
- {
- "filterId": "3"
- },
- {
- "filterId": "4"
- },
- {
- "filterId": "5"
- },
- {
- "filterId": "6"
- }
- ]
- }
- ]
+ "views": [{
+ "viewName": "vnfSearch",
+ "filters": [{
+ "filterId": "1"
+ },
+ {
+ "filterId": "2"
+ },
+ {
+ "filterId": "7"
+ },
+ {
+ "filterId": "8"
+ }]
+ }]
} \ No newline at end of file