991b50c0992bc9bdeaaaad5960b1c694b324a24e
[aai/search-data-service.git] / src / main / java / org / openecomp / sa / searchdbabstraction / searchapi / Query.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.openecomp.sa.searchdbabstraction.searchapi;
24
25 public class Query {
26
27   private QueryStatement may;
28   private QueryStatement must;
29
30   public QueryStatement getMay() {
31     return may;
32   }
33
34   public void setMay(QueryStatement may) {
35     this.may = may;
36   }
37
38   public QueryStatement getMust() {
39     return must;
40   }
41
42   public void setMust(QueryStatement must) {
43     this.must = must;
44   }
45
46   public QueryStatement getQueryStatement() {
47     if (isMust()) {
48       return must;
49     } else if (isMay()) {
50       return may;
51     } else {
52       return null;
53     }
54   }
55
56   public boolean isMust() {
57     return must != null;
58   }
59
60   public boolean isMay() {
61     return may != null;
62   }
63
64   public String toElasticSearch() {
65
66     if (isMust()) {
67       return must.toElasticSearch();
68     } else if (isMay()) {
69       return may.toElasticSearch();
70     } else {
71       return ""; // throw an exception?
72     }
73   }
74
75   @Override
76   public String toString() {
77
78     StringBuilder sb = new StringBuilder();
79
80     sb.append("Query:[");
81     if (isMust()) {
82       sb.append("must: ").append(must.toString());
83     } else if (isMay()) {
84       sb.append("may: ").append(may.toString());
85     } else {
86       sb.append("INVALID");
87     }
88     sb.append("]");
89
90     return sb.toString();
91   }
92 }