Update poms to conform to merge job requirements
[aai/search-data-service.git] / search-data-service-app / src / main / java / org / onap / aai / sa / searchdbabstraction / searchapi / DateRange.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
25 /**
26  * This class represents the ranges specification in an date_range statement.
27  * <p>
28  * The expected JSON structure for a ranges is as follows:
29  * <p>
30  *
31  * <pre>
32  * {
33  *  "from": <from-date>
34  * }
35  * </pre>
36  * <p>
37  * or
38  * <p>
39  *
40  * <pre>
41  * {
42  *  "to": <to-date>
43  * }
44  * </pre>
45  * <p>
46  * or
47  * <p>
48  *
49  * <pre>
50  * {
51  *  "from": <from-date>,
52  *  "to": <to-date>
53  * }
54  * </pre>
55  *
56  * @author sye
57  */
58 public class DateRange {
59
60     @JsonProperty("from")
61     private String fromDate;
62
63     @JsonProperty("to")
64     private String toDate;
65
66     public String getFromDate() {
67         return fromDate;
68     }
69
70     public void setFromDate(String fromDate) {
71         this.fromDate = fromDate;
72     }
73
74     public String getToDate() {
75         return toDate;
76     }
77
78     public void setToDate(String toDate) {
79         this.toDate = toDate;
80     }
81
82     public String toElasticSearch() {
83         StringBuilder sb = new StringBuilder();
84
85         sb.append("{");
86
87         if (fromDate != null) {
88             sb.append("\"from\": \"");
89             sb.append(fromDate);
90             sb.append("\"");
91         }
92
93         if (toDate != null) {
94             if (fromDate != null) {
95                 sb.append(", \"to\": \"");
96                 sb.append(toDate);
97                 sb.append("\"");
98             } else {
99                 sb.append("\"to\": \"");
100                 sb.append(toDate);
101                 sb.append("\"");
102             }
103         }
104
105         sb.append("}");
106
107         return sb.toString();
108     }
109
110     @Override
111     public String toString() {
112         return "{from: " + fromDate + ", to: " + toDate + "}";
113     }
114
115 }