www/biomaterials/bioplatetypes/ajax.jsp

Code
Comments
Other
Rev Date Author Line
6056 12 Jun 12 nicklas 1 <%-- $Id: ajax.jsp 5557 2011-01-28 11:48:15Z nicklas $
6056 12 Jun 12 nicklas 2   ------------------------------------------------------------------
6056 12 Jun 12 nicklas 3   Copyright (C) 2010 Nicklas Nordborg
6056 12 Jun 12 nicklas 4
6056 12 Jun 12 nicklas 5   This file is part of BASE - BioArray Software Environment.
6056 12 Jun 12 nicklas 6   Available at http://base.thep.lu.se/
6056 12 Jun 12 nicklas 7
6056 12 Jun 12 nicklas 8   BASE is free software; you can redistribute it and/or
6056 12 Jun 12 nicklas 9   modify it under the terms of the GNU General Public License
6056 12 Jun 12 nicklas 10   as published by the Free Software Foundation; either version 3
6056 12 Jun 12 nicklas 11   of the License, or (at your option) any later version.
6056 12 Jun 12 nicklas 12
6056 12 Jun 12 nicklas 13   BASE is distributed in the hope that it will be useful,
6056 12 Jun 12 nicklas 14   but WITHOUT ANY WARRANTY; without even the implied warranty of
6056 12 Jun 12 nicklas 15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6056 12 Jun 12 nicklas 16   GNU General Public License for more details.
6056 12 Jun 12 nicklas 17
6056 12 Jun 12 nicklas 18   You should have received a copy of the GNU General Public License
6056 12 Jun 12 nicklas 19   along with BASE. If not, see <http://www.gnu.org/licenses/>.
6056 12 Jun 12 nicklas 20   ------------------------------------------------------------------
6056 12 Jun 12 nicklas 21
6056 12 Jun 12 nicklas 22   @author Nicklas
6056 12 Jun 12 nicklas 23 --%>
6056 12 Jun 12 nicklas 24 <%@page import="net.sf.basedb.core.ItemSubtype"%>
6056 12 Jun 12 nicklas 25 <%@ page pageEncoding="UTF-8" session="false" contentType="application/json"
6056 12 Jun 12 nicklas 26   import="net.sf.basedb.core.BioPlateType"
6056 12 Jun 12 nicklas 27   import="net.sf.basedb.core.BioPlate"
6056 12 Jun 12 nicklas 28   import="net.sf.basedb.core.BioWell"
6056 12 Jun 12 nicklas 29   import="net.sf.basedb.core.ItemSubtype"
6056 12 Jun 12 nicklas 30   import="net.sf.basedb.core.DbControl"
6056 12 Jun 12 nicklas 31   import="net.sf.basedb.core.MeasuredBioMaterial"
6056 12 Jun 12 nicklas 32   import="net.sf.basedb.core.PlateGeometry"
6056 12 Jun 12 nicklas 33   import="net.sf.basedb.core.SessionControl"
6056 12 Jun 12 nicklas 34   import="net.sf.basedb.util.Values"
6056 12 Jun 12 nicklas 35   import="net.sf.basedb.util.error.ThrowableUtil"
6056 12 Jun 12 nicklas 36   import="net.sf.basedb.clients.web.Base"
6056 12 Jun 12 nicklas 37   import="net.sf.basedb.clients.web.WebException"
6056 12 Jun 12 nicklas 38   import="org.json.simple.JSONObject"
6056 12 Jun 12 nicklas 39   import="org.json.simple.JSONArray"
6056 12 Jun 12 nicklas 40 %>
6056 12 Jun 12 nicklas 41 <%
6124 13 Sep 12 nicklas 42 response.setHeader("Cache-Control", "no-cache, max-age=0");
6056 12 Jun 12 nicklas 43 final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
6056 12 Jun 12 nicklas 44 final String ID = sc.getId();
6056 12 Jun 12 nicklas 45 final String cmd = request.getParameter("cmd");
6056 12 Jun 12 nicklas 46 final String root = request.getContextPath()+"/";
6056 12 Jun 12 nicklas 47 final int itemId = Values.getInt(request.getParameter("item_id"));
6056 12 Jun 12 nicklas 48 DbControl dc = null;
6056 12 Jun 12 nicklas 49 out.clear();
6056 12 Jun 12 nicklas 50 JSONObject json = new JSONObject();
6056 12 Jun 12 nicklas 51 json.put("status", "ok");
6056 12 Jun 12 nicklas 52 try
6056 12 Jun 12 nicklas 53 {
6056 12 Jun 12 nicklas 54   if ("GetPlateTypeInfo".equals(cmd))
6056 12 Jun 12 nicklas 55   {
7954 12 May 21 nicklas 56     dc = sc.newDbControl(":Get plate type information");
6056 12 Jun 12 nicklas 57     BioPlateType plateType = BioPlateType.getById(dc, itemId);
6056 12 Jun 12 nicklas 58     
6056 12 Jun 12 nicklas 59     json.put("id", plateType.getId());
6056 12 Jun 12 nicklas 60     json.put("name", plateType.getName());
6056 12 Jun 12 nicklas 61     
6056 12 Jun 12 nicklas 62     
6056 12 Jun 12 nicklas 63     ItemSubtype storageType = plateType.getStorageType();
6056 12 Jun 12 nicklas 64     if (storageType != null)
6056 12 Jun 12 nicklas 65     {
6056 12 Jun 12 nicklas 66       JSONObject jsonStorageType = new JSONObject();
6056 12 Jun 12 nicklas 67       jsonStorageType.put("id", storageType.getId());
6056 12 Jun 12 nicklas 68       jsonStorageType.put("name", storageType.getName());
6056 12 Jun 12 nicklas 69       json.put("storageType", jsonStorageType);
6056 12 Jun 12 nicklas 70     }
6056 12 Jun 12 nicklas 71     
6056 12 Jun 12 nicklas 72     dc.close();
6056 12 Jun 12 nicklas 73   }
6056 12 Jun 12 nicklas 74   else
6056 12 Jun 12 nicklas 75   {
6056 12 Jun 12 nicklas 76     throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
6056 12 Jun 12 nicklas 77   }
6056 12 Jun 12 nicklas 78 }
6056 12 Jun 12 nicklas 79 catch (Throwable t)
6056 12 Jun 12 nicklas 80 {
6056 12 Jun 12 nicklas 81   t.printStackTrace();
6056 12 Jun 12 nicklas 82   json.clear();
6056 12 Jun 12 nicklas 83   json.put("status", "error");
6056 12 Jun 12 nicklas 84   json.put("message", t.getMessage());
6056 12 Jun 12 nicklas 85   json.put("stacktrace", ThrowableUtil.stackTraceToString(t));
6056 12 Jun 12 nicklas 86 }
6056 12 Jun 12 nicklas 87 finally
6056 12 Jun 12 nicklas 88 {
6056 12 Jun 12 nicklas 89   json.writeJSONString(out);
6056 12 Jun 12 nicklas 90   out.flush();
6056 12 Jun 12 nicklas 91   if (dc != null) dc.close();
6056 12 Jun 12 nicklas 92 }
6056 12 Jun 12 nicklas 93 %>