Mercurial > hg > LGDataverses
comparison src/main/java/de/mpiwg/monographs/servlet/AbstractMonographServlet.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.util.logging.Level; | |
| 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.http.HttpServlet; | |
| 10 | |
| 11 import org.codehaus.jettison.json.JSONArray; | |
| 12 import org.codehaus.jettison.json.JSONException; | |
| 13 import org.codehaus.jettison.json.JSONObject; | |
| 14 import org.swordapp.server.SwordServerException; | |
| 15 | |
| 16 import edu.harvard.iq.dvn.core.study.EditStudyService; | |
| 17 import edu.harvard.iq.dvn.core.study.FileMetadata; | |
| 18 import edu.harvard.iq.dvn.core.study.Study; | |
| 19 import edu.harvard.iq.dvn.core.study.StudyVersion; | |
| 20 | |
| 21 public class AbstractMonographServlet extends HttpServlet { | |
| 22 | |
| 23 private static final Logger logger = Logger.getLogger("monographs.AbstractMonographServlet"); | |
| 24 | |
| 25 private Context ctx = null; | |
| 26 | |
| 27 protected JSONObject jsonStudyVersion(String studyGlobalId) throws SwordServerException{ | |
| 28 | |
| 29 Study study0 = getStudy(studyGlobalId); | |
| 30 StudyVersion study = study0.getLatestVersion(); | |
| 31 | |
| 32 return MonographUtils.jsonStudyVersion(study); | |
| 33 } | |
| 34 | |
| 35 protected Study getStudy(String studyGlobalId) throws SwordServerException{ | |
| 36 | |
| 37 EditStudyService editStudyService; | |
| 38 | |
| 39 try { | |
| 40 editStudyService = (EditStudyService) getCtx().lookup("java:comp/env/editStudy"); | |
| 41 } catch (NamingException ex) { | |
| 42 logger.info("problem looking up editStudyService"); | |
| 43 throw new SwordServerException("problem looking up editStudyService"); | |
| 44 } | |
| 45 | |
| 46 Study study = editStudyService.getStudyByGlobalId(studyGlobalId); | |
| 47 return study; | |
| 48 } | |
| 49 | |
| 50 protected Context getCtx() throws NamingException{ | |
| 51 if(ctx == null) | |
| 52 ctx = new InitialContext(); | |
| 53 return ctx; | |
| 54 } | |
| 55 | |
| 56 protected void error(JSONObject jsonResponse, Exception e){ | |
| 57 logger.log(Level.SEVERE, e.getMessage()); | |
| 58 try { | |
| 59 jsonResponse.put("status", "error"); | |
| 60 jsonResponse.put("error", e.getMessage()); | |
| 61 } catch (JSONException e1) { | |
| 62 e1.printStackTrace(); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 } |
