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   
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   * <p>Java class for searchParams complex type.
20   * <p/>
21   * <p>The following schema fragment specifies the expected content contained within this class.
22   * <p/>
23   * <pre>
24   * &lt;complexType name="searchParams">
25   *   &lt;complexContent>
26   *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
27   *       &lt;sequence>
28   *         &lt;element name="pageSize" type="{http://www.w3.org/2001/XMLSchema}int"/>
29   *         &lt;element name="searchConditions" type="{}searchCondition" maxOccurs="unbounded" minOccurs="0"/>
30   *         &lt;element name="searchResultFields" type="{}searchResultField" maxOccurs="unbounded" minOccurs="0"/>
31   *         &lt;element name="sortConditions" type="{}sortCondition" maxOccurs="unbounded" minOccurs="0"/>
32   *         &lt;element name="startIndex" type="{http://www.w3.org/2001/XMLSchema}int"/>
33   *       &lt;/sequence>
34   *     &lt;/restriction>
35   *   &lt;/complexContent>
36   * &lt;/complexType>
37   * </pre>
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       * Gets the value of the facetCondtions property.
96       * <p/>
97       * <p/>
98       * This accessor method returns a reference to the live list,
99       * not a snapshot. Therefore any modification you make to the
100      * returned list will be present inside the JAXB object.
101      * This is why there is not a <CODE>set</CODE> method for the facetCondtions property.
102      * <p/>
103      * <p/>
104      * For example, to add a new item, do as follows:
105      * <pre>
106      *    getFacetCondtions().add(newItem);
107      * </pre>
108      * <p/>
109      * <p/>
110      * <p/>
111      * Objects of the following type(s) are allowed in the list
112      * {@link FacetCondition}
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      * Gets the value of the pageSize property.
131      */
132     public int getPageSize() {
133         return pageSize;
134     }
135 
136     /**
137      * Sets the value of the pageSize property.
138      */
139     public void setPageSize(int value) {
140         this.pageSize = value;
141     }
142 
143     /**
144      * Gets the value of the searchConditions property.
145      * <p/>
146      * <p/>
147      * This accessor method returns a reference to the live list,
148      * not a snapshot. Therefore any modification you make to the
149      * returned list will be present inside the JAXB object.
150      * This is why there is not a <CODE>set</CODE> method for the searchConditions property.
151      * <p/>
152      * <p/>
153      * For example, to add a new item, do as follows:
154      * <pre>
155      *    getSearchConditions().add(newItem);
156      * </pre>
157      * <p/>
158      * <p/>
159      * <p/>
160      * Objects of the following type(s) are allowed in the list
161      * {@link SearchCondition }
162      */
163     public List<SearchCondition> getSearchConditions() {
164         if (searchConditions == null) {
165             searchConditions = new ArrayList<SearchCondition>();
166         }
167         return this.searchConditions;
168     }
169 
170     /**
171      * Gets the value of the searchResultFields property.
172      * <p/>
173      * <p/>
174      * This accessor method returns a reference to the live list,
175      * not a snapshot. Therefore any modification you make to the
176      * returned list will be present inside the JAXB object.
177      * This is why there is not a <CODE>set</CODE> method for the searchResultFields property.
178      * <p/>
179      * <p/>
180      * For example, to add a new item, do as follows:
181      * <pre>
182      *    getSearchResultFields().add(newItem);
183      * </pre>
184      * <p/>
185      * <p/>
186      * <p/>
187      * Objects of the following type(s) are allowed in the list
188      * {@link SearchResultField }
189      */
190     public List<SearchResultField> getSearchResultFields() {
191         if (searchResultFields == null) {
192             searchResultFields = new ArrayList<SearchResultField>();
193         }
194         return this.searchResultFields;
195     }
196 
197     /**
198      * Gets the value of the sortConditions property.
199      * <p/>
200      * <p/>
201      * This accessor method returns a reference to the live list,
202      * not a snapshot. Therefore any modification you make to the
203      * returned list will be present inside the JAXB object.
204      * This is why there is not a <CODE>set</CODE> method for the sortConditions property.
205      * <p/>
206      * <p/>
207      * For example, to add a new item, do as follows:
208      * <pre>
209      *    getSortConditions().add(newItem);
210      * </pre>
211      * <p/>
212      * <p/>
213      * <p/>
214      * Objects of the following type(s) are allowed in the list
215      * {@link SortCondition }
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      * Gets the value of the startIndex property.
233      */
234     public int getStartIndex() {
235         return startIndex;
236     }
237 
238     /**
239      * Sets the value of the startIndex property.
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 }