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

Last change on this file since 5709 was 5709, checked in by Nicklas Nordborg, 10 years ago

References #1597: Subtypes of items

Added link to item subtype from bioplate type which makes it possible to restrict/filter on the biomaterial subtype when selecting biomaterial for a plate. The "restriction" is in the gui only and is not checked by the core since it is possible to change the subtype of a biomaterial after it has been placed on a plate.

As a result of this the "Labeled extract reaction plate" is brought back to life again.

Also discovered that the bioplate event wizards should probably be able to utilize subtype information for some improvements. So there are still some things to fix before this ticket can be closed.

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