Mercurial > hg > LGDataverses
comparison src/main/java/de/mpiwg/monographs/servlet/GetStudyInformation.java @ 0:fcb8807fbd84
Fist commit!
| author | "jurzua <jurzua@mpiwg-berlin.mpg.de>" |
|---|---|
| date | Tue, 10 Mar 2015 15:15:30 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:fcb8807fbd84 |
|---|---|
| 1 package de.mpiwg.monographs.servlet; | |
| 2 | |
| 3 import java.io.IOException; | |
| 4 import java.util.logging.Logger; | |
| 5 | |
| 6 import javax.naming.Context; | |
| 7 import javax.naming.InitialContext; | |
| 8 import javax.naming.NamingException; | |
| 9 import javax.servlet.ServletException; | |
| 10 import javax.servlet.http.HttpServlet; | |
| 11 import javax.servlet.http.HttpServletRequest; | |
| 12 import javax.servlet.http.HttpServletResponse; | |
| 13 | |
| 14 import org.apache.commons.lang.StringUtils; | |
| 15 import org.codehaus.jettison.json.JSONArray; | |
| 16 import org.codehaus.jettison.json.JSONException; | |
| 17 import org.codehaus.jettison.json.JSONObject; | |
| 18 import org.swordapp.server.SwordServerException; | |
| 19 | |
| 20 import edu.harvard.iq.dvn.core.study.EditStudyService; | |
| 21 import edu.harvard.iq.dvn.core.study.FileMetadata; | |
| 22 import edu.harvard.iq.dvn.core.study.Study; | |
| 23 import edu.harvard.iq.dvn.core.study.StudyVersion; | |
| 24 | |
| 25 public class GetStudyInformation extends AbstractMonographServlet { | |
| 26 | |
| 27 private static final Logger logger = Logger.getLogger("monographs.GetStudyInformation"); | |
| 28 | |
| 29 @Override | |
| 30 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
| 31 // Set response content type | |
| 32 response.setContentType("application/json"); | |
| 33 JSONObject jsonResponse = new JSONObject(); | |
| 34 | |
| 35 String studyGlobalId = request.getParameter("studyId"); | |
| 36 if(StringUtils.isNotEmpty(studyGlobalId)){ | |
| 37 | |
| 38 try { | |
| 39 | |
| 40 JSONObject jsonStudy = jsonStudyVersion(studyGlobalId); | |
| 41 jsonResponse.put("study", jsonStudy); | |
| 42 | |
| 43 } catch (SwordServerException e){ | |
| 44 try { | |
| 45 jsonResponse.put("error", e.getMessage()); | |
| 46 } catch (JSONException e1) { | |
| 47 e1.printStackTrace(); | |
| 48 } | |
| 49 } catch (JSONException e) { | |
| 50 try { | |
| 51 jsonResponse.put("error", e.getMessage()); | |
| 52 } catch (JSONException e1) { | |
| 53 e1.printStackTrace(); | |
| 54 } | |
| 55 } | |
| 56 }else{ | |
| 57 try { | |
| 58 jsonResponse.put("error", "Request error. Parameter studyId no found."); | |
| 59 } catch (JSONException e) { | |
| 60 e.printStackTrace(); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 | |
| 65 java.io.PrintWriter out = response.getWriter(); | |
| 66 out.print(jsonResponse); | |
| 67 out.flush(); | |
| 68 } | |
| 69 } |
