source: trunk/www/biomaterials/bioplatetypes/index.jsp @ 5590

Last change on this file since 5590 was 5590, checked in by Nicklas Nordborg, 11 years ago

References #1589: Delete deprecated classes and methods

Removed deprecated methods and classes from the core API.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 11.2 KB
Line 
1<%-- $Id $
2  ------------------------------------------------------------------
3  Copyright (C) 2010 Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23  @version 2.0
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.Include"
30  import="net.sf.basedb.core.BioPlateType"
31  import="net.sf.basedb.core.BioWell"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.ItemResultIterator"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.ItemContext"
36  import="net.sf.basedb.core.MultiPermissions"
37  import="net.sf.basedb.core.PermissionDeniedException"
38  import="net.sf.basedb.core.ItemAlreadyExistsException"
39  import="net.sf.basedb.core.query.Hql"
40  import="net.sf.basedb.core.query.Expressions"
41  import="net.sf.basedb.core.query.Orders"
42  import="net.sf.basedb.core.query.Restrictions"
43  import="net.sf.basedb.util.formatter.NameableFormatter"
44  import="net.sf.basedb.util.RemovableUtil"
45  import="net.sf.basedb.util.Values"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.clients.web.WebException" 
48  import="net.sf.basedb.clients.web.plugins.ItemQueryLoader"
49  import="net.sf.basedb.clients.web.util.HTML"
50  import="net.sf.basedb.core.plugin.GuiContext"
51  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
52  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
53  import="net.sf.basedb.clients.web.extensions.JspContext"
54  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
55  import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer"
56  import="java.util.Enumeration"
57  import="java.util.Set"
58  import="java.util.HashSet"
59  import="java.util.List"
60  import="java.util.ArrayList"
61  import="java.util.Collections"
62%>
63<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
64<%!
65  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,bioMaterialType,description");
66  private static final Item itemType = Item.BIOPLATETYPE;
67%>
68<%
69final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
70final String ID = sc.getId();
71final String cmd = request.getParameter("cmd");
72final String root = request.getContextPath()+"/";
73final String mode = request.getParameter("mode");
74final String callback = request.getParameter("callback");
75final String itemId = request.getParameter("item_id");
76final String listPage = "list_platetypes.jsp?ID="+ID
77  +(mode == null ? "" : "&mode="+mode)
78  +(callback == null ? "" : "&callback="+callback)
79  +(itemId == null ? "" : "&item_id="+itemId);
80final String viewPage = "view_platetype.jsp?ID="+ID;
81final String editPage = "edit_platetype.jsp?ID="+ID;
82
83String forward = null;
84String redirect = null;
85String message = null;
86DbControl dc = null;
87
88try
89{
90  if (cmd == null || "List".equals(cmd))
91  {
92    // Display the list page without updatinging the current context
93    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
94    redirect = listPage;
95  }
96  else if ("UpdateContext".equals(cmd))
97  {
98    // Display the list page after updating the current context from the request parameters
99    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
100    redirect = listPage;
101  }
102  else if ("LoadContext".equals(cmd))
103  {
104    // Display the list page after loading a saved context
105    int contextId = Values.getInt(request.getParameter("context"));
106    Base.loadContext(sc, contextId, defaultContext);
107    redirect = listPage;
108  }
109
110  else if ("ViewItem".equals(cmd))
111  {
112    // Display the view page for a single item
113    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
114    forward = viewPage;
115  }
116  else if ("EditItem".equals(cmd))
117  {
118    // Display the edit page for a single item (should be opened in a popup)
119    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
120    redirect = editPage;
121  }
122  else if ("NewItem".equals(cmd))
123  {
124    // Display the edit page for a new item (should be opened in a popup)
125    if (!sc.hasPermission(Permission.CREATE, itemType))
126    {
127      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
128    }
129    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
130    cc.setId(0);
131    redirect = editPage;
132  }
133  else if ("UpdateItem".equals(cmd))
134  {
135    // Update the properties on an item (will close the popup)
136    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
137    dc = sc.newDbControl();
138    BioPlateType plateType = (BioPlateType)cc.getObject("item");
139    if (plateType == null)
140    {
141      plateType = BioPlateType.getNew(dc);
142      String bioMaterialType = Values.getStringOrNull(request.getParameter("bioMaterialType"));
143      if (bioMaterialType != null)
144      {
145        plateType.setBioMaterialType(Item.valueOf(bioMaterialType));
146      }
147      message = "Plate type created";
148      dc.saveItem(plateType);
149    }
150    else
151    {
152      dc.reattachItem(plateType, false);
153      message = "Plate type updated";
154    }
155    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.BIOPLATETYPE), plateType);
156    ExtensionsInvoker invoker = EditUtil.useOnSaveExtensions(jspContext);
157    try
158    {
159      plateType.setName(Values.getStringOrNull(request.getParameter("name")));
160      plateType.setDescription(Values.getStringOrNull(request.getParameter("description")));
161      plateType.setLockMode(BioWell.LockMode.valueOf(request.getParameter("lockMode")));
162     
163      // OnSave extensions
164      invoker.render(OnSaveRenderer.ON_SAVE);
165      dc.commit();
166      invoker.render(OnSaveRenderer.ON_COMMIT);
167    }
168    catch (Exception ex)
169    {
170      invoker.render(OnSaveRenderer.onRollback(ex));
171      throw ex;
172    }
173    finally
174    {
175      cc.removeObject("item");
176    }
177  }
178  else if ("DeleteItem".equals(cmd))
179  {
180    // Delete a single item and then return to the view page
181    dc = sc.newDbControl();
182    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
183    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
184    dc.commit();
185    redirect = viewPage;
186  }
187  else if ("DeleteItems".equals(cmd))
188  {
189    // Delete all selected items on the list page
190    dc = sc.newDbControl();
191    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
192    int numTotal = cc.getSelected().size();
193    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
194    dc.commit();
195    if (numTotal != numRemoved)
196    {
197      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
198    }
199    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
200  }
201  else if ("RestoreItem".equals(cmd))
202  {
203    // Restore a single item and then return to the view page
204    dc = sc.newDbControl();
205    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
206    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
207    dc.commit();
208    redirect = viewPage;
209  }
210  else if ("RestoreItems".equals(cmd))
211  {
212    // Restore all selected items on the list page
213    dc = sc.newDbControl();
214    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
215    int numTotal = cc.getSelected().size();
216    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
217    dc.commit();
218    if (numTotal != numRemoved)
219    {
220      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
221    }
222    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
223  }
224  else if ("ExportItems".equals(cmd))
225  {
226    // Run an export plugin in a list context
227    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
228    final ItemQuery<BioPlateType> query = BioPlateType.getQuery();
229    dc = sc.newDbControl();
230    cc.configureQuery(dc, query, true);
231    dc.close();
232    cc.setQuery(query);
233    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+bio+plate+types";
234  }
235  else if ("ExportItem".equals(cmd))
236  {
237    // Run an export plugin in single-item context
238    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
239    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+bio+plate+type";
240  }
241  else if ("ImportItems".equals(cmd))
242  {
243    // Run an import plugin in a list context
244    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
245    final ItemQuery<BioPlateType> query = BioPlateType.getQuery();
246    dc = sc.newDbControl();
247    cc.configureQuery(dc, query, true);
248    dc.close();
249    cc.setQuery(query);
250    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+bio+plate+types";
251  }
252  else if ("ImportItem".equals(cmd))
253  {
254    // Run an import plugin in single-item context
255    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
256    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+bio+plate+type";
257  }
258  else if ("RunListPlugin".equals(cmd))
259  {
260    // Run another plugin in a list context
261    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
262    final ItemQuery<BioPlateType> query = BioPlateType.getQuery();
263    dc = sc.newDbControl();
264    cc.configureQuery(dc, query, true);
265    dc.close();
266    cc.setQuery(query);
267    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
268  }
269  else if ("RunPlugin".equals(cmd))
270  {
271    // Run another plugin in single-item context
272    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
273    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
274  }
275  else
276  {
277    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
278  }
279}
280finally
281{
282  if (dc != null) dc.close();
283}
284
285if (forward != null)
286{
287  pageContext.forward(forward);
288}
289else if (redirect != null)
290{
291  response.sendRedirect(redirect);
292}
293else if (message == null)
294{
295  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
296}
297else
298{
299  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
300}
301%>
302
Note: See TracBrowser for help on using the repository browser.