Mercurial > hg > LGServices
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetSectionMetadata.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,89 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; + +import de.mpiwg.gazetteer.db.DBBook; +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.gazetteer.utils.DBService; + +public class GetSectionMetadata extends AbstractServletMethod { + + public static String name = "getSectionMetadata"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + Long sectionId = getQueryLongParam(request, "sectionId"); + + if(sectionId != null){ + DBSection section = DBService.getSectionWithContent(sectionId); + if(section != null){ + //DBBook book = DBService.getBookFromDB(section.getBookId()); + DBBook book = DBService.getInstance().getBook(section.getBookId()); + + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "ok"); + + + JSONObject sectionJson = new JSONObject(); + sectionJson.put("id", section.getId()); + sectionJson.put("name", section.getName()); + sectionJson.put("start_page", section.getStart_page()); + sectionJson.put("end_page", section.getEnd_page()); + + + JSONObject bookJson = new JSONObject(); + bookJson.put("id", book.getId()); + bookJson.put("name", book.getName()); + bookJson.put("author", book.getAuthor()); + bookJson.put("edition", book.getEdition()); + bookJson.put("line", book.getLine()); + bookJson.put("period", book.getPeriod()); + bookJson.put("volume", book.getVolume()); + + bookJson.put("level1", book.getLevel1()); + bookJson.put("level2", book.getLevel2()); + bookJson.put("admin_type", book.getAdmin_type()); + bookJson.put("in_jibengujiku", book.getIn_jibengujiku()); + + + bookJson.put("dynasty", book.getDynasty()); + bookJson.put("start_year", book.getStart_year()); + bookJson.put("end_year", book.getEnd_year()); + + + sectionJson.put("book", bookJson); + + + json.put("section", sectionJson); + + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Section no found (" + sectionId + ")"); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: sectionId."); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + } +}