1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.docsearch;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.kew.engine.node.RouteNode;
21 import org.kuali.rice.kew.service.KEWServiceLocator;
22 import org.kuali.rice.kew.util.Utilities;
23 import org.kuali.rice.kns.bo.BusinessObject;
24 import org.kuali.rice.kns.bo.BusinessObjectBase;
25 import org.kuali.rice.kns.web.ui.Field;
26 import org.kuali.rice.kns.web.ui.Row;
27
28 import java.util.*;
29
30
31
32
33
34
35
36 public class DocSearchCriteriaDTO extends BusinessObjectBase implements BusinessObject, DocumentRouteHeaderEBO {
37
38 private static final long serialVersionUID = -5738747438282249790L;
39
40 public static final String ADVANCED_SEARCH_INDICATOR_STRING = "YES";
41 public static final String SUPER_USER_SEARCH_INDICATOR_STRING = "YES";
42 public static final int DEFAULT_PAGE_SIZE = 10;
43
44 private String namedSearch;
45 private Integer pageSize;
46 private String routeHeaderId;
47 private String docRouteStatus;
48 private String appDocStatus;
49 private String docTitle;
50 private String appDocId;
51 private String overrideInd;
52 private String initiator;
53 private String viewer;
54 private String workgroupViewerNamespace;
55 private String workgroupViewerName;
56 private String approver;
57 private String docRouteNodeId;
58 private String docRouteNodeLogic;
59 private String docVersion;
60 private String docTypeFullName;
61 private String workgroupViewerId;
62
63
64 private String fromDateCreated;
65 private String fromDateLastModified;
66 private String fromDateApproved;
67 private String fromDateFinalized;
68 private String fromStatusTransitionDate;
69 private String toDateCreated;
70 private String toDateLastModified;
71 private String toDateApproved;
72 private String toDateFinalized;
73 private String toStatusTransitionDate;
74 private java.sql.Timestamp dateCreated;
75
76
77 private List<Row> searchableAttributeRows = new ArrayList<Row>();
78
79
80 private List<SearchAttributeCriteriaComponent> searchableAttributes = new ArrayList<SearchAttributeCriteriaComponent>();
81
82
83 private String isAdvancedSearch;
84 private String superUserSearch = "NO";
85
86
87 private Integer threshold = Integer.valueOf(DocumentSearchGenerator.DEFAULT_SEARCH_RESULT_CAP);
88 private Integer fetchLimit = Integer.valueOf(0);
89
90
91 private boolean isOverThreshold = false;
92
93
94 private int securityFilteredRows = 0;
95
96
97 private boolean overridingUserSession = false;
98 private boolean saveSearchForUser = false;
99
100 private boolean onlyDocTypeFilled = false;
101
102 public DocSearchCriteriaDTO() {
103 super();
104 }
105
106
107
108
109
110
111 public boolean isStandardCriteriaConsideredEmpty(boolean excludeDocumentTypeName) {
112 boolean docTypeNameIsEmpty = Utilities.isEmpty(this.docTypeFullName);
113 boolean standardFieldsAreEmpty = ((Utilities.isEmpty(routeHeaderId)) &&
114
115 (Utilities.isEmpty(initiator)) && (Utilities.isEmpty(workgroupViewerName)) &&
116
117 (Utilities.isEmpty(docVersion)) && (Utilities.isEmpty(fromDateCreated)) && (Utilities.isEmpty(toDateCreated)) && (Utilities.isEmpty(appDocId)) && (Utilities.isEmpty(approver)) && (Utilities.isEmpty(docRouteNodeId)) && (Utilities.isEmpty(docRouteStatus)) && (Utilities.isEmpty(docTitle)) && (Utilities.isEmpty(viewer)) && (Utilities.isEmpty(fromDateApproved)) && (Utilities.isEmpty(toDateApproved)) && (Utilities.isEmpty(fromDateFinalized)) && (Utilities.isEmpty(toDateFinalized)) && (Utilities.isEmpty(fromDateLastModified)) && (Utilities.isEmpty(toDateLastModified)));
118 if (excludeDocumentTypeName) {
119 return standardFieldsAreEmpty;
120 } else {
121 return docTypeNameIsEmpty && standardFieldsAreEmpty;
122 }
123 }
124
125
126
127
128
129
130 public String getDocRouteNodeLogic() {
131 return docRouteNodeLogic;
132 }
133
134 public void setDocRouteNodeLogic(String docRouteLevelLogic) {
135 this.docRouteNodeLogic = docRouteLevelLogic;
136 }
137
138
139
140
141
142
143 public String getAppDocId() {
144 return appDocId;
145 }
146
147 public void setAppDocId(String appDocId) {
148 this.appDocId = appDocId;
149 }
150
151
152
153
154
155
156 public String getApprover() {
157 return approver;
158 }
159
160 public void setApprover(String approver) {
161 this.approver = approver;
162 }
163
164
165
166
167
168
169 public String getDocRouteNodeId() {
170 return docRouteNodeId;
171 }
172
173 public void setDocRouteNodeId(String docRouteLevel) {
174 this.docRouteNodeId = docRouteLevel;
175 }
176
177
178
179
180
181
182 public String getDocRouteStatus() {
183 return docRouteStatus;
184 }
185
186 public void setDocRouteStatus(String docRouteStatus) {
187 this.docRouteStatus = docRouteStatus;
188 }
189
190
191
192
193
194
195 public String getAppDocStatus() {
196 return appDocStatus;
197 }
198
199 public void setAppDocStatus(String appDocStatus) {
200 this.appDocStatus = appDocStatus;
201 }
202
203
204
205
206
207
208 public String getDocTitle() {
209 return docTitle;
210 }
211
212 public void setDocTitle(String docTitle) {
213 this.docTitle = docTitle;
214 }
215
216
217
218
219
220
221 public String getDocTypeFullName() {
222 return docTypeFullName;
223 }
224
225 public void setDocTypeFullName(String docTypeFullName) {
226 this.docTypeFullName = docTypeFullName;
227 }
228
229
230
231
232
233
234 public String getDocVersion() {
235 return docVersion;
236 }
237
238 public void setDocVersion(String docVersion) {
239 this.docVersion = docVersion;
240 }
241
242
243
244
245
246
247 public String getInitiator() {
248 return initiator;
249 }
250
251 public void setInitiator(String initiator) {
252 this.initiator = initiator;
253 }
254
255
256
257
258
259
260 public String getOverrideInd() {
261 return overrideInd;
262 }
263
264 public void setOverrideInd(String overrideInd) {
265 this.overrideInd = overrideInd;
266 }
267
268
269
270
271
272
273 public String getRouteHeaderId() {
274 return routeHeaderId;
275 }
276
277 public void setRouteHeaderId(String routeHeaderId) {
278 this.routeHeaderId = routeHeaderId;
279 }
280
281
282
283
284
285
286 public String getViewer() {
287 return viewer;
288 }
289
290 public void setViewer(String viewer) {
291 this.viewer = viewer;
292 }
293
294
295
296
297
298
299 public Integer getPageSize() {
300 return pageSize;
301 }
302
303 public void setPageSize(Integer pageSize) {
304 this.pageSize = pageSize;
305 }
306
307
308
309
310
311
312 public String getFromDateApproved() {
313 return fromDateApproved;
314 }
315
316
317
318
319
320
321 public String getFromDateCreated() {
322 return fromDateCreated;
323 }
324
325
326
327
328
329
330 public String getFromDateFinalized() {
331 return fromDateFinalized;
332 }
333
334
335
336
337
338
339 public String getFromDateLastModified() {
340 return fromDateLastModified;
341 }
342
343 public String getFromStatusTransitionDate() {
344 return fromStatusTransitionDate;
345 }
346
347
348
349
350
351 public String getToDateApproved() {
352 return toDateApproved;
353 }
354
355
356
357
358
359
360 public String getToDateCreated() {
361 return toDateCreated;
362 }
363
364
365
366
367
368
369 public String getToDateFinalized() {
370 return toDateFinalized;
371 }
372
373
374
375
376
377
378 public String getToDateLastModified() {
379 return toDateLastModified;
380 }
381
382 public String getToStatusTransitionDate() {
383 return toStatusTransitionDate;
384 }
385 public void setFromDateApproved(String fromDateApproved) {
386 this.fromDateApproved = safeTrimmer(fromDateApproved);
387 }
388
389 public void setFromDateCreated(String fromDateCreated) {
390 this.fromDateCreated = safeTrimmer(fromDateCreated);
391 }
392
393 public void setFromDateFinalized(String fromDateFinalized) {
394 this.fromDateFinalized = safeTrimmer(fromDateFinalized);
395 }
396
397 public void setFromDateLastModified(String fromDateLastModified) {
398 this.fromDateLastModified = safeTrimmer(fromDateLastModified);
399 }
400
401 public void setFromStatusTransitionDate(String fromStatusTransitionDate) {
402 this.fromStatusTransitionDate = safeTrimmer(fromStatusTransitionDate);
403 }
404
405 public void setToDateApproved(String toDateApproved) {
406 this.toDateApproved = safeTrimmer(toDateApproved);
407 }
408
409 public void setToDateCreated(String toDateCreated) {
410 this.toDateCreated = safeTrimmer(toDateCreated);
411 }
412
413 public void setToDateFinalized(String toDateFinalized) {
414 this.toDateFinalized = safeTrimmer(toDateFinalized);
415 }
416
417 public void setToDateLastModified(String toDateLastModified) {
418 this.toDateLastModified = safeTrimmer(toDateLastModified);
419 }
420
421 public void setToStatusTransitionDate(String toStatusTransitionDate) {
422 this.toStatusTransitionDate = safeTrimmer(toStatusTransitionDate);
423 }
424
425 private String safeTrimmer(String value) {
426 if (!Utilities.isEmpty(value)) {
427 return value.trim();
428 }
429 return value;
430 }
431
432
433
434
435
436
437 public String getNamedSearch() {
438 return namedSearch;
439 }
440
441 public void setNamedSearch(String namedSearch) {
442 this.namedSearch = namedSearch;
443 }
444
445
446
447
448
449
450 public String getDocumentSearchAbbreviatedString() {
451 StringBuffer abbreviatedString = new StringBuffer();
452 String dateApprovedString = getRangeString(this.toDateApproved, this.fromDateApproved);
453 String dateCreatedString = getRangeString(this.toDateCreated, this.fromDateCreated);
454 String dateLastModifiedString = getRangeString(this.toDateLastModified, this.fromDateLastModified);
455 String dateFinalizedString = getRangeString(this.toDateFinalized, this.fromDateFinalized);
456 String dateStatusTransitionString = getRangeString(this.toStatusTransitionDate, this.fromStatusTransitionDate);
457 if (appDocId != null && !"".equals(appDocId.trim())) {
458 abbreviatedString.append("Application Document Id=").append(appDocId).append("; ");
459 }
460 if (approver != null && !"".equals(approver.trim())) {
461 abbreviatedString.append("Approver=").append(approver).append("; ");
462 }
463 if (docRouteNodeId != null && !"".equals(docRouteNodeId.trim())) {
464 RouteNode routeNode = KEWServiceLocator.getRouteNodeService().findRouteNodeById(new Long(docRouteNodeId));
465 abbreviatedString.append("Document Route Node=").append(routeNode.getRouteNodeName()).append("; ");
466 }
467 if (docRouteStatus != null && !"".equals(docRouteStatus.trim())) {
468 abbreviatedString.append("Document Route Status=").append(docRouteStatus).append("; ");
469 }
470 if (docTitle != null && !"".equals(docTitle.trim())) {
471 abbreviatedString.append("Document Title=").append(docTitle).append("; ");
472 }
473 if (docTypeFullName != null && !"".equals(docTypeFullName.trim())) {
474 abbreviatedString.append("Document Type=").append(docTypeFullName).append("; ");
475 }
476 if (initiator != null && !"".equals(initiator.trim())) {
477 abbreviatedString.append("Initiator=").append(initiator).append("; ");
478 }
479 if (routeHeaderId != null) {
480 abbreviatedString.append("Document Id=").append(routeHeaderId.toString()).append("; ");
481 }
482 if (viewer != null && !"".equals(viewer.trim())) {
483 abbreviatedString.append("Viewer=").append(viewer).append("; ");
484 }
485 if (workgroupViewerName != null) {
486 abbreviatedString.append("Group Viewer=").append(workgroupViewerName).append(";");
487 }
488 if (dateLastModifiedString != null) {
489 abbreviatedString.append("Date Last Modified=").append(dateLastModifiedString).append("; ");
490 }
491 if (dateFinalizedString != null) {
492 abbreviatedString.append("Date Finalized=").append(dateFinalizedString).append("; ");
493 }
494 if (dateCreatedString != null) {
495 abbreviatedString.append("Date Created=").append(dateCreatedString).append("; ");
496 }
497 if (dateApprovedString != null) {
498 abbreviatedString.append("Date Approved=").append(dateApprovedString).append("; ");
499 }
500 if (dateStatusTransitionString != null) {
501 abbreviatedString.append("Date Status Transition=").append(dateStatusTransitionString).append("; ");
502 }
503
504 Set<String> alreadyAddedRangeAttributes = new HashSet<String>();
505 for (SearchAttributeCriteriaComponent searchableAttribute : searchableAttributes)
506 {
507 if (!Utilities.isEmpty(searchableAttribute.getValue()))
508 {
509
510 if (searchableAttribute.isRangeSearch())
511 {
512
513 if (!alreadyAddedRangeAttributes.contains(searchableAttribute.getSavedKey()))
514 {
515
516 String lowerSearchAttributeRangeValue = (searchableAttribute.getFormKey().startsWith(SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX)) ? searchableAttribute.getValue() : null;
517 String upperSearchAttributeRangeValue = (searchableAttribute.getFormKey().startsWith(SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX)) ? searchableAttribute.getValue() : null;
518
519 for (SearchAttributeCriteriaComponent searchableAttribute1 : searchableAttributes)
520 {
521 if ((searchableAttribute1.getSavedKey().equals(searchableAttribute.getSavedKey())) && (!(searchableAttribute1.getFormKey().equals(searchableAttribute.getFormKey()))))
522 {
523
524 if (lowerSearchAttributeRangeValue == null)
525 {
526 lowerSearchAttributeRangeValue = (searchableAttribute1.getFormKey().startsWith(SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX)) ? searchableAttribute1.getValue() : null;
527 }
528 if (upperSearchAttributeRangeValue == null)
529 {
530 upperSearchAttributeRangeValue = (searchableAttribute1.getFormKey().startsWith(SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX)) ? searchableAttribute1.getValue() : null;
531 }
532 break;
533 }
534 }
535
536 abbreviatedString.append(searchableAttribute.getSavedKey()).append("=").append(getRangeString(lowerSearchAttributeRangeValue, upperSearchAttributeRangeValue)).append(";");
537 alreadyAddedRangeAttributes.add(searchableAttribute.getSavedKey());
538 }
539 } else
540 {
541 abbreviatedString.append(searchableAttribute.getSavedKey()).append("=").append(searchableAttribute.getValue()).append(";");
542 }
543 } else if (!Utilities.isEmpty(searchableAttribute.getValues()))
544 {
545
546 StringBuffer tempAbbreviatedString = new StringBuffer();
547 tempAbbreviatedString.append(searchableAttribute.getSavedKey()).append("=");
548 boolean firstValue = true;
549 for (String value : searchableAttribute.getValues())
550 {
551 if (StringUtils.isNotBlank(value))
552 {
553 if (firstValue)
554 {
555 tempAbbreviatedString.append(value);
556 firstValue = false;
557 } else
558 {
559 tempAbbreviatedString.append(" or ").append(value);
560 }
561 }
562 }
563 String testString = tempAbbreviatedString.toString().replaceAll("=", "").replaceAll(" or ", "");
564 if (testString.trim().length() > 0)
565 {
566 abbreviatedString.append(tempAbbreviatedString).append(";");
567 }
568 }
569 }
570
571 return abbreviatedString.toString();
572 }
573
574 private String getRangeString(String to, String from) {
575 String dateString = null;
576 if (to != null && !"".equals(to.trim()) && from != null && !"".equals(from.trim())) {
577 dateString = "(" + from + " - " + to + ")";
578 } else {
579 if (to != null && !"".equals(to.trim())) {
580 dateString = "to " + to;
581 } else if (from != null && !"".equals(from.trim())) {
582 dateString = "from " + from;
583 } else {
584
585 }
586 }
587 return dateString;
588 }
589
590
591
592
593
594 public boolean isAdvancedSearch() {
595 return ((appDocId != null && !"".equals(appDocId.trim())) || (approver != null && !"".equals(approver.trim())) || (docRouteNodeId != null && !"".equals(docRouteNodeId.trim())) || (docRouteStatus != null && !"".equals(docRouteStatus.trim())) || (docTitle != null && !"".equals(docTitle.trim())) || (viewer != null && !"".equals(viewer.trim())) || (fromDateApproved != null && !"".equals(fromDateApproved.trim())) || (toDateApproved != null && !"".equals(toDateApproved.trim())) || (toDateFinalized != null && !"".equals(toDateFinalized.trim())) || (fromDateFinalized != null && !"".equals(fromDateFinalized.trim())) || (toDateLastModified != null && !"".equals(toDateLastModified.trim())) || (fromDateLastModified != null && !"".equals(fromDateLastModified.trim())));
596 }
597
598
599
600
601
602
603 public String getWorkgroupViewerName() {
604 return workgroupViewerName;
605 }
606
607 public void setWorkgroupViewerName(String workgroupViewerName) {
608 this.workgroupViewerName = workgroupViewerName;
609 }
610
611
612
613
614
615
616 public String getIsAdvancedSearch() {
617 return isAdvancedSearch;
618 }
619
620 public void setIsAdvancedSearch(String isAdvancedSearch) {
621 this.isAdvancedSearch = isAdvancedSearch;
622 }
623
624
625
626
627
628
629 public String getSuperUserSearch() {
630 return superUserSearch;
631 }
632
633 public void setSuperUserSearch(String superUserSearch) {
634 this.superUserSearch = superUserSearch;
635 }
636
637
638
639
640
641
642
643 public boolean isOverThreshold() {
644 return isOverThreshold;
645 }
646
647 public void setOverThreshold(boolean isOverThreshold) {
648 this.isOverThreshold = isOverThreshold;
649 }
650
651
652
653
654
655
656 public int getSecurityFilteredRows() {
657 return securityFilteredRows;
658 }
659
660 public void setSecurityFilteredRows(int securityFilteredRows) {
661 this.securityFilteredRows = securityFilteredRows;
662 }
663
664
665
666
667
668
669 public Integer getThreshold() {
670 return this.threshold;
671 }
672
673 public void setThreshold(Integer threshold) {
674 this.threshold = threshold;
675 }
676
677
678
679
680
681
682 public Integer getFetchLimit() {
683 return this.fetchLimit;
684 }
685
686 public void setFetchLimit(Integer fetchLimit) {
687 this.fetchLimit = fetchLimit;
688 }
689
690 public void addSearchableAttribute(SearchAttributeCriteriaComponent searchableAttribute) {
691 searchableAttributes.add(searchableAttribute);
692 }
693
694
695
696
697 public void setSearchableAttributes(List<SearchAttributeCriteriaComponent> searchableAttributes) {
698 this.searchableAttributes = searchableAttributes;
699 }
700
701
702
703
704
705
706 public List<SearchAttributeCriteriaComponent> getSearchableAttributes() {
707 return searchableAttributes;
708 }
709
710 public void setSearchableAttributeRows(List<Row> searchableAttributeRows) {
711 this.searchableAttributeRows = searchableAttributeRows;
712 }
713
714
715
716
717
718
719 public List<Row> getSearchableAttributeRows() {
720 return searchableAttributeRows;
721 }
722
723
724
725
726
727
728 public List<Row> getProcessedSearchableAttributeRows() {
729 return searchableAttributeRows;
730 }
731
732 public void addSearchableAttributeRow(Row row) {
733 searchableAttributeRows.add(row);
734 }
735
736
737
738
739
740
741 public Row getSearchableAttributeRow(int index) {
742 while (getSearchableAttributeRows().size() <= index) {
743 Row row = new Row(new ArrayList<Field>());
744 getSearchableAttributeRows().add(row);
745 }
746 return (Row) getSearchableAttributeRows().get(index);
747 }
748
749 public void setSearchableAttributeRow(int index, Row row) {
750 searchableAttributeRows.set(index, row);
751 }
752
753
754
755
756
757
758 public boolean isOverridingUserSession() {
759 return this.overridingUserSession;
760 }
761
762 public void setOverridingUserSession(boolean overridingUserSession) {
763 this.overridingUserSession = overridingUserSession;
764 }
765
766
767
768
769
770
771 public boolean isSaveSearchForUser() {
772 return this.saveSearchForUser;
773 }
774
775 public void setSaveSearchForUser(boolean saveSearchForUser) {
776 this.saveSearchForUser = saveSearchForUser;
777 }
778
779
780
781
782
783 public String getWorkgroupViewerNamespace() {
784 return this.workgroupViewerNamespace;
785 }
786
787
788
789
790
791 public void setWorkgroupViewerNamespace(String workgroupViewerNamespace) {
792 this.workgroupViewerNamespace = workgroupViewerNamespace;
793 }
794
795
796
797
798
799
800 @Override
801 protected LinkedHashMap toStringMapper() {
802
803 return null;
804 }
805
806
807
808
809
810
811 public void refresh() {
812
813
814 }
815
816
817
818
819
820
821 public java.sql.Timestamp getDateCreated() {
822 return this.dateCreated;
823 }
824
825
826
827
828 public void setDateCreated(java.sql.Timestamp dateCreated) {
829 this.dateCreated = dateCreated;
830 }
831
832
833
834
835 public boolean isOnlyDocTypeFilled() {
836 return this.onlyDocTypeFilled;
837 }
838
839
840
841
842 public void setOnlyDocTypeFilled(boolean onlyDocTypeFilled) {
843 this.onlyDocTypeFilled = onlyDocTypeFilled;
844 }
845
846
847
848
849 public String getWorkgroupViewerId() {
850 return this.workgroupViewerId;
851 }
852
853
854
855
856 public void setWorkgroupViewerId(String workgroupViewerId) {
857 this.workgroupViewerId = workgroupViewerId;
858 }
859
860
861 }