Mercurial > hg > LGDataverses
changeset 11:08c950a22cee
new: add getAllDataverseAlias api for LGServices
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 09 Sep 2015 17:13:18 +0200 |
parents | a50cf11e5178 |
children | c2e2d794847f |
files | src/main/java/de/mpiwg/monographs/servlet/GetAllDataverseAlias.java src/main/webapp/WEB-INF/web.xml |
diffstat | 2 files changed, 66 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/monographs/servlet/GetAllDataverseAlias.java Wed Sep 09 17:13:18 2015 +0200 @@ -0,0 +1,56 @@ +package de.mpiwg.monographs.servlet; + +import java.io.IOException; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.ejb.EJB; +import javax.persistence.EntityManager; +import javax.persistence.NonUniqueResultException; +import javax.persistence.PersistenceContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.primefaces.json.JSONArray; +import org.primefaces.json.JSONException; +import org.primefaces.json.JSONObject; + +import edu.harvard.iq.dataverse.Dataverse; +import edu.harvard.iq.dataverse.DataverseServiceBean; + +public class GetAllDataverseAlias extends AbstractMonographServlet{ + + private static final Logger logger = Logger.getLogger("monographs.GetAllDataverseAlias"); + + @EJB + protected DataverseServiceBean dataverseServiceBean; + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // Set response content type + response.setContentType("application/json"); + JSONObject jsonResponse = new JSONObject(); + + //get all dataverse records + List<Dataverse> dataverseList = dataverseServiceBean.findAll(); + + JSONArray dataverseAliasArray = new JSONArray(); + + for(Dataverse aDataverse : dataverseList){ + dataverseAliasArray.put(aDataverse.getAlias()); + } + + try { + jsonResponse.put("state", "ok"); + jsonResponse.put("dataverseAlias", dataverseAliasArray); + } catch (JSONException e) { + e.printStackTrace(); + } + + java.io.PrintWriter out = response.getWriter(); + out.print(jsonResponse); + out.flush(); + } + +}
--- a/src/main/webapp/WEB-INF/web.xml Tue Sep 08 17:00:21 2015 +0200 +++ b/src/main/webapp/WEB-INF/web.xml Wed Sep 09 17:13:18 2015 +0200 @@ -271,6 +271,16 @@ <servlet-class>de.mpiwg.monographs.servlet.GetDatafile</servlet-class> </servlet> + <!-- Get AllDataverseAlias --> + <servlet-mapping> + <servlet-name>de.mpiwg.monographs.servlet.GetAllDataverseAlias</servlet-name> + <url-pattern>/getAllDataverseAlias</url-pattern> + </servlet-mapping> + <servlet> + <servlet-name>de.mpiwg.monographs.servlet.GetAllDataverseAlias</servlet-name> + <servlet-class>de.mpiwg.monographs.servlet.GetAllDataverseAlias</servlet-class> + </servlet> + <!-- zoe end --> </web-app>