001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.docsearch;
018:
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.HashSet;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Set;
025:
026: import org.apache.commons.lang.StringUtils;
027:
028: import edu.iu.uis.eden.KEWServiceLocator;
029: import edu.iu.uis.eden.engine.node.RouteNode;
030: import edu.iu.uis.eden.util.Utilities;
031:
032: /**
033: * Model bean representing document searches. Persisted each search as part of the users saved searches.
034: *
035: * @author bmcgough
036: * @author rkirkend
037: */
038: public class DocSearchCriteriaVO implements Serializable {
039:
040: private static final long serialVersionUID = -5738747438282249790L;
041: public static final int SEARCH_RESULT_CAP = 500;
042: public static final int SEARCH_RESULT_FETCH_SIZE = 100;
043: public static final int DEFAULT_PAGE_SIZE = 10;
044: private String namedSearch; // if populated the name of the search that they want to save
045: private Integer pageSize; // the number of items to display on a page of results
046: private String routeHeaderId; // id generated by Eden
047: private String docRouteStatus; // route status of the document
048: private String docTitle; // document title provided by the application
049: private String appDocId; // application provided ID - defaults to routeHeaderId
050: private String overrideInd; // flag to indicate overridden business values - set by app
051: private String initiator; // network Id of the person who initiated the document
052: private String viewer; // network Id of the person who is currently viewing the document
053: private String workgroupViewerName; // workgroup Id that has had an action request to the document
054: private String approver; // network Id of the person who is approving the document
055: private String docRouteNodeId; // current level of routing, i.e. which route method is the document currently in
056: private String docRouteNodeLogic; // exactly, before or after
057: private String docVersion; // document version
058: private String docTypeFullName; // the fullname for the document's docType
059:
060: //date range properties
061: private String fromDateCreated; // the begin range for DateCreated
062: private String fromDateLastModified; // the begin range for LastModified
063: private String fromDateApproved; // the begin range for Approved
064: private String fromDateFinalized; // the begin range for Finalized
065: private String toDateCreated; // the end range for created
066: private String toDateLastModified; // the end range for last modified
067: private String toDateApproved; // the end range for approved
068: private String toDateFinalized; // the end range for finalized
069:
070: // searchable attribute properties
071: private List searchableAttributes = new ArrayList();
072:
073: //properties to preserve view from saved and history searches as well as generate results
074: private String isAdvancedSearch;
075: private String super UserSearch = "NO";
076:
077: // used as an "out" parameter to indicate that the rows fetched for this criteria are over the indicated threshold
078: private boolean isOverThreshold = false;
079:
080: public boolean isStandardCriteriaConsideredEmpty(
081: boolean excludeDocumentTypeName) {
082: boolean docTypeNameIsEmpty = Utilities
083: .isEmpty(this .docTypeFullName);
084: boolean standardFieldsAreEmpty = ((Utilities
085: .isEmpty(routeHeaderId))
086: &&
087: /*
088: (Utilities.isEmpty(overrideInd)) &&
089: */
090: (Utilities.isEmpty(initiator))
091: && (Utilities.isEmpty(workgroupViewerName))
092: &&
093: /*
094: (Utilities.isEmpty(docRouteNodeLogic)) &&
095: */
096: (Utilities.isEmpty(docVersion))
097: && (Utilities.isEmpty(fromDateCreated))
098: && (Utilities.isEmpty(toDateCreated))
099: && (Utilities.isEmpty(appDocId))
100: && (Utilities.isEmpty(approver))
101: && (Utilities.isEmpty(docRouteNodeId))
102: && (Utilities.isEmpty(docRouteStatus))
103: && (Utilities.isEmpty(docTitle))
104: && (Utilities.isEmpty(viewer))
105: && (Utilities.isEmpty(fromDateApproved))
106: && (Utilities.isEmpty(toDateApproved))
107: && (Utilities.isEmpty(fromDateFinalized))
108: && (Utilities.isEmpty(toDateFinalized))
109: && (Utilities.isEmpty(fromDateLastModified)) && (Utilities
110: .isEmpty(toDateLastModified)));
111: if (excludeDocumentTypeName) {
112: return standardFieldsAreEmpty;
113: } else {
114: return docTypeNameIsEmpty && standardFieldsAreEmpty;
115: }
116: }
117:
118: public String getDocRouteNodeLogic() {
119: return docRouteNodeLogic;
120: }
121:
122: public void setDocRouteNodeLogic(String docRouteLevelLogic) {
123: this .docRouteNodeLogic = docRouteLevelLogic;
124: }
125:
126: public String getAppDocId() {
127: return appDocId;
128: }
129:
130: public void setAppDocId(String appDocId) {
131: this .appDocId = appDocId;
132: }
133:
134: public String getApprover() {
135: return approver;
136: }
137:
138: public void setApprover(String approver) {
139: this .approver = approver;
140: }
141:
142: public String getDocRouteNodeId() {
143: return docRouteNodeId;
144: }
145:
146: public void setDocRouteNodeId(String docRouteLevel) {
147: this .docRouteNodeId = docRouteLevel;
148: }
149:
150: public String getDocRouteStatus() {
151: return docRouteStatus;
152: }
153:
154: public void setDocRouteStatus(String docRouteStatus) {
155: this .docRouteStatus = docRouteStatus;
156: }
157:
158: public String getDocTitle() {
159: return docTitle;
160: }
161:
162: public void setDocTitle(String docTitle) {
163: this .docTitle = docTitle;
164: }
165:
166: public String getDocTypeFullName() {
167: return docTypeFullName;
168: }
169:
170: public void setDocTypeFullName(String docTypeFullName) {
171: this .docTypeFullName = docTypeFullName;
172: }
173:
174: public String getDocVersion() {
175: return docVersion;
176: }
177:
178: public void setDocVersion(String docVersion) {
179: this .docVersion = docVersion;
180: }
181:
182: public String getInitiator() {
183: return initiator;
184: }
185:
186: public void setInitiator(String initiator) {
187: this .initiator = initiator;
188: }
189:
190: public String getOverrideInd() {
191: return overrideInd;
192: }
193:
194: public void setOverrideInd(String overrideInd) {
195: this .overrideInd = overrideInd;
196: }
197:
198: public String getRouteHeaderId() {
199: return routeHeaderId;
200: }
201:
202: public void setRouteHeaderId(String routeHeaderId) {
203: this .routeHeaderId = routeHeaderId;
204: }
205:
206: public String getViewer() {
207: return viewer;
208: }
209:
210: public void setViewer(String viewer) {
211: this .viewer = viewer;
212: }
213:
214: public Integer getPageSize() {
215: return pageSize;
216: }
217:
218: public void setPageSize(Integer pageSize) {
219: this .pageSize = pageSize;
220: }
221:
222: public String getFromDateApproved() {
223: return fromDateApproved;
224: }
225:
226: public String getFromDateCreated() {
227: return fromDateCreated;
228: }
229:
230: public String getFromDateFinalized() {
231: return fromDateFinalized;
232: }
233:
234: public String getFromDateLastModified() {
235: return fromDateLastModified;
236: }
237:
238: public String getToDateApproved() {
239: return toDateApproved;
240: }
241:
242: public String getToDateCreated() {
243: return toDateCreated;
244: }
245:
246: public String getToDateFinalized() {
247: return toDateFinalized;
248: }
249:
250: public String getToDateLastModified() {
251: return toDateLastModified;
252: }
253:
254: public void setFromDateApproved(String fromDateApproved) {
255: this .fromDateApproved = safeTrimmer(fromDateApproved);
256: }
257:
258: public void setFromDateCreated(String fromDateCreated) {
259: this .fromDateCreated = safeTrimmer(fromDateCreated);
260: }
261:
262: public void setFromDateFinalized(String fromDateFinalized) {
263: this .fromDateFinalized = safeTrimmer(fromDateFinalized);
264: }
265:
266: public void setFromDateLastModified(String fromDateLastModified) {
267: this .fromDateLastModified = safeTrimmer(fromDateLastModified);
268: }
269:
270: public void setToDateApproved(String toDateApproved) {
271: this .toDateApproved = safeTrimmer(toDateApproved);
272: }
273:
274: public void setToDateCreated(String toDateCreated) {
275: this .toDateCreated = safeTrimmer(toDateCreated);
276: }
277:
278: public void setToDateFinalized(String toDateFinalized) {
279: this .toDateFinalized = safeTrimmer(toDateFinalized);
280: }
281:
282: public void setToDateLastModified(String toDateLastModified) {
283: this .toDateLastModified = safeTrimmer(toDateLastModified);
284: }
285:
286: private String safeTrimmer(String value) {
287: if (!Utilities.isEmpty(value)) {
288: return value.trim();
289: }
290: return value;
291: }
292:
293: public String getNamedSearch() {
294: return namedSearch;
295: }
296:
297: public void setNamedSearch(String namedSearch) {
298: this .namedSearch = namedSearch;
299: }
300:
301: public String getDocumentSearchAbbreviatedString() {
302: StringBuffer abbreviatedString = new StringBuffer();
303: String dateApprovedString = getRangeString(this .toDateApproved,
304: this .fromDateApproved);
305: String dateCreatedString = getRangeString(this .toDateCreated,
306: this .fromDateCreated);
307: String dateLastModifiedString = getRangeString(
308: this .toDateLastModified, this .fromDateLastModified);
309: String dateFinalizedString = getRangeString(
310: this .toDateFinalized, this .fromDateFinalized);
311: if (appDocId != null && !"".equals(appDocId.trim())) {
312: abbreviatedString.append("Application Document Id=")
313: .append(appDocId).append("; ");
314: }
315: if (approver != null && !"".equals(approver.trim())) {
316: abbreviatedString.append("Approver Network Id=").append(
317: approver).append("; ");
318: }
319: if (docRouteNodeId != null && !"".equals(docRouteNodeId.trim())) {
320: RouteNode routeNode = KEWServiceLocator
321: .getRouteNodeService().findRouteNodeById(
322: new Long(docRouteNodeId));
323: abbreviatedString.append("Document Route Node=").append(
324: routeNode.getRouteNodeName()).append("; ");
325: }
326: if (docRouteStatus != null && !"".equals(docRouteStatus.trim())) {
327: abbreviatedString.append("Document Route Status=").append(
328: docRouteStatus).append("; ");
329: }
330: if (docTitle != null && !"".equals(docTitle.trim())) {
331: abbreviatedString.append("Document Title=")
332: .append(docTitle).append("; ");
333: }
334: if (docTypeFullName != null
335: && !"".equals(docTypeFullName.trim())) {
336: abbreviatedString.append("Document Type=").append(
337: docTypeFullName).append("; ");
338: }
339: if (initiator != null && !"".equals(initiator.trim())) {
340: abbreviatedString.append("Initiator Network Id=").append(
341: initiator).append("; ");
342: }
343: if (routeHeaderId != null) {
344: abbreviatedString.append("Document Id=").append(
345: routeHeaderId.toString()).append("; ");
346: }
347: if (viewer != null && !"".equals(viewer.trim())) {
348: abbreviatedString.append("Viewer Network Id=").append(
349: viewer).append("; ");
350: }
351: if (workgroupViewerName != null) {
352: abbreviatedString.append("Workgroup Viewer Id=").append(
353: workgroupViewerName).append(";");
354: }
355: if (dateLastModifiedString != null) {
356: abbreviatedString.append("Date Last Modified=").append(
357: dateLastModifiedString).append("; ");
358: }
359: if (dateFinalizedString != null) {
360: abbreviatedString.append("Date Finalized=").append(
361: dateFinalizedString).append("; ");
362: }
363: if (dateCreatedString != null) {
364: abbreviatedString.append("Date Created=").append(
365: dateCreatedString).append("; ");
366: }
367: if (dateApprovedString != null) {
368: abbreviatedString.append("Date Approved=").append(
369: dateApprovedString).append("; ");
370: }
371:
372: Set<String> alreadyAddedRangeAttributes = new HashSet<String>();
373: for (Iterator iter = searchableAttributes.iterator(); iter
374: .hasNext();) {
375: SearchAttributeCriteriaComponent searchAttributeEntry = (SearchAttributeCriteriaComponent) iter
376: .next();
377: if (!Utilities.isEmpty(searchAttributeEntry.getValue())) {
378: // single value entered
379: if (searchAttributeEntry.isRangeSearch()) {
380: // if search attribute criteria component is member of a range we must find it's potential matching partner to build the string
381: if (!alreadyAddedRangeAttributes
382: .contains(searchAttributeEntry
383: .getSavedKey())) {
384: // the key has not been processed yet
385: String lowerSearchAttributeRangeValue = (searchAttributeEntry
386: .getFormKey()
387: .startsWith(SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX)) ? searchAttributeEntry
388: .getValue()
389: : null;
390: String upperSearchAttributeRangeValue = (searchAttributeEntry
391: .getFormKey()
392: .startsWith(SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX)) ? searchAttributeEntry
393: .getValue()
394: : null;
395: // loop through the attributes to find this search attribute criteria components potential match
396: for (Iterator iterator = searchableAttributes
397: .iterator(); iterator.hasNext();) {
398: SearchAttributeCriteriaComponent testSearchCriteria = (SearchAttributeCriteriaComponent) iterator
399: .next();
400: if ((testSearchCriteria.getSavedKey()
401: .equals(searchAttributeEntry
402: .getSavedKey()))
403: && (!(testSearchCriteria
404: .getFormKey()
405: .equals(searchAttributeEntry
406: .getFormKey())))) {
407: // we found the other side of the range
408: if (lowerSearchAttributeRangeValue == null) {
409: lowerSearchAttributeRangeValue = (testSearchCriteria
410: .getFormKey()
411: .startsWith(SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX)) ? testSearchCriteria
412: .getValue()
413: : null;
414: }
415: if (upperSearchAttributeRangeValue == null) {
416: upperSearchAttributeRangeValue = (testSearchCriteria
417: .getFormKey()
418: .startsWith(SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX)) ? testSearchCriteria
419: .getValue()
420: : null;
421: }
422: break;
423: }
424: }
425: // we should have valid values for the 'to' and 'from' range field values by now
426: abbreviatedString
427: .append(
428: searchAttributeEntry
429: .getSavedKey())
430: .append("=")
431: .append(
432: getRangeString(
433: lowerSearchAttributeRangeValue,
434: upperSearchAttributeRangeValue))
435: .append(";");
436: alreadyAddedRangeAttributes
437: .add(searchAttributeEntry.getSavedKey());
438: }
439: } else {
440: abbreviatedString.append(
441: searchAttributeEntry.getSavedKey()).append(
442: "=")
443: .append(searchAttributeEntry.getValue())
444: .append(";");
445: }
446: } else if (!Utilities.isEmpty(searchAttributeEntry
447: .getValues())) {
448: // multiple values entered
449: StringBuffer tempAbbreviatedString = new StringBuffer();
450: tempAbbreviatedString.append(
451: searchAttributeEntry.getSavedKey()).append("=");
452: boolean firstValue = true;
453: for (Iterator iterator = searchAttributeEntry
454: .getValues().iterator(); iterator.hasNext();) {
455: String value = (String) iterator.next();
456: if (StringUtils.isNotBlank(value)) {
457: if (firstValue) {
458: tempAbbreviatedString.append(value);
459: firstValue = false;
460: } else {
461: tempAbbreviatedString.append(" or ")
462: .append(value);
463: }
464: }
465: }
466: String testString = tempAbbreviatedString.toString()
467: .replaceAll("=", "").replaceAll(" or ", "");
468: if (testString.trim().length() > 0) {
469: abbreviatedString.append(tempAbbreviatedString)
470: .append(";");
471: }
472: }
473: }
474:
475: return abbreviatedString.toString();
476: }
477:
478: private String getRangeString(String to, String from) {
479: String dateString = null;
480: if (to != null && !"".equals(to.trim()) && from != null
481: && !"".equals(from.trim())) {
482: dateString = "(" + from + " - " + to + ")";
483: } else {
484: if (to != null && !"".equals(to.trim())) {
485: dateString = "to " + to;
486: } else if (from != null && !"".equals(from.trim())) {
487: dateString = "from " + from;
488: } else {
489: //
490: }
491: }
492: return dateString;
493: }
494:
495: /**
496: * TODO this is here for historic reasons and has been replaced by a managed state in the CriteriaVO... eliminate
497: * @deprecated
498: */
499: public boolean isAdvancedSearch() {
500: return ((appDocId != null && !"".equals(appDocId.trim()))
501: || (approver != null && !"".equals(approver.trim()))
502: || (docRouteNodeId != null && !"".equals(docRouteNodeId
503: .trim()))
504: || (docRouteStatus != null && !"".equals(docRouteStatus
505: .trim()))
506: || (docTitle != null && !"".equals(docTitle.trim()))
507: || (viewer != null && !"".equals(viewer.trim()))
508: || (fromDateApproved != null && !""
509: .equals(fromDateApproved.trim()))
510: || (toDateApproved != null && !"".equals(toDateApproved
511: .trim()))
512: || (toDateFinalized != null && !""
513: .equals(toDateFinalized.trim()))
514: || (fromDateFinalized != null && !""
515: .equals(fromDateFinalized.trim()))
516: || (toDateLastModified != null && !""
517: .equals(toDateLastModified.trim())) || (fromDateLastModified != null && !""
518: .equals(fromDateLastModified.trim())));
519: }
520:
521: public void addSearchableAttribute(
522: SearchAttributeCriteriaComponent searchableAttribute) {
523: searchableAttributes.add(searchableAttribute);
524: }
525:
526: /**
527: * @param searchableAttributes The searchableAttributes to set.
528: */
529: public void setSearchableAttributes(List searchableAttributes) {
530: this .searchableAttributes = searchableAttributes;
531: }
532:
533: /**
534: * @return Returns the searchableAttributes.
535: */
536: public List getSearchableAttributes() {
537: return searchableAttributes;
538: }
539:
540: public String getWorkgroupViewerName() {
541: return workgroupViewerName;
542: }
543:
544: public void setWorkgroupViewerName(String workgroupViewerName) {
545: this .workgroupViewerName = workgroupViewerName;
546: }
547:
548: public String getIsAdvancedSearch() {
549: return isAdvancedSearch;
550: }
551:
552: public void setIsAdvancedSearch(String isAdvancedSearch) {
553: this .isAdvancedSearch = isAdvancedSearch;
554: }
555:
556: public String getSuperUserSearch() {
557: return super UserSearch;
558: }
559:
560: public void setSuperUserSearch(String super UserSearch) {
561: this .super UserSearch = super UserSearch;
562: }
563:
564: public boolean isOverThreshold() {
565: return isOverThreshold;
566: }
567:
568: public void setOverThreshold(boolean isOverThreshold) {
569: this.isOverThreshold = isOverThreshold;
570: }
571: }
|