View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.api.document.search;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.joda.time.DateTime;
20  import org.joda.time.DateTimeZone;
21  import org.kuali.rice.core.api.CoreConstants;
22  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
23  import org.kuali.rice.core.api.mo.ModelBuilder;
24  import org.kuali.rice.core.api.mo.ModelObjectUtils;
25  import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
26  import org.kuali.rice.core.api.util.jaxb.MultiValuedStringMapAdapter;
27  import org.kuali.rice.kew.api.document.DocumentStatus;
28  import org.kuali.rice.kew.api.document.DocumentStatusCategory;
29  import org.springframework.util.CollectionUtils;
30  import org.w3c.dom.Element;
31  
32  import javax.xml.bind.annotation.XmlAccessType;
33  import javax.xml.bind.annotation.XmlAccessorType;
34  import javax.xml.bind.annotation.XmlAnyElement;
35  import javax.xml.bind.annotation.XmlElement;
36  import javax.xml.bind.annotation.XmlElementWrapper;
37  import javax.xml.bind.annotation.XmlRootElement;
38  import javax.xml.bind.annotation.XmlType;
39  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
40  import java.io.Serializable;
41  import java.util.ArrayList;
42  import java.util.Collection;
43  import java.util.HashMap;
44  import java.util.List;
45  import java.util.Map;
46  
47  /**
48   * An immutable data transfer object implementation of the {@link DocumentSearchCriteriaContract}.  Instances of this
49   * class should be constructed using the nested {@link Builder} class.
50   *
51   * @author Kuali Rice Team (rice.collab@kuali.org)
52   */
53  @XmlRootElement(name = DocumentSearchCriteria.Constants.ROOT_ELEMENT_NAME)
54  @XmlAccessorType(XmlAccessType.NONE)
55  @XmlType(name = DocumentSearchCriteria.Constants.TYPE_NAME, propOrder = {
56      DocumentSearchCriteria.Elements.DOCUMENT_ID,
57      DocumentSearchCriteria.Elements.DOCUMENT_STATUSES,
58      DocumentSearchCriteria.Elements.DOCUMENT_STATUS_CATEGORIES,
59      DocumentSearchCriteria.Elements.TITLE,
60      DocumentSearchCriteria.Elements.APPLICATION_DOCUMENT_ID,
61      DocumentSearchCriteria.Elements.APPLICATION_DOCUMENT_STATUS,
62      DocumentSearchCriteria.Elements.INITIATOR_PRINCIPAL_NAME,
63      DocumentSearchCriteria.Elements.VIEWER_PRINCIPAL_NAME,
64      DocumentSearchCriteria.Elements.GROUP_VIEWER_ID,
65      DocumentSearchCriteria.Elements.GROUP_VIEWER_NAME,
66      DocumentSearchCriteria.Elements.APPROVER_PRINCIPAL_NAME,
67      DocumentSearchCriteria.Elements.ROUTE_NODE_NAME,
68      DocumentSearchCriteria.Elements.ROUTE_NODE_LOOKUP_LOGIC,
69      DocumentSearchCriteria.Elements.DOCUMENT_TYPE_NAME,
70      DocumentSearchCriteria.Elements.ADDITIONAL_DOCUMENT_TYPE_NAMES,
71      DocumentSearchCriteria.Elements.DATE_CREATED_FROM,
72      DocumentSearchCriteria.Elements.DATE_CREATED_TO,
73      DocumentSearchCriteria.Elements.DATE_LAST_MODIFIED_FROM,
74      DocumentSearchCriteria.Elements.DATE_LAST_MODIFIED_TO,
75      DocumentSearchCriteria.Elements.DATE_APPROVED_FROM,
76      DocumentSearchCriteria.Elements.DATE_APPROVED_TO,
77      DocumentSearchCriteria.Elements.DATE_FINALIZED_FROM,
78      DocumentSearchCriteria.Elements.DATE_FINALIZED_TO,
79      DocumentSearchCriteria.Elements.DATE_APPLICATION_DOCUMENT_STATUS_CHANGED_FROM,
80      DocumentSearchCriteria.Elements.DATE_APPLICATION_DOCUMENT_STATUS_CHANGED_TO,
81      DocumentSearchCriteria.Elements.DOCUMENT_ATTRIBUTE_VALUES,
82      DocumentSearchCriteria.Elements.SAVE_NAME,
83      DocumentSearchCriteria.Elements.START_AT_INDEX,
84      DocumentSearchCriteria.Elements.MAX_RESULTS,
85      DocumentSearchCriteria.Elements.IS_ADVANCED_SEARCH,
86      DocumentSearchCriteria.Elements.SEARCH_OPTIONS,
87      DocumentSearchCriteria.Elements.APPLICATION_DOCUMENT_STATUSES,
88      DocumentSearchCriteria.Elements.DOC_SEARCH_USER_ID,
89      DocumentSearchCriteria.Elements.INITIATOR_PRINCIPAL_ID,
90      DocumentSearchCriteria.Elements.VIEWER_PRINCIPAL_ID,
91      DocumentSearchCriteria.Elements.APPROVER_PRINCIPAL_ID,
92      CoreConstants.CommonElements.FUTURE_ELEMENTS
93  })
94  public final class DocumentSearchCriteria extends AbstractDataTransferObject implements DocumentSearchCriteriaContract {
95  
96      private static final long serialVersionUID = -221440103480740497L;
97      
98      @XmlElement(name = Elements.DOCUMENT_ID, required = false)
99      private final String documentId;
100 
101     @XmlElementWrapper(name = Elements.DOCUMENT_STATUSES, required = false)
102     @XmlElement(name = Elements.DOCUMENT_STATUS, required = false)
103     private final List<DocumentStatus> documentStatuses;
104 
105     @XmlElementWrapper(name = Elements.DOCUMENT_STATUS_CATEGORIES, required = false)
106     @XmlElement(name = Elements.DOCUMENT_STATUS_CATEGORY, required = false)
107     private final List<DocumentStatusCategory> documentStatusCategories;
108 
109     @XmlElement(name = Elements.TITLE, required = false)
110     private final String title;
111 
112     @XmlElement(name = Elements.APPLICATION_DOCUMENT_ID, required = false)
113     private final String applicationDocumentId;
114 
115     @XmlElement(name = Elements.APPLICATION_DOCUMENT_STATUS, required = false)
116     private final String applicationDocumentStatus;
117 
118     @XmlElement(name = Elements.INITIATOR_PRINCIPAL_NAME, required = false)
119     private final String initiatorPrincipalName;
120 
121     @XmlElement(name = Elements.INITIATOR_PRINCIPAL_ID, required = false)
122     private final String initiatorPrincipalId;
123 
124     @XmlElement(name = Elements.VIEWER_PRINCIPAL_NAME, required = false)
125     private final String viewerPrincipalName;
126 
127     @XmlElement(name = Elements.VIEWER_PRINCIPAL_ID, required = false)
128     private final String viewerPrincipalId;
129 
130     @XmlElement(name = Elements.GROUP_VIEWER_ID, required = false)
131     private final String groupViewerId;
132 
133     @XmlElement(name = Elements.GROUP_VIEWER_NAME, required = false)
134     private final String groupViewerName;
135     
136     @XmlElement(name = Elements.APPROVER_PRINCIPAL_NAME, required = false)
137     private final String approverPrincipalName;
138 
139     @XmlElement(name = Elements.APPROVER_PRINCIPAL_ID, required = false)
140     private final String approverPrincipalId;
141 
142     @XmlElement(name = Elements.ROUTE_NODE_NAME, required = false)
143     private final String routeNodeName;
144 
145     @XmlElement(name = Elements.ROUTE_NODE_LOOKUP_LOGIC, required = false)
146     private final RouteNodeLookupLogic routeNodeLookupLogic;
147 
148     @XmlElement(name = Elements.DOCUMENT_TYPE_NAME, required = false)
149     private final String documentTypeName;
150 
151     @XmlElementWrapper(name = Elements.ADDITIONAL_DOCUMENT_TYPE_NAMES, required = false)
152     @XmlElement(name = Elements.ADDITIONAL_DOCUMENT_TYPE_NAME, required = false)
153     private final List<String> additionalDocumentTypeNames;
154 
155     @XmlElement(name = Elements.DATE_CREATED_FROM, required = false)
156     @XmlJavaTypeAdapter(DateTimeAdapter.class)
157     private final DateTime dateCreatedFrom;
158 
159     @XmlElement(name = Elements.DATE_CREATED_TO, required = false)
160     @XmlJavaTypeAdapter(DateTimeAdapter.class)
161     private final DateTime dateCreatedTo;
162 
163     @XmlElement(name = Elements.DATE_LAST_MODIFIED_FROM, required = false)
164     @XmlJavaTypeAdapter(DateTimeAdapter.class)
165     private final DateTime dateLastModifiedFrom;
166 
167     @XmlElement(name = Elements.DATE_LAST_MODIFIED_TO, required = false)
168     @XmlJavaTypeAdapter(DateTimeAdapter.class)
169     private final DateTime dateLastModifiedTo;
170 
171     @XmlElement(name = Elements.DATE_APPROVED_FROM, required = false)
172     @XmlJavaTypeAdapter(DateTimeAdapter.class)
173     private final DateTime dateApprovedFrom;
174 
175     @XmlElement(name = Elements.DATE_APPROVED_TO, required = false)
176     @XmlJavaTypeAdapter(DateTimeAdapter.class)
177     private final DateTime dateApprovedTo;
178 
179     @XmlElement(name = Elements.DATE_FINALIZED_FROM, required = false)
180     @XmlJavaTypeAdapter(DateTimeAdapter.class)
181     private final DateTime dateFinalizedFrom;
182 
183     @XmlElement(name = Elements.DATE_FINALIZED_TO, required = false)
184     @XmlJavaTypeAdapter(DateTimeAdapter.class)
185     private final DateTime dateFinalizedTo;
186 
187     @XmlElement(name = Elements.DATE_APPLICATION_DOCUMENT_STATUS_CHANGED_FROM, required = false)
188     @XmlJavaTypeAdapter(DateTimeAdapter.class)
189     private final DateTime dateApplicationDocumentStatusChangedFrom;
190 
191     @XmlElement(name = Elements.DATE_APPLICATION_DOCUMENT_STATUS_CHANGED_TO, required = false)
192     @XmlJavaTypeAdapter(DateTimeAdapter.class)
193     private final DateTime dateApplicationDocumentStatusChangedTo;
194 
195     @XmlElement(name = Elements.DOCUMENT_ATTRIBUTE_VALUES, required = false)
196     @XmlJavaTypeAdapter(MultiValuedStringMapAdapter.class)
197     private final Map<String, List<String>> documentAttributeValues;
198 
199     @XmlElement(name = Elements.SAVE_NAME, required = false)
200     private final String saveName;
201 
202     @XmlElement(name = Elements.START_AT_INDEX, required = false)
203     private final Integer startAtIndex;
204 
205     @XmlElement(name = Elements.MAX_RESULTS, required = false)
206     private final Integer maxResults;
207 
208     @XmlElement(name = Elements.IS_ADVANCED_SEARCH, required = false)
209     private final String isAdvancedSearch;
210 
211     @XmlElement(name = Elements.SEARCH_OPTIONS, required = false)
212     @XmlJavaTypeAdapter(MultiValuedStringMapAdapter.class)
213     private final Map<String, List<String>> searchOptions;
214 
215     /**
216      * @since 2.1.2
217      */
218     @XmlElement(name = Elements.APPLICATION_DOCUMENT_STATUS, required = false)
219     @XmlElementWrapper(name = Elements.APPLICATION_DOCUMENT_STATUSES, required = false)
220     private final List<String> applicationDocumentStatuses;
221 
222     @XmlElement(name = Elements.DOC_SEARCH_USER_ID, required = false)
223     private final String docSearchUserId;
224 
225     @SuppressWarnings("unused")
226     @XmlAnyElement
227     private final Collection<Element> _futureElements = null;
228 
229     /**
230      * Private constructor used only by JAXB.
231      */
232     private DocumentSearchCriteria() {
233         this.documentId = null;
234         this.documentStatuses = null;
235         this.documentStatusCategories = null;
236         this.title = null;
237         this.applicationDocumentId = null;
238         this.applicationDocumentStatus = null;
239         this.initiatorPrincipalName = null;
240         this.initiatorPrincipalId = null;
241         this.viewerPrincipalName = null;
242         this.viewerPrincipalId = null;
243         this.groupViewerId = null;
244         this.groupViewerName = null;
245         this.approverPrincipalName = null;
246         this.approverPrincipalId = null;
247         this.routeNodeName = null;
248         this.routeNodeLookupLogic = null;
249         this.documentTypeName = null;
250         this.additionalDocumentTypeNames = null;
251         this.dateCreatedFrom = null;
252         this.dateCreatedTo = null;
253         this.dateLastModifiedFrom = null;
254         this.dateLastModifiedTo = null;
255         this.dateApprovedFrom = null;
256         this.dateApprovedTo = null;
257         this.dateFinalizedFrom = null;
258         this.dateFinalizedTo = null;
259         this.dateApplicationDocumentStatusChangedFrom = null;
260         this.dateApplicationDocumentStatusChangedTo = null;
261         this.documentAttributeValues = null;
262         this.searchOptions = null;
263         this.saveName = null;
264         this.startAtIndex = null;
265         this.maxResults = null;
266         this.isAdvancedSearch = null;
267         this.docSearchUserId = null;
268         this.applicationDocumentStatuses = null;
269     }
270 
271     private DocumentSearchCriteria(Builder builder) {
272         this.documentId = builder.getDocumentId();
273         this.documentStatuses = ModelObjectUtils.createImmutableCopy(builder.getDocumentStatuses());
274         this.documentStatusCategories = ModelObjectUtils.createImmutableCopy(builder.getDocumentStatusCategories());
275         this.title = builder.getTitle();
276         this.applicationDocumentId = builder.getApplicationDocumentId();
277         this.applicationDocumentStatus = builder.getApplicationDocumentStatus();
278         this.initiatorPrincipalName = builder.getInitiatorPrincipalName();
279         this.initiatorPrincipalId = builder.getInitiatorPrincipalId();
280         this.viewerPrincipalName = builder.getViewerPrincipalName();
281         this.viewerPrincipalId = builder.getViewerPrincipalId();
282         this.groupViewerId = builder.getGroupViewerId();
283         this.groupViewerName = builder.getGroupViewerName();
284         this.approverPrincipalName = builder.getApproverPrincipalName();
285         this.approverPrincipalId = builder.getApproverPrincipalId();
286         this.routeNodeName = builder.getRouteNodeName();
287         this.routeNodeLookupLogic = builder.getRouteNodeLookupLogic();
288         this.documentTypeName = builder.getDocumentTypeName();
289         this.additionalDocumentTypeNames = ModelObjectUtils.createImmutableCopy(
290                 builder.getAdditionalDocumentTypeNames());
291         this.dateCreatedFrom = builder.getDateCreatedFrom();
292         this.dateCreatedTo = builder.getDateCreatedTo();
293         this.dateLastModifiedFrom = builder.getDateLastModifiedFrom();
294         this.dateLastModifiedTo = builder.getDateLastModifiedTo();
295         this.dateApprovedFrom = builder.getDateApprovedFrom();
296         this.dateApprovedTo = builder.getDateApprovedTo();
297         this.dateFinalizedFrom = builder.getDateFinalizedFrom();
298         this.dateFinalizedTo = builder.getDateFinalizedTo();
299         this.dateApplicationDocumentStatusChangedFrom = builder.getDateApplicationDocumentStatusChangedFrom();
300         this.dateApplicationDocumentStatusChangedTo = builder.getDateApplicationDocumentStatusChangedTo();
301         this.documentAttributeValues = ModelObjectUtils.createImmutableCopy(builder.getDocumentAttributeValues());
302         this.searchOptions = ModelObjectUtils.createImmutableCopy(builder.getSearchOptions());
303         this.saveName = builder.getSaveName();
304         this.startAtIndex = builder.getStartAtIndex();
305         this.maxResults = builder.getMaxResults();
306         this.isAdvancedSearch = builder.getIsAdvancedSearch();
307         this.docSearchUserId = builder.getDocSearchUserId();
308         this.applicationDocumentStatuses = builder.getApplicationDocumentStatuses();
309     }
310 
311     @Override
312     public String getDocumentId() {
313         return this.documentId;
314     }
315 
316     @Override
317     public List<DocumentStatus> getDocumentStatuses() {
318         return this.documentStatuses;
319     }
320 
321     @Override
322     public List<DocumentStatusCategory> getDocumentStatusCategories() {
323         return this.documentStatusCategories;
324     }
325 
326     @Override
327     public String getTitle() {
328         return this.title;
329     }
330 
331     @Override
332     public String getApplicationDocumentId() {
333         return this.applicationDocumentId;
334     }
335 
336     /**
337      * @deprecated use {@link #getApplicationDocumentStatuses()} instead
338      * @return
339      */
340     @Deprecated
341     @Override
342     public String getApplicationDocumentStatus() {
343         return this.applicationDocumentStatus;
344     }
345 
346     /**
347      * @deprecated use {@link #getInitiatorPrincipalId()} instead
348      */
349     @Deprecated
350     @Override
351     public String getInitiatorPrincipalName() {
352         return this.initiatorPrincipalName;
353     }
354 
355     @Override
356     public String getInitiatorPrincipalId() {
357         return this.initiatorPrincipalId;
358     }
359 
360     /**
361      * @deprecated use {@link #getViewerPrincipalId()} instead
362      */
363     @Deprecated
364     @Override
365     public String getViewerPrincipalName() {
366         return this.viewerPrincipalName;
367     }
368 
369     @Override
370     public String getViewerPrincipalId() {
371         return this.viewerPrincipalId;
372     }
373 
374     @Override
375     public String getGroupViewerId() {
376         return this.groupViewerId;
377     }
378     
379     @Override
380     public String getGroupViewerName() {
381         return this.groupViewerName;
382     }
383 
384     /**
385      * @deprecated use {@link #getApproverPrincipalId()} instead
386      */
387     @Deprecated
388     @Override
389     public String getApproverPrincipalName() {
390         return this.approverPrincipalName;
391     }
392 
393     @Override
394     public String getApproverPrincipalId() {
395         return this.approverPrincipalId;
396     }
397 
398     @Override
399     public String getRouteNodeName() {
400         return this.routeNodeName;
401     }
402 
403     @Override
404     public RouteNodeLookupLogic getRouteNodeLookupLogic() {
405         return this.routeNodeLookupLogic;
406     }
407 
408     @Override
409     public String getDocumentTypeName() {
410         return this.documentTypeName;
411     }
412 
413     @Override
414     public List<String> getAdditionalDocumentTypeNames() {
415         return this.additionalDocumentTypeNames;
416     }
417 
418     @Override
419     public DateTime getDateCreatedFrom() {
420         return this.dateCreatedFrom;
421     }
422 
423     @Override
424     public DateTime getDateCreatedTo() {
425         return this.dateCreatedTo;
426     }
427 
428     @Override
429     public DateTime getDateLastModifiedFrom() {
430         return this.dateLastModifiedFrom;
431     }
432 
433     @Override
434     public DateTime getDateLastModifiedTo() {
435         return this.dateLastModifiedTo;
436     }
437 
438     @Override
439     public DateTime getDateApprovedFrom() {
440         return this.dateApprovedFrom;
441     }
442 
443     @Override
444     public DateTime getDateApprovedTo() {
445         return this.dateApprovedTo;
446     }
447 
448     @Override
449     public DateTime getDateFinalizedFrom() {
450         return this.dateFinalizedFrom;
451     }
452 
453     @Override
454     public DateTime getDateFinalizedTo() {
455         return this.dateFinalizedTo;
456     }
457 
458     @Override
459     public DateTime getDateApplicationDocumentStatusChangedFrom() {
460         return dateApplicationDocumentStatusChangedFrom;
461     }
462 
463     @Override
464     public DateTime getDateApplicationDocumentStatusChangedTo() {
465         return dateApplicationDocumentStatusChangedTo;
466     }
467 
468     @Override
469     public Map<String, List<String>> getDocumentAttributeValues() {
470         return this.documentAttributeValues;
471     }
472 
473     @Override
474     public Map<String, List<String>> getSearchOptions() {
475         return this.searchOptions;
476     }
477 
478     @Override
479     public String getSaveName() {
480         return saveName;
481     }
482 
483     @Override
484     public Integer getStartAtIndex() {
485         return this.startAtIndex;
486     }
487 
488     @Override
489     public Integer getMaxResults() {
490         return this.maxResults;
491     }
492 
493     @Override
494     public String getIsAdvancedSearch() {
495         return this.isAdvancedSearch;
496     }
497 
498     /**
499      * @since 2.1.2
500      */
501     @Override
502     public List<String> getApplicationDocumentStatuses() {
503         return applicationDocumentStatuses;
504     }
505 
506     @Override
507     public String getDocSearchUserId(){
508         return docSearchUserId;
509     }
510     /**
511      * A builder which can be used to construct {@link DocumentSearchCriteria} instances.  Enforces the constraints of
512      * the {@link DocumentSearchCriteriaContract}.
513      */
514     public final static class Builder implements Serializable, ModelBuilder, DocumentSearchCriteriaContract {
515 
516         private String documentId;
517         private List<DocumentStatus> documentStatuses;
518         private List<DocumentStatusCategory> documentStatusCategories;
519         private String title;
520         private String applicationDocumentId;
521         private String applicationDocumentStatus;
522         private String initiatorPrincipalName;
523         private String initiatorPrincipalId;
524         private String viewerPrincipalName;
525         private String viewerPrincipalId;
526         private String groupViewerId;
527         private String groupViewerName;
528         private String approverPrincipalName;
529         private String approverPrincipalId;
530         private String routeNodeName;
531         private RouteNodeLookupLogic routeNodeLookupLogic;
532         private String documentTypeName;
533         private List<String> additionalDocumentTypeNames;
534         private DateTime dateCreatedFrom;
535         private DateTime dateCreatedTo;
536         private DateTime dateLastModifiedFrom;
537         private DateTime dateLastModifiedTo;
538         private DateTime dateApprovedFrom;
539         private DateTime dateApprovedTo;
540         private DateTime dateFinalizedFrom;
541         private DateTime dateFinalizedTo;
542         private DateTime dateApplicationDocumentStatusChangedFrom;
543         private DateTime dateApplicationDocumentStatusChangedTo;
544         private Map<String, List<String>> documentAttributeValues;
545         private Map<String, List<String>> searchOptions;
546         private String saveName;
547         private Integer startAtIndex;
548         private Integer maxResults;
549         private String isAdvancedSearch;
550         private String docSearchUserId;
551         private List<String> applicationDocumentStatuses;
552 
553         private Builder() {
554             setDocumentStatuses(new ArrayList<DocumentStatus>());
555             setDocumentStatusCategories(new ArrayList<DocumentStatusCategory>());
556             setAdditionalDocumentTypeNames(new ArrayList<String>());
557             setDocumentAttributeValues(new HashMap<String, List<String>>());
558             setSearchOptions(new HashMap<String, List<String>>());
559             setApplicationDocumentStatuses(new ArrayList<String>());
560         }
561 
562         /**
563          * Creates an empty builder instance.  All collections on the new instance are initialized to empty collections.
564          *
565          * @return a new builder instance
566          */
567         public static Builder create() {
568             return new Builder();
569         }
570 
571         /**
572          * Creates a new builder instance initialized with copies of the properties from the given contract.
573          *
574          * @param contract the contract from which to copy properties
575          *
576          * @return a builder instance initialized with properties from the given contract
577          *
578          * @throws IllegalArgumentException if the given contract is null
579          */
580         public static Builder create(DocumentSearchCriteriaContract contract) {
581             if (contract == null) {
582                 throw new IllegalArgumentException("contract was null");
583             }
584             Builder builder = create();
585             builder.setDocumentId(contract.getDocumentId());
586             if (contract.getDocumentStatuses() != null) {
587                 builder.setDocumentStatuses(new ArrayList<DocumentStatus>(contract.getDocumentStatuses()));
588             }
589             if (contract.getDocumentStatusCategories() != null) {
590                 builder.setDocumentStatusCategories(new ArrayList<DocumentStatusCategory>(contract.getDocumentStatusCategories()));
591             }
592             builder.setTitle(contract.getTitle());
593             builder.setApplicationDocumentId(contract.getApplicationDocumentId());
594             builder.setInitiatorPrincipalName(contract.getInitiatorPrincipalName());
595             builder.setInitiatorPrincipalId(contract.getInitiatorPrincipalId());
596             builder.setViewerPrincipalName(contract.getViewerPrincipalName());
597             builder.setViewerPrincipalId(contract.getViewerPrincipalId());
598             builder.setGroupViewerId(contract.getGroupViewerId());
599             builder.setGroupViewerName(contract.getGroupViewerName());
600             builder.setApproverPrincipalName(contract.getApproverPrincipalName());
601             builder.setApproverPrincipalId(contract.getApproverPrincipalId());
602             builder.setRouteNodeName(contract.getRouteNodeName());
603             builder.setRouteNodeLookupLogic(contract.getRouteNodeLookupLogic());
604             builder.setDocumentTypeName(contract.getDocumentTypeName());
605             if (contract.getAdditionalDocumentTypeNames() != null) {
606                 builder.setAdditionalDocumentTypeNames(new ArrayList<String>(contract.getAdditionalDocumentTypeNames()));
607             }
608             builder.setDateCreatedFrom(contract.getDateCreatedFrom());
609             builder.setDateCreatedTo(contract.getDateCreatedTo());
610             builder.setDateLastModifiedFrom(contract.getDateLastModifiedFrom());
611             builder.setDateLastModifiedTo(contract.getDateLastModifiedTo());
612             builder.setDateApprovedFrom(contract.getDateApprovedFrom());
613             builder.setDateApprovedTo(contract.getDateApprovedTo());
614             builder.setDateFinalizedFrom(contract.getDateFinalizedFrom());
615             builder.setDateFinalizedTo(contract.getDateFinalizedTo());
616             builder.setDateApplicationDocumentStatusChangedFrom(contract.getDateApplicationDocumentStatusChangedFrom());
617             builder.setDateApplicationDocumentStatusChangedTo(contract.getDateApplicationDocumentStatusChangedTo());
618             if (contract.getDocumentAttributeValues() != null) {
619                 builder.setDocumentAttributeValues(new HashMap<String, List<String>>(contract.getDocumentAttributeValues()));
620             }
621             if (contract.getSearchOptions() != null) {
622                 builder.setSearchOptions(new HashMap<String, List<String>>(contract.getSearchOptions()));
623             }
624             builder.setSaveName(contract.getSaveName());
625             builder.setStartAtIndex(contract.getStartAtIndex());
626             builder.setMaxResults(contract.getMaxResults());
627             builder.setIsAdvancedSearch(contract.getIsAdvancedSearch());
628 
629             // Set applicationDocumentStatuses (plural!)
630             builder.setApplicationDocumentStatuses(contract.getApplicationDocumentStatuses());
631             // Set applicationDocumentStatus (singular!)
632             builder.setApplicationDocumentStatus(contract.getApplicationDocumentStatus());
633             builder.setDocSearchUserId(contract.getDocSearchUserId());
634 
635             return builder;
636         }
637 
638         @Override
639         public DocumentSearchCriteria build() {
640             if (StringUtils.isNotBlank(routeNodeName) && StringUtils.isBlank(documentTypeName)) {
641                 throw new IllegalStateException("documentTypeName must be set if routeNodeName is set.");
642             }
643             return new DocumentSearchCriteria(this);
644         }
645 
646         @Override
647         public String getDocumentId() {
648             return this.documentId;
649         }
650 
651         @Override
652         public List<DocumentStatus> getDocumentStatuses() {
653             return this.documentStatuses;
654         }
655 
656         @Override
657         public List<DocumentStatusCategory> getDocumentStatusCategories() {
658             return this.documentStatusCategories;
659         }
660 
661         @Override
662         public String getTitle() {
663             return this.title;
664         }
665 
666         @Override
667         public String getApplicationDocumentId() {
668             return this.applicationDocumentId;
669         }
670 
671         /**
672          * @deprecated use {@link #getApplicationDocumentStatuses()} instead
673          */
674         @Deprecated
675         @Override
676         public String getApplicationDocumentStatus() {
677             return this.applicationDocumentStatus;
678         }
679 
680         /**
681          *  @deprecated use {@link #getInitiatorPrincipalId()} instead
682          */
683         @Deprecated
684         @Override
685         public String getInitiatorPrincipalName() {
686             return this.initiatorPrincipalName;
687         }
688 
689         @Override
690         public String getInitiatorPrincipalId() {
691             return this.initiatorPrincipalId;
692         }
693 
694         /**
695          * @deprecated use {@link #getViewerPrincipalId()} instead
696          */
697         @Deprecated
698         @Override
699         public String getViewerPrincipalName() {
700             return this.viewerPrincipalName;
701         }
702 
703         @Override
704         public String getViewerPrincipalId() {
705             return this.viewerPrincipalId;
706         }
707 
708         @Override
709         public String getGroupViewerId() {
710             return this.groupViewerId;
711         }
712 
713         @Override
714         public String getGroupViewerName() {
715             return this.groupViewerName;
716         }
717 
718         /**
719          * @deprecated use {@link #getApproverPrincipalId()} instead
720          */
721         @Deprecated
722         @Override
723         public String getApproverPrincipalName() {
724             return this.approverPrincipalName;
725         }
726 
727         @Override
728         public String getApproverPrincipalId() {
729             return this.approverPrincipalId;
730         }
731 
732         @Override
733         public String getRouteNodeName() {
734             return this.routeNodeName;
735         }
736 
737         @Override
738         public RouteNodeLookupLogic getRouteNodeLookupLogic() {
739             return this.routeNodeLookupLogic;
740         }
741 
742         @Override
743         public String getDocumentTypeName() {
744             return this.documentTypeName;
745         }
746 
747         @Override
748         public List<String> getAdditionalDocumentTypeNames() {
749             return additionalDocumentTypeNames;
750         }
751 
752         @Override
753         public DateTime getDateCreatedFrom() {
754             return this.dateCreatedFrom;
755         }
756 
757         @Override
758         public DateTime getDateCreatedTo() {
759             return this.dateCreatedTo;
760         }
761 
762         @Override
763         public DateTime getDateLastModifiedFrom() {
764             return this.dateLastModifiedFrom;
765         }
766 
767         @Override
768         public DateTime getDateLastModifiedTo() {
769             return this.dateLastModifiedTo;
770         }
771 
772         @Override
773         public DateTime getDateApprovedFrom() {
774             return this.dateApprovedFrom;
775         }
776 
777         @Override
778         public DateTime getDateApprovedTo() {
779             return this.dateApprovedTo;
780         }
781 
782         @Override
783         public DateTime getDateFinalizedFrom() {
784             return this.dateFinalizedFrom;
785         }
786 
787         @Override
788         public DateTime getDateFinalizedTo() {
789             return this.dateFinalizedTo;
790         }
791 
792         @Override
793         public DateTime getDateApplicationDocumentStatusChangedFrom() {
794             return dateApplicationDocumentStatusChangedFrom;
795         }
796 
797         @Override
798         public DateTime getDateApplicationDocumentStatusChangedTo() {
799             return dateApplicationDocumentStatusChangedTo;
800         }
801 
802         @Override
803         public Map<String, List<String>> getDocumentAttributeValues() {
804             return this.documentAttributeValues;
805         }
806 
807         @Override
808         public Map<String, List<String>> getSearchOptions() {
809             return this.searchOptions;
810         }
811 
812         @Override
813         public String getSaveName() {
814             return this.saveName;
815         }
816 
817         @Override
818         public Integer getStartAtIndex() {
819             return this.startAtIndex;
820         }
821 
822         @Override
823         public Integer getMaxResults() {
824             return this.maxResults;
825         }
826 
827         @Override
828         public String getIsAdvancedSearch() {
829             return this.isAdvancedSearch;
830         }
831 
832         public List<String> getApplicationDocumentStatuses() {
833             return applicationDocumentStatuses;
834         }
835 
836         public String getDocSearchUserId(){
837           return docSearchUserId;
838         }
839 
840         public void setDocumentId(String documentId) {
841             this.documentId = documentId;
842         }
843 
844         public void setDocumentStatuses(List<DocumentStatus> documentStatuses) {
845             this.documentStatuses = documentStatuses;
846         }
847 
848         public void setDocumentStatusCategories(List<DocumentStatusCategory> documentStatusCategories) {
849             this.documentStatusCategories = documentStatusCategories;
850         }
851 
852         public void setTitle(String title) {
853             this.title = title;
854         }
855 
856         public void setApplicationDocumentId(String applicationDocumentId) {
857             this.applicationDocumentId = applicationDocumentId;
858         }
859 
860         /**
861          * @deprecated use {@link #setApplicationDocumentStatuses(java.util.List)} instead
862          */
863         @Deprecated
864         public void setApplicationDocumentStatus(String applicationDocumentStatus) {
865             this.applicationDocumentStatus = applicationDocumentStatus;
866         }
867 
868         /**
869          * @deprecated use {@link #setInitiatorPrincipalId(String)} instead
870          * @param initiatorPrincipalName
871          */
872         public void setInitiatorPrincipalName(String initiatorPrincipalName) {
873             this.initiatorPrincipalName = initiatorPrincipalName;
874         }
875 
876         public void setInitiatorPrincipalId(String initiatorPrincipalId) {
877             this.initiatorPrincipalId = initiatorPrincipalId;
878         }
879 
880         /**
881          * @deprecated use {@link #setViewerPrincipalId(String)} instead
882          * @param viewerPrincipalName
883          */
884         @Deprecated
885         public void setViewerPrincipalName(String viewerPrincipalName) {
886             this.viewerPrincipalName = viewerPrincipalName;
887         }
888 
889         public void setViewerPrincipalId(String viewerPrincipalId) {
890             this.viewerPrincipalId = viewerPrincipalId;
891         }
892 
893         public void setGroupViewerId(String groupViewerId) {
894             this.groupViewerId = groupViewerId;
895         }
896         
897         public void setGroupViewerName (String groupViewerName) {
898             this.groupViewerName = groupViewerName;
899         }
900 
901         /**
902          * @deprecated use {@link #setApproverPrincipalId(String)} instead
903          * @param approverPrincipalName
904          */
905         @Deprecated
906         public void setApproverPrincipalName(String approverPrincipalName) {
907             this.approverPrincipalName = approverPrincipalName;
908         }
909 
910         public void setApproverPrincipalId(String approverPrincipalId) {
911             this.approverPrincipalId = approverPrincipalId;
912         }
913 
914         public void setRouteNodeName(String routeNodeName) {
915             this.routeNodeName = routeNodeName;
916         }
917 
918         public void setRouteNodeLookupLogic(RouteNodeLookupLogic routeNodeLookupLogic) {
919             this.routeNodeLookupLogic = routeNodeLookupLogic;
920         }
921 
922         public void setDocumentTypeName(String documentTypeName) {
923             this.documentTypeName = documentTypeName;
924         }
925 
926         public void setAdditionalDocumentTypeNames(List<String> additionalDocumentTypeNames) {
927             this.additionalDocumentTypeNames = additionalDocumentTypeNames;
928         }
929 
930         public void setDateCreatedFrom(DateTime dateCreatedFrom) {
931             this.dateCreatedFrom = dateCreatedFrom;
932         }
933 
934         public void setDateCreatedTo(DateTime dateCreatedTo) {
935             this.dateCreatedTo = dateCreatedTo;
936         }
937 
938         public void setDateLastModifiedFrom(DateTime dateLastModifiedFrom) {
939             this.dateLastModifiedFrom = dateLastModifiedFrom;
940         }
941 
942         public void setDateLastModifiedTo(DateTime dateLastModifiedTo) {
943             this.dateLastModifiedTo = dateLastModifiedTo;
944         }
945 
946         public void setDateApprovedFrom(DateTime dateApprovedFrom) {
947             this.dateApprovedFrom = dateApprovedFrom;
948         }
949 
950         public void setDateApprovedTo(DateTime dateApprovedTo) {
951             this.dateApprovedTo = dateApprovedTo;
952         }
953 
954         public void setDateFinalizedFrom(DateTime dateFinalizedFrom) {
955             this.dateFinalizedFrom = dateFinalizedFrom;
956         }
957 
958         public void setDateFinalizedTo(DateTime dateFinalizedTo) {
959             this.dateFinalizedTo = dateFinalizedTo;
960         }
961 
962         public void setDateApplicationDocumentStatusChangedFrom(DateTime dateApplicationDocumentStatusChangedFrom) {
963             this.dateApplicationDocumentStatusChangedFrom = dateApplicationDocumentStatusChangedFrom;
964         }
965 
966         public void setDateApplicationDocumentStatusChangedTo(DateTime dateApplicationDocumentStatusChangedTo) {
967             this.dateApplicationDocumentStatusChangedTo = dateApplicationDocumentStatusChangedTo;
968         }
969 
970         public void setDocumentAttributeValues(Map<String, List<String>> documentAttributeValues) {
971             this.documentAttributeValues = documentAttributeValues;
972         }
973 
974         /**
975          * add document attribute value to an internal map
976          * @param name - the attribute name
977          * @param value - the attribute value
978          */
979         public void addDocumentAttributeValue(String name, String value) {
980             if (StringUtils.isBlank(value)) {
981                 throw new IllegalArgumentException("value was null or blank");
982             }
983             List<String> values = getDocumentAttributeValues().get(name);
984             if (values == null) {
985                 values = new ArrayList<String>();
986                 getDocumentAttributeValues().put(name, values);
987             }
988             values.add(value);
989         }
990 
991         public void setSearchOptions(Map<String, List<String>> searchOptions) {
992             this.searchOptions = searchOptions;
993         }
994 
995         public void setSaveName(String saveName) {
996             this.saveName = saveName;
997         }
998 
999         public void setStartAtIndex(Integer startAtIndex) {
1000             this.startAtIndex = startAtIndex;
1001         }
1002 
1003         public void setMaxResults(Integer maxResults) {
1004             this.maxResults = maxResults;
1005         }
1006 
1007         public void setIsAdvancedSearch(String isAdvancedSearch) {
1008             this.isAdvancedSearch = isAdvancedSearch;
1009         }
1010 
1011         /**
1012          * @since 2.1.2
1013          */
1014         public void setApplicationDocumentStatuses(List<String> applicationDocumentStatuses) {
1015             this.applicationDocumentStatuses = applicationDocumentStatuses;
1016         }
1017 
1018         public void setDocSearchUserId(String docSearchUserId){
1019             this.docSearchUserId = docSearchUserId;
1020         }
1021         /**
1022          * Resets DateTimes to local TimeZone (preserving absolute time)
1023          *
1024          * @see <a href="http://jira.codehaus.org/browse/JACKSON-279">Modify Joda DateTime</a>
1025          */
1026         public void normalizeDateTimes() {
1027             if (dateCreatedFrom != null) dateCreatedFrom = dateCreatedFrom.withZone(DateTimeZone.getDefault());
1028             if (dateCreatedTo != null) dateCreatedTo = dateCreatedTo.withZone(DateTimeZone.getDefault());
1029             if (dateLastModifiedFrom != null) dateLastModifiedFrom = dateLastModifiedFrom.withZone(DateTimeZone.getDefault());
1030             if (dateLastModifiedTo != null) dateLastModifiedTo = dateLastModifiedTo.withZone(DateTimeZone.getDefault());
1031             if (dateApprovedFrom != null) dateApprovedFrom = dateApprovedFrom.withZone(DateTimeZone.getDefault());
1032             if (dateApprovedTo != null) dateApprovedTo = dateApprovedTo.withZone(DateTimeZone.getDefault());
1033             if (dateFinalizedFrom != null) dateFinalizedFrom = dateFinalizedFrom.withZone(DateTimeZone.getDefault());
1034             if (dateFinalizedTo != null) dateFinalizedTo = dateFinalizedTo.withZone(DateTimeZone.getDefault());
1035             if (dateApplicationDocumentStatusChangedFrom != null) dateApplicationDocumentStatusChangedFrom = dateApplicationDocumentStatusChangedFrom.withZone(DateTimeZone.getDefault());
1036             if (dateApplicationDocumentStatusChangedTo != null) dateApplicationDocumentStatusChangedTo = dateApplicationDocumentStatusChangedTo.withZone(DateTimeZone.getDefault());
1037         }
1038 
1039     }
1040 
1041     /**
1042      * Defines some internal constants used on this class.
1043      */
1044     static class Constants {
1045         final static String ROOT_ELEMENT_NAME = "documentSearchCriteria";
1046         final static String TYPE_NAME = "DocumentSearchCriteriaType";
1047     }
1048 
1049     /**
1050      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
1051      */
1052     static class Elements {
1053         final static String DOCUMENT_ID = "documentId";
1054         final static String DOCUMENT_STATUSES = "documentStatuses";
1055         final static String DOCUMENT_STATUS = "documentStatus";
1056         final static String DOCUMENT_STATUS_CATEGORIES = "documentStatusCategories";
1057         final static String DOCUMENT_STATUS_CATEGORY = "documentStatusCategory";
1058         final static String TITLE = "title";
1059         final static String APPLICATION_DOCUMENT_ID = "applicationDocumentId";
1060         final static String APPLICATION_DOCUMENT_STATUS = "applicationDocumentStatus";
1061         final static String INITIATOR_PRINCIPAL_NAME = "initiatorPrincipalName";
1062         final static String INITIATOR_PRINCIPAL_ID = "initiatorPrincipalId";
1063         final static String VIEWER_PRINCIPAL_NAME = "viewerPrincipalName";
1064         final static String VIEWER_PRINCIPAL_ID = "viewerPrincipalId";
1065         final static String GROUP_VIEWER_ID = "groupViewerId";
1066         final static String GROUP_VIEWER_NAME = "groupViewerName";
1067         final static String APPROVER_PRINCIPAL_NAME = "approverPrincipalName";
1068         final static String APPROVER_PRINCIPAL_ID = "approverPrincipalId";
1069         final static String ROUTE_NODE_NAME = "routeNodeName";
1070         final static String ROUTE_NODE_LOOKUP_LOGIC = "routeNodeLookupLogic";
1071         final static String DOCUMENT_TYPE_NAME = "documentTypeName";
1072         final static String ADDITIONAL_DOCUMENT_TYPE_NAMES = "additionalDocumentTypeNames";
1073         final static String ADDITIONAL_DOCUMENT_TYPE_NAME = "additionalDocumentTypeName";
1074         final static String DATE_CREATED_FROM = "dateCreatedFrom";
1075         final static String DATE_CREATED_TO = "dateCreatedTo";
1076         final static String DATE_LAST_MODIFIED_FROM = "dateLastModifiedFrom";
1077         final static String DATE_LAST_MODIFIED_TO = "dateLastModifiedTo";
1078         final static String DATE_APPROVED_FROM = "dateApprovedFrom";
1079         final static String DATE_APPROVED_TO = "dateApprovedTo";
1080         final static String DATE_FINALIZED_FROM = "dateFinalizedFrom";
1081         final static String DATE_FINALIZED_TO = "dateFinalizedTo";
1082         final static String DATE_APPLICATION_DOCUMENT_STATUS_CHANGED_FROM = "dateApplicationDocumentStatusChangedFrom";
1083         final static String DATE_APPLICATION_DOCUMENT_STATUS_CHANGED_TO = "dateApplicationDocumentStatusChangedTo";
1084         final static String DOCUMENT_ATTRIBUTE_VALUES = "documentAttributeValues";
1085         final static String SAVE_NAME = "saveName";
1086         final static String START_AT_INDEX = "startAtIndex";
1087         final static String MAX_RESULTS = "maxResults";
1088         final static String IS_ADVANCED_SEARCH = "isAdvancedSearch";
1089         final static String SEARCH_OPTIONS = "searchOptions";
1090         final static String APPLICATION_DOCUMENT_STATUSES = "applicationDocumentStatuses";
1091         final static String DOC_SEARCH_USER_ID = "docSearchUserId";
1092     }
1093 
1094 }