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 | 0 | @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 | 0 | 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 | 0 | @SuppressWarnings("unused") |
72 | |
@XmlAnyElement |
73 | |
private final Collection<Element> _futureElements = null; |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
@SuppressWarnings("unused") |
79 | 0 | private DocumentSearchResults() { |
80 | 0 | this.searchResults = null; |
81 | 0 | this.criteria = null; |
82 | 0 | this.criteriaModified = false; |
83 | 0 | this.overThreshold = false; |
84 | 0 | this.numberOfSecurityFilteredResults = 0; |
85 | 0 | } |
86 | |
|
87 | 0 | private DocumentSearchResults(Builder builder) { |
88 | 0 | this.searchResults = ModelObjectUtils.buildImmutableCopy(builder.getSearchResults()); |
89 | 0 | this.criteria = builder.getCriteria().build(); |
90 | 0 | this.criteriaModified = builder.isCriteriaModified(); |
91 | 0 | this.overThreshold = builder.isOverThreshold(); |
92 | 0 | this.numberOfSecurityFilteredResults = builder.getNumberOfSecurityFilteredResults(); |
93 | 0 | } |
94 | |
|
95 | |
@Override |
96 | |
public List<DocumentSearchResult> getSearchResults() { |
97 | 0 | return this.searchResults; |
98 | |
} |
99 | |
|
100 | |
@Override |
101 | |
public DocumentSearchCriteria getCriteria() { |
102 | 0 | return this.criteria; |
103 | |
} |
104 | |
|
105 | |
@Override |
106 | |
public boolean isCriteriaModified() { |
107 | 0 | return this.criteriaModified; |
108 | |
} |
109 | |
|
110 | |
@Override |
111 | |
public boolean isOverThreshold() { |
112 | 0 | return this.overThreshold; |
113 | |
} |
114 | |
|
115 | |
@Override |
116 | |
public int getNumberOfSecurityFilteredResults() { |
117 | 0 | return this.numberOfSecurityFilteredResults; |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | 0 | 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 | 0 | private Builder(DocumentSearchCriteria.Builder criteria) { |
133 | 0 | setSearchResults(new ArrayList<DocumentSearchResult.Builder>()); |
134 | 0 | setCriteria(criteria); |
135 | 0 | setCriteriaModified(false); |
136 | 0 | setOverThreshold(false); |
137 | 0 | setNumberOfSecurityFilteredResults(0); |
138 | |
|
139 | 0 | } |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
public static Builder create(DocumentSearchCriteria.Builder criteria) { |
153 | 0 | return new Builder(criteria); |
154 | |
} |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
public static Builder create(DocumentSearchResultsContract contract) { |
166 | 0 | if (contract == null) { |
167 | 0 | throw new IllegalArgumentException("contract was null"); |
168 | |
} |
169 | 0 | Builder builder = create(DocumentSearchCriteria.Builder.create(contract.getCriteria())); |
170 | 0 | if (!CollectionUtils.isEmpty(contract.getSearchResults())) { |
171 | 0 | for (DocumentSearchResultContract searchResultContract : contract.getSearchResults()) { |
172 | 0 | builder.getSearchResults().add(DocumentSearchResult.Builder.create(searchResultContract)); |
173 | |
} |
174 | |
} |
175 | 0 | builder.setCriteriaModified(contract.isCriteriaModified()); |
176 | 0 | builder.setOverThreshold(contract.isOverThreshold()); |
177 | 0 | builder.setNumberOfSecurityFilteredResults(contract.getNumberOfSecurityFilteredResults()); |
178 | 0 | return builder; |
179 | |
} |
180 | |
|
181 | |
public DocumentSearchResults build() { |
182 | 0 | return new DocumentSearchResults(this); |
183 | |
} |
184 | |
|
185 | |
@Override |
186 | |
public List<DocumentSearchResult.Builder> getSearchResults() { |
187 | 0 | return this.searchResults; |
188 | |
} |
189 | |
|
190 | |
@Override |
191 | |
public DocumentSearchCriteria.Builder getCriteria() { |
192 | 0 | return this.criteria; |
193 | |
} |
194 | |
|
195 | |
@Override |
196 | |
public boolean isCriteriaModified() { |
197 | 0 | return this.criteriaModified; |
198 | |
} |
199 | |
|
200 | |
@Override |
201 | |
public boolean isOverThreshold() { |
202 | 0 | return this.overThreshold; |
203 | |
} |
204 | |
|
205 | |
@Override |
206 | |
public int getNumberOfSecurityFilteredResults() { |
207 | 0 | return this.numberOfSecurityFilteredResults; |
208 | |
} |
209 | |
|
210 | |
public void setSearchResults(List<DocumentSearchResult.Builder> searchResults) { |
211 | 0 | this.searchResults = searchResults; |
212 | 0 | } |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
public void setCriteria(DocumentSearchCriteria.Builder criteria) { |
222 | 0 | if (criteria == null) { |
223 | 0 | throw new IllegalArgumentException("criteria was null"); |
224 | |
} |
225 | 0 | this.criteria = criteria; |
226 | 0 | } |
227 | |
|
228 | |
public void setCriteriaModified(boolean criteriaModified) { |
229 | 0 | this.criteriaModified = criteriaModified; |
230 | 0 | } |
231 | |
|
232 | |
public void setOverThreshold(boolean overThreshold) { |
233 | 0 | this.overThreshold = overThreshold; |
234 | 0 | } |
235 | |
|
236 | |
public void setNumberOfSecurityFilteredResults(int numberOfSecurityFilteredResults) { |
237 | 0 | this.numberOfSecurityFilteredResults = numberOfSecurityFilteredResults; |
238 | 0 | } |
239 | |
|
240 | |
} |
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | 0 | static class Constants { |
246 | |
final static String ROOT_ELEMENT_NAME = "documentSearchResults"; |
247 | |
final static String TYPE_NAME = "DocumentSearchResultsType"; |
248 | |
} |
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | 0 | 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 | |
} |