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