source: trunk/www/biomaterials/tags/index.jsp @ 5632

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

References #1153: Handling short read transcript sequence data

Replaced Label with Tag. It re-uses much of the old code including the database table.

The code compiles and most test programs pass. Not all gui pages in the web client work. Since LabeledExtract is going to be removed functionality that is related with this may not do what is expected.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.7 KB
Line 
1<%-- $Id: index.jsp 5632 2011-05-17 09:35:34Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page pageEncoding="UTF-8" session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.Include"
31  import="net.sf.basedb.core.Tag"
32  import="net.sf.basedb.core.ItemSubtype"
33  import="net.sf.basedb.core.ItemQuery"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.ItemContext"
36  import="net.sf.basedb.core.ItemQuery"
37  import="net.sf.basedb.core.MultiPermissions"
38  import="net.sf.basedb.core.OwnedItem"
39  import="net.sf.basedb.core.PermissionDeniedException"
40  import="net.sf.basedb.core.ItemAlreadyExistsException"
41  import="net.sf.basedb.util.RemovableUtil"
42  import="net.sf.basedb.util.ShareableUtil"
43  import="net.sf.basedb.util.OwnableUtil"
44  import="net.sf.basedb.clients.web.Base"
45  import="net.sf.basedb.clients.web.WebException"
46  import="net.sf.basedb.util.Values"
47  import="net.sf.basedb.clients.web.util.HTML"
48  import="net.sf.basedb.core.plugin.GuiContext"
49  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
50  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
51  import="net.sf.basedb.clients.web.extensions.JspContext"
52  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
53  import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer"
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%>
61<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
62<%!
63  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,itemSubtype,description");
64  private static final Item itemType = Item.TAG;
65%>
66<%
67final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
68final String ID = sc.getId();
69final String cmd = request.getParameter("cmd");
70final String root = request.getContextPath()+"/";
71final String mode = request.getParameter("mode");
72final String callback = request.getParameter("callback");
73final String itemId = request.getParameter("item_id");
74final String listPage = "list_tags.jsp?ID="+ID
75  +(mode == null ? "" : "&mode="+mode)
76  +(callback == null ? "" : "&callback="+callback)
77  +(itemId == null ? "" : "&item_id="+itemId);
78final String viewPage = "view_tag.jsp?ID="+ID;
79final String editPage = "edit_tag.jsp?ID="+ID;
80
81String forward = null;
82String redirect = null;
83String message = null;
84DbControl dc = null;
85
86try
87{
88  if (cmd == null || "List".equals(cmd))
89  {
90    // Display the list page without updatinging the current context
91    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
92    redirect = listPage;
93  }
94  else if ("UpdateContext".equals(cmd))
95  {
96    // Display the list page after updating the current context from the request parameters
97    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
98    redirect = listPage;
99  }
100  else if ("LoadContext".equals(cmd))
101  {
102    // Display the list page after loading a saved context
103    int contextId = Values.getInt(request.getParameter("context"));
104    Base.loadContext(sc, contextId, defaultContext);
105    redirect = listPage;
106  }
107
108  else if ("ViewItem".equals(cmd))
109  {
110    // Display the view page for a single item
111    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
112    forward = viewPage;
113  }
114  else if ("EditItem".equals(cmd))
115  {
116    // Display the edit page for a single item (should be opened in a popup)
117    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
118    redirect = editPage;
119  }
120  else if ("NewItem".equals(cmd))
121  {
122    // Display the edit page for a new item (should be opened in a popup)
123    if (!sc.hasPermission(Permission.CREATE, itemType))
124    {
125      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
126    }
127    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
128    cc.setId(0);
129    redirect = editPage;
130  }
131  else if ("UpdateItem".equals(cmd))
132  {
133    // Update the properties on an item (will close the popup)
134    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
135    final int maxRecent = Base.getMaxRecent(sc);
136    dc = sc.newDbControl();
137    Tag tag = (Tag)cc.getObject("item");
138    if (tag == null)
139    {
140      tag = Tag.getNew(dc);
141      message = "Tag created";
142      dc.saveItem(tag);
143    }
144    else
145    {
146      dc.reattachItem(tag, false);
147      message = "Tag updated";
148    }
149    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), tag);
150    ExtensionsInvoker invoker = EditUtil.useOnSaveExtensions(jspContext);
151    try
152    {
153      tag.setName(Values.getStringOrNull(request.getParameter("name")));
154      tag.setDescription(Values.getStringOrNull(request.getParameter("description")));
155      int tagTypeId = Values.getInt(request.getParameter("tagtype_id"), -1);
156      if (tagTypeId >= 0) // < 0 = denied or unchanged
157      {
158        ItemSubtype subtype = tagTypeId == 0 ? null : ItemSubtype.getById(dc, tagTypeId);
159        tag.setItemSubtype(subtype);
160        if (subtype != null) cc.setRecent(subtype, maxRecent);
161      }
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 ("ShareItem".equals(cmd))
225  {
226    // Display a popup window for sharing a single item
227    dc = sc.newDbControl();
228    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
229    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
230    dc.close();
231    cc.setObject("MultiPermissions", permissions);
232    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
233  }
234  else if ("ShareItems".equals(cmd))
235  {
236    // Display a popup window for sharing all selected items on the list page
237    dc = sc.newDbControl();
238    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
239    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
240    dc.close();
241    cc.setObject("MultiPermissions", permissions);
242    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
243  }
244  else if ("SetOwnerOfItem".equals(cmd))
245  {
246    // Change owner of items selected on a list page
247    dc = sc.newDbControl();
248    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
249    OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId());
250    cc.setObject("OwnedItems", Collections.singleton(item));
251    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
252  }
253  else if ("SetOwnerOfItems".equals(cmd))
254  {
255    // Change owner of items selected on a list page
256    dc = sc.newDbControl();
257    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
258    Set<OwnedItem> items = new HashSet<OwnedItem>();
259    for (Integer id : cc.getSelected())
260    {
261      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
262    }
263    dc.close();
264    cc.setObject("OwnedItems", items);
265    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
266  }
267  else if ("ExportItems".equals(cmd))
268  {
269    // Run an export plugin in a list context
270    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
271    final ItemQuery<Tag> query = Tag.getQuery();
272    dc = sc.newDbControl();
273    cc.configureQuery(dc, query, true);
274    dc.close();
275    cc.setQuery(query);
276    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+tags";
277  }
278  else if ("ExportItem".equals(cmd))
279  {
280    // Run an export plugin in single-item context
281    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
282    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+tag";
283  }
284  else if ("ImportItems".equals(cmd))
285  {
286    // Run an import plugin in a list context
287    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
288    final ItemQuery<Tag> query = Tag.getQuery();
289    dc = sc.newDbControl();
290    cc.configureQuery(dc, query, true);
291    dc.close();
292    cc.setQuery(query);
293    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+tags";
294  }
295  else if ("ImportItem".equals(cmd))
296  {
297    // Run an import plugin in single-item context
298    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
299    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+tag";
300  }
301  else if ("RunListPlugin".equals(cmd))
302  {
303    // Run another plugin in a list context
304    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
305    final ItemQuery<Tag> query = Tag.getQuery();
306    dc = sc.newDbControl();
307    cc.configureQuery(dc, query, true);
308    dc.close();
309    cc.setQuery(query);
310    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
311  }
312  else if ("RunPlugin".equals(cmd))
313  {
314    // Run another plugin in single-item context
315    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
316    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
317  }
318  else
319  {
320    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
321  }
322}
323finally
324{
325  if (dc != null) dc.close();
326}
327
328if (forward != null)
329{
330  pageContext.forward(forward);
331}
332else if (redirect != null)
333{
334  response.sendRedirect(redirect);
335}
336else if (message == null)
337{
338  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
339}
340else
341{
342  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
343}
344%>
345
Note: See TracBrowser for help on using the repository browser.