1 package org.kuali.ole.docstore.common.search;
2
3
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.docstore.common.document.content.enums.DocType;
6
7 import java.io.ByteArrayInputStream;
8 import java.io.StringWriter;
9 import java.util.*;
10 import javax.xml.bind.JAXBContext;
11 import javax.xml.bind.JAXBElement;
12 import javax.xml.bind.Marshaller;
13 import javax.xml.bind.Unmarshaller;
14 import javax.xml.bind.annotation.*;
15 import javax.xml.transform.stream.StreamSource;
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 @XmlAccessorType(XmlAccessType.FIELD)
40 @XmlType(name = "searchParams", propOrder = {
41 "pageSize",
42 "searchConditions",
43 "facetConditions",
44 "searchResultFields",
45 "sortConditions",
46 "facetFields",
47 "startIndex",
48 "facetLimit",
49 "facetPrefix",
50 "facetSort",
51 "facetOffset"
52 })
53
54 @XmlRootElement
55 public class SearchParams {
56
57 private static final Logger LOG = Logger.getLogger(SearchParams.class);
58 protected int pageSize = 0;
59 @XmlElementWrapper(name = "facetConditions")
60 @XmlElement(name = "facetCondition")
61 protected List<FacetCondition> facetConditions;
62 @XmlElementWrapper(name = "searchConditions")
63 @XmlElement(name = "searchCondition")
64 protected List<SearchCondition> searchConditions=new ArrayList<SearchCondition>();
65 @XmlElementWrapper(name = "searchResultFields")
66 @XmlElement(name = "searchResultField")
67 protected List<SearchResultField> searchResultFields;
68 @XmlElementWrapper(name = "sortConditions")
69 @XmlElement(name = "sortCondition")
70 protected List<SortCondition> sortConditions;
71 protected TreeSet<String> facetFields;
72 protected int startIndex = 0;
73 protected int facetLimit =0;
74 protected String facetPrefix;
75 protected String facetSort = "count";
76 protected int facetOffset = 0;
77
78 public int getFacetLimit() {
79 return facetLimit;
80 }
81
82 public SearchParams() {
83
84 }
85
86
87
88 public void setFacetLimit(int facetLimit) {
89 this.facetLimit = facetLimit;
90 }
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 public List<FacetCondition> getFacetConditions() {
113 if (facetConditions == null) {
114 facetConditions = new ArrayList<FacetCondition>();
115 }
116 return this.facetConditions;
117 }
118
119
120
121
122 public int getPageSize() {
123 return pageSize;
124 }
125
126
127
128
129 public void setPageSize(int value) {
130 this.pageSize = value;
131 }
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153 public List<SearchCondition> getSearchConditions() {
154 if (searchConditions == null) {
155 searchConditions = new ArrayList<SearchCondition>();
156 }
157 return this.searchConditions;
158 }
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180 public List<SearchResultField> getSearchResultFields() {
181 if (searchResultFields == null) {
182 searchResultFields = new ArrayList<SearchResultField>();
183 }
184 return this.searchResultFields;
185 }
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207 public List<SortCondition> getSortConditions() {
208 if (sortConditions == null) {
209 sortConditions = new ArrayList<SortCondition>();
210 }
211 return this.sortConditions;
212 }
213
214 public TreeSet<String> getFacetFields() {
215 if(facetFields == null) {
216 facetFields = new TreeSet<>();
217 }
218 return facetFields;
219 }
220
221
222
223
224 public int getStartIndex() {
225 return startIndex;
226 }
227
228
229
230
231 public void setStartIndex(int value) {
232 this.startIndex = value;
233 }
234
235 public String getFacetPrefix() {
236 return facetPrefix;
237 }
238
239 public void setFacetPrefix(String facetPrefix) {
240 this.facetPrefix = facetPrefix;
241 }
242
243 public String getFacetSort() {
244 return facetSort;
245 }
246
247 public void setFacetSort(String facetSort) {
248 this.facetSort = facetSort;
249 }
250
251 public int getFacetOffset() {
252 return facetOffset;
253 }
254
255 public void setFacetOffset(int facetOffset) {
256 this.facetOffset = facetOffset;
257 }
258
259 public SearchCondition buildSearchCondition(String searchScope, SearchField searchField, String operator) {
260 SearchCondition searchCondition = new SearchCondition();
261 searchCondition.setSearchScope(searchScope);
262 searchCondition.setSearchField(searchField);
263 searchCondition.setOperator(operator);
264 return searchCondition;
265 }
266
267 public SearchField buildSearchField(String docType, String fieldName, String fieldValue) {
268 SearchField searchField = new SearchField();
269 searchField.setDocType(docType);
270 searchField.setFieldName(fieldName);
271 searchField.setFieldValue(fieldValue);
272 return searchField;
273 }
274
275 public SortCondition buildSortCondition(String sortField, String sortOrder) {
276 SortCondition sortCondition = new SortCondition();
277 sortCondition.setSortOrder(sortOrder);
278 sortCondition.setSortField(sortField);
279 return sortCondition;
280 }
281
282 public SearchResultField buildSearchResultField(String docType, String fieldName) {
283 SearchResultField searchResultField = new SearchResultField();
284 searchResultField.setDocType(docType);
285 searchResultField.setFieldName(fieldName);
286 return searchResultField;
287 }
288
289 public String serialize(Object object) {
290 String result = null;
291 StringWriter sw = new StringWriter();
292 SearchParams searchParams = (SearchParams) object;
293 try {
294 JAXBContext jaxbContext = JAXBContext.newInstance(SearchParams.class);
295 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
296 jaxbMarshaller.marshal(searchParams, sw);
297 result = sw.toString();
298 } catch (Exception e) {
299 LOG.error("Exception ", e);
300 }
301 return result;
302 }
303
304 public Object deserialize(String content) {
305
306 JAXBElement<SearchParams> SearchParamsElement = null;
307 try {
308 JAXBContext jaxbContext = JAXBContext.newInstance(SearchParams.class);
309 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
310 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
311 SearchParamsElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), SearchParams.class);
312 } catch (Exception e) {
313 LOG.error("Exception ", e);
314 }
315 return SearchParamsElement.getValue();
316 }
317
318 public void buildSearchParams(SearchParams searchParams, String docType){
319
320 if(DocType.BIB.getCode().equalsIgnoreCase(docType)){
321 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "LocalId_display"));
322 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Title_sort"));
323 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Title_display"));
324 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "JournalTitle_display"));
325 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Author_display"));
326 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Publisher_display"));
327 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ISBN_display"));
328 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ISSN_display"));
329 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Subject_display"));
330 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Publisher_display"));
331 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "PublicationDate_display"));
332 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Edition_display"));
333 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Format_display"));
334 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Language_display"));
335 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Description_display"));
336 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "FormGenre_display"));
337 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DocFormat"));
338 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "staffOnlyFlag"));
339 } else if(DocType.HOLDINGS.getCode().equalsIgnoreCase(docType)){
340 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "LocalId_display"));
341 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), "Title_sort"));
342 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CallNumber_display"));
343 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CallNumberPrefix_display"));
344 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ClassificationPart_display"));
345 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingOrder_display"));
346 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingOrderCode_display"));
347 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingSchemeCode_display"));
348 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingSchemeValue_display"));
349 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Uri_display"));
350 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ReceiptStatus_display"));
351 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CopyNumber_display"));
352 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Location_display"));
353 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DocFormat"));
354 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "bibIdentifier"));
355 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "itemIdentifier"));
356 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "holdingsIdentifier"));
357 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Location_display"));
358 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "LocationLevelName_display"));
359 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "HoldingsNote_display"));
360 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "staffOnlyFlag"));
361 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "isSeries"));
362 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "isAnalytic"));
363 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "isBoundwith"));
364 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ExtentOfOwnership_Type_display"));
365 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ExtentOfOwnership_Note_Value_display"));
366 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ExtentOfOwnership_Note_Type_display"));
367 } else if(DocType.EHOLDINGS.getCode().equalsIgnoreCase(docType)){
368 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "LocalId_display"));
369 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), "Title_sort"));
370 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "AccessStatus_display"));
371 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Platform_display"));
372 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Imprint_display"));
373 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "StatisticalSearchingFullValue_display"));
374 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "StatisticalSearchingCodeValue_display"));
375 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DocFormat"));
376 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "bibIdentifier"));
377 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "holdingsIdentifier"));
378 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "staffOnlyFlag"));
379 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Location_display"));
380 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "LocationLevelName_display"));
381 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CallNumber_display"));
382 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CallNumberPrefix_display"));
383 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingSchemeCode_display"));
384 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingSchemeValue_display"));
385 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Access_Password_display"));
386 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Access_UserName_display"));
387 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "AccessLocation_display"));
388 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Admin_Password_display"));
389 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Admin_url_display"));
390 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Admin_UserName_display"));
391 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Authentication_display"));
392 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CoverageDate_display"));
393 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DonorCode_display"));
394 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DonorPublic_display"));
395 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DonorNote_display"));
396 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "E_Publisher_display"));
397 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "HoldingsNote_display"));
398 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ILL_display"));
399 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemPart_display"));
400 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Link_Text_display"));
401 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "NumberOfSimultaneousUses_display"));
402 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "PerpetualAccess_display"));
403 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Persist_Link_display"));
404 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Proxied_display"));
405 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ReceiptStatus_display"));
406 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Subscription_display"));
407 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Url_display"));
408 } else if(DocType.ITEM.getCode().equalsIgnoreCase(docType)){
409 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "LocalId_display"));
410 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), "Title_sort"));
411 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Location_display"));
412 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CallNumber_display"));
413 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CallNumberPrefix_display"));
414 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ClassificationPart_display"));
415 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingOrder_display"));
416 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingOrderCode_display"));
417 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingSchemeCode_display"));
418 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingSchemeValue_display"));
419 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DocFormat"));
420 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "bibIdentifier"));
421 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "holdingsIdentifier"));
422 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "id"));
423 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemBarcode_display"));
424 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemStatus_display"));
425 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Location_display"));
426 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemUri_display"));
427 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CopyNumber_display"));
428 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CopyNumberLabel_display"));
429 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "VolumeNumber_display"));
430 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "VolumeNumberLabel_display"));
431 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Enumeration_display"));
432 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Chronology_display"));
433 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "staffOnlyFlag"));
434 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "isAnalytic"));
435 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemTypeCodeValue_display"));
436 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemTypeFullValue_display"));
437
438 }
439 }
440
441 }