Merge "Fix potential null pointer"
authorJames Forsyth <jf2512@att.com>
Wed, 22 Aug 2018 18:47:05 +0000 (18:47 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 22 Aug 2018 18:47:05 +0000 (18:47 +0000)
41 files changed:
sparkybe-onap-application/config/application-gizmo.properties
sparkybe-onap-application/config/application-resources.properties
sparkybe-onap-application/config/application.properties
sparkybe-onap-application/config/spring-beans/sparky-aggregate-vnf-search-provider.xml
sparkybe-onap-application/config/spring-beans/sparky-filters.xml
sparkybe-onap-application/config/spring-beans/sparky-view-inspect-with-gizmo.xml
sparkybe-onap-application/config/spring-beans/sparky-view-inspect-with-resources.xml
sparkybe-onap-application/pom.xml
sparkybe-onap-application/src/main/docker/Dockerfile
sparkybe-onap-service/pom.xml
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateSummaryProcessor.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProvider.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmConfigTranslator.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/logging/util/ServletUtils.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterProcessor.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilterQueryBuilder.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/FilteredSearchHelper.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/config/FiltersConfig.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/searchservice/FileBasedFilters.java [new file with mode: 0644]
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/filters/searchservice/FilterQueryAndResponseBuilder.java [new file with mode: 0644]
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/security/EcompSso.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/StoreDocumentTask.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/topology/sync/GeoSynchronizer.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/util/RestletUtils.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/ActiveInventoryNode.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/search/ViewInspectSearchProvider.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContext.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java
sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java
sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregatevnf/search/AggregateVnfSearchProviderTest.java
sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/SearchServiceAdapterTest.java
sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/filters/FilterProcessorTest.java
sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/SparkyTestConstants.java
sparkybe-onap-service/src/test/resources/filters/aaiui_filters.json
sparkybe-onap-service/src/test/resources/filters/aaiui_views.json

index e988873..69750c7 100644 (file)
@@ -5,3 +5,4 @@ gizmo.client-cert=client-cert-onap.p12
 gizmo.client-cert-password=1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10
 gizmo.trust-store=tomcat_keystore
 gizmo.apiVersion=v12
+gizmo.maxSelfLinkTraversalDepth=2
index 2a7770f..5860c7a 100644 (file)
@@ -6,3 +6,4 @@ resources.basicAuthPassword=AAI
 resources.client-cert=client-cert-onap.p12
 resources.client-cert-password=1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10
 resources.trust-store=tomcat_keystore
+resources.maxSelfLinkTraversalDepth=2
index 54f4f40..f3ba9a9 100644 (file)
@@ -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
index 25da171..03218d1 100644 (file)
@@ -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>
index 2dc4936..6cd9b06 100644 (file)
                <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">
index d7b9ff1..9afd8a3 100644 (file)
@@ -6,7 +6,7 @@
 
        <bean id="visualizationConfigurations"
                class="org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs">
-               <property name="maxSelfLinkTraversalDepth" value="2" />
+               <property name="maxSelfLinkTraversalDepth" value="${gizmo.maxSelfLinkTraversalDepth:2}" />
                <property name="visualizationDebugEnabled" value="false" />
                <property name="aaiEntityNodeDescriptors" value="/descriptors/aaiEntityNodeDescriptors.json" />
                <property name="generalNodeClassName" value="generalNodeClass" />
index 97fa807..7c34697 100644 (file)
@@ -6,7 +6,7 @@
 
        <bean id="visualizationConfigurations"
                class="org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs">
-               <property name="maxSelfLinkTraversalDepth" value="2" />
+               <property name="maxSelfLinkTraversalDepth" value="${resources.maxSelfLinkTraversalDepth:2}" />
                <property name="visualizationDebugEnabled" value="false" />
                <property name="aaiEntityNodeDescriptors" value="/descriptors/aaiEntityNodeDescriptors.json" />
                <property name="generalNodeClassName" value="generalNodeClass" />
index 622ac67..0f81a17 100644 (file)
                <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>
                                <groupId>com.spotify</groupId>
                                <artifactId>docker-maven-plugin</artifactId>
                                <version>0.4.11</version>
-                               <dependencies>
-                                       <dependency>
-                                               <groupId>com.github.jnr</groupId>
-                                               <artifactId>jnr-unixsocket</artifactId>
-                                               <version>0.13</version>
-                                       </dependency>
-                               </dependencies>
                                <configuration>
                                        <verbose>true</verbose>
                                        <serverId>docker-hub</serverId>
index 3f05ff9..eda77fa 100644 (file)
@@ -10,7 +10,7 @@ RUN apt-get update && apt-get install -y software-properties-common
 ## sudo -E is required to preserve the environment. If you remove that line, it will most like freeze at this step
 RUN sudo -E add-apt-repository ppa:openjdk-r/ppa && apt-get update && apt-get install -y openjdk-8-jdk
 ## Setup JAVA_HOME, this is useful for docker commandline
-ENV JAVA_HOME usr/lib/jvm/java-8-openjdk-$(dpkg --print-architecture)
+ENV JAVA_HOME usr/lib/jvm/java-8-openjdk-amd64
 RUN export JAVA_HOME
 
 # Build up the deployment folder structure
index 370f9f0..5527f71 100644 (file)
@@ -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>
index 24ba725..7ba4f24 100644 (file)
  */
 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();
   }
 }
