1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.api.document.search;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.kuali.rice.core.api.CoreConstants;
20 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
21 import org.kuali.rice.core.api.mo.ModelBuilder;
22 import org.kuali.rice.core.api.mo.ModelObjectUtils;
23 import org.w3c.dom.Element;
24
25 import javax.xml.bind.annotation.XmlAccessType;
26 import javax.xml.bind.annotation.XmlAccessorType;
27 import javax.xml.bind.annotation.XmlAnyElement;
28 import javax.xml.bind.annotation.XmlElement;
29 import javax.xml.bind.annotation.XmlElementWrapper;
30 import javax.xml.bind.annotation.XmlRootElement;
31 import javax.xml.bind.annotation.XmlType;
32 import java.io.Serializable;
33 import java.util.ArrayList;
34 import java.util.Collection;
35 import java.util.List;
36
37
38
39
40
41
42
43 @XmlRootElement(name = DocumentSearchResults.Constants.ROOT_ELEMENT_NAME)
44 @XmlAccessorType(XmlAccessType.NONE)
45 @XmlType(name = DocumentSearchResults.Constants.TYPE_NAME, propOrder = {
46 DocumentSearchResults.Elements.SEARCH_RESULTS,
47 DocumentSearchResults.Elements.CRITERIA,
48 DocumentSearchResults.Elements.CRITERIA_MODIFIED,
49 DocumentSearchResults.Elements.OVER_THRESHOLD,
50 DocumentSearchResults.Elements.NUMBER_OF_SECURITY_FILTERED_RESULTS,
51 CoreConstants.CommonElements.FUTURE_ELEMENTS
52 })
53 public final class DocumentSearchResults extends AbstractDataTransferObject implements DocumentSearchResultsContract {
54
55 @XmlElementWrapper(name = Elements.SEARCH_RESULTS, required = true)
56 @XmlElement(name = Elements.SEARCH_RESULT, required = false)
57 private final List<DocumentSearchResult> searchResults;
58
59 @XmlElement(name = Elements.CRITERIA, required = true)
60 private final DocumentSearchCriteria criteria;
61
62 @XmlElement(name = Elements.CRITERIA_MODIFIED, required = true)
63 private final boolean criteriaModified;
64
65 @XmlElement(name = Elements.OVER_THRESHOLD, required = true)
66 private final boolean overThreshold;
67
68 @XmlElement(name = Elements.NUMBER_OF_SECURITY_FILTERED_RESULTS, required = true)
69 private final int numberOfSecurityFilteredResults;
70
71 @SuppressWarnings("unused")
72 @XmlAnyElement
73 private final Collection<Element> _futureElements = null;
74
75
76
77
78 @SuppressWarnings("unused")
79 private DocumentSearchResults() {
80 this.searchResults = null;
81 this.criteria = null;
82 this.criteriaModified = false;
83 this.overThreshold = false;
84 this.numberOfSecurityFilteredResults = 0;
85 }
86
87 private DocumentSearchResults(Builder builder) {
88 this.searchResults = ModelObjectUtils.buildImmutableCopy(builder.getSearchResults());
89 this.criteria = builder.getCriteria().build();
90 this.criteriaModified = builder.isCriteriaModified();
91 this.overThreshold = builder.isOverThreshold();
92 this.numberOfSecurityFilteredResults = builder.getNumberOfSecurityFilteredResults();
93 }
94
95 @Override
96 public List<DocumentSearchResult> getSearchResults() {
97 return this.searchResults;
98 }
99
100 @Override
101 public DocumentSearchCriteria getCriteria() {
102 return this.criteria;
103 }
104
105 @Override
106 public boolean isCriteriaModified() {
107 return this.criteriaModified;
108 }
109
110 @Override
111 public boolean isOverThreshold() {
112 return this.overThreshold;
113 }
114
115 @Override
116 public int getNumberOfSecurityFilteredResults() {
117 return this.numberOfSecurityFilteredResults;
118 }
119
120
121
122
123
124 public final static class Builder implements Serializable, ModelBuilder, DocumentSearchResultsContract {
125
126 private List<DocumentSearchResult.Builder> searchResults;
127 private DocumentSearchCriteria.Builder criteria;
128 private boolean criteriaModified;
129 private boolean overThreshold;
130 private int numberOfSecurityFilteredResults;
131
132 private Builder(DocumentSearchCriteria.Builder criteria) {
133 setSearchResults(new ArrayList<DocumentSearchResult.Builder>());
134 setCriteria(criteria);
135 setCriteriaModified(false);
136 setOverThreshold(false);
137 setNumberOfSecurityFilteredResults(0);
138
139 }
140
141
142
143
144
145
146
147
148
149
150
151
152 public static Builder create(DocumentSearchCriteria.Builder criteria) {
153 return new Builder(criteria);
154 }
155
156
157
158
159
160
161
162
163
164
165 public static Builder create(DocumentSearchResultsContract contract) {
166 if (contract == null) {
167 throw new IllegalArgumentException("contract was null");
168 }
169 Builder builder = create(DocumentSearchCriteria.Builder.create(contract.getCriteria()));
170 if (!CollectionUtils.isEmpty(contract.getSearchResults())) {
171 for (DocumentSearchResultContract searchResultContract : contract.getSearchResults()) {
172 builder.getSearchResults().add(DocumentSearchResult.Builder.create(searchResultContract));
173 }
174 }
175 builder.setCriteriaModified(contract.isCriteriaModified());
176 builder.setOverThreshold(contract.isOverThreshold());
177 builder.setNumberOfSecurityFilteredResults(contract.getNumberOfSecurityFilteredResults());
178 return builder;
179 }
180
181 public DocumentSearchResults build() {
182 return new DocumentSearchResults(this);
183 }
184
185 @Override
186 public List<DocumentSearchResult.Builder> getSearchResults() {
187 return this.searchResults;
188 }
189
190 @Override
191 public DocumentSearchCriteria.Builder getCriteria() {
192 return this.criteria;
193 }
194
195 @Override
196 public boolean isCriteriaModified() {
197 return this.criteriaModified;
198 }
199
200 @Override
201 public boolean isOverThreshold() {
202 return this.overThreshold;
203 }
204
205 @Override
206 public int getNumberOfSecurityFilteredResults() {
207 return this.numberOfSecurityFilteredResults;
208 }
209
210 public void setSearchResults(List<DocumentSearchResult.Builder> searchResults) {
211 this.searchResults = searchResults;
212 }
213
214
215
216
217
218
219
220
221 public void setCriteria(DocumentSearchCriteria.Builder criteria) {
222 if (criteria == null) {
223 throw new IllegalArgumentException("criteria was null");
224 }
225 this.criteria = criteria;
226 }
227
228 public void setCriteriaModified(boolean criteriaModified) {
229 this.criteriaModified = criteriaModified;
230 }
231
232 public void setOverThreshold(boolean overThreshold) {
233 this.overThreshold = overThreshold;
234 }
235
236 public void setNumberOfSecurityFilteredResults(int numberOfSecurityFilteredResults) {
237 this.numberOfSecurityFilteredResults = numberOfSecurityFilteredResults;
238 }
239
240 }
241
242
243
244
245 static class Constants {
246 final static String ROOT_ELEMENT_NAME = "documentSearchResults";
247 final static String TYPE_NAME = "DocumentSearchResultsType";
248 }
249
250
251
252
253 static class Elements {
254 final static String SEARCH_RESULTS = "searchResults";
255 final static String SEARCH_RESULT = "searchResult";
256 final static String CRITERIA = "criteria";
257 final static String CRITERIA_MODIFIED = "criteriaModified";
258 final static String OVER_THRESHOLD = "overThreshold";
259 final static String NUMBER_OF_SECURITY_FILTERED_RESULTS = "numberOfSecurityFilteredResults";
260 }
261
262 }