source: trunk/www/biomaterials/lists/index.jsp @ 4681

Last change on this file since 4681 was 4681, checked in by Nicklas Nordborg, 14 years ago

References #1175: Biomaterial lists

Basic web interface is now in place.

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