annotate src/main/java/de/mpiwg/gazetteer/rest/GetFullTextSearchHtmlFile.java @ 39:37840afb7b80

new: full text search
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Fri, 04 Dec 2015 14:28:44 +0100
parents
children b8ad346e39a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1 package de.mpiwg.gazetteer.rest;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
2
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
3 import java.io.PrintWriter;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
4
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
5 import javax.servlet.http.HttpServletRequest;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
6 import javax.servlet.http.HttpServletResponse;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
7
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
8 import org.apache.commons.lang.StringUtils;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
9 import org.apache.log4j.Logger;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
10 import org.json.JSONObject;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
11
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
12 import de.mpiwg.gazetteer.bo.LGFile;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
13 import de.mpiwg.gazetteer.bo.LGFullTextSearchFile;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
14 import de.mpiwg.gazetteer.utils.DataProvider;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
15 import de.mpiwg.gazetteer.utils.FileManager;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
16 import de.mpiwg.gazetteer.utils.HTTPUtils;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
17 import de.mpiwg.gazetteer.utils.exceptions.GazetteerException;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
18 import de.mpiwg.web.jsp.FullTextSearchPage;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
19
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
20 public class GetFullTextSearchHtmlFile extends AbstractServletMethod {
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
21 public static String name = "getFullTextSearchHtmlFile";
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
22
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
23 private static Logger logger = Logger.getLogger(GetFullTextSearchHtmlFile.class);
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
24
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
25
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
26 public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
27
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
28 Long fileId = getQueryLongParam(request, "fileId");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
29
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
30 logger.debug("getting full text search html file.");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
31
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
32 // get html file from /gazetteer-server/ftsearch-data/html/...
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
33 if(fileId != null){
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
34
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
35 LGFullTextSearchFile file = DataProvider.getInstance().getFullTextSearchFile(fileId);
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
36 if(file != null){
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
37
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
38 String text = FileManager.getFullTextSearchHtmlFileText(file);
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
39 PrintWriter out = response.getWriter();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
40 out.print(text);
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
41 out.flush();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
42 response.setContentType("text/plain; charset=UTF-8");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
43
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
44 }else{
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
45 response.setContentType("application/json");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
46 JSONObject json = new JSONObject();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
47 json.put("status", "error");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
48 json.put("message", "File no found (" + fileId + ")");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
49 json.put("code", GazetteerException.CODE);
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
50 PrintWriter out = response.getWriter();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
51 out.print(json.toString());
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
52 out.flush();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
53 }
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
54
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
55
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
56
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
57 }else{
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
58 response.setContentType("application/json");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
59 JSONObject json = new JSONObject();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
60 json.put("status", "error");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
61 json.put("message", "Following parameters are mandatory: fileId, userId");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
62 PrintWriter out = response.getWriter();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
63 out.print(json.toString());
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
64 out.flush();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
65 }
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
66
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
67 }
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
68
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
69 }