comparison src/main/java/de/mpiwg/gazetteer/rest/GetSectionMetadata.java @ 0:3e62083dbcbf

First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
author "jurzua <jurzua@mpiwg-berlin.mpg.de>"
date Thu, 23 Apr 2015 15:46:01 +0200
parents
children 9c4937b290c6
comparison
equal deleted inserted replaced
-1:000000000000 0:3e62083dbcbf
1 package de.mpiwg.gazetteer.rest;
2
3 import java.io.PrintWriter;
4
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7
8 import org.json.JSONObject;
9
10 import de.mpiwg.gazetteer.db.DBBook;
11 import de.mpiwg.gazetteer.db.DBSection;
12 import de.mpiwg.gazetteer.utils.DBService;
13
14 public class GetSectionMetadata extends AbstractServletMethod {
15
16 public static String name = "getSectionMetadata";
17
18 public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{
19
20 Long sectionId = getQueryLongParam(request, "sectionId");
21
22 if(sectionId != null){
23 DBSection section = DBService.getSectionWithContent(sectionId);
24 if(section != null){
25 //DBBook book = DBService.getBookFromDB(section.getBookId());
26 DBBook book = DBService.getInstance().getBook(section.getBookId());
27
28 response.setContentType("application/json");
29 JSONObject json = new JSONObject();
30 json.put("status", "ok");
31
32
33 JSONObject sectionJson = new JSONObject();
34 sectionJson.put("id", section.getId());
35 sectionJson.put("name", section.getName());
36 sectionJson.put("start_page", section.getStart_page());
37 sectionJson.put("end_page", section.getEnd_page());
38
39
40 JSONObject bookJson = new JSONObject();
41 bookJson.put("id", book.getId());
42 bookJson.put("name", book.getName());
43 bookJson.put("author", book.getAuthor());
44 bookJson.put("edition", book.getEdition());
45 bookJson.put("line", book.getLine());
46 bookJson.put("period", book.getPeriod());
47 bookJson.put("volume", book.getVolume());
48
49 bookJson.put("level1", book.getLevel1());
50 bookJson.put("level2", book.getLevel2());
51 bookJson.put("admin_type", book.getAdmin_type());
52 bookJson.put("in_jibengujiku", book.getIn_jibengujiku());
53
54
55 bookJson.put("dynasty", book.getDynasty());
56 bookJson.put("start_year", book.getStart_year());
57 bookJson.put("end_year", book.getEnd_year());
58
59
60 sectionJson.put("book", bookJson);
61
62
63 json.put("section", sectionJson);
64
65
66 PrintWriter out = response.getWriter();
67 out.print(json.toString());
68 out.flush();
69
70 }else{
71 response.setContentType("application/json");
72 JSONObject json = new JSONObject();
73 json.put("status", "error");
74 json.put("message", "Section no found (" + sectionId + ")");
75 PrintWriter out = response.getWriter();
76 out.print(json.toString());
77 out.flush();
78 }
79 }else{
80 response.setContentType("application/json");
81 JSONObject json = new JSONObject();
82 json.put("status", "error");
83 json.put("message", "Following parameters are mandatory: sectionId.");
84 PrintWriter out = response.getWriter();
85 out.print(json.toString());
86 out.flush();
87 }
88 }
89 }