2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.common.database.queries;
24 import org.json.JSONArray;
25 import org.json.JSONObject;
27 public class BoolQueryBuilder extends QueryBuilder {
29 private JSONObject inner;
31 public BoolQueryBuilder() {
33 this.inner = new JSONObject();
34 this.setQuery("bool", this.inner);
38 public String toString() {
39 return "BoolQueryBuilder [inner=" + inner + "]";
42 public BoolQueryBuilder must(QueryBuilder query) {
44 if(this.inner.has("must") || this.inner.has("match") || this.inner.has("regexp") || this.inner.has("range")) {
45 Object x = this.inner.has("must") ?this.inner.get("must"):this.inner;
46 if(x instanceof JSONArray) {
47 ((JSONArray)x).put(query.getInner());
50 this.inner = new JSONObject();
51 this.inner.put("must", new JSONObject());
52 JSONArray a=new JSONArray();
54 a.put(query.getInner());
55 this.inner.put("must", a);
60 this.inner = query.getInner();
62 this.setQuery("bool", this.inner);