source: trunk/www/views/reporters/index.jsp @ 4305

Last change on this file since 4305 was 4305, checked in by Nicklas Nordborg, 15 years ago

References #1015: Add reporter list from tables that list reporters/reporter info

It is now possible to create reporter lists from features, wells and raw data, eg. all DataQuery?-based item types. Creating the lists using queries from the dynamic database needs a different solution.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.9 KB
Line 
1<%-- $Id: index.jsp 4305 2008-05-21 11:11:20Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Johan Enell, Jari Hakkinen, Nicklas Nordborg
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 2
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 this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330,
22  Boston, MA  02111-1307, USA.
23  ------------------------------------------------------------------
24
25  @author Nicklas
26  @version 2.0
27--%>
28<%@ page session="false"
29  import="net.sf.basedb.core.SessionControl"
30  import="net.sf.basedb.core.DbControl"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.ExtendedProperties"
34  import="net.sf.basedb.core.ExtendedProperty"
35  import="net.sf.basedb.core.ReporterBatcher"
36  import="net.sf.basedb.core.Reporter"
37  import="net.sf.basedb.core.ReporterType"
38  import="net.sf.basedb.core.FileType"
39  import="net.sf.basedb.core.data.ReporterData"
40  import="net.sf.basedb.core.Permission"
41  import="net.sf.basedb.core.DataQuery"
42  import="net.sf.basedb.core.PermissionDeniedException"
43  import="net.sf.basedb.core.BaseException"
44  import="net.sf.basedb.core.User"
45  import="net.sf.basedb.util.RemovableUtil"
46  import="net.sf.basedb.util.ShareableUtil"
47  import="net.sf.basedb.clients.web.Base"
48  import="net.sf.basedb.clients.web.WebException"
49  import="net.sf.basedb.util.Values"
50  import="net.sf.basedb.clients.web.util.HTML"
51  import="java.util.Enumeration"
52  import="java.util.List"
53%>
54<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
55<%!
56  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,externalId,symbol,description");
57  private static final Item itemType = Item.REPORTER;
58%>
59<%
60final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
61final String ID = sc.getId();
62final String cmd = request.getParameter("cmd");
63final String root = request.getContextPath()+"/";
64final String mode = request.getParameter("mode");
65final String callback = request.getParameter("callback");
66final String itemId = request.getParameter("item_id");
67final String listPage = "list_reporters.jsp?ID="+ID
68  +(mode == null ? "" : "&mode="+mode)
69  +(callback == null ? "" : "&callback="+callback)
70  +(itemId == null ? "" : "&item_id="+itemId);
71final String viewPage = "view_reporter.jsp?ID="+ID;
72final String editPage = "edit_reporter.jsp?ID="+ID;
73
74String forward = null;
75String redirect = null;
76String message = null;
77DbControl dc = null;
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    final int maxRecent = Base.getMaxRecent(sc);
128    dc = sc.newDbControl();
129    ReporterData reporter = (ReporterData)cc.getObject("item");
130    if (reporter == null)
131    {
132      reporter = Reporter.getNew(Values.getStringOrNull(request.getParameter("externalId")));
133    }
134    else
135    {
136      reporter.setExternalId(Values.getStringOrNull(request.getParameter("externalId")));
137    }
138    reporter.setName(Values.getStringOrNull(request.getParameter("name")));
139    reporter.setDescription(Values.getStringOrNull(request.getParameter("description")));
140    reporter.setSymbol(Values.getStringOrNull(request.getParameter("symbol")));
141    int reporterTypeId = Values.getInt(request.getParameter("reportertype_id"), -1);
142    if (reporterTypeId >= 0) // < 0 = denied or unchanged
143    {
144      ReporterType rt = reporterTypeId == 0 ? null : ReporterType.getById(dc, reporterTypeId);
145      Reporter.setReporterType(reporter, rt);
146      if (rt != null) cc.setRecent(rt, maxRecent);
147    }
148    List<ExtendedProperty> reporterProperties = ExtendedProperties.getProperties("ReporterData");
149    if (reporterProperties != null)
150    {
151      for (ExtendedProperty ep : reporterProperties)
152      {
153        String name = ep.getName();
154        Object value = ep.getType().parseString(Values.getStringOrNull(request.getParameter(name)));
155        reporter.setExtended(name, value);
156      }
157    }
158    ReporterBatcher batcher = ReporterBatcher.getNew(dc);
159    if (reporter.getId() != 0)
160    {
161      message = "Reporter updated";
162      batcher.update(reporter);
163    }
164    else
165    {
166      message = "Reporter created";
167      batcher.insert(reporter);
168    }
169    batcher.close();
170    dc.commit();
171    cc.removeObject("item");
172  }
173  else if ("DeleteItem".equals(cmd))
174  {
175    // Delete a single item and then return to the list page
176    dc = sc.newDbControl();
177    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
178    ReporterBatcher batcher = ReporterBatcher.getNew(dc);
179    try
180    {
181      batcher.delete(cc.getId());
182      batcher.close();
183      dc.commit();   
184      redirect = listPage;
185    }
186    catch (BaseException bex)
187    {
188      message = "The reporter can not be deleted. " +
189        "Probably because it is used by other items";
190      redirect = viewPage + "&popmessage="+HTML.urlEncode(message);
191    }
192  }
193  else if ("DeleteItems".equals(cmd))
194  {
195    // Delete all selected items on the list page
196    dc = sc.newDbControl();
197    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
198    ReporterBatcher batcher = ReporterBatcher.getNew(dc);
199    batcher.setBatchSize(1);
200    int notDeleted = 0;
201    for (int reporterId : cc.getSelected())
202    {
203      try
204      {
205        batcher.delete(reporterId);
206      }
207      catch (BaseException bex)
208      {
209        notDeleted++;
210      }     
211    }   
212    dc.commit();
213    message = notDeleted > 0 ? notDeleted + " reporters can not be deleted. " +
214        "Probably because they are used by other items" : null;
215    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
216  }
217  else if ("ExportItems".equals(cmd))
218  {
219    // Run an export plugin in a list context
220    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
221    final DataQuery<ReporterData> query = Reporter.getQuery();
222    cc.configureQuery(query, true);
223    cc.setQuery(query);
224    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+reporters";
225  }
226  else if ("ExportItem".equals(cmd))
227  {
228    // Run an export plugin in single-item context
229    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
230    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+reporter";
231  }
232  else if ("ImportItems".equals(cmd))
233  {
234    // Run an import plugin in a list context
235    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
236    final DataQuery<ReporterData> query = Reporter.getQuery();
237    cc.configureQuery(query, true);
238    cc.setQuery(query);
239    // Set file type filter
240    ItemContext fileContext = sc.getCurrentContext(Item.FILE);
241    fileContext.setPropertyFilter(FileType.getPropertyFilter(FileType.REPORTER));
242    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+reporters";
243  }
244  else if ("ImportItem".equals(cmd))
245  {
246    // Run an import plugin in single-item context
247    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
248    // Set file type filter
249    ItemContext fileContext = sc.getCurrentContext(Item.FILE);
250    fileContext.setPropertyFilter(FileType.getPropertyFilter(FileType.REPORTER));
251    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+reporter";
252  }
253  else if ("RunListPlugin".equals(cmd))
254  {
255    // Run another plugin in a list context
256    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
257    final DataQuery<ReporterData> query = Reporter.getQuery();
258    cc.configureQuery(query, true);
259    cc.setQuery(query);
260    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
261  }
262  else if ("RunPlugin".equals(cmd))
263  {
264    // Run another plugin in single-item context
265    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
266    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
267  }
268  else if ("CreateReporterList".equals(cmd))
269  {
270    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
271    final DataQuery<ReporterData> query = Reporter.getQuery();
272    cc.configureQuery(query, true);
273    cc.setQuery(query);
274    redirect = "../reporterlists/index.jsp?ID="+ID+"&cmd=NewItem&addReporters=1&formId=reporters&fromContext=REPORTER";
275  }
276  else
277  {
278    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
279  }
280}
281finally
282{
283  if (dc != null) dc.close();
284}
285
286if (forward != null)
287{
288  pageContext.forward(forward);
289}
290else if (redirect != null)
291{
292  response.sendRedirect(redirect);
293}
294else if (message == null)
295{
296  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
297}
298else
299{
300  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
301}
302%>
303
Note: See TracBrowser for help on using the repository browser.