View Javadoc
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   * <p>Java class for searchParams complex type.
19   * <p/>
20   * <p>The following schema fragment specifies the expected content contained within this class.
21   * <p/>
22   * <pre>
23   * &lt;complexType name="searchParams">
24   *   &lt;complexContent>
25   *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
26   *       &lt;sequence>
27   *         &lt;element name="pageSize" type="{http://www.w3.org/2001/XMLSchema}int"/>
28   *         &lt;element name="searchConditions" type="{}searchCondition" maxOccurs="unbounded" minOccurs="0"/>
29   *         &lt;element name="searchResultFields" type="{}searchResultField" maxOccurs="unbounded" minOccurs="0"/>
30   *         &lt;element name="sortConditions" type="{}sortCondition" maxOccurs="unbounded" minOccurs="0"/>
31   *         &lt;element name="startIndex" type="{http://www.w3.org/2001/XMLSchema}int"/>
32   *       &lt;/sequence>
33   *     &lt;/restriction>
34   *   &lt;/complexContent>
35   * &lt;/complexType>
36   * </pre>
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       * Gets the value of the facetCondtions property.
95       * <p/>
96       * <p/>
97       * This accessor method returns a reference to the live list,
98       * not a snapshot. Therefore any modification you make to the
99       * returned list will be present inside the JAXB object.
100      * This is why there is not a <CODE>set</CODE> method for the facetCondtions property.
101      * <p/>
102      * <p/>
103      * For example, to add a new item, do as follows:
104      * <pre>
105      *    getFacetCondtions().add(newItem);
106      * </pre>
107      * <p/>
108      * <p/>
109      * <p/>
110      * Objects of the following type(s) are allowed in the list
111      * {@link FacetCondition}
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      * Gets the value of the pageSize property.
130      */
131     public int getPageSize() {
132         return pageSize;
133     }
134 
135     /**
136      * Sets the value of the pageSize property.
137      */
138     public void setPageSize(int value) {
139         this.pageSize = value;
140     }
141 
142     /**
143      * Gets the value of the searchConditions property.
144      * <p/>
145      * <p/>
146      * This accessor method returns a reference to the live list,
147      * not a snapshot. Therefore any modification you make to the
148      * returned list will be present inside the JAXB object.
149      * This is why there is not a <CODE>set</CODE> method for the searchConditions property.
150      * <p/>
151      * <p/>
152      * For example, to add a new item, do as follows:
153      * <pre>
154      *    getSearchConditions().add(newItem);
155      * </pre>
156      * <p/>
157      * <p/>
158      * <p/>
159      * Objects of the following type(s) are allowed in the list
160      * {@link SearchCondition }
161      */
162     public List<SearchCondition> getSearchConditions() {
163         if (searchConditions == null) {
164             searchConditions = new ArrayList<SearchCondition>();
165         }
166         return this.searchConditions;
167     }
168 
169     /**
170      * Gets the value of the searchResultFields property.
171      * <p/>
172      * <p/>
173      * This accessor method returns a reference to the live list,
174      * not a snapshot. Therefore any modification you make to the
175      * returned list will be present inside the JAXB object.
176      * This is why there is not a <CODE>set</CODE> method for the searchResultFields property.
177      * <p/>
178      * <p/>
179      * For example, to add a new item, do as follows:
180      * <pre>
181      *    getSearchResultFields().add(newItem);
182      * </pre>
183      * <p/>
184      * <p/>
185      * <p/>
186      * Objects of the following type(s) are allowed in the list
187      * {@link SearchResultField }
188      */
189     public List<SearchResultField> getSearchResultFields() {
190         if (searchResultFields == null) {
191             searchResultFields = new ArrayList<SearchResultField>();
192         }
193         return this.searchResultFields;
194     }
195 
196     /**
197      * Gets the value of the sortConditions property.
198      * <p/>
199      * <p/>
200      * This accessor method returns a reference to the live list,
201      * not a snapshot. Therefore any modification you make to the
202      * returned list will be present inside the JAXB object.
203      * This is why there is not a <CODE>set</CODE> method for the sortConditions property.
204      * <p/>
205      * <p/>
206      * For example, to add a new item, do as follows:
207      * <pre>
208      *    getSortConditions().add(newItem);
209      * </pre>
210      * <p/>
211      * <p/>
212      * <p/>
213      * Objects of the following type(s) are allowed in the list
214      * {@link SortCondition }
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      * Gets the value of the startIndex property.
232      */
233     public int getStartIndex() {
234         return startIndex;
235     }
236 
237     /**
238      * Sets the value of the startIndex property.
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, "Language_display"));
348             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Description_display"));
349             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "FormGenre_display"));
350             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DocFormat"));
351             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "staffOnlyFlag"));
352         } else if(DocType.HOLDINGS.getCode().equalsIgnoreCase(docType)){
353             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "LocalId_display"));
354             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Title_sort"));
355             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Title_display"));
356             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CallNumber_display"));
357             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CallNumberPrefix_display"));
358             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ClassificationPart_display"));
359             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingOrder_display"));
360             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingOrderCode_display"));
361             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingSchemeCode_display"));
362             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingSchemeValue_display"));
363             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Uri_display"));
364             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ReceiptStatus_display"));
365             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CopyNumber_display"));
366             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Location_display"));
367             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DocFormat"));
368             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "bibIdentifier"));
369             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "itemIdentifier"));
370             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "holdingsIdentifier"));
371             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Location_display"));
372             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "LocationLevelName_display"));
373             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "HoldingsNote_display"));
374             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "staffOnlyFlag"));
375             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "isSeries"));
376             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "isAnalytic"));
377             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "isBoundwith"));
378             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ExtentOfOwnership_Type_display"));
379             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ExtentOfOwnership_Note_Value_display"));
380             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ExtentOfOwnership_Note_Type_display"));
381         } else if(DocType.EHOLDINGS.getCode().equalsIgnoreCase(docType)){
382             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "LocalId_display"));
383             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Title_sort"));
384             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Title_display"));
385             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "AccessStatus_display"));
386             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Platform_display"));
387             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Imprint_display"));
388             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "StatisticalSearchingFullValue_display"));
389             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "StatisticalSearchingCodeValue_display"));
390             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DocFormat"));
391             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "bibIdentifier"));
392             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "holdingsIdentifier"));
393             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "staffOnlyFlag"));
394             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Location_display"));
395             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "LocationLevelName_display"));
396             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CallNumber_display"));
397             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CallNumberPrefix_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, "Access_Password_display"));
401             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Access_UserName_display"));
402             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "AccessLocation_display"));
403             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Admin_Password_display"));
404             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Admin_url_display"));
405             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Admin_UserName_display"));
406             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Authentication_display"));
407             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CoverageDate_display"));
408             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DonorCode_display"));
409             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DonorPublic_display"));
410             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DonorNote_display"));
411             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "E_Publisher_display"));
412             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "HoldingsNote_display"));
413             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ILL_display"));
414             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemPart_display"));
415             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Link_Text_display"));
416             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "NumberOfSimultaneousUses_display"));
417             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "PerpetualAccess_display"));
418             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Persist_Link_display"));
419             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Proxied_display"));
420             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ReceiptStatus_display"));
421             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Subscription_display"));
422             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Url_display"));
423         } else if(DocType.ITEM.getCode().equalsIgnoreCase(docType)){
424             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "LocalId_display"));
425             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Title_sort"));
426             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Title_display"));
427             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Location_display"));
428             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CallNumber_display"));
429             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CallNumberPrefix_display"));
430             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ClassificationPart_display"));
431             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingOrder_display"));
432             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingOrderCode_display"));
433             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingSchemeCode_display"));
434             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ShelvingSchemeValue_display"));
435             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DocFormat"));
436             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "bibIdentifier"));
437             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "holdingsIdentifier"));
438             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "id"));
439             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemBarcode_display"));
440             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemStatus_display"));
441             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Location_display"));
442             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemUri_display"));
443             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CopyNumber_display"));
444             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "CopyNumberLabel_display"));
445             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "VolumeNumber_display"));
446             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "VolumeNumberLabel_display"));
447             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Enumeration_display"));
448             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "Chronology_display"));
449             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "staffOnlyFlag"));
450             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "isAnalytic"));
451             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemTypeCodeValue_display"));
452             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemTypeFullValue_display"));
453             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "ItemType_display"));
454             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "dueDateTime"));
455             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(docType, "DonorCode_display"));
456         }
457     }
458 
459 }