1
2
3
4
5
6
7
8
9
10
11 package psiprobe.model;
12
13 import java.io.Serializable;
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.regex.Pattern;
17 import java.util.regex.PatternSyntaxException;
18
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22
23
24
25 public class SessionSearchInfo implements Serializable {
26
27
28 private static final long serialVersionUID = 1L;
29
30
31 private static final Logger logger = LoggerFactory.getLogger(SessionSearchInfo.class);
32
33
34 public static final String SESS_ATTR_NAME = "sessionSearchInfo";
35
36
37 public static final String ACTION_NONE = "none";
38
39
40 public static final String ACTION_APPLY = "apply";
41
42
43 public static final String ACTION_CLEAR = "clear";
44
45
46 private String searchAction = ACTION_NONE;
47
48
49 private boolean apply;
50
51
52 private boolean clear;
53
54
55 private String sessionId;
56
57
58 private Pattern sessionIdPattern;
59
60
61 private String sessionIdMsg;
62
63
64 private String attrName;
65
66
67 private final List<Pattern> attrNamePatterns = new ArrayList<>();
68
69
70 private final List<String> attrNameMsgs = new ArrayList<>();
71
72
73 private String ageFrom;
74
75
76 private Integer ageFromSec;
77
78
79 private String ageTo;
80
81
82 private Integer ageToSec;
83
84
85 private String idleTimeFrom;
86
87
88 private Integer idleTimeFromSec;
89
90
91 private String idleTimeTo;
92
93
94 private Integer idleTimeToSec;
95
96
97 private String lastIp;
98
99
100 private String infoMessage;
101
102
103 private final List<String> errorMessages = new ArrayList<>();
104
105
106
107
108
109
110 public boolean isEmpty() {
111 return sessionId == null && attrName == null && ageFrom == null && ageTo == null
112 && idleTimeFrom == null && idleTimeTo == null && lastIp == null;
113 }
114
115
116
117
118
119
120 public boolean isSessionIdValid() {
121 return sessionId == null || sessionIdPattern != null;
122 }
123
124
125
126
127
128
129 public boolean isAttrNameValid() {
130 return attrName == null || !attrNamePatterns.isEmpty();
131 }
132
133
134
135
136
137
138 public boolean isAgeFromValid() {
139 return ageFrom == null || ageFromSec != null;
140 }
141
142
143
144
145
146
147 public boolean isAgeToValid() {
148 return ageTo == null || ageToSec != null;
149 }
150
151
152
153
154
155
156 public boolean isIdleTimeFromValid() {
157 return idleTimeFrom == null || idleTimeFromSec != null;
158 }
159
160
161
162
163
164
165 public boolean isIdleTimeToValid() {
166 return idleTimeTo == null || idleTimeToSec != null;
167 }
168
169
170
171
172
173
174 public boolean isValid() {
175 return isSessionIdValid() && isAttrNameValid() && isAgeFromValid() && isAgeToValid()
176 && isIdleTimeFromValid() && isIdleTimeToValid();
177 }
178
179
180
181
182
183
184 public boolean isUseSearch() {
185 return isApply() && !isEmpty() && isValid();
186 }
187
188
189
190
191
192
193 public boolean isUseSessionId() {
194 return sessionIdPattern != null;
195 }
196
197
198
199
200
201
202 public boolean isUseAttrName() {
203 return !attrNamePatterns.isEmpty();
204 }
205
206
207
208
209
210
211 public boolean isUseAttr() {
212 return isUseSearch() && isUseAttrName();
213 }
214
215
216
217
218
219
220 public boolean isUseAgeFrom() {
221 return ageFromSec != null;
222 }
223
224
225
226
227
228
229 public boolean isUseAgeTo() {
230 return ageToSec != null;
231 }
232
233
234
235
236
237
238 public boolean isUseIdleTimeFrom() {
239 return idleTimeFromSec != null;
240 }
241
242
243
244
245
246
247 public boolean isUseIdleTimeTo() {
248 return idleTimeToSec != null;
249 }
250
251
252
253
254
255
256 public boolean isUseLastIp() {
257 return lastIp != null;
258 }
259
260
261
262
263
264
265 public String getSearchAction() {
266 return searchAction;
267 }
268
269
270
271
272
273
274 public void setSearchAction(String searchAction) {
275 this.searchAction = searchAction;
276 if (searchAction == null) {
277 apply = false;
278 clear = false;
279 } else {
280 apply = ACTION_APPLY.equals(searchAction);
281 clear = ACTION_CLEAR.equals(searchAction);
282 }
283 }
284
285
286
287
288
289
290 public boolean isApply() {
291 return apply;
292 }
293
294
295
296
297
298
299 public boolean isClear() {
300 return clear;
301 }
302
303
304
305
306
307
308 public String getSessionId() {
309 return sessionId;
310 }
311
312
313
314
315
316
317 public void setSessionId(String sessionId) {
318 this.sessionId = sessionId;
319 sessionIdPattern = null;
320 sessionIdMsg = null;
321
322 if (sessionId != null) {
323 try {
324 sessionIdPattern = Pattern.compile(sessionId);
325 } catch (PatternSyntaxException e) {
326 logger.trace("", e);
327 sessionIdMsg = e.getDescription();
328 }
329 }
330 }
331
332
333
334
335
336
337 public Pattern getSessionIdPattern() {
338 return sessionIdPattern;
339 }
340
341
342
343
344
345
346 public String getSessionIdMsg() {
347 return sessionIdMsg;
348 }
349
350
351
352
353
354
355 public String getAttrName() {
356 return attrName;
357 }
358
359
360
361
362
363
364 public void setAttrName(String attrName) {
365 this.attrName = attrName;
366 attrNamePatterns.clear();
367 attrNameMsgs.clear();
368
369 if (attrName != null) {
370 String[] attrNames = attrName.split(",", -1);
371 if (attrNames.length == 0 && !attrName.isEmpty()) {
372 attrNameMsgs.add("");
373 } else {
374 for (String regex : attrNames) {
375 try {
376 attrNamePatterns.add(Pattern.compile(regex));
377 } catch (PatternSyntaxException e) {
378 logger.trace("", e);
379 attrNameMsgs.add(e.getDescription());
380 }
381 }
382 }
383 }
384 }
385
386
387
388
389
390
391 public List<Pattern> getAttrNamePatterns() {
392 return new ArrayList<>(attrNamePatterns);
393 }
394
395
396
397
398
399
400 public List<String> getAttrNameMsgs() {
401 return new ArrayList<>(attrNameMsgs);
402 }
403
404
405
406
407
408
409 public String getAgeFrom() {
410 return ageFrom;
411 }
412
413
414
415
416
417
418 public void setAgeFrom(String ageFrom) {
419 this.ageFrom = ageFrom;
420 ageFromSec = null;
421
422 if (ageFrom != null) {
423 try {
424 ageFromSec = Integer.valueOf(ageFrom);
425 } catch (NumberFormatException e) {
426 logger.trace("", e);
427 }
428 }
429 }
430
431
432
433
434
435
436 public Integer getAgeFromSec() {
437 return ageFromSec;
438 }
439
440
441
442
443
444
445 public String getAgeTo() {
446 return ageTo;
447 }
448
449
450
451
452
453
454 public void setAgeTo(String ageTo) {
455 this.ageTo = ageTo;
456 ageToSec = null;
457
458 if (ageTo != null) {
459 try {
460 ageToSec = Integer.valueOf(ageTo);
461 } catch (NumberFormatException e) {
462 logger.trace("", e);
463 }
464 }
465 }
466
467
468
469
470
471
472 public Integer getAgeToSec() {
473 return ageToSec;
474 }
475
476
477
478
479
480
481 public String getIdleTimeFrom() {
482 return idleTimeFrom;
483 }
484
485
486
487
488
489
490 public void setIdleTimeFrom(String idleTimeFrom) {
491 this.idleTimeFrom = idleTimeFrom;
492 idleTimeFromSec = null;
493
494 if (idleTimeFrom != null) {
495 try {
496 idleTimeFromSec = Integer.valueOf(idleTimeFrom);
497 } catch (NumberFormatException e) {
498 logger.trace("", e);
499 }
500 }
501 }
502
503
504
505
506
507
508 public Integer getIdleTimeFromSec() {
509 return idleTimeFromSec;
510 }
511
512
513
514
515
516
517 public String getIdleTimeTo() {
518 return idleTimeTo;
519 }
520
521
522
523
524
525
526 public void setIdleTimeTo(String idleTimeTo) {
527 this.idleTimeTo = idleTimeTo;
528 idleTimeToSec = null;
529
530 if (idleTimeTo != null) {
531 try {
532 idleTimeToSec = Integer.valueOf(idleTimeTo);
533 } catch (NumberFormatException e) {
534 logger.trace("", e);
535 }
536 }
537 }
538
539
540
541
542
543
544 public Integer getIdleTimeToSec() {
545 return idleTimeToSec;
546 }
547
548
549
550
551
552
553 public String getLastIp() {
554 return lastIp;
555 }
556
557
558
559
560
561
562 public void setLastIp(String lastIp) {
563 this.lastIp = lastIp;
564 }
565
566
567
568
569
570
571 public String getInfoMessage() {
572 return infoMessage;
573 }
574
575
576
577
578
579
580 public void setInfoMessage(String infoMessage) {
581 this.infoMessage = infoMessage;
582 }
583
584
585
586
587
588
589 public List<String> getErrorMessages() {
590 return new ArrayList<>(errorMessages);
591 }
592
593
594
595
596
597
598 public void addErrorMessage(String msg) {
599 errorMessages.add(msg);
600 }
601
602 }