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