Initial search service commit
[aai/search-data-service.git] / src / main / java / org / openecomp / sa / searchdbabstraction / searchapi / Query.java
1 /**
2  * ============LICENSE_START=======================================================
3  * Search Data Service
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License ati
12  *
13  *    http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25 package org.openecomp.sa.searchdbabstraction.searchapi;
26
27 public class Query {
28
29   private QueryStatement may;
30   private QueryStatement must;
31
32   public QueryStatement getMay() {
33     return may;
34   }
35
36   public void setMay(QueryStatement may) {
37     this.may = may;
38   }
39
40   public QueryStatement getMust() {
41     return must;
42   }
43
44   public void setMust(QueryStatement must) {
45     this.must = must;
46   }
47
48   public QueryStatement getQueryStatement() {
49     if (isMust()) {
50       return must;
51     } else if (isMay()) {
52       return may;
53     } else {
54       return null;
55     }
56   }
57
58   public boolean isMust() {
59     return must != null;
60   }
61
62   public boolean isMay() {
63     return may != null;
64   }
65
66   public String toElasticSearch() {
67
68     if (isMust()) {
69       return must.toElasticSearch();
70     } else if (isMay()) {
71       return may.toElasticSearch();
72     } else {
73       return ""; // throw an exception?
74     }
75   }
76
77   @Override
78   public String toString() {
79
80     StringBuilder sb = new StringBuilder();
81
82     sb.append("Query:[");
83     if (isMust()) {
84       sb.append("must: ").append(must.toString());
85     } else if (isMay()) {
86       sb.append("may: ").append(may.toString());
87     } else {
88       sb.append("INVALID");
89     }
90     sb.append("]");
91
92     return sb.toString();
93   }
94 }