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