EqxValidateUtil.java
10.6 KB
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
package th.co.ais.ssbsrfc.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.lang.ArrayUtils;
import th.co.ais.ssbsrfc.config.Constant.Parameter;
import th.co.ais.ssbsrfc.config.Constant.ValidateType;
import ec02.utils.AppLog;
public class EqxValidateUtil {
private boolean isMissing = false;
private boolean isInvalid = false;
private boolean isBlank = false;
private String name = "";
public boolean isMissing() {
return isMissing;
}
public void setMissing(boolean isMissing) {
this.isMissing = isMissing;
}
public boolean isInvalid() {
return isInvalid;
}
public void setInvalid(boolean isInvalid) {
this.isInvalid = isInvalid;
}
public boolean isBlank() {
return isBlank;
}
public void setBlank(boolean isBlank) {
this.isBlank = isBlank;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void validate(String paramName, Object paramValue, Parameter paramType, ValidateType type) {
this.name = paramName;
if (paramValue == null) {
this.printMissingLog();
}
}
public void validate(String paramName, Object[] paramValue, Parameter paramType, ValidateType type) {
this.name = paramName;
if (paramValue == null || paramValue.length == 0) {
this.printMissingLog();
}
}
public void validate(String paramName, String paramValue, Parameter paramType, ValidateType type) {
this.validate(paramName, paramValue, paramType, type, -1, -1, null);
}
public void validate(String paramName, String paramValue, Parameter paramType, ValidateType type, String format) {
this.validate(paramName, paramValue, paramType, type, -1, -1, format);
}
public void validate(String paramName, String paramValue, Parameter paramType, ValidateType type, int minLength, int maxLength) {
this.validate(paramName, paramValue, paramType, type, minLength, maxLength, null);
}
public void validate(String paramName, String paramValue, Parameter paramType, ValidateType type, int minLength, int maxLength, String format) {
this.name = paramName;
if (paramType == Parameter.MANDATORY && paramValue == null) {
this.printMissingLog();
} else if (paramValue != null) {
switch (type) {
case STRING:
{
if(maxLength > 0) {
this.checkLength(paramValue, minLength, maxLength);
}
if(format != null) {
this.checkMatch(paramValue, format);
}
break;
}
case NUMBER:
{
String pattern = "[0-9]*";
this.checkMatch(paramValue, pattern);
if(maxLength > 0) {
this.checkLength(paramValue, minLength, maxLength);
}
break;
}
case CURRENCY:
{
if(!paramValue.equals("0") && !paramValue.equals("0.00")) {
String pattern = "[1-9][0-9]*([.][0-9]{2})?";
this.checkMatch(paramValue, pattern);
}
break;
}
case MOBILE:
{
String pattern = "66\\d{9}";
this.checkMatch(paramValue, pattern);
break;
}
case DATETIME:
{
this.checkDateFormat(paramValue, format);
break;
}
case BOOLEAN:
{
String[] arrValidValue = new String[] {"true", "false"};
this.checkContain(paramValue.toLowerCase(), arrValidValue);
break;
}
case BOOLEANUPPERCASE:
{
String[] arrValidValue = new String[] {"TRUE", "FALSE"};
this.checkContain(paramValue, arrValidValue);
break;
}
case FIX:
{
this.checkFix(paramValue, format);
break;
}
// case LANG:
// {
// String[] arrValidValue = new String[] {"eng", "tha"};
// this.checkContain(paramValue.toLowerCase(), arrValidValue);
// break;
// }
// case LANGUPPER:
// {
// String[] arrValidValue = new String[] {"ENG", "THA"};
// this.checkContain(paramValue.toUpperCase(), arrValidValue);
// break;
// }
case YESNO:
{
String[] arrValidValue = new String[] {"yes", "no"};
this.checkContain(paramValue.toLowerCase(), arrValidValue);
break;
}
case DECIMAL:
{
String pattern = "[0-9]+([.][0-9]{2})";
this.checkMatch(paramValue, pattern);
break;
}
// case SUBSCRIPTIONSTATE:
// {
// String[] arrValidValue = new String[] {"active", "suspendFraud", "suspendDebt", "barredLeasing", "creditLimitted", "barredRequest", "terminated", "barredDisconnect", "barredPending", "prep", "test", "freeze", "barredDebtOut", "suspendDebt1way", "creditLimitted1way", "barredDisconnectOver30", "barredCredit", "barredCreditOut", "terminatedOver30", "prepaidSuspend", "prepaidDisable", "pool"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case AEMFCHARACTERISTIC:
// {
// String[] arrValidValue = new String[] {"dynamic", "static"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case AEMFVALUETYPE:
// {
// String[] arrValidValue = new String[] {"numeric", "latitude_longtitude", "text"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case AEMFALERTPOINT:
// {
// String[] arrValidValue = new String[] {"targetDecisionPoint", "referencePoint", "both"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case AMFLOANSTATE:
// {
// String[] arrValidValue = new String[] {"idle", "active", "terminated", "borrowed"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
case URL:
{
this.checkMatch(paramValue, format);
break;
}
case EMAIL:
{
String pattern = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$";
this.checkMatch(paramValue, pattern);
break;
}
// case DS3CUSTOMERCATEGORY:
// {
// String[] arrValidValue = new String[] {"residential", "business", "exclusive", "governmentAndNonProfit", "inHouse"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case DS3CUSTOMERSUBCATEGORY:
// {
// String[] arrValidValue = new String[] {"keyAccount", "sme", "royal", "tot", "government", "stateEnterprise", "embassy", "nonProfit", "ais", "prepaid", "foreigner", "thaiCitizen"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case DS3CUSTOMERSEGMENT:
// {
// String[] arrValidValue = new String[] {"standard", "classic", "gold", "platinum", "platinumPlus", "serenadeCeo", "serenadePrestige"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case AEMFACHIEVE:
// {
// String[] arrValidValue = new String[] {"target", "reference", "expire"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case AEMFSTATUS:
// {
// String[] arrValidValue = new String[] {"terminate", "recall", "prep", "port out", "active"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case AEMFSTATUS2:
// {
// String[] arrValidValue = new String[] {"terminate", "refund", "recall", "prep", "port out"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case ARMEDPARAM:
// {
// String[] arrValidValue = new String[] {"topup", "repay", "lowbalance", "status"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case SDFGUPDATASERVLIFESTYLE:
// {
// String[] arrValidValue = new String[] {"speedy", "business", "decent", "pennyPicker"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case SDFGUPAUTHENLEVEL:
// {
// String[] arrValidValue = new String[] {"no", "password", "token", "bio"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case MOBILESTATUS:
// {
// String[] arrValidValue = new String[] {"SS", "SA", "SD", "T", "SF"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
// case DAAERRORCODE:
// {
// String[] arrValidValue = new String[] {"0", "1000", "1001", "110", "111", "120", "130", "150", "310"};
// this.checkContain(paramValue, arrValidValue);
// break;
// }
case OutbandChannel:
{
String[] arrValidValue = new String[] {"0", "1", "2", "3", "4"};
this.checkContain(paramValue, arrValidValue);
break;
}
case TOROSUBSCRIPTIONIDTYPE:
{
String[] arrValidValue = new String[] {"0", "1", "2", "3", "4"};
this.checkContain(paramValue, arrValidValue);
break;
}
case BEARERTYPE:
{
String[] arrValidValue = new String[] {"0", "1", "2", "3"};
this.checkContain(paramValue, arrValidValue);
break;
}
case REESULTCODE:
{
String[] arrValidValue = new String[] {"2001", "3001", "5003", "5004", "5005", "5006", "5012"};
this.checkContain(paramValue, arrValidValue);
break;
}
case WAITRESULTINDICATOR:
{
String[] arrValidValue = new String[] {"0", "1"};
this.checkContain(paramValue, arrValidValue);
break;
}
case OUTBANDCHANNELOTP:
{
String[] arrValidValue = new String[] {"0", "1"};
this.checkContain(paramValue, arrValidValue);
break;
}
case TOROLANGUAGEPREFERENCE:
{
String[] arrValidValue = new String[] {"1", "2"};
this.checkContain(paramValue, arrValidValue);
break;
}
case INBANDINDICATOR:
{
String[] arrValidValue = new String[] {"0", "1", "2"};
this.checkContain(paramValue, arrValidValue);
break;
}
case NOTCHECKINVALID:
default:
break;
}
}
}
private void checkLength(String value, int min, int max) {
int length = value.length();
if(length < min || length > max) {
this.printInvalidLog("LENGTH", value);
}
}
private void checkDateFormat(String value, String format) {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
try {
Date date = (Date) dateFormat.parse(value);
String strDate = dateFormat.format(date);
if(!value.equals(strDate)) {
this.printInvalidLog("DATE FORMAT", value);
}
}
catch(Exception e){
this.printInvalidLog("DATE FORMAT", value);
}
}
private void checkFix(String value, String fix) {
if(!value.equals(fix)) {
this.printInvalidLog("VALUE", value);
}
}
private void checkMatch(String value, String pattern) {
if(!value.matches(pattern)) {
this.printInvalidLog("FORMAT", value);
}
}
private void checkContain(String value, String[] arrValidValue) {
if(!ArrayUtils.contains(arrValidValue, value)) {
this.printInvalidLog("VALUE", value);
}
}
private void printInvalidLog(String invalidType, String value) {
this.isInvalid = true;
AppLog.d("## INVALID " + invalidType + " : " + this.name + " : " + value);
}
private void printMissingLog() {
this.isMissing = true;
AppLog.d("## MISSING PARAMETER : " + this.name);
}
}