index 5fd0dc9..74cc940 100644 (file)
@@ -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 {
@@ -106,11 +106,10 @@ public class AggregateVnfSearchProvider implements SearchProvider {
     }
 
     ObjectMapper mapper = new ObjectMapper();
-    JsonNode rootNode = null;
     List<SearchSuggestion> suggestionEntityList = new ArrayList<SearchSuggestion>();
 
     try {
-      rootNode = mapper.readTree(operationResult);
+      JsonNode rootNode = mapper.readTree(operationResult);
       JsonNode hitsNode = rootNode.get(KEY_SEARCH_RESULT);
       // Check if there are hits that are coming back
       if (hitsNode.has(KEY_HITS)) {
@@ -120,30 +119,14 @@ public class AggregateVnfSearchProvider implements SearchProvider {
          * next we iterate over the values in the hit array elements
          */
         Iterator<JsonNode> nodeIterator = hitsArray.elements();
-        JsonNode entityNode = null;
-        CommonSearchSuggestion responseSuggestion = null;
-        JsonNode sourceNode = null;
-
         while (nodeIterator.hasNext()) {
-          entityNode = nodeIterator.next();
-          String responseText = getValueFromNode(entityNode, KEY_TEXT);
-          // do the point transformation as we build the response?
-          responseSuggestion = new CommonSearchSuggestion();
-          responseSuggestion.setRoute(vnfSearchSuggestionRoute);
-          responseSuggestion.setText(responseText);
-          responseSuggestion.setHashId(NodeUtils.generateUniqueShaDigest(responseText));
-
-          sourceNode = entityNode.get(KEY_DOCUMENT).get(KEY_CONTENT);
-          if (sourceNode.has(KEY_FILTER_LIST)) {
-            ArrayNode filtersArray = (ArrayNode) sourceNode.get(KEY_FILTER_LIST);
-            for (int i = 0; i < filtersArray.size(); i++) {
-              String filterValueString = filtersArray.get(i).toString();
-              UiFilterValueEntity filterValue =
-                  mapper.readValue(filterValueString, UiFilterValueEntity.class);
-              responseSuggestion.getFilterValues().add(filterValue);
-            }
+          JsonNode entityNode = nodeIterator.next();
+          if(entityNode != null) {
+            String responseText = getValueFromNode(entityNode, KEY_TEXT);
+
+            CommonSearchSuggestion responseSuggestion = createCommonSearchSuggestion(mapper, entityNode, responseText);
+            suggestionEntityList.add(responseSuggestion);
           }
-          suggestionEntityList.add(responseSuggestion);
         }
       }
     } catch (IOException exc) {
@@ -153,9 +136,30 @@ public class AggregateVnfSearchProvider implements SearchProvider {
 
   }
 
+  private CommonSearchSuggestion createCommonSearchSuggestion(ObjectMapper mapper, JsonNode entityNode, String responseText) throws IOException {
+    // do the point transformation as we build the response?
+    CommonSearchSuggestion responseSuggestion = new CommonSearchSuggestion();
+    responseSuggestion.setRoute(vnfSearchSuggestionRoute);
+    responseSuggestion.setText(responseText);
+    responseSuggestion.setHashId(NodeUtils.generateUniqueShaDigest(responseText));
+
+    JsonNode keyDocument = entityNode.get(KEY_DOCUMENT);
+    JsonNode sourceNode = keyDocument.get(KEY_CONTENT);
+    if (sourceNode.has(KEY_FILTER_LIST)) {
+      ArrayNode filtersArray = (ArrayNode) sourceNode.get(KEY_FILTER_LIST);
+      for (int i = 0; i < filtersArray.size(); i++) {
+        String filterValueString = filtersArray.get(i).toString();
+        UiFilterValueEntity filterValue =
+            mapper.readValue(filterValueString, UiFilterValueEntity.class);
+        responseSuggestion.getFilterValues().add(filterValue);
+      }
+    }
+    return responseSuggestion;
+  }
+
   private String getValueFromNode(JsonNode node, String fieldName) {
 
-    if (node == null || fieldName == null) {
+    if (fieldName == null) {
       return null;
     }
 
index e0b6955..b4c254a 100644 (file)
@@ -118,7 +118,6 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
   /**
    * Instantiates a new entity aggregation synchronizer.
    *
-   * @param indexName the index name
    * @throws Exception the exception
    */
   public AggregationSynchronizer(String entityType, ElasticSearchSchemaConfig schemaConfig,
@@ -613,7 +612,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
     Map<String, Object> map = mapper.convertValue(entityNode, Map.class);
     doc.copyAttributeKeyValuePair(map);
   }
-  
+
   /**
    * Process entity type self links.
    *
@@ -621,10 +620,8 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
    */
   private void processEntityTypeSelfLinks(OperationResult operationResult) {
 
-    JsonNode rootNode = null;
-    
-    if ( operationResult == null ) {
-       return;
+    if (operationResult == null) {
+      return;
     }
 
     final String jsonResult = operationResult.getResult();
@@ -632,46 +629,41 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer
     if (jsonResult != null && jsonResult.length() > 0 && operationResult.wasSuccessful()) {
 
       try {
-        rootNode = mapper.readTree(jsonResult);
-      } catch (IOException exc) {
-        String message =
-            "Could not deserialize JSON (representing operation result) as node tree. " +
-            "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
-        LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
-      }
+        JsonNode rootNode = mapper.readTree(jsonResult);
 
-      JsonNode resultData = rootNode.get("result-data");
-      ArrayNode resultDataArrayNode = null;
+        JsonNode resultData = rootNode.get("result-data");
 
-      if (resultData.isArray()) {
-        resultDataArrayNode = (ArrayNode) resultData;
+        if (resultData.isArray()) {
+          ArrayNode resultDataArrayNode = (ArrayNode) resultData;
 
-        Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
-        JsonNode element = null;
+          Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
 
-        while (elementIterator.hasNext()) {
-          element = elementIterator.next();
+          while (elementIterator.hasNext()) {
+            JsonNode element = elementIterator.next();
 
-          final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
-          final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
+            final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
+            final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
 
-          OxmEntityDescriptor descriptor = null;
+            if (resourceType != null && resourceLink != null) {
 
-          if (resourceType != null && resourceLink != null) {
+              OxmEntityDescriptor descriptor = oxmEntityLookup.getEntityDescriptors().get(resourceType);
 
-            descriptor = oxmEntityLookup.getEntityDescriptors().get(resourceType);
-
-            if (descriptor == null) {
-              LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
-              // go to next element in iterator
-              continue;
-            }
+              if (descriptor == null) {
+                LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
+                // go to next element in iterator
+                continue;
+              }
 
-            selflinks.add(new SelfLinkDescriptor(resourceLink, SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
-            
+              selflinks.add(new SelfLinkDescriptor(resourceLink, SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
 
+            }
           }
         }
+      } catch (IOException exc) {
+        String message =
+                "Could not deserialize JSON (representing operation result) as node tree. " +
+                        "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
+        LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
       }
     }
 
index ab1c7af..6f8299c 100644 (file)
@@ -120,7 +120,6 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
   /**
    * Instantiates a new historical entity summarizer.
    *
-   * @param indexName the index name
    * @throws Exception the exception
    */
   public AutosuggestionSynchronizer(ElasticSearchSchemaConfig schemaConfig, int internalSyncWorkers,
@@ -260,10 +259,8 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
    */
   private void processEntityTypeSelfLinks(OperationResult operationResult) {
 
-    JsonNode rootNode = null;
-    
-    if ( operationResult == null ) {
-       return;
+    if (operationResult == null) {
+      return;
     }
 
     final String jsonResult = operationResult.getResult();
@@ -271,45 +268,38 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer
     if (jsonResult != null && jsonResult.length() > 0 && operationResult.wasSuccessful()) {
 
       try {
-        rootNode = mapper.readTree(jsonResult);
-      } catch (IOException exc) {
-        String message = "Could not deserialize JSON (representing operation result) as node tree. "
-            + "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
-        LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
-      }
-
-      JsonNode resultData = rootNode.get("result-data");
-      ArrayNode resultDataArrayNode = null;
+        JsonNode rootNode = mapper.readTree(jsonResult);
+        JsonNode resultData = rootNode.get("result-data");
 
-      if (resultData.isArray()) {
-        resultDataArrayNode = (ArrayNode) resultData;
+        if (resultData.isArray()) {
+          ArrayNode resultDataArrayNode = (ArrayNode) resultData;
 
-        Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
-        JsonNode element = null;
+          Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
 
-        while (elementIterator.hasNext()) {
-          element = elementIterator.next();
+          while (elementIterator.hasNext()) {
+            JsonNode element = elementIterator.next();
 
-          final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
-          final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
+            final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
+            final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
 
-          OxmEntityDescriptor descriptor = null;
+            if (resourceType != null && resourceLink != null) {
 
-          if (resourceType != null && resourceLink != null) {
+              OxmEntityDescriptor descriptor = oxmEntityLookup.getEntityDescriptors().get(resourceType);
 
-            descriptor = oxmEntityLookup.getEntityDescriptors().get(resourceType);
-
-            if (descriptor == null) {
-              LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
-              // go to next element in iterator
-              continue;
+              if (descriptor == null) {
+                LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
+                // go to next element in iterator
+                continue;
+              }
+              selflinks.add(new SelfLinkDescriptor(resourceLink,
+                      SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
             }
-            selflinks.add(new SelfLinkDescriptor(resourceLink,
-                SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
-
-
           }
         }
+      } catch (IOException exc) {
+        String message = "Could not deserialize JSON (representing operation result) as node tree. "
+                + "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
+        LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
       }
     }
   }
index 65181c1..4a46e22 100644 (file)
@@ -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.
index fad6fdd..0c89dcb 100644 (file)
@@ -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.
index d95e507..a817eb9 100644 (file)
@@ -123,7 +123,6 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
   /**
    * Instantiates a new cross entity reference synchronizer.
    *
-   * @param indexName the index name
    * @throws Exception the exception
    */
   public CrossEntityReferenceSynchronizer(ElasticSearchSchemaConfig schemaConfig,
@@ -349,49 +348,42 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
    */
   private void processEntityTypeSelfLinks(OperationResult operationResult) {
 
-    JsonNode rootNode = null;
-
     final String jsonResult = operationResult.getResult();
 
     if (jsonResult != null && jsonResult.length() > 0) {
 
       try {
-        rootNode = mapper.readTree(jsonResult);
-      } catch (IOException exc) {
-        // TODO // TODO -> LOG, waht should be logged here?
-      }
-
-      JsonNode resultData = rootNode.get("result-data");
-      ArrayNode resultDataArrayNode = null;
-
-      if (resultData.isArray()) {
-        resultDataArrayNode = (ArrayNode) resultData;
+        JsonNode rootNode = mapper.readTree(jsonResult);
+        JsonNode resultData = rootNode.get("result-data");
 
-        Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
-        JsonNode element = null;
+        if (resultData.isArray()) {
+          ArrayNode resultDataArrayNode = (ArrayNode) resultData;
 
-        while (elementIterator.hasNext()) {
-          element = elementIterator.next();
+          Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
 
-          final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
-          final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
+          while (elementIterator.hasNext()) {
+            JsonNode element = elementIterator.next();
 
-          CrossEntityReferenceDescriptor descriptor = null;
+            final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
+            final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
 
-          if (resourceType != null && resourceLink != null) {
-            descriptor = crossEntityReferenceLookup.getCrossReferenceEntityDescriptors().get(resourceType);
+            if (resourceType != null && resourceLink != null) {
+              CrossEntityReferenceDescriptor descriptor = crossEntityReferenceLookup.getCrossReferenceEntityDescriptors().get(resourceType);
 
-            if (descriptor == null) {
-              LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
-              // go to next element in iterator
-              continue;
-            }
-            if (descriptor.hasCrossEntityReferences()) {
-              selflinks.add(new SelfLinkDescriptor(
-                  resourceLink,SynchronizerConstants.DEPTH_ALL_MODIFIER, resourceType));
+              if (descriptor == null) {
+                LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
+                // go to next element in iterator
+                continue;
+              }
+              if (descriptor.hasCrossEntityReferences()) {
+                selflinks.add(new SelfLinkDescriptor(
+                        resourceLink, SynchronizerConstants.DEPTH_ALL_MODIFIER, resourceType));
+              }
             }
           }
         }
+      } catch (IOException exc) {
+        // TODO // TODO -> LOG, waht should be logged here?
       }
     }
   }
@@ -625,7 +617,8 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer
                         }
                         
                       } else {
-                        String message = "Entity sync failed because AAI query failed with error " + aaiQueryResult.getResult(); 
+                        String result = aaiQueryResult != null ? aaiQueryResult.getResult() : "unknown";
+                        String message = "Entity sync failed because AAI query failed with error " + result;
                         LOG.error(AaiUiMsgs.ENTITY_SYNC_FAILED_QUERY_ERROR, message);
                       }
                       
index 2316679..1b077c3 100644 (file)
@@ -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());
index 614968e..cb3e5e4 100644 (file)
@@ -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);
index 3cef322..77a435d 100644 (file)
  */
 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;
         }
index 26e6997..3f7640f 100644 (file)
@@ -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);
         
index d3fd7fe..e908900 100644 (file)
  */
 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;
   }
 }
index 7d0a3ac..b507fa3 100644 (file)
@@ -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 (file)
index 0000000..69010b5
--- /dev/null
@@ -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 (file)
index 0000000..1373d59
--- /dev/null
@@ -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;
+  }
+}
index d248df9..fd64f97 100644 (file)
@@ -109,7 +109,7 @@ public class EcompSso {
       String[] cspFields = getCspData(request);
       if (cspFields != null && cspFields.length > 5)
         uid = cspFields[5];
-    } catch (Throwable t) {
+    } catch (Exception t) {
       LOG.info(AaiUiMsgs.LOGIN_FILTER_INFO,
           "getLoginIdFromCookie failed " + t.getLocalizedMessage());
     }
index 983a2ad..301e65d 100644 (file)
@@ -48,7 +48,7 @@ public class StoreDocumentTask implements Supplier<NetworkTransaction> {
    *
    * @param doc the doc
    * @param txn the txn
-   * @param esDataProvider the es data provider
+   * @param esAdapter the es adapter
    */
   public StoreDocumentTask(IndexDocument doc, NetworkTransaction txn,
       ElasticSearchAdapter esAdapter) {
@@ -67,7 +67,7 @@ public class StoreDocumentTask implements Supplier<NetworkTransaction> {
 
     long startTimeInMs = System.currentTimeMillis();
     MDC.setContextMap(contextMap);
-    OperationResult operationResult = null;
+    OperationResult operationResult = new OperationResult();
 
     try {
 
index a91ebc4..809c21a 100644 (file)
@@ -78,7 +78,6 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
   /**
    * Instantiates a new geo synchronizer.
    *
-   * @param indexName the index name
    * @throws Exception the exception
    */
   public GeoSynchronizer(ElasticSearchSchemaConfig schemaConfig, int internalSyncWorkers,
@@ -245,45 +244,40 @@ public class GeoSynchronizer extends AbstractEntitySynchronizer implements Index
    */
   private void processEntityTypeSelfLinks(OperationResult operationResult) {
 
-    JsonNode rootNode = null;
-
     final String jsonResult = operationResult.getResult();
 
     if (jsonResult != null && jsonResult.length() > 0 && operationResult.wasSuccessful()) {
 
       try {
-        rootNode = mapper.readTree(jsonResult);
-      } catch (IOException exc) {
-        LOG.error(AaiUiMsgs.ERROR_GENERIC, exc);
-      }
+        JsonNode rootNode = mapper.readTree(jsonResult);
+        JsonNode resultData = rootNode.get("result-data");
 
-      JsonNode resultData = rootNode.get("result-data");
-      ArrayNode resultDataArrayNode = null;
+        if (resultData.isArray()) {
+          ArrayNode resultDataArrayNode = (ArrayNode) resultData;
 
-      if (resultData.isArray()) {
-        resultDataArrayNode = (ArrayNode) resultData;
+          Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
 
-        Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
-        JsonNode element = null;
+          while (elementIterator.hasNext()) {
+            JsonNode element = elementIterator.next();
 
-        while (elementIterator.hasNext()) {
-          element = elementIterator.next();
+            final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
+            final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
 
-          final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
-          final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
+            if (resourceType != null && resourceLink != null) {
 
-          if (resourceType != null && resourceLink != null) {
+              if (geoDescriptorMap.containsKey(resourceType)) {
+                selflinks.add(new SelfLinkDescriptor(resourceLink + "?nodes-only", resourceType));
+              } else {
+                LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
+                // go to next element in iterator
+                continue;
+              }
 
-            if (geoDescriptorMap.containsKey(resourceType)) {
-              selflinks.add(new SelfLinkDescriptor(resourceLink + "?nodes-only", resourceType));
-            } else {
-              LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
-              // go to next element in iterator
-              continue;
             }
-
           }
         }
+      } catch (IOException exc) {
+        LOG.error(AaiUiMsgs.ERROR_GENERIC, exc);
       }
     }
 
index cd2d8fd..69812dc 100644 (file)
@@ -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());
index b5f72bc..6dc8441 100644 (file)
@@ -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";
index a13ffdb..4d83509 100644 (file)
@@ -667,28 +667,19 @@ public class ActiveInventoryNode {
         } else {
           JsonNode nodeValue = field.getValue();
 
-          if (nodeValue != null && nodeValue.isValueNode()) {
+          if (nodeValue != null) {
+            if (nodeValue.isValueNode()) {
 
-            /*
-             * before we blindly add the fieldName and value to our property set, let's do one more
-             * check to see if the field name is an entity type. If it is, then our complex
-             * attribute processing code will pick it up and process it instead, but this is
-             * probably more likely just for array node types, but we'll see.
-             */
-
-            if (oxmEntityLookup.getEntityDescriptors().get(fieldName) == null) {
               /*
-               * this is no an entity type as far as we can tell, so we can add it to our property
-               * set.
+               * before we blindly add the fieldName and value to our property set, let's do one more
+               * check to see if the field name is an entity type. If it is, then our complex
+               * attribute processing code will pick it up and process it instead, but this is
+               * probably more likely just for array node types, but we'll see.
                */
 
-              addProperty(fieldName, nodeValue.asText());
-
-            }
-
-          } else {
+              handleNodeValue(fieldName, nodeValue.asText());
 
-            if (nodeValue.isArray()) {
+            } else if (nodeValue.isArray()) {
 
               /*
                * make sure array entity-type collection is not an entityType before adding it to the
@@ -696,26 +687,13 @@ public class ActiveInventoryNode {
                * complex group or relationship.
                */
 
-              if (oxmEntityLookup.getEntityDescriptors().get(field.getKey()) == null) {
-                /*
-                 * this is no an entity type as far as we can tell, so we can add it to our property
-                 * set.
-                 */
-
-                addProperty(field.getKey(), nodeValue.toString());
-
-              }
-
+              handleNodeValue(field.getKey(), nodeValue.toString());
             } else {
-
               complexGroups.add(nodeValue);
-
             }
 
           }
-
         }
-
       }
 
     } catch (IOException exc) {
@@ -727,6 +705,18 @@ public class ActiveInventoryNode {
 
   }
 
+  private void handleNodeValue(String fieldName, String fieldValue) {
+    if (oxmEntityLookup.getEntityDescriptors().get(fieldName) == null) {
+      /*
+       * this is no an entity type as far as we can tell, so we can add it to our property
+       * set.
+       */
+
+      addProperty(fieldName, fieldValue);
+
+    }
+  }
+
   public void setSelfLink(String selfLink) {
     this.selfLink = selfLink;
   }
index 610aec6..1937891 100644 (file)
@@ -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());
@@ -194,7 +194,8 @@ public class ViewInspectSearchProvider implements SearchProvider {
             suggestionEntity
                 .setText(annotateSearchTags(searchTags, searchTagIds, entityType, queryStr));
           } catch (Exception exc) {
-            LOG.error(AaiUiMsgs.SEARCH_TAG_ANNOTATION_ERROR, searchTags.toString(),
+            String searchTagsAsText = searchTags != null ? searchTags.toString() : "n/a";
+            LOG.error(AaiUiMsgs.SEARCH_TAG_ANNOTATION_ERROR, searchTagsAsText,
                 exc.getLocalizedMessage());
             // at least send back the un-annotated search tags
             suggestionEntity.setText(searchTags);
index aa4508c..0cbd52e 100644 (file)
@@ -538,38 +538,15 @@ public class BaseVisualizationContext implements VisualizationContext {
 
         JsonNode nodeValue = field.getValue();
 
-        if (nodeValue != null && nodeValue.isValueNode()) {
-
-          if (oxmEntityLookup.getEntityDescriptors().get(fieldName) == null) {
-
-            /*
-             * entity property name is not an entity, thus we can add this property name and value
-             * to our property set
-             */
-
-            ain.addProperty(fieldName, nodeValue.asText());
-
-          }
-
-        } else {
-
-          if (nodeValue.isArray()) {
-
-            if (oxmEntityLookup.getEntityDescriptors().get(fieldName) == null) {
-
-              /*
-               * entity property name is not an entity, thus we can add this property name and value
-               * to our property set
-               */
-
-              ain.addProperty(field.getKey(), nodeValue.toString());
-
-            }
-
+        if(nodeValue!=null) {
+          if (nodeValue.isValueNode()) {
+            String key = fieldName;
+            handleNodeValue(ain, fieldName, key, nodeValue.asText());
+          } else if (nodeValue.isArray()) {
+            String key = field.getKey();
+            handleNodeValue(ain, fieldName, key, nodeValue.toString());
           } else {
-
-            ain.addComplexGroup(nodeValue);
-
+              ain.addComplexGroup(nodeValue);
           }
 
         }
@@ -628,6 +605,19 @@ public class BaseVisualizationContext implements VisualizationContext {
 
   }
 
+  private void handleNodeValue(ActiveInventoryNode ain, String fieldName, String key, String value) {
+    if (oxmEntityLookup.getEntityDescriptors().get(fieldName) == null) {
+
+      /*
+       * entity property name is not an entity, thus we can add this property name and value
+       * to our property set
+       */
+
+      ain.addProperty(key, value);
+
+    }
+  }
+
   /**
    * Perform self link resolve.
    *
@@ -826,7 +816,6 @@ public class BaseVisualizationContext implements VisualizationContext {
   /**
    * Process current node states.
    *
-   * @param rootNodeDiscovered the root node discovered
    */
   private void processCurrentNodeStates(QueryParams queryParams) {
     /*
index a81ab9c..69acc42 100644 (file)
@@ -294,8 +294,6 @@ public class BaseVisualizationService implements VisualizationService {
       throw new ServletException(e1);
     }
 
-    String jsonResponse = null;
-
     long startTimeInMs = System.currentTimeMillis();
 
     visContext.processSelfLinks(searchtargetEntity, queryParams);
@@ -338,28 +336,24 @@ public class BaseVisualizationService implements VisualizationService {
     
     GraphMeta graphMeta = new GraphMeta();
 
-    D3VisualizationOutput output = null;
-    try {
-      output = transformer
-          .generateVisualizationOutput((System.currentTimeMillis() - opStartTimeInMs), graphMeta);
-    } catch (JsonProcessingException exc) {
-      throw new ServletException("Caught an exception while generation visualization output", exc);
-    } catch (IOException exc) {
-      LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST, exc.getLocalizedMessage());
-    }
+    D3VisualizationOutput output = getD3VisualizationOutput(opStartTimeInMs, transformer, graphMeta);
 
-    output.setInlineMessage(visContext.getInlineMessage());
-    output.getGraphMeta().setNumLinkResolveFailed(visContext.getNumFailedLinkResolve());
-    output.getGraphMeta().setNumLinksResolvedSuccessfullyFromCache(
-        visContext.getNumSuccessfulLinkResolveFromCache());
-    output.getGraphMeta().setNumLinksResolvedSuccessfullyFromServer(
-        visContext.getNumSuccessfulLinkResolveFromFromServer());
+    String jsonResponse = null;
 
-    try {
-      jsonResponse = transformer.convertVisualizationOutputToJson(output);
-    } catch (JsonProcessingException jpe) {
-      throw new ServletException(
-          "Caught an exception while converting visualization output to json", jpe);
+    if (output != null) {
+      output.setInlineMessage(visContext.getInlineMessage());
+      output.getGraphMeta().setNumLinkResolveFailed(visContext.getNumFailedLinkResolve());
+      output.getGraphMeta().setNumLinksResolvedSuccessfullyFromCache(
+              visContext.getNumSuccessfulLinkResolveFromCache());
+      output.getGraphMeta().setNumLinksResolvedSuccessfullyFromServer(
+              visContext.getNumSuccessfulLinkResolveFromFromServer());
+
+      try {
+        jsonResponse = transformer.convertVisualizationOutputToJson(output);
+      } catch (JsonProcessingException jpe) {
+        throw new ServletException(
+                "Caught an exception while converting visualization output to json", jpe);
+      }
     }
 
     logOptime("[build flat node array, add relationship data, search target,"
@@ -370,7 +364,20 @@ public class BaseVisualizationService implements VisualizationService {
     return jsonResponse;
 
   }
-  
+
+  private D3VisualizationOutput getD3VisualizationOutput(long opStartTimeInMs, VisualizationTransformer transformer, GraphMeta graphMeta) throws ServletException {
+    D3VisualizationOutput output = null;
+    try {
+      output = transformer
+          .generateVisualizationOutput((System.currentTimeMillis() - opStartTimeInMs), graphMeta);
+    } catch (JsonProcessingException exc) {
+      throw new ServletException("Caught an exception while generation visualization output", exc);
+    } catch (IOException exc) {
+      LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST, exc.getLocalizedMessage());
+    }
+    return output;
+  }
+
   public void shutdown() {
     aaiExecutorService.shutdown();
   }
index ecf4e56..285a76b 100644 (file)
@@ -115,7 +115,6 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
   /**
    * Instantiates a new searchable entity synchronizer.
    *
-   * @param indexName the index name
    * @throws Exception the exception
    */
   public ViewInspectEntitySynchronizer(ElasticSearchSchemaConfig schemaConfig,
@@ -255,54 +254,49 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer
    */
   private void processEntityTypeSelfLinks(OperationResult operationResult) {
 
-    JsonNode rootNode = null;
-
     final String jsonResult = operationResult.getResult();
 
     if (jsonResult != null && jsonResult.length() > 0 && operationResult.wasSuccessful()) {
 
       try {
-        rootNode = mapper.readTree(jsonResult);
-      } catch (IOException exc) {
-        String message =
-            "Could not deserialize JSON (representing operation result) as node tree. " +
-            "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
-        LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
-      }
+        JsonNode rootNode = mapper.readTree(jsonResult);
+        JsonNode resultData = rootNode.get("result-data");
 
-      JsonNode resultData = rootNode.get("result-data");
-      ArrayNode resultDataArrayNode = null;
+        if (resultData.isArray()) {
+          ArrayNode resultDataArrayNode = (ArrayNode) resultData;
 
-      if (resultData.isArray()) {
-        resultDataArrayNode = (ArrayNode) resultData;
+          Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
 
-        Iterator<JsonNode> elementIterator = resultDataArrayNode.elements();
-        JsonNode element = null;
+          while (elementIterator.hasNext()) {
+            JsonNode element = elementIterator.next();
 
-        while (elementIterator.hasNext()) {
-          element = elementIterator.next();
+            final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
+            final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
 
-          final String resourceType = NodeUtils.getNodeFieldAsText(element, "resource-type");
-          final String resourceLink = NodeUtils.getNodeFieldAsText(element, "resource-link");
+            SearchableOxmEntityDescriptor descriptor = null;
 
-          SearchableOxmEntityDescriptor descriptor = null;
+            if (resourceType != null && resourceLink != null) {
 
-          if (resourceType != null && resourceLink != null) {
+              descriptor = searchableEntityLookup.getSearchableEntityDescriptors().get(resourceType);
 
-            descriptor = searchableEntityLookup.getSearchableEntityDescriptors().get(resourceType);
+              if (descriptor == null) {
+                LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
+                // go to next element in iterator
+                continue;
+              }
 
-            if (descriptor == null) {
-              LOG.error(AaiUiMsgs.MISSING_ENTITY_DESCRIPTOR, resourceType);
-              // go to next element in iterator
-              continue;
-            }
+              if (descriptor.hasSearchableAttributes()) {
+                selflinks.add(new SelfLinkDescriptor(resourceLink, SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
+              }
 
-            if (descriptor.hasSearchableAttributes()) {
-              selflinks.add(new SelfLinkDescriptor(resourceLink, SynchronizerConstants.NODES_ONLY_MODIFIER, resourceType));
             }
-
           }
         }
+      } catch (IOException exc) {
+        String message =
+            "Could not deserialize JSON (representing operation result) as node tree. " +
+            "Operation result = " + jsonResult + ". " + exc.getLocalizedMessage();
+        LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
       }
     }
 
index 06ebafa..2a8e503 100644 (file)
@@ -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);
 
index ca7eab9..59db5c2 100644 (file)
@@ -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"));
index 0644a53..f313a3a 100644 (file)
@@ -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
index ffb27fa..b5ff1fd 100644 (file)
@@ -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";
 }
index 31716ed..e053442 100644 (file)
@@ -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",
                "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",
                        "fieldName": "prov-status"
                }
        },
-       {
-               "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
index e6ece9f..dce8926 100644 (file)
@@ -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