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