comparison src/main/java/de/mpiwg/gazetteer/rest/GetSectionText.java @ 81:881461e4f37d

more specific warning message for section without contents
author Calvin Yeh <cyeh@mpiwg-berlin.mpg.de>
date Thu, 04 May 2017 14:45:32 +0200
parents 3e62083dbcbf
children
comparison
equal deleted inserted replaced
80:7f10544e27dd 81:881461e4f37d
11 import de.mpiwg.gazetteer.utils.DBService; 11 import de.mpiwg.gazetteer.utils.DBService;
12 12
13 public class GetSectionText extends AbstractServletMethod { 13 public class GetSectionText extends AbstractServletMethod {
14 14
15 public static String name = "getSectionText"; 15 public static String name = "getSectionText";
16 16
17 public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ 17 public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{
18 18
19 Long sectionId = getQueryLongParam(request, "sectionId"); 19 Long sectionId = getQueryLongParam(request, "sectionId");
20 20
21 if(sectionId != null){ 21 if(sectionId != null){
22 String text = DBService.getSectionWithContent(sectionId).getText(); 22 String text = DBService.getSectionWithContent(sectionId).getText();
23 if(StringUtils.isNotEmpty(text)){ 23 if(StringUtils.isNotEmpty(text)){
24 24
25 PrintWriter out = response.getWriter(); 25 PrintWriter out = response.getWriter();
26 out.print(text); 26 out.print(text);
27 out.flush(); 27 out.flush();
28 response.setContentType("text/plain; charset=UTF-8"); 28 response.setContentType("text/plain; charset=UTF-8");
29 29
30 }else{ 30 }else{
31 response.setContentType("application/json"); 31 response.setContentType("application/json");
32 JSONObject json = new JSONObject(); 32 JSONObject json = new JSONObject();
33 json.put("status", "error"); 33 json.put("status", "error");
34 json.put("message", "Section no found (" + sectionId + ")"); 34 json.put("message", "The content of this section is not available yet (" + sectionId + ")");
35 PrintWriter out = response.getWriter(); 35 PrintWriter out = response.getWriter();
36 out.print(json.toString()); 36 out.print(json.toString());
37 out.flush(); 37 out.flush();
38 } 38 }
39 }else{ 39 }else{
44 PrintWriter out = response.getWriter(); 44 PrintWriter out = response.getWriter();
45 out.print(json.toString()); 45 out.print(json.toString());
46 out.flush(); 46 out.flush();
47 } 47 }
48 } 48 }
49 49
50 } 50 }