Add missing distributionManagement section to poms
[aai/search-data-service.git] / search-data-service-app / src / main / java / org / onap / aai / sa / searchdbabstraction / searchapi / DateHistogramAggregation.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  * An example of elasticsearch date_histogram aggregation:
27  *
28  * <p>
29  * 
30  * <pre>
31  * {
32  *    "aggs": {
33  *        "my_group": {
34  *            "date_histogram" : {
35  *               "field" : "date",
36  *               "interval" : "month"
37  *           }
38  *        }
39  *    }
40  * }
41  * </pre>
42  */
43
44 public class DateHistogramAggregation extends AbstractAggregation {
45
46     private String interval;
47
48     private String format;
49
50     @JsonProperty("time-zone")
51     private String timeZone;
52
53
54     public String getInterval() {
55         return interval;
56     }
57
58     public void setInterval(String interval) {
59         this.interval = interval;
60     }
61
62     public String getTimeZone() {
63         return timeZone;
64     }
65
66     public String getFormat() {
67         return format;
68     }
69
70     public void setFormat(String format) {
71         this.format = format;
72     }
73
74     public void setTimeZone(String timeZone) {
75         this.timeZone = timeZone;
76     }
77
78     @Override
79     public String toElasticSearch() {
80         StringBuilder sb = new StringBuilder();
81
82         sb.append("\"date_histogram\": {\"field\": \"");
83         sb.append(field);
84         sb.append("\"");
85         if (interval != null) {
86             sb.append(", \"interval\": \"");
87             sb.append(interval);
88             sb.append("\"");
89         }
90         if (format != null) {
91             sb.append(", \"format\": \"");
92             sb.append(format);
93             sb.append("\"");
94         }
95         if (timeZone != null) {
96             sb.append(", \"time_zone\": \"");
97             sb.append(timeZone);
98             sb.append("\"");
99         }
100         if (size != null) {
101             sb.append(", \"size\": ");
102             sb.append(size);
103         }
104         if (minThreshold != null) {
105             sb.append(", \"min_doc_count\": ").append(minThreshold);
106         }
107         sb.append("}");
108
109         return sb.toString();
110     }
111
112     @Override
113     public String toString() {
114         return "DateHistogramAggregation: [field=" + field + ", interval=" + interval + ", format=" + format
115                 + ", timeZone=" + timeZone + ", size=" + size + " minThreshold=" + minThreshold;
116     }
117 }