/** * ============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.sa.searchdbabstraction.searchapi; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import org.radeox.util.logging.Logger; /** * This class represents the structure of a search statement. * *
* The expected JSON structure to represent a search statement is as follows: * *
* *
* { * "results-start": int, - Optional: index of starting point in result set. * "results-size": int, - Optional: maximum number of documents to include in result set. * * "filter": { * { filter structure - see {@link Filter} } * }, * * "queries": [ * { query structure - see {@link QueryStatement} }, * { query structure - see {@link QueryStatement} }, * . * . * { query structure - see {@link QueryStatement} }, * ], * * "aggregations": [ * { aggregation structure - see {@link AggregationStatement} }, * { aggregation structure - see {@link AggregationStatement} }, * . * . * { aggregation structure - see {@link AggregationStatement} }, * ] * } **/ public class SearchStatement { /** * Defines the filters that should be applied before running the actual queries. This is optional. */ private Filter filter; /** * The list of queries to be applied to the document store. */ private Query[] queries; /** * The list of aggregations to be applied to the search */ private Aggregation[] aggregations; /** * Defines the sort criteria to apply to the query result set. This is optional. */ private Sort sort; @JsonProperty("results-start") private Integer resultsStart; @JsonProperty("results-size") private Integer size; public Filter getFilter() { return filter; } public void setFilter(Filter filter) { this.filter = filter; } public Query[] getQueries() { return queries; } public void setQueries(Query[] queries) { this.queries = queries; } public Sort getSort() { return sort; } public void setSort(Sort sort) { this.sort = sort; } public boolean isFiltered() { return filter != null; } public Aggregation[] getAggregations() { return aggregations; } public void setAggregations(Aggregation[] aggregations) { this.aggregations = aggregations; } public boolean hasAggregations() { return aggregations != null && aggregations.length > 0; } public Integer getFrom() { return resultsStart; } public void setFrom(Integer from) { this.resultsStart = from; } public Integer getSize() { return size; } public void setSize(Integer size) { this.size = size; } /** * This method returns a string which represents this statement in syntax that is understandable by ElasticSearch * and is suitable for inclusion in an ElasticSearch query string. * * @return - ElasticSearch syntax string. */ public String toElasticSearch() { StringBuilder sb = new StringBuilder(); List