annotate src/main/java/de/mpiwg/gazetteer/rest/GetFullTextSearchHtmlFile.java @ 58:b8ad346e39a0

new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 02 May 2016 12:03:30 +0200
parents 37840afb7b80
children 824b808a7481
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;
58
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
4 import java.util.ArrayList;
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
5 import java.util.List;
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
6
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
7 import javax.servlet.http.HttpServletRequest;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
8 import javax.servlet.http.HttpServletResponse;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
9
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
10 import org.apache.commons.lang.StringUtils;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
11 import org.apache.log4j.Logger;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
12 import org.json.JSONObject;
58
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
13 import org.jsoup.Jsoup;
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
14 import org.jsoup.nodes.Document;
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
15 import org.jsoup.nodes.Element;
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
16 import org.jsoup.select.Elements;
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
17
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
18 import de.mpiwg.gazetteer.bo.LGFile;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
19 import de.mpiwg.gazetteer.bo.LGFullTextSearchFile;
58
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
20 import de.mpiwg.gazetteer.db.DBContents;
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
21 import de.mpiwg.gazetteer.utils.DataProvider;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
22 import de.mpiwg.gazetteer.utils.FileManager;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
23 import de.mpiwg.gazetteer.utils.HTTPUtils;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
24 import de.mpiwg.gazetteer.utils.exceptions.GazetteerException;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
25 import de.mpiwg.web.jsp.FullTextSearchPage;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
26
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
27 public class GetFullTextSearchHtmlFile extends AbstractServletMethod {
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
28 public static String name = "getFullTextSearchHtmlFile";
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 private static Logger logger = Logger.getLogger(GetFullTextSearchHtmlFile.class);
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
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
33 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
34
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
35 Long fileId = getQueryLongParam(request, "fileId");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
36
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
37 logger.debug("getting full text search html file.");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
38
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
39 // get html file from /gazetteer-server/ftsearch-data/html/...
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
40 if(fileId != null){
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
41
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
42 LGFullTextSearchFile file = DataProvider.getInstance().getFullTextSearchFile(fileId);
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
43 if(file != null){
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
44
58
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
45 String html = FileManager.getFullTextSearchHtmlFileText(file);
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
46
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
47 // parse text so that it doesn't show the field "isRemoved", which has two values, true or false
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
48 html = html.replaceAll("isRemoved", "");
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
49 html = html.replaceAll("true", "");
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
50 html = html.replaceAll("false", "");
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
51
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
52 PrintWriter out = response.getWriter();
58
b8ad346e39a0 new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 39
diff changeset
53 out.print(html);
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
54 out.flush();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
55 response.setContentType("text/plain; charset=UTF-8");
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", "File no found (" + fileId + ")");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
62 json.put("code", GazetteerException.CODE);
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
63 PrintWriter out = response.getWriter();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
64 out.print(json.toString());
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
65 out.flush();
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 }else{
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
70 response.setContentType("application/json");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
71 JSONObject json = new JSONObject();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
72 json.put("status", "error");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
73 json.put("message", "Following parameters are mandatory: fileId, userId");
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
74 PrintWriter out = response.getWriter();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
75 out.print(json.toString());
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
76 out.flush();
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
77 }
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
78
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
79 }
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
80
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
81 }