/
SmsMessageFilter.java
222 lines (182 loc) · 6.38 KB
/
SmsMessageFilter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* TeleStax, Open Source Cloud Communications
* Copyright 2011-2014, Telestax Inc and individual contributors
* by the @authors tag.
*
* This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
package org.restcomm.connect.dao.entities;
import org.restcomm.connect.commons.annotations.concurrency.Immutable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* @author <a href="mailto:n.congvu@gmail.com">vunguyen</a>
* @author Henrique Rosa (henrique.rosa@telestax.com)
*/
@Immutable
public class SmsMessageFilter {
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
private String accountSid;
private List<String> accountSidSet; // if not-null we need the cdrs that belong to several accounts
private String recipient;
private String sender;
private String startTime; // to initialize it pass string arguments with yyyy-MM-dd format
private String endTime;
private String body;
private Integer limit;
private Integer offset;
private String instanceid;
private String smppMessageId;
public SmsMessageFilter() {
}
@Deprecated
public SmsMessageFilter(String accountSid, List<String> accountSidSet, String recipient, String sender, String startTime, String endTime,
String body, Integer limit, Integer offset) throws ParseException {
this(accountSid, accountSidSet, recipient, sender, startTime, endTime, body, limit, offset, null);
}
@Deprecated
public SmsMessageFilter(String accountSid, List<String> accountSidSet, String recipient, String sender, String startTime, String endTime,
String body, Integer limit, Integer offset, String instanceId) throws ParseException {
this.accountSid = accountSid;
this.accountSidSet = accountSidSet;
// The LIKE keyword uses '%' to match any (including 0) number of characters, and '_' to match exactly one character
// Add here the '%' keyword so +15126002188 will be the same as 15126002188 and 6002188
if (recipient != null)
recipient = "%".concat(recipient);
if (sender != null)
sender = "%".concat(sender);
this.recipient = recipient;
this.sender = sender;
this.body = body;
this.limit = limit;
this.offset = offset;
if (startTime != null) {
//Date date = DATE_FORMAT.parse(startTime);
this.startTime = startTime;
} else
this.startTime = null;
if (endTime != null) {
//Date date = DATE_FORMAT.parse(endTime);
this.endTime = endTime;
} else {
this.endTime = null;
}
if (instanceId != null && !instanceId.isEmpty()) {
this.instanceid = instanceId;
} else {
this.instanceid = null;
}
}
public String getSid() {
return accountSid;
}
public List<String> getAccountSidSet() {
return accountSidSet;
}
public String getRecipient() {
return recipient;
}
public String getSender() {
return sender;
}
public String getStartTime() {
return startTime;
}
public String getEndTime() {
return endTime;
}
public String getBody() {
return body;
}
public int getLimit() {
return limit;
}
public int getOffset() {
return offset;
}
public String getInstanceid() {
return instanceid;
}
public String getSmppMessageId() {
return smppMessageId;
}
public static Builder builer() {
return new Builder();
}
public static class Builder {
private final SmsMessageFilter filter;
private Builder() {
this.filter = new SmsMessageFilter();
}
public Builder accountSid(String accountSid) {
this.filter.accountSid = accountSid;
return this;
}
public Builder accountSidSet(List<String> accountSidSet) {
this.filter.accountSidSet = accountSidSet;
return this;
}
public Builder recipient(String recipient) {
if (recipient != null && !recipient.isEmpty()) {
this.filter.recipient = (recipient.startsWith("%") ? "" : "%") + this.filter.recipient;
}
return this;
}
public Builder sender(String sender) {
if (sender != null && !sender.isEmpty()) {
this.filter.sender = (sender.startsWith("%") ? "" : "%") + this.filter.sender;
}
return this;
}
public Builder startTime(Date startTime) {
if (startTime != null) {
this.filter.startTime = DATE_FORMAT.format(startTime);
}
return this;
}
public Builder endTime(Date endTime) {
if (endTime != null) {
this.filter.endTime = DATE_FORMAT.format(endTime);
}
return this;
}
public Builder body(String body) {
this.filter.body = body;
return this;
}
public Builder limit(int limit) {
this.filter.limit = limit;
return this;
}
public Builder offset(int offset) {
this.filter.offset = offset;
return this;
}
public Builder instanceId(String instanceId) {
this.filter.instanceid = instanceId;
return this;
}
public Builder smppMessageId(String smppMessageId) {
this.filter.smppMessageId = smppMessageId;
return this;
}
public SmsMessageFilter build() {
return this.filter;
}
}
}