View Javadoc
1   package org.kuali.ole.docstore.engine.service.rest;
2   
3   import org.kuali.ole.docstore.common.exception.DocstoreException;
4   import org.kuali.ole.docstore.common.exception.DocstoreExceptionProcessor;
5   import org.kuali.ole.docstore.common.search.BrowseParams;
6   import org.kuali.ole.docstore.common.search.SearchResponse;
7   import org.kuali.ole.docstore.common.service.DocstoreService;
8   import org.kuali.ole.docstore.service.BeanLocator;
9   import org.slf4j.Logger;
10  import org.slf4j.LoggerFactory;
11  import org.springframework.stereotype.Controller;
12  import org.springframework.web.bind.annotation.RequestBody;
13  import org.springframework.web.bind.annotation.RequestMapping;
14  import org.springframework.web.bind.annotation.RequestMethod;
15  import org.springframework.web.bind.annotation.ResponseBody;
16  
17  /**
18   * Created with IntelliJ IDEA.
19   * User: jayabharathreddy
20   * Date: 1/6/14
21   * Time: 2:59 PM
22   * To change this template use File | Settings | File Templates.
23   */
24  @Controller
25  @RequestMapping("/browse")
26  
27  public class BrowseRestController extends AbstractRestService {
28  
29      private static final Logger LOG = LoggerFactory.getLogger(BrowseRestController.class);
30  
31      @Override
32      @RequestMapping(value = "/items", method = RequestMethod.POST, consumes = "application/xml", produces = "application/xml")
33      @ResponseBody
34      public String browseItems(@RequestBody String requestBody) {
35          DocstoreService ds = BeanLocator.getDocstoreService();
36          BrowseParams browseParams = new BrowseParams();
37          browseParams = (BrowseParams) browseParams.deserialize(requestBody);
38          SearchResponse searchResponse = null;
39          try {
40              searchResponse = ds.browseItems(browseParams);
41          } catch (DocstoreException e) {
42              LOG.info("Exception :", e);
43              return DocstoreExceptionProcessor.toXml(e);
44          }
45          return searchResponse.serialize(searchResponse);
46      }
47  
48      @Override
49      @RequestMapping(value = "/holdings", method = RequestMethod.POST, consumes = "application/xml", produces = "application/xml")
50      @ResponseBody
51      public String browseHoldings(@RequestBody String requestBody) {
52          DocstoreService ds = BeanLocator.getDocstoreService();
53          BrowseParams browseParams = new BrowseParams();
54          browseParams = (BrowseParams) browseParams.deserialize(requestBody);
55          SearchResponse searchResponse = null;
56          try {
57              searchResponse = ds.browseHoldings(browseParams);
58          } catch (DocstoreException e) {
59              LOG.info("Exception :", e);
60              return DocstoreExceptionProcessor.toXml(e);
61          }
62          return searchResponse.serialize(searchResponse);
63      }
64  }