001package org.kuali.ole.docstore.discovery.rest; 002 003import org.apache.commons.lang.StringUtils; 004import org.kuali.ole.docstore.discovery.service.ServiceLocator; 005import org.kuali.ole.docstore.service.BeanLocator; 006import org.kuali.ole.docstore.service.IngestNIndexHandlerService; 007import org.kuali.ole.repository.DocumentStoreManager; 008import org.slf4j.Logger; 009import org.slf4j.LoggerFactory; 010 011import javax.servlet.http.HttpServletRequest; 012import javax.ws.rs.GET; 013import javax.ws.rs.Path; 014import javax.ws.rs.Produces; 015import javax.ws.rs.core.Context; 016import javax.ws.rs.core.MediaType; 017import java.util.List; 018 019/** 020 * Created with IntelliJ IDEA. 021 * User: Sreekanth 022 * Date: 9/17/12 023 * Time: 5:37 PM 024 * To change this template use File | Settings | File Templates. 025 */ 026 027@Path("/documentTitles") 028public class DocumentTitleResources { 029 030 private static final Logger LOG = LoggerFactory.getLogger(DocumentTitleResources.class); 031 032 /** 033 * @param request 034 * @return 035 * @throws Exception 036 */ 037 @GET 038 @Produces({MediaType.TEXT_XML, MediaType.TEXT_PLAIN}) 039 public String getTitles(@Context HttpServletRequest request) throws Exception { 040 String fieldValue = request.getParameter("title"); 041 LOG.info("title-->" + fieldValue); 042 String xmlResponse = null; 043 if (!StringUtils.isBlank(fieldValue)) { 044 List<String> titleList = ServiceLocator.getQueryService().getTitleValues(fieldValue); 045 xmlResponse = buildResponse(titleList); 046 LOG.debug("xml response-->" + xmlResponse); 047 } 048 049 return xmlResponse; 050 } 051 052 /** 053 * @param titleList 054 * @return 055 */ 056 private String buildResponse(List<String> titleList) { 057 StringBuffer buffer = new StringBuffer(); 058 buffer.append("<titles>\n"); 059 for (String title : titleList) { 060 buffer.append("\t<title>" + title + "</title>\n"); 061 062 } 063 buffer.append("</titles>\n"); 064 return buffer.toString(); 065 } 066 067}