source: trunk/www/views/hybridizations/index.jsp @ 3005

Last change on this file since 3005 was 3005, checked in by Martin Svensson, 17 years ago

Fixes #455 Empty date field is not accepted at several places.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 14.1 KB
Line 
1<%-- $Id: index.jsp 3005 2006-12-07 08:25:06Z martin $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
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 2
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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.Include"
32  import="net.sf.basedb.core.Hybridization"
33  import="net.sf.basedb.core.ArraySlide"
34  import="net.sf.basedb.core.BioMaterialEvent"
35  import="net.sf.basedb.core.LabeledExtract"
36  import="net.sf.basedb.core.Protocol"
37  import="net.sf.basedb.core.Hardware"
38  import="net.sf.basedb.core.ItemQuery"
39  import="net.sf.basedb.core.ItemResultIterator"
40  import="net.sf.basedb.core.Permission"
41  import="net.sf.basedb.core.ItemContext"
42  import="net.sf.basedb.core.MultiPermissions"
43  import="net.sf.basedb.core.PermissionDeniedException"
44  import="net.sf.basedb.core.ItemAlreadyExistsException"
45  import="net.sf.basedb.util.RemovableUtil"
46  import="net.sf.basedb.util.ShareableUtil"
47  import="net.sf.basedb.util.OwnableUtil"
48  import="net.sf.basedb.clients.web.Base"
49  import="net.sf.basedb.clients.web.WebException"
50  import="net.sf.basedb.util.Values"
51  import="net.sf.basedb.clients.web.util.HTML"
52  import="net.sf.basedb.util.formatter.Formatter"
53  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
54  import="java.util.Enumeration"
55  import="java.util.Set"
56  import="java.util.HashSet"
57  import="java.util.List"
58  import="java.util.ArrayList"
59  import="java.util.Collections"
60  import="java.util.Date"
61%>
62<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
63<%!
64  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,labeledExtracts,arraySlide,scans,description");
65  private static final Item itemType = Item.HYBRIDIZATION;
66%>
67<%
68final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
69final String ID = sc.getId();
70final String cmd = request.getParameter("cmd");
71final String root = request.getContextPath()+"/";
72final String mode = request.getParameter("mode");
73final String callback = request.getParameter("callback");
74final String itemId = request.getParameter("item_id");
75final String listPage = "list_hybridizations.jsp?ID="+ID
76  +(mode == null ? "" : "&mode="+mode)
77  +(callback == null ? "" : "&callback="+callback)
78  +(itemId == null ? "" : "&item_id="+itemId);
79final String viewPage = "view_hybridization.jsp?ID="+ID;
80final String editPage = "edit_hybridization.jsp?ID="+ID;
81
82String forward = null;
83String redirect = null;
84String message = null;
85DbControl dc = null;
86
87try
88{
89  if (cmd == null || "List".equals(cmd))
90  {
91    // Display the list page without updatinging the current context
92    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
93    redirect = listPage;
94  }
95  else if ("UpdateContext".equals(cmd))
96  {
97    // Display the list page after updating the current context from the request parameters
98    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
99    redirect = listPage;
100  }
101  else if ("LoadContext".equals(cmd))
102  {
103    // Display the list page after loading a saved context
104    int contextId = Values.getInt(request.getParameter("context"));
105    Base.loadContext(sc, contextId, defaultContext);
106    redirect = listPage;
107  }
108
109  else if ("ViewItem".equals(cmd))
110  {
111    // Display the view page for a single item
112    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
113    forward = viewPage;
114  }
115  else if ("EditItem".equals(cmd))
116  {
117    // Display the edit page for a single item (should be opened in a popup)
118    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
119    redirect = editPage;
120  }
121  else if ("NewItem".equals(cmd))
122  {
123    // Display the edit page for a new item (should be opened in a popup)
124    if (!sc.hasPermission(Permission.CREATE, itemType))
125    {
126      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
127    }
128    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
129    cc.setId(0);
130    forward = editPage;
131  }
132  else if ("UpdateItem".equals(cmd))
133  {
134    // Update the properties on an item (will close the popup)
135    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
136    final int maxRecent = Base.getMaxRecent(sc);
137    dc = sc.newDbControl();
138    Hybridization hyb = (Hybridization)cc.getObject("item");
139    BioMaterialEvent creationEvent = null;
140    if (hyb == null)
141    {
142      hyb = Hybridization.getNew(dc);
143      creationEvent = hyb.getCreationEvent();
144      message = "Hybridization created";
145      dc.saveItem(hyb);
146    }
147    else
148    {
149      creationEvent = hyb.getCreationEvent();
150      dc.reattachItem(hyb);
151      dc.reattachItem(creationEvent);
152      message = "Hybridization updated";
153    }
154    hyb.setName(Values.getStringOrNull(request.getParameter("name")));
155    hyb.setDescription(Values.getStringOrNull(request.getParameter("description")));
156    int arraySlideId = Values.getInt(request.getParameter("arrayslide_id"), -1);
157    if (arraySlideId >= 0) // < 0 = denied or unchanged
158    {
159      ArraySlide slide = arraySlideId == 0 ? null : ArraySlide.getById(dc, arraySlideId);
160      hyb.setArraySlide(slide);
161    }
162    Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
163    creationEvent.setEventDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("event_date"))));
164    int protocolId = Values.getInt(request.getParameter("protocol_id"), -1);
165    if (protocolId >= 0) // < 0 = denied or unchanged
166    {
167      Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId);
168      creationEvent.setProtocol(pt);
169      if (pt != null) cc.setRecent(pt, maxRecent);
170    }
171   
172    //Hybridization station
173    int hybStationId = Values.getInt(request.getParameter("hardware_id"), -1);
174    if (hybStationId >= 0) // < 0 denied or unchanged
175    {
176      Hardware hw = hybStationId == 0 ? null : Hardware.getById(dc, hybStationId);
177      creationEvent.setHardware(hw);
178      if (hw != null) cc.setRecent(hw, maxRecent);
179    }
180   
181    // Labeled extracts
182    String[] modifiedLabeledExtracts = Values.getString(request.getParameter("modifiedLabeledExtracts")).split(",");
183    for (int i = 0; i < modifiedLabeledExtracts.length; ++i)
184    {
185      int leId = Values.getInt(modifiedLabeledExtracts[i], -1);
186      if (leId != -1) 
187      {
188        LabeledExtract le = LabeledExtract.getById(dc, leId);
189        creationEvent.addSource(le, Values.getFloat(request.getParameter("L"+leId), null));
190      }
191    }
192    String[] removedLabeledExtracts = Values.getString(request.getParameter("removedLabeledExtracts")).split(",");
193    for (int i = 0; i < removedLabeledExtracts.length; ++i)
194    {
195      int leId = Values.getInt(removedLabeledExtracts[i], -1);
196      if (leId != -1) creationEvent.removeSource(LabeledExtract.getById(dc, leId));
197    }
198   
199    // Annotations tab
200    Base.updateAnnotations(dc, hyb, hyb, request);
201    dc.commit();
202    cc.removeObject("item");
203  }
204  else if ("DeleteItem".equals(cmd))
205  {
206    // Delete a single item and then return to the view page
207    dc = sc.newDbControl();
208    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
209    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
210    dc.commit();
211    redirect = viewPage;
212  }
213  else if ("DeleteItems".equals(cmd))
214  {
215    // Delete all selected items on the list page
216    dc = sc.newDbControl();
217    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
218    int numTotal = cc.getSelected().size();
219    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
220    dc.commit();
221    if (numTotal != numRemoved)
222    {
223      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
224    }
225    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
226  }
227  else if ("RestoreItem".equals(cmd))
228  {
229    // Restore a single item and then return to the view page
230    dc = sc.newDbControl();
231    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
232    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
233    dc.commit();
234    redirect = viewPage;
235  }
236  else if ("RestoreItems".equals(cmd))
237  {
238    // Restore all selected items on the list page
239    dc = sc.newDbControl();
240    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
241    int numTotal = cc.getSelected().size();
242    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
243    dc.commit();
244    if (numTotal != numRemoved)
245    {
246      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
247    }
248    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
249  }
250  else if ("ShareItem".equals(cmd))
251  {
252    // Display a popup window for sharing a single item
253    dc = sc.newDbControl();
254    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
255    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
256    dc.close();
257    cc.setObject("MultiPermissions", permissions);
258    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
259  }
260  else if ("ShareItems".equals(cmd))
261  {
262    // Display a popup window for sharing all selected items on the list page
263    dc = sc.newDbControl();
264    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
265    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
266    dc.close();
267    cc.setObject("MultiPermissions", permissions);
268    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
269  }
270  else if ("TakeOwnershipOfItem".equals(cmd))
271  {
272    // Take ownership a single item and then return to the view page
273    dc = sc.newDbControl();
274    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
275    OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null);
276    dc.commit();
277    redirect = viewPage;
278  }
279  else if ("TakeOwnershipOfItems".equals(cmd))
280  {
281    // Take ownership all selected items on the list page
282    dc = sc.newDbControl();
283    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
284    int numTotal = cc.getSelected().size();
285    int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null);
286    dc.commit();
287    if (numTotal != numOwned)
288    {
289      message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission";
290    }
291    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
292  }
293  else if ("ExportItems".equals(cmd))
294  {
295    // Run an export plugin in a list context
296    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
297    final ItemQuery<Hybridization> query = Hybridization.getQuery();
298    cc.configureQuery(query, true);
299    cc.setQuery(query);
300    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+hybridizations";
301  }
302  else if ("ExportItem".equals(cmd))
303  {
304    // Run an export plugin in single-item context
305    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
306    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+hybridization";
307  }
308  else if ("ImportItems".equals(cmd))
309  {
310    // Run an import plugin in a list context
311    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
312    final ItemQuery<Hybridization> query = Hybridization.getQuery();
313    cc.configureQuery(query, true);
314    cc.setQuery(query);
315    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+hybrydizations";
316  }
317  else if ("ImportItem".equals(cmd))
318  {
319    // Run an import plugin in single-item context
320    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
321    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+hybridization";
322  }
323  else if ("RunListPlugin".equals(cmd))
324  {
325    // Run another plugin in a list context
326    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
327    final ItemQuery<Hybridization> query = Hybridization.getQuery();
328    cc.configureQuery(query, true);
329    cc.setQuery(query);
330    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
331  }
332  else if ("RunPlugin".equals(cmd))
333  {
334    // Run another plugin in single-item context
335    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
336    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
337  }
338  else
339  {
340    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
341  }
342}
343finally
344{
345  if (dc != null) dc.close();
346}
347
348if (forward != null)
349{
350  pageContext.forward(forward);
351}
352else if (redirect != null)
353{
354  response.sendRedirect(redirect);
355}
356else if (message == null)
357{
358  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
359}
360else
361{
362  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
363}
364%>
365
Note: See TracBrowser for help on using the repository browser.