1 package org.kuali.ole.docstore.discovery.rest;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.docstore.discovery.service.ServiceLocator;
5 import org.kuali.ole.docstore.service.BeanLocator;
6 import org.kuali.ole.docstore.service.IngestNIndexHandlerService;
7 import org.kuali.ole.repository.DocumentStoreManager;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
10
11 import javax.servlet.http.HttpServletRequest;
12 import javax.ws.rs.GET;
13 import javax.ws.rs.Path;
14 import javax.ws.rs.Produces;
15 import javax.ws.rs.core.Context;
16 import javax.ws.rs.core.MediaType;
17 import java.util.List;
18
19
20
21
22
23
24
25
26
27 @Path("/documentTitles")
28 public class DocumentTitleResources {
29
30 private static final Logger LOG = LoggerFactory.getLogger(DocumentTitleResources.class);
31
32
33
34
35
36
37 @GET
38 @Produces({MediaType.TEXT_XML, MediaType.TEXT_PLAIN})
39 public String getTitles(@Context HttpServletRequest request) throws Exception {
40 String fieldValue = request.getParameter("title");
41 LOG.info("title-->" + fieldValue);
42 String xmlResponse = null;
43 if (!StringUtils.isBlank(fieldValue)) {
44 List<String> titleList = ServiceLocator.getQueryService().getTitleValues(fieldValue);
45 xmlResponse = buildResponse(titleList);
46 LOG.debug("xml response-->" + xmlResponse);
47 }
48
49 return xmlResponse;
50 }
51
52
53
54
55
56 private String buildResponse(List<String> titleList) {
57 StringBuffer buffer = new StringBuffer();
58 buffer.append("<titles>\n");
59 for (String title : titleList) {
60 buffer.append("\t<title>" + title + "</title>\n");
61
62 }
63 buffer.append("</titles>\n");
64 return buffer.toString();
65 }
66
67 }