852 |
30 Jun 05 |
nicklas |
1 |
<%-- $Id$ |
852 |
30 Jun 05 |
nicklas |
2 |
------------------------------------------------------------------ |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Nicklas Nordborg |
5425 |
23 Sep 10 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
852 |
30 Jun 05 |
nicklas |
5 |
|
2304 |
22 May 06 |
jari |
6 |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
7 |
Available at http://base.thep.lu.se/ |
852 |
30 Jun 05 |
nicklas |
8 |
|
852 |
30 Jun 05 |
nicklas |
9 |
BASE is free software; you can redistribute it and/or |
852 |
30 Jun 05 |
nicklas |
10 |
modify it under the terms of the GNU General Public License |
4476 |
05 Sep 08 |
jari |
11 |
as published by the Free Software Foundation; either version 3 |
852 |
30 Jun 05 |
nicklas |
12 |
of the License, or (at your option) any later version. |
852 |
30 Jun 05 |
nicklas |
13 |
|
852 |
30 Jun 05 |
nicklas |
14 |
BASE is distributed in the hope that it will be useful, |
852 |
30 Jun 05 |
nicklas |
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
852 |
30 Jun 05 |
nicklas |
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
852 |
30 Jun 05 |
nicklas |
17 |
GNU General Public License for more details. |
852 |
30 Jun 05 |
nicklas |
18 |
|
852 |
30 Jun 05 |
nicklas |
19 |
You should have received a copy of the GNU General Public License |
4510 |
11 Sep 08 |
jari |
20 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
852 |
30 Jun 05 |
nicklas |
21 |
------------------------------------------------------------------ |
852 |
30 Jun 05 |
nicklas |
22 |
|
852 |
30 Jun 05 |
nicklas |
23 |
@author Nicklas |
852 |
30 Jun 05 |
nicklas |
24 |
@version 2.0 |
852 |
30 Jun 05 |
nicklas |
25 |
--%> |
5426 |
24 Sep 10 |
nicklas |
26 |
<%@ page pageEncoding="UTF-8" session="false" |
852 |
30 Jun 05 |
nicklas |
27 |
import="net.sf.basedb.core.SessionControl" |
852 |
30 Jun 05 |
nicklas |
28 |
import="net.sf.basedb.core.DbControl" |
852 |
30 Jun 05 |
nicklas |
29 |
import="net.sf.basedb.core.Item" |
1866 |
30 Jan 06 |
nicklas |
30 |
import="net.sf.basedb.core.Include" |
852 |
30 Jun 05 |
nicklas |
31 |
import="net.sf.basedb.core.BioSource" |
5643 |
26 May 11 |
nicklas |
32 |
import="net.sf.basedb.core.ItemSubtype" |
1418 |
07 Oct 05 |
nicklas |
33 |
import="net.sf.basedb.core.ItemQuery" |
1418 |
07 Oct 05 |
nicklas |
34 |
import="net.sf.basedb.core.ItemResultIterator" |
852 |
30 Jun 05 |
nicklas |
35 |
import="net.sf.basedb.core.Permission" |
1866 |
30 Jan 06 |
nicklas |
36 |
import="net.sf.basedb.core.ItemContext" |
1866 |
30 Jan 06 |
nicklas |
37 |
import="net.sf.basedb.core.MultiPermissions" |
4587 |
15 Oct 08 |
martin |
38 |
import="net.sf.basedb.core.OwnedItem" |
1866 |
30 Jan 06 |
nicklas |
39 |
import="net.sf.basedb.core.PermissionDeniedException" |
1866 |
30 Jan 06 |
nicklas |
40 |
import="net.sf.basedb.core.ItemAlreadyExistsException" |
4901 |
23 Apr 09 |
martin |
41 |
import="net.sf.basedb.core.Sample" |
4901 |
23 Apr 09 |
martin |
42 |
import="net.sf.basedb.core.query.Hql" |
4901 |
23 Apr 09 |
martin |
43 |
import="net.sf.basedb.core.query.Orders" |
4901 |
23 Apr 09 |
martin |
44 |
import="net.sf.basedb.core.query.Restrictions" |
4901 |
23 Apr 09 |
martin |
45 |
import="net.sf.basedb.core.query.Expressions" |
1866 |
30 Jan 06 |
nicklas |
46 |
import="net.sf.basedb.util.RemovableUtil" |
1866 |
30 Jan 06 |
nicklas |
47 |
import="net.sf.basedb.util.ShareableUtil" |
2916 |
15 Nov 06 |
nicklas |
48 |
import="net.sf.basedb.util.OwnableUtil" |
4901 |
23 Apr 09 |
martin |
49 |
import="net.sf.basedb.util.formatter.NameableFormatter" |
852 |
30 Jun 05 |
nicklas |
50 |
import="net.sf.basedb.clients.web.Base" |
1866 |
30 Jan 06 |
nicklas |
51 |
import="net.sf.basedb.clients.web.WebException" |
2753 |
20 Oct 06 |
nicklas |
52 |
import="net.sf.basedb.util.Values" |
4901 |
23 Apr 09 |
martin |
53 |
import="net.sf.basedb.clients.web.plugins.ItemQueryLoader" |
4901 |
23 Apr 09 |
martin |
54 |
import="net.sf.basedb.clients.web.util.HTML" |
5492 |
16 Nov 10 |
nicklas |
55 |
import="net.sf.basedb.core.plugin.GuiContext" |
5492 |
16 Nov 10 |
nicklas |
56 |
import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
5492 |
16 Nov 10 |
nicklas |
57 |
import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
5492 |
16 Nov 10 |
nicklas |
58 |
import="net.sf.basedb.clients.web.extensions.JspContext" |
5492 |
16 Nov 10 |
nicklas |
59 |
import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
7604 |
25 Feb 19 |
nicklas |
60 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveAction" |
5492 |
16 Nov 10 |
nicklas |
61 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer" |
6038 |
29 Mar 12 |
nicklas |
62 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer" |
7604 |
25 Feb 19 |
nicklas |
63 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnAction" |
6038 |
29 Mar 12 |
nicklas |
64 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil" |
1866 |
30 Jan 06 |
nicklas |
65 |
import="java.util.Enumeration" |
1866 |
30 Jan 06 |
nicklas |
66 |
import="java.util.Set" |
1866 |
30 Jan 06 |
nicklas |
67 |
import="java.util.HashSet" |
933 |
14 Jul 05 |
nicklas |
68 |
import="java.util.List" |
1866 |
30 Jan 06 |
nicklas |
69 |
import="java.util.ArrayList" |
1866 |
30 Jan 06 |
nicklas |
70 |
import="java.util.Collections" |
852 |
30 Jun 05 |
nicklas |
71 |
%> |
852 |
30 Jun 05 |
nicklas |
72 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
852 |
30 Jun 05 |
nicklas |
73 |
<%! |
5643 |
26 May 11 |
nicklas |
74 |
private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,itemSubtype,samples,description"); |
1866 |
30 Jan 06 |
nicklas |
75 |
private static final Item itemType = Item.BIOSOURCE; |
4901 |
23 Apr 09 |
martin |
76 |
|
4901 |
23 Apr 09 |
martin |
77 |
private static void registerExportUtils(ItemContext cc) |
4901 |
23 Apr 09 |
martin |
78 |
{ |
4901 |
23 Apr 09 |
martin |
79 |
// Register formatters |
4901 |
23 Apr 09 |
martin |
80 |
cc.setObject("export.formatter.&children(name)", new NameableFormatter()); |
4901 |
23 Apr 09 |
martin |
81 |
|
4901 |
23 Apr 09 |
martin |
82 |
// Register dataloaders |
4901 |
23 Apr 09 |
martin |
83 |
String bioSourceParameter = "bioSource"; |
4901 |
23 Apr 09 |
martin |
84 |
final ItemQuery<Sample> sampleQuery = Sample.getQuery(); |
4901 |
23 Apr 09 |
martin |
85 |
sampleQuery.include(cc.getInclude()); |
4901 |
23 Apr 09 |
martin |
86 |
sampleQuery.restrict(Restrictions.eq(Hql.property("parent"), Expressions.parameter(bioSourceParameter))); |
4901 |
23 Apr 09 |
martin |
87 |
sampleQuery.order(Orders.asc(Hql.property("name"))); |
7604 |
25 Feb 19 |
nicklas |
88 |
cc.setObject("export.dataloader.&children(name)", new ItemQueryLoader<BioSource>(sampleQuery, bioSourceParameter)); |
4901 |
23 Apr 09 |
martin |
89 |
} |
852 |
30 Jun 05 |
nicklas |
90 |
%> |
852 |
30 Jun 05 |
nicklas |
91 |
<% |
1866 |
30 Jan 06 |
nicklas |
92 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
852 |
30 Jun 05 |
nicklas |
93 |
final String ID = sc.getId(); |
1866 |
30 Jan 06 |
nicklas |
94 |
final String cmd = request.getParameter("cmd"); |
1866 |
30 Jan 06 |
nicklas |
95 |
final String root = request.getContextPath()+"/"; |
1866 |
30 Jan 06 |
nicklas |
96 |
final String mode = request.getParameter("mode"); |
1866 |
30 Jan 06 |
nicklas |
97 |
final String callback = request.getParameter("callback"); |
1866 |
30 Jan 06 |
nicklas |
98 |
final String itemId = request.getParameter("item_id"); |
1866 |
30 Jan 06 |
nicklas |
99 |
final String listPage = "list_biosources.jsp?ID="+ID |
1866 |
30 Jan 06 |
nicklas |
100 |
+(mode == null ? "" : "&mode="+mode) |
1866 |
30 Jan 06 |
nicklas |
101 |
+(callback == null ? "" : "&callback="+callback) |
1866 |
30 Jan 06 |
nicklas |
102 |
+(itemId == null ? "" : "&item_id="+itemId); |
1866 |
30 Jan 06 |
nicklas |
103 |
final String viewPage = "view_biosource.jsp?ID="+ID; |
1866 |
30 Jan 06 |
nicklas |
104 |
final String editPage = "edit_biosource.jsp?ID="+ID; |
852 |
30 Jun 05 |
nicklas |
105 |
|
1866 |
30 Jan 06 |
nicklas |
106 |
String forward = null; |
1866 |
30 Jan 06 |
nicklas |
107 |
String redirect = null; |
1866 |
30 Jan 06 |
nicklas |
108 |
String message = null; |
1866 |
30 Jan 06 |
nicklas |
109 |
DbControl dc = null; |
1866 |
30 Jan 06 |
nicklas |
110 |
|
852 |
30 Jun 05 |
nicklas |
111 |
try |
852 |
30 Jun 05 |
nicklas |
112 |
{ |
1866 |
30 Jan 06 |
nicklas |
113 |
if (cmd == null || "List".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
114 |
{ |
1866 |
30 Jan 06 |
nicklas |
115 |
// Display the list page without updatinging the current context |
2811 |
26 Oct 06 |
nicklas |
116 |
Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true); |
1866 |
30 Jan 06 |
nicklas |
117 |
redirect = listPage; |
1866 |
30 Jan 06 |
nicklas |
118 |
} |
1866 |
30 Jan 06 |
nicklas |
119 |
else if ("UpdateContext".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
120 |
{ |
1866 |
30 Jan 06 |
nicklas |
121 |
// Display the list page after updating the current context from the request parameters |
1866 |
30 Jan 06 |
nicklas |
122 |
Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
123 |
redirect = listPage; |
1866 |
30 Jan 06 |
nicklas |
124 |
} |
1866 |
30 Jan 06 |
nicklas |
125 |
else if ("LoadContext".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
126 |
{ |
1866 |
30 Jan 06 |
nicklas |
127 |
// Display the list page after loading a saved context |
1866 |
30 Jan 06 |
nicklas |
128 |
int contextId = Values.getInt(request.getParameter("context")); |
1866 |
30 Jan 06 |
nicklas |
129 |
Base.loadContext(sc, contextId, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
130 |
redirect = listPage; |
1866 |
30 Jan 06 |
nicklas |
131 |
} |
945 |
15 Jul 05 |
nicklas |
132 |
|
1866 |
30 Jan 06 |
nicklas |
133 |
else if ("ViewItem".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
134 |
{ |
1866 |
30 Jan 06 |
nicklas |
135 |
// Display the view page for a single item |
1866 |
30 Jan 06 |
nicklas |
136 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
137 |
forward = viewPage; |
1866 |
30 Jan 06 |
nicklas |
138 |
} |
1866 |
30 Jan 06 |
nicklas |
139 |
else if ("EditItem".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
140 |
{ |
1866 |
30 Jan 06 |
nicklas |
141 |
// Display the edit page for a single item (should be opened in a popup) |
1866 |
30 Jan 06 |
nicklas |
142 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
143 |
redirect = editPage; |
1866 |
30 Jan 06 |
nicklas |
144 |
} |
1866 |
30 Jan 06 |
nicklas |
145 |
else if ("NewItem".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
146 |
{ |
1866 |
30 Jan 06 |
nicklas |
147 |
// Display the edit page for a new item (should be opened in a popup) |
1866 |
30 Jan 06 |
nicklas |
148 |
if (!sc.hasPermission(Permission.CREATE, itemType)) |
852 |
30 Jun 05 |
nicklas |
149 |
{ |
1866 |
30 Jan 06 |
nicklas |
150 |
throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
852 |
30 Jun 05 |
nicklas |
151 |
} |
1866 |
30 Jan 06 |
nicklas |
152 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
153 |
cc.setId(0); |
1866 |
30 Jan 06 |
nicklas |
154 |
redirect = editPage; |
1866 |
30 Jan 06 |
nicklas |
155 |
} |
1866 |
30 Jan 06 |
nicklas |
156 |
else if ("UpdateItem".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
157 |
{ |
1866 |
30 Jan 06 |
nicklas |
158 |
// Update the properties on an item (will close the popup) |
1866 |
30 Jan 06 |
nicklas |
159 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
5643 |
26 May 11 |
nicklas |
160 |
final int maxRecent = Base.getMaxRecent(sc); |
7954 |
12 May 21 |
nicklas |
161 |
dc = sc.newDbControl(":Edit "+itemType); |
7605 |
26 Feb 19 |
nicklas |
162 |
BioSource bioSource = cc.getObject("item"); |
1866 |
30 Jan 06 |
nicklas |
163 |
if (bioSource == null) |
852 |
30 Jun 05 |
nicklas |
164 |
{ |
1866 |
30 Jan 06 |
nicklas |
165 |
bioSource = BioSource.getNew(dc); |
1866 |
30 Jan 06 |
nicklas |
166 |
message = "Biosource created"; |
1866 |
30 Jan 06 |
nicklas |
167 |
dc.saveItem(bioSource); |
852 |
30 Jun 05 |
nicklas |
168 |
} |
1866 |
30 Jan 06 |
nicklas |
169 |
else |
852 |
30 Jun 05 |
nicklas |
170 |
{ |
5060 |
19 Aug 09 |
nicklas |
171 |
dc.reattachItem(bioSource, false); |
1866 |
30 Jan 06 |
nicklas |
172 |
message = "Biosource updated"; |
852 |
30 Jun 05 |
nicklas |
173 |
} |
5492 |
16 Nov 10 |
nicklas |
174 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.BIOSOURCE), bioSource); |
7604 |
25 Feb 19 |
nicklas |
175 |
ExtensionsInvoker<OnSaveAction> invoker = EditUtil.useOnSaveExtensions(jspContext); |
5492 |
16 Nov 10 |
nicklas |
176 |
try |
5492 |
16 Nov 10 |
nicklas |
177 |
{ |
5492 |
16 Nov 10 |
nicklas |
178 |
bioSource.setName(Values.getStringOrNull(request.getParameter("name"))); |
5492 |
16 Nov 10 |
nicklas |
179 |
bioSource.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
5492 |
16 Nov 10 |
nicklas |
180 |
bioSource.setExternalId(Values.getStringOrNull(request.getParameter("external_id"))); |
5492 |
16 Nov 10 |
nicklas |
181 |
|
5643 |
26 May 11 |
nicklas |
182 |
int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1); |
5643 |
26 May 11 |
nicklas |
183 |
if (subtypeId >= 0) // < 0 = denied or unchanged |
5643 |
26 May 11 |
nicklas |
184 |
{ |
5643 |
26 May 11 |
nicklas |
185 |
ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId); |
5643 |
26 May 11 |
nicklas |
186 |
bioSource.setItemSubtype(subtype); |
7703 |
11 Apr 19 |
nicklas |
187 |
cc.setRecent(Item.ITEMSUBTYPE, subtype, maxRecent); |
5643 |
26 May 11 |
nicklas |
188 |
} |
5643 |
26 May 11 |
nicklas |
189 |
|
5492 |
16 Nov 10 |
nicklas |
190 |
// Annotations tab |
5492 |
16 Nov 10 |
nicklas |
191 |
Base.updateAnnotations(dc, bioSource, bioSource, request); |
5492 |
16 Nov 10 |
nicklas |
192 |
|
5492 |
16 Nov 10 |
nicklas |
193 |
// OnSave extensions |
5492 |
16 Nov 10 |
nicklas |
194 |
invoker.render(OnSaveRenderer.ON_SAVE); |
5492 |
16 Nov 10 |
nicklas |
195 |
dc.commit(); |
5492 |
16 Nov 10 |
nicklas |
196 |
invoker.render(OnSaveRenderer.ON_COMMIT); |
5492 |
16 Nov 10 |
nicklas |
197 |
} |
5492 |
16 Nov 10 |
nicklas |
198 |
catch (Exception ex) |
5492 |
16 Nov 10 |
nicklas |
199 |
{ |
5492 |
16 Nov 10 |
nicklas |
200 |
invoker.render(OnSaveRenderer.onRollback(ex)); |
5492 |
16 Nov 10 |
nicklas |
201 |
throw ex; |
5492 |
16 Nov 10 |
nicklas |
202 |
} |
5492 |
16 Nov 10 |
nicklas |
203 |
finally |
5492 |
16 Nov 10 |
nicklas |
204 |
{ |
5492 |
16 Nov 10 |
nicklas |
205 |
cc.removeObject("item"); |
5492 |
16 Nov 10 |
nicklas |
206 |
} |
1866 |
30 Jan 06 |
nicklas |
207 |
} |
1866 |
30 Jan 06 |
nicklas |
208 |
else if ("DeleteItem".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
209 |
{ |
1866 |
30 Jan 06 |
nicklas |
210 |
// Delete a single item and then return to the view page |
7954 |
12 May 21 |
nicklas |
211 |
dc = sc.newDbControl(":Delete "+itemType); |
1866 |
30 Jan 06 |
nicklas |
212 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
213 |
RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true); |
1866 |
30 Jan 06 |
nicklas |
214 |
dc.commit(); |
1866 |
30 Jan 06 |
nicklas |
215 |
redirect = viewPage; |
1866 |
30 Jan 06 |
nicklas |
216 |
} |
1866 |
30 Jan 06 |
nicklas |
217 |
else if ("DeleteItems".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
218 |
{ |
1866 |
30 Jan 06 |
nicklas |
219 |
// Delete all selected items on the list page |
7954 |
12 May 21 |
nicklas |
220 |
dc = sc.newDbControl(":Delete "+itemType); |
1866 |
30 Jan 06 |
nicklas |
221 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
222 |
int numTotal = cc.getSelected().size(); |
1866 |
30 Jan 06 |
nicklas |
223 |
int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true); |
1866 |
30 Jan 06 |
nicklas |
224 |
dc.commit(); |
1866 |
30 Jan 06 |
nicklas |
225 |
if (numTotal != numRemoved) |
852 |
30 Jun 05 |
nicklas |
226 |
{ |
1866 |
30 Jan 06 |
nicklas |
227 |
message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
852 |
30 Jun 05 |
nicklas |
228 |
} |
6192 |
31 Oct 12 |
nicklas |
229 |
redirect = listPage; |
1866 |
30 Jan 06 |
nicklas |
230 |
} |
1866 |
30 Jan 06 |
nicklas |
231 |
else if ("RestoreItem".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
232 |
{ |
1866 |
30 Jan 06 |
nicklas |
233 |
// Restore a single item and then return to the view page |
7954 |
12 May 21 |
nicklas |
234 |
dc = sc.newDbControl(":Restore "+itemType); |
1866 |
30 Jan 06 |
nicklas |
235 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
236 |
RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false); |
1866 |
30 Jan 06 |
nicklas |
237 |
dc.commit(); |
1866 |
30 Jan 06 |
nicklas |
238 |
redirect = viewPage; |
1866 |
30 Jan 06 |
nicklas |
239 |
} |
1866 |
30 Jan 06 |
nicklas |
240 |
else if ("RestoreItems".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
241 |
{ |
1866 |
30 Jan 06 |
nicklas |
242 |
// Restore all selected items on the list page |
7954 |
12 May 21 |
nicklas |
243 |
dc = sc.newDbControl(":Restore "+itemType); |
1866 |
30 Jan 06 |
nicklas |
244 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
245 |
int numTotal = cc.getSelected().size(); |
1866 |
30 Jan 06 |
nicklas |
246 |
int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false); |
1866 |
30 Jan 06 |
nicklas |
247 |
dc.commit(); |
1866 |
30 Jan 06 |
nicklas |
248 |
if (numTotal != numRemoved) |
852 |
30 Jun 05 |
nicklas |
249 |
{ |
2528 |
15 Aug 06 |
martin |
250 |
message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
852 |
30 Jun 05 |
nicklas |
251 |
} |
6192 |
31 Oct 12 |
nicklas |
252 |
redirect = listPage; |
1866 |
30 Jan 06 |
nicklas |
253 |
} |
1866 |
30 Jan 06 |
nicklas |
254 |
else if ("ShareItem".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
255 |
{ |
1866 |
30 Jan 06 |
nicklas |
256 |
// Display a popup window for sharing a single item |
7954 |
12 May 21 |
nicklas |
257 |
dc = sc.newDbControl(":Share "+itemType); |
1866 |
30 Jan 06 |
nicklas |
258 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
259 |
MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId())); |
1866 |
30 Jan 06 |
nicklas |
260 |
dc.close(); |
1866 |
30 Jan 06 |
nicklas |
261 |
cc.setObject("MultiPermissions", permissions); |
1866 |
30 Jan 06 |
nicklas |
262 |
redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
1866 |
30 Jan 06 |
nicklas |
263 |
} |
1866 |
30 Jan 06 |
nicklas |
264 |
else if ("ShareItems".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
265 |
{ |
1866 |
30 Jan 06 |
nicklas |
266 |
// Display a popup window for sharing all selected items on the list page |
7954 |
12 May 21 |
nicklas |
267 |
dc = sc.newDbControl(":Share "+itemType); |
1866 |
30 Jan 06 |
nicklas |
268 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
269 |
MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected()); |
1866 |
30 Jan 06 |
nicklas |
270 |
dc.close(); |
1866 |
30 Jan 06 |
nicklas |
271 |
cc.setObject("MultiPermissions", permissions); |
1866 |
30 Jan 06 |
nicklas |
272 |
redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
1866 |
30 Jan 06 |
nicklas |
273 |
} |
4578 |
13 Oct 08 |
martin |
274 |
else if ("SetOwnerOfItem".equals(cmd)) |
2916 |
15 Nov 06 |
nicklas |
275 |
{ |
4578 |
13 Oct 08 |
martin |
276 |
// Change owner of items selected on a list page |
7954 |
12 May 21 |
nicklas |
277 |
dc = sc.newDbControl(":Set owner of "+itemType); |
2916 |
15 Nov 06 |
nicklas |
278 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
4587 |
15 Oct 08 |
martin |
279 |
OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId()); |
4587 |
15 Oct 08 |
martin |
280 |
cc.setObject("OwnedItems", Collections.singleton(item)); |
4578 |
13 Oct 08 |
martin |
281 |
redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
2916 |
15 Nov 06 |
nicklas |
282 |
} |
4578 |
13 Oct 08 |
martin |
283 |
else if ("SetOwnerOfItems".equals(cmd)) |
2916 |
15 Nov 06 |
nicklas |
284 |
{ |
4578 |
13 Oct 08 |
martin |
285 |
// Change owner of items selected on a list page |
7954 |
12 May 21 |
nicklas |
286 |
dc = sc.newDbControl(":Set owner of "+itemType); |
2916 |
15 Nov 06 |
nicklas |
287 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
4587 |
15 Oct 08 |
martin |
288 |
Set<OwnedItem> items = new HashSet<OwnedItem>(); |
4587 |
15 Oct 08 |
martin |
289 |
for (Integer id : cc.getSelected()) |
4587 |
15 Oct 08 |
martin |
290 |
{ |
4587 |
15 Oct 08 |
martin |
291 |
if (id != null) items.add((OwnedItem)itemType.getById(dc, id)); |
4587 |
15 Oct 08 |
martin |
292 |
} |
4587 |
15 Oct 08 |
martin |
293 |
dc.close(); |
4587 |
15 Oct 08 |
martin |
294 |
cc.setObject("OwnedItems", items); |
4578 |
13 Oct 08 |
martin |
295 |
redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
2916 |
15 Nov 06 |
nicklas |
296 |
} |
1866 |
30 Jan 06 |
nicklas |
297 |
else if ("ExportItems".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
298 |
{ |
1866 |
30 Jan 06 |
nicklas |
299 |
// Run an export plugin in a list context |
1866 |
30 Jan 06 |
nicklas |
300 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
4901 |
23 Apr 09 |
martin |
301 |
registerExportUtils(cc); |
1866 |
30 Jan 06 |
nicklas |
302 |
final ItemQuery<BioSource> query = BioSource.getQuery(); |
7954 |
12 May 21 |
nicklas |
303 |
dc = sc.newDbControl(":Export "+itemType); |
7914 |
23 Feb 21 |
nicklas |
304 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
305 |
cc.configureQuery(dc, query, jspContext, true); |
6038 |
29 Mar 12 |
nicklas |
306 |
cc.setQuery(query); |
7604 |
25 Feb 19 |
nicklas |
307 |
ExtensionsInvoker<ListColumnAction<BioSource,?>> listInvoker = ListColumnUtil.useExtensions(jspContext); |
7604 |
25 Feb 19 |
nicklas |
308 |
listInvoker.render(new ListColumnExportRenderer<BioSource>(cc)); |
5590 |
16 Mar 11 |
nicklas |
309 |
dc.close(); |
1866 |
30 Jan 06 |
nicklas |
310 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+biosources"; |
1866 |
30 Jan 06 |
nicklas |
311 |
} |
1866 |
30 Jan 06 |
nicklas |
312 |
else if ("ExportItem".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
313 |
{ |
1866 |
30 Jan 06 |
nicklas |
314 |
// Run an export plugin in single-item context |
1866 |
30 Jan 06 |
nicklas |
315 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
4901 |
23 Apr 09 |
martin |
316 |
registerExportUtils(cc); |
1866 |
30 Jan 06 |
nicklas |
317 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+biosource"; |
1866 |
30 Jan 06 |
nicklas |
318 |
} |
1866 |
30 Jan 06 |
nicklas |
319 |
else if ("ImportItems".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
320 |
{ |
1866 |
30 Jan 06 |
nicklas |
321 |
// Run an import plugin in a list context |
1866 |
30 Jan 06 |
nicklas |
322 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
323 |
final ItemQuery<BioSource> query = BioSource.getQuery(); |
7954 |
12 May 21 |
nicklas |
324 |
dc = sc.newDbControl(":Import "+itemType); |
7914 |
23 Feb 21 |
nicklas |
325 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
326 |
cc.configureQuery(dc, query, jspContext, true); |
5590 |
16 Mar 11 |
nicklas |
327 |
dc.close(); |
1866 |
30 Jan 06 |
nicklas |
328 |
cc.setQuery(query); |
1866 |
30 Jan 06 |
nicklas |
329 |
redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+biosources"; |
1866 |
30 Jan 06 |
nicklas |
330 |
} |
1866 |
30 Jan 06 |
nicklas |
331 |
else if ("ImportItem".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
332 |
{ |
1866 |
30 Jan 06 |
nicklas |
333 |
// Run an import plugin in single-item context |
1866 |
30 Jan 06 |
nicklas |
334 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
335 |
redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+biosource"; |
1866 |
30 Jan 06 |
nicklas |
336 |
} |
1866 |
30 Jan 06 |
nicklas |
337 |
else if ("RunListPlugin".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
338 |
{ |
1866 |
30 Jan 06 |
nicklas |
339 |
// Run another plugin in a list context |
1866 |
30 Jan 06 |
nicklas |
340 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
341 |
final ItemQuery<BioSource> query = BioSource.getQuery(); |
7954 |
12 May 21 |
nicklas |
342 |
dc = sc.newDbControl(":Run plugin "+itemType); |
7914 |
23 Feb 21 |
nicklas |
343 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
344 |
cc.configureQuery(dc, query, jspContext, true); |
5590 |
16 Mar 11 |
nicklas |
345 |
dc.close(); |
1866 |
30 Jan 06 |
nicklas |
346 |
cc.setQuery(query); |
1866 |
30 Jan 06 |
nicklas |
347 |
redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
1866 |
30 Jan 06 |
nicklas |
348 |
} |
1866 |
30 Jan 06 |
nicklas |
349 |
else if ("RunPlugin".equals(cmd)) |
1866 |
30 Jan 06 |
nicklas |
350 |
{ |
1866 |
30 Jan 06 |
nicklas |
351 |
// Run another plugin in single-item context |
1866 |
30 Jan 06 |
nicklas |
352 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1866 |
30 Jan 06 |
nicklas |
353 |
redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
1866 |
30 Jan 06 |
nicklas |
354 |
} |
6756 |
20 Feb 15 |
nicklas |
355 |
else if ("CreateItemList".equals(cmd)) |
4712 |
19 Dec 08 |
nicklas |
356 |
{ |
4712 |
19 Dec 08 |
nicklas |
357 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
4712 |
19 Dec 08 |
nicklas |
358 |
final ItemQuery<BioSource> query = BioSource.getQuery(); |
7954 |
12 May 21 |
nicklas |
359 |
dc = sc.newDbControl(":Create "+itemType+" item list"); |
7914 |
23 Feb 21 |
nicklas |
360 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
361 |
cc.configureQuery(dc, query, jspContext, true); |
5590 |
16 Mar 11 |
nicklas |
362 |
dc.close(); |
4712 |
19 Dec 08 |
nicklas |
363 |
cc.setQuery(query); |
6756 |
20 Feb 15 |
nicklas |
364 |
redirect = "../../views/itemlists/index.jsp?ID="+ID+"&cmd=NewItem&addItems=1&memberType=BIOSOURCE&formId=biosources"; |
4712 |
19 Dec 08 |
nicklas |
365 |
} |
7813 |
19 May 20 |
nicklas |
366 |
else if ("AddItemsToList".equals(cmd)) |
7813 |
19 May 20 |
nicklas |
367 |
{ |
7813 |
19 May 20 |
nicklas |
368 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
7813 |
19 May 20 |
nicklas |
369 |
final ItemQuery<BioSource> query = BioSource.getQuery(); |
7954 |
12 May 21 |
nicklas |
370 |
dc = sc.newDbControl(":Add to "+itemType+" item list"); |
7914 |
23 Feb 21 |
nicklas |
371 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
372 |
cc.configureQuery(dc, query, jspContext, true); |
7813 |
19 May 20 |
nicklas |
373 |
dc.close(); |
7813 |
19 May 20 |
nicklas |
374 |
cc.setQuery(query); |
7813 |
19 May 20 |
nicklas |
375 |
redirect = "../../views/itemlists/add_items.jsp?ID="+ID+"&memberType=BIOSOURCE&formId=biosources"; |
7813 |
19 May 20 |
nicklas |
376 |
} |
1866 |
30 Jan 06 |
nicklas |
377 |
else |
1866 |
30 Jan 06 |
nicklas |
378 |
{ |
1866 |
30 Jan 06 |
nicklas |
379 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
1866 |
30 Jan 06 |
nicklas |
380 |
} |
852 |
30 Jun 05 |
nicklas |
381 |
} |
852 |
30 Jun 05 |
nicklas |
382 |
finally |
852 |
30 Jun 05 |
nicklas |
383 |
{ |
852 |
30 Jun 05 |
nicklas |
384 |
if (dc != null) dc.close(); |
852 |
30 Jun 05 |
nicklas |
385 |
} |
1866 |
30 Jan 06 |
nicklas |
386 |
|
1866 |
30 Jan 06 |
nicklas |
387 |
if (forward != null) |
1866 |
30 Jan 06 |
nicklas |
388 |
{ |
6192 |
31 Oct 12 |
nicklas |
389 |
sc.setSessionSetting("alert-message", message); |
1866 |
30 Jan 06 |
nicklas |
390 |
pageContext.forward(forward); |
1866 |
30 Jan 06 |
nicklas |
391 |
} |
1866 |
30 Jan 06 |
nicklas |
392 |
else if (redirect != null) |
1866 |
30 Jan 06 |
nicklas |
393 |
{ |
6192 |
31 Oct 12 |
nicklas |
394 |
sc.setSessionSetting("alert-message", message); |
1866 |
30 Jan 06 |
nicklas |
395 |
response.sendRedirect(redirect); |
1866 |
30 Jan 06 |
nicklas |
396 |
} |
1866 |
30 Jan 06 |
nicklas |
397 |
else if (message == null) |
1866 |
30 Jan 06 |
nicklas |
398 |
{ |
1866 |
30 Jan 06 |
nicklas |
399 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
1866 |
30 Jan 06 |
nicklas |
400 |
} |
1866 |
30 Jan 06 |
nicklas |
401 |
else |
1866 |
30 Jan 06 |
nicklas |
402 |
{ |
1866 |
30 Jan 06 |
nicklas |
403 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
1866 |
30 Jan 06 |
nicklas |
404 |
} |
1866 |
30 Jan 06 |
nicklas |
405 |
%> |
1866 |
30 Jan 06 |
nicklas |
406 |
|