source: trunk/www/biomaterials/labeledextracts/index.jsp @ 2811

Last change on this file since 2811 was 2811, checked in by Nicklas Nordborg, 17 years ago

Clear hidden 'exclude' filter that was set by popups

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