Organise imports to ONAP Java standards
[aai/search-data-service.git] / src / main / java / org / onap / aai / sa / searchdbabstraction / searchapi / SuggestionStatement.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 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 package org.onap.aai.sa.searchdbabstraction.searchapi;
22
23 import com.fasterxml.jackson.annotation.JsonProperty;
24 import org.radeox.util.logging.Logger;
25
26 /**
27  * This class represents the structure of a search statement.
28  *
29  * <p>
30  * The expected JSON structure to represent a Completion suggest search statement is as follows:
31  *
32  * { "suggest-vnf" : { "text" : "VNFs", "completion" : { "field" : "entity_suggest", "size": 1 } } }
33  */
34 public class SuggestionStatement {
35
36     @JsonProperty("results-size")
37     private Integer size;
38
39     @JsonProperty("suggest-field")
40     private String field;
41
42     @JsonProperty("suggest-text")
43     private String text;
44
45     public Integer getSize() {
46         return size;
47     }
48
49     public void setSize(Integer size) {
50         this.size = size;
51     }
52
53     public String getField() {
54         return field;
55     }
56
57     public void setField(String field) {
58         this.field = field;
59     }
60
61     public String getText() {
62         return text;
63     }
64
65     public void setText(String text) {
66         this.text = text;
67     }
68
69     /**
70      * This method returns a string which represents this statement in syntax that is understandable
71      * by ElasticSearch and is suitable for inclusion in an ElasticSearch query string.
72      *
73      * @return - ElasticSearch syntax string.
74      */
75     public String toElasticSearch() {
76
77         StringBuilder sb = new StringBuilder();
78
79         sb.append("{");
80         sb.append("\"suggest-vnf\": {");
81         sb.append("\"text\": ").append("\"" + text + "\"").append(", ");
82         sb.append("\"completion\": {");
83         sb.append("\"field\": ").append("\"" + field + "\"").append(", ");
84         sb.append("\"size\": ").append(size);
85         sb.append("}");
86         sb.append("}");
87         sb.append("}");
88
89         Logger.debug("Generated raw ElasticSearch suggest statement: " + sb.toString());
90         return sb.toString();
91     }
92
93 }