source: trunk/www/admin/reporterclonetemplates/index.jsp @ 5878

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

References #1616: Clone reporter information to per-experiment tables in the dynamic database

Added a reporter cloning plug-in and buttons in the gui for starting it and for removing the cloned table. The gui probaby need some improvements and it should be possible to get more information about the cloned reporters...

Added permission checks in the ReporterCloneBatcher.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 13.4 KB
Line 
1<%-- $Id $
2  ------------------------------------------------------------------
3  Copyright (C) 2011 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--%>
23<%@ page pageEncoding="UTF-8" session="false"
24  import="net.sf.basedb.core.SessionControl"
25  import="net.sf.basedb.core.DbControl"
26  import="net.sf.basedb.core.Item"
27  import="net.sf.basedb.core.Include"
28  import="net.sf.basedb.core.ReporterCloneTemplate"
29  import="net.sf.basedb.core.ClonedProperty"
30  import="net.sf.basedb.core.ItemQuery"
31  import="net.sf.basedb.core.Permission"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.MultiPermissions"
34  import="net.sf.basedb.core.OwnedItem"
35  import="net.sf.basedb.core.PermissionDeniedException"
36  import="net.sf.basedb.core.ItemAlreadyExistsException"
37  import="net.sf.basedb.util.RemovableUtil"
38  import="net.sf.basedb.util.ShareableUtil"
39  import="net.sf.basedb.util.OwnableUtil"
40  import="net.sf.basedb.clients.web.Base"
41  import="net.sf.basedb.clients.web.WebException"
42  import="net.sf.basedb.util.Values"
43  import="net.sf.basedb.clients.web.util.HTML"
44  import="net.sf.basedb.core.plugin.GuiContext"
45  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
46  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
47  import="net.sf.basedb.clients.web.extensions.JspContext"
48  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
49  import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer"
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,properties,description");
60  private static final Item itemType = Item.REPORTERCLONETEMPLATE;
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_templates.jsp?ID="+ID
71  +(mode == null ? "" : "&mode="+mode)
72  +(callback == null ? "" : "&callback="+callback)
73  +(itemId == null ? "" : "&item_id="+itemId);
74final String viewPage = "view_template.jsp?ID="+ID;
75final String editPage = "edit_template.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 ("UpdateItem".equals(cmd))
128  {
129    // Update the properties on an item (will close the popup)
130    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
131    final int maxRecent = Base.getMaxRecent(sc);
132    dc = sc.newDbControl();
133    ReporterCloneTemplate template = (ReporterCloneTemplate)cc.getObject("item");
134    if (template == null)
135    {
136      template = ReporterCloneTemplate.getNew(dc);
137      message = "Reporter clone template created";
138      dc.saveItem(template);
139    }
140    else
141    {
142      dc.reattachItem(template, false);
143      message = "Reporter clone template updated";
144    }
145    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), template);
146    ExtensionsInvoker invoker = EditUtil.useOnSaveExtensions(jspContext);
147    try
148    {
149      template.setName(Values.getStringOrNull(request.getParameter("name")));
150      template.setDescription(Values.getStringOrNull(request.getParameter("description")));
151      //template.setExternalId(Values.getStringOrNull(request.getParameter("external_id")));
152 
153      // Template properties
154      String[] cloned = request.getParameterValues("cloned_properties");
155      if (cloned != null)
156      {
157        for (String propertyName : cloned)
158        {
159          if (!template.hasClonedProperty(propertyName)) 
160          {
161            template.addClonedProperty(ClonedProperty.create(propertyName));
162          }
163        }
164      }
165     
166      String[] uncloned = request.getParameterValues("uncloned_properties");
167      if (uncloned != null)
168      {
169        for (String propertyName : uncloned)
170        {
171          if (template.hasClonedProperty(propertyName)) 
172          {
173            template.removeClonedProperty(propertyName);
174          }
175        }
176      }
177     
178      // OnSave extensions
179      invoker.render(OnSaveRenderer.ON_SAVE);
180      dc.commit();
181      invoker.render(OnSaveRenderer.ON_COMMIT);
182    }
183    catch (Exception ex)
184    {
185      invoker.render(OnSaveRenderer.onRollback(ex));
186      throw ex;
187    }
188    finally
189    {
190      cc.removeObject("item");
191    }
192
193  }
194  else if ("DeleteItem".equals(cmd))
195  {
196    // Delete a single item and then return to the view page
197    dc = sc.newDbControl();
198    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
199    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
200    dc.commit();
201    redirect = viewPage;
202  }
203  else if ("DeleteItems".equals(cmd))
204  {
205    // Delete all selected items on the list page
206    dc = sc.newDbControl();
207    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
208    int numTotal = cc.getSelected().size();
209    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
210    dc.commit();
211    if (numTotal != numRemoved)
212    {
213      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
214    }
215    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
216  }
217  else if ("RestoreItem".equals(cmd))
218  {
219    // Restore a single item and then return to the view page
220    dc = sc.newDbControl();
221    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
222    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
223    dc.commit();
224    redirect = viewPage;
225  }
226  else if ("RestoreItems".equals(cmd))
227  {
228    // Restore all selected items on the list page
229    dc = sc.newDbControl();
230    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
231    int numTotal = cc.getSelected().size();
232    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
233    dc.commit();
234    if (numTotal != numRemoved)
235    {
236      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
237    }
238    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
239  }
240  else if ("ShareItem".equals(cmd))
241  {
242    // Display a popup window for sharing a single item
243    dc = sc.newDbControl();
244    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
245    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
246    dc.close();
247    cc.setObject("MultiPermissions", permissions);
248    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
249  }
250  else if ("ShareItems".equals(cmd))
251  {
252    // Display a popup window for sharing all selected items on the list page
253    dc = sc.newDbControl();
254    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
255    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
256    dc.close();
257    cc.setObject("MultiPermissions", permissions);
258    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
259  }
260  else if ("SetOwnerOfItem".equals(cmd))
261  {
262    // Change owner of items selected on a list page
263    dc = sc.newDbControl();
264    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
265    OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId());
266    cc.setObject("OwnedItems", Collections.singleton(item));
267    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
268  }
269  else if ("SetOwnerOfItems".equals(cmd))
270  {
271    // Change owner of items selected on a list page
272    dc = sc.newDbControl();
273    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
274    Set<OwnedItem> items = new HashSet<OwnedItem>();
275    for (Integer id : cc.getSelected())
276    {
277      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
278    }
279    dc.close();
280    cc.setObject("OwnedItems", items);
281    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
282  }
283  else if ("ExportItems".equals(cmd))
284  {
285    // Run an export plugin in a list context
286    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
287    final ItemQuery<ReporterCloneTemplate> query = ReporterCloneTemplate.getQuery();
288    dc = sc.newDbControl();
289    cc.configureQuery(dc, query, true);
290    dc.close();
291    cc.setQuery(query);
292    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+reporter+clone+templates";
293  }
294  else if ("ExportItem".equals(cmd))
295  {
296    // Run an export plugin in single-item context
297    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
298    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+reporter+clone+template";
299  }
300  else if ("ImportItems".equals(cmd))
301  {
302    // Run an import plugin in a list context
303    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
304    final ItemQuery<ReporterCloneTemplate> query = ReporterCloneTemplate.getQuery();
305    dc = sc.newDbControl();
306    cc.configureQuery(dc, query, true);
307    dc.close();
308    cc.setQuery(query);
309    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+reporter+clone+template";
310  }
311  else if ("ImportItem".equals(cmd))
312  {
313    // Run an import plugin in single-item context
314    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
315    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+reporter+clone+template";
316  }
317  else if ("RunListPlugin".equals(cmd))
318  {
319    // Run another plugin in a list context
320    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
321    final ItemQuery<ReporterCloneTemplate> query = ReporterCloneTemplate.getQuery();
322    dc = sc.newDbControl();
323    cc.configureQuery(dc, query, true);
324    dc.close();
325    cc.setQuery(query);
326    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
327  }
328  else if ("RunPlugin".equals(cmd))
329  {
330    // Run another plugin in single-item context
331    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
332    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
333  }
334  else
335  {
336    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
337  }
338}
339finally
340{
341  if (dc != null) dc.close();
342}
343
344if (forward != null)
345{
346  pageContext.forward(forward);
347}
348else if (redirect != null)
349{
350  response.sendRedirect(redirect);
351}
352else if (message == null)
353{
354  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
355}
356else
357{
358  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
359}
360%>
361
Note: See TracBrowser for help on using the repository browser.