001package org.kuali.ole.docstore.engine.service.rest;
002
003import org.kuali.ole.docstore.common.exception.DocstoreException;
004import org.kuali.ole.docstore.common.exception.DocstoreExceptionProcessor;
005import org.kuali.ole.docstore.common.search.SearchParams;
006import org.kuali.ole.docstore.common.search.SearchResponse;
007import org.kuali.ole.docstore.common.service.DocstoreService;
008import org.kuali.ole.docstore.service.BeanLocator;
009import org.slf4j.Logger;
010import org.slf4j.LoggerFactory;
011import org.springframework.stereotype.Controller;
012import org.springframework.web.bind.annotation.RequestBody;
013import org.springframework.web.bind.annotation.RequestMapping;
014import org.springframework.web.bind.annotation.RequestMethod;
015import org.springframework.web.bind.annotation.ResponseBody;
016
017import java.util.List;
018
019/**
020 * Created with IntelliJ IDEA.
021 * User: jayabharathreddy
022 * Date: 12/27/13
023 * Time: 12:02 PM
024 * To change this template use File | Settings | File Templates.
025 */
026
027@Controller
028@RequestMapping("/search")
029public class SearchRestController extends AbstractRestService {
030
031    private static final Logger LOG = LoggerFactory.getLogger(SearchRestController.class);
032
033    @Override
034    @RequestMapping(value = "/", method = RequestMethod.POST, consumes = "application/xml", produces = "application/xml")
035    @ResponseBody
036    public String search(@RequestBody String requestBody) {
037        DocstoreService ds = BeanLocator.getDocstoreService();
038        SearchParams searchParams = new SearchParams();
039        searchParams = (SearchParams) searchParams.deserialize(requestBody);
040        SearchResponse searchResponse = null;
041        try {
042            searchResponse = ds.search(searchParams);
043        } catch (DocstoreException e) {
044            LOG.error("SearchRestController Exception : ", e);
045            return DocstoreExceptionProcessor.toXml(e);
046        }
047        return searchResponse.serialize(searchResponse);
048    }
049
050}