1 | <%-- $Id: index.jsp 5878 2011-11-17 11:41:31Z 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.Experiment" |
---|
32 | import="net.sf.basedb.core.RawBioAssay" |
---|
33 | import="net.sf.basedb.core.AnnotationType" |
---|
34 | import="net.sf.basedb.core.RawDataType" |
---|
35 | import="net.sf.basedb.core.RawDataTypes" |
---|
36 | import="net.sf.basedb.core.User" |
---|
37 | import="net.sf.basedb.core.Directory" |
---|
38 | import="net.sf.basedb.core.ReporterCloneTemplate" |
---|
39 | import="net.sf.basedb.core.ReporterCloneBatcher" |
---|
40 | import="net.sf.basedb.core.PluginDefinition" |
---|
41 | import="net.sf.basedb.core.Job" |
---|
42 | import="net.sf.basedb.core.ItemParameterType" |
---|
43 | import="net.sf.basedb.core.ItemQuery" |
---|
44 | import="net.sf.basedb.core.ItemResultIterator" |
---|
45 | import="net.sf.basedb.core.Permission" |
---|
46 | import="net.sf.basedb.core.ItemContext" |
---|
47 | import="net.sf.basedb.core.MultiPermissions" |
---|
48 | import="net.sf.basedb.core.OwnedItem" |
---|
49 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
50 | import="net.sf.basedb.core.ItemAlreadyExistsException" |
---|
51 | import="net.sf.basedb.core.SimpleProgressReporter" |
---|
52 | import="net.sf.basedb.core.snapshot.SnapshotManager" |
---|
53 | import="net.sf.basedb.plugins.CloneReportersPlugin" |
---|
54 | import="net.sf.basedb.util.RemovableUtil" |
---|
55 | import="net.sf.basedb.util.ShareableUtil" |
---|
56 | import="net.sf.basedb.util.OwnableUtil" |
---|
57 | import="net.sf.basedb.clients.web.Base" |
---|
58 | import="net.sf.basedb.clients.web.WebException" |
---|
59 | import="net.sf.basedb.util.Values" |
---|
60 | import="net.sf.basedb.clients.web.util.HTML" |
---|
61 | import="net.sf.basedb.util.formatter.Formatter" |
---|
62 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
63 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
64 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
65 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
66 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
67 | import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
---|
68 | import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer" |
---|
69 | import="java.util.Enumeration" |
---|
70 | import="java.util.Set" |
---|
71 | import="java.util.HashSet" |
---|
72 | import="java.util.List" |
---|
73 | import="java.util.ArrayList" |
---|
74 | import="java.util.Collections" |
---|
75 | import="java.util.Date" |
---|
76 | %> |
---|
77 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
78 | <%! |
---|
79 | private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,rawDataType,description,actions"); |
---|
80 | private static final Item itemType = Item.EXPERIMENT; |
---|
81 | %> |
---|
82 | <% |
---|
83 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
84 | final String ID = sc.getId(); |
---|
85 | final String cmd = request.getParameter("cmd"); |
---|
86 | final String root = request.getContextPath()+"/"; |
---|
87 | final String mode = request.getParameter("mode"); |
---|
88 | final String callback = request.getParameter("callback"); |
---|
89 | final String itemId = request.getParameter("item_id"); |
---|
90 | final String listPage = "list_experiments.jsp?ID="+ID |
---|
91 | +(mode == null ? "" : "&mode="+mode) |
---|
92 | +(callback == null ? "" : "&callback="+callback) |
---|
93 | +(itemId == null ? "" : "&item_id="+itemId); |
---|
94 | final String viewPage = "view_experiment.jsp?ID="+ID; |
---|
95 | final String editPage = "edit_experiment.jsp?ID="+ID; |
---|
96 | |
---|
97 | String forward = null; |
---|
98 | String redirect = null; |
---|
99 | String message = null; |
---|
100 | DbControl dc = null; |
---|
101 | try |
---|
102 | { |
---|
103 | if (cmd == null || "List".equals(cmd)) |
---|
104 | { |
---|
105 | // Display the list page without updatinging the current context |
---|
106 | Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true); |
---|
107 | redirect = listPage; |
---|
108 | } |
---|
109 | else if ("UpdateContext".equals(cmd)) |
---|
110 | { |
---|
111 | // Display the list page after updating the current context from the request parameters |
---|
112 | Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
113 | redirect = listPage; |
---|
114 | } |
---|
115 | else if ("LoadContext".equals(cmd)) |
---|
116 | { |
---|
117 | // Display the list page after loading a saved context |
---|
118 | int contextId = Values.getInt(request.getParameter("context")); |
---|
119 | Base.loadContext(sc, contextId, defaultContext); |
---|
120 | redirect = listPage; |
---|
121 | } |
---|
122 | |
---|
123 | else if ("ViewItem".equals(cmd)) |
---|
124 | { |
---|
125 | // Display the view page for a single item |
---|
126 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
127 | forward = viewPage; |
---|
128 | } |
---|
129 | else if ("EditItem".equals(cmd)) |
---|
130 | { |
---|
131 | // Display the edit page for a single item (should be opened in a popup) |
---|
132 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
133 | redirect = editPage; |
---|
134 | } |
---|
135 | else if ("NewItem".equals(cmd)) |
---|
136 | { |
---|
137 | // Display the edit page for a new item (should be opened in a popup) |
---|
138 | if (!sc.hasPermission(Permission.CREATE, itemType)) |
---|
139 | { |
---|
140 | throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
---|
141 | } |
---|
142 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
143 | cc.setId(0); |
---|
144 | forward = editPage; |
---|
145 | } |
---|
146 | else if ("UpdateItem".equals(cmd)) |
---|
147 | { |
---|
148 | // Update the properties on an item (will close the popup) |
---|
149 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
---|
150 | final int maxRecent = Base.getMaxRecent(sc); |
---|
151 | dc = sc.newDbControl(); |
---|
152 | |
---|
153 | Experiment experiment = (Experiment)cc.getObject("item"); |
---|
154 | if (experiment == null) |
---|
155 | { |
---|
156 | RawDataType rdt = RawDataTypes.getRawDataType(Values.getStringOrNull(request.getParameter("rawdatatype"))); |
---|
157 | if (rdt != null) cc.setRecent("RawDataType", rdt.getId(), maxRecent); |
---|
158 | experiment = Experiment.getNew(dc, rdt); |
---|
159 | message = "Experiment created"; |
---|
160 | dc.saveItem(experiment); |
---|
161 | } |
---|
162 | else |
---|
163 | { |
---|
164 | dc.reattachItem(experiment, false); |
---|
165 | message = "Experiment updated"; |
---|
166 | } |
---|
167 | |
---|
168 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.EXPERIMENT), experiment); |
---|
169 | ExtensionsInvoker invoker = EditUtil.useOnSaveExtensions(jspContext); |
---|
170 | try |
---|
171 | { |
---|
172 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
173 | experiment.setName(Values.getStringOrNull(request.getParameter("name"))); |
---|
174 | experiment.setTitle(Values.getStringOrNull(request.getParameter("title"))); |
---|
175 | experiment.setAbstract(Values.getStringOrNull(request.getParameter("abstract"))); |
---|
176 | experiment.setAffiliations(Values.getStringOrNull(request.getParameter("affiliations"))); |
---|
177 | experiment.setAuthors(Values.getStringOrNull(request.getParameter("authors"))); |
---|
178 | experiment.setExperimentDesign(Values.getStringOrNull(request.getParameter("experimentDesign"))); |
---|
179 | experiment.setExperimentType(Values.getStringOrNull(request.getParameter("experimentType"))); |
---|
180 | experiment.setPublication(Values.getStringOrNull(request.getParameter("publication"))); |
---|
181 | experiment.setPublicationDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("publicationDate")))); |
---|
182 | experiment.setPubMedId(Values.getStringOrNull(request.getParameter("pubMedId"))); |
---|
183 | experiment.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
184 | |
---|
185 | int directoryId = Values.getInt(request.getParameter("directory_id"), -1); |
---|
186 | if (directoryId >= 0) // < 0 = denied or unchanged |
---|
187 | { |
---|
188 | Directory dir = directoryId == 0 ? null : Directory.getById(dc, directoryId); |
---|
189 | experiment.setDirectory(dir); |
---|
190 | if (dir != null) cc.setRecent(dir, maxRecent); |
---|
191 | } |
---|
192 | |
---|
193 | String[] removeRawBioAssays = Values.getString(request.getParameter("removedRawBioAssays")).split(","); |
---|
194 | for (int i = 0; i < removeRawBioAssays.length; ++i) |
---|
195 | { |
---|
196 | int rawBioAssayId = Values.getInt(removeRawBioAssays[i], -1); |
---|
197 | if (rawBioAssayId != -1) experiment.removeRawBioAssay(RawBioAssay.getById(dc, rawBioAssayId)); |
---|
198 | } |
---|
199 | |
---|
200 | String[] addRawBioAssays = Values.getString(request.getParameter("addedRawBioAssays")).split(","); |
---|
201 | for (int i = 0; i < addRawBioAssays.length; ++i) |
---|
202 | { |
---|
203 | int rawBioAssayId = Values.getInt(addRawBioAssays[i], -1); |
---|
204 | if (rawBioAssayId != -1) experiment.addRawBioAssay(RawBioAssay.getById(dc, rawBioAssayId)); |
---|
205 | } |
---|
206 | |
---|
207 | String[] removeAnnotationTypes = Values.getString(request.getParameter("removedAnnotationTypes")).split(","); |
---|
208 | for (int i = 0; i < removeAnnotationTypes.length; ++i) |
---|
209 | { |
---|
210 | int annotationTypeId = Values.getInt(removeAnnotationTypes[i], -1); |
---|
211 | if (annotationTypeId != -1) experiment.removeExperimentalFactor(AnnotationType.getById(dc, annotationTypeId)); |
---|
212 | } |
---|
213 | |
---|
214 | String[] addAnnotationTypes = Values.getString(request.getParameter("addedAnnotationTypes")).split(","); |
---|
215 | for (int i = 0; i < addAnnotationTypes.length; ++i) |
---|
216 | { |
---|
217 | int annotationTypeId = Values.getInt(addAnnotationTypes[i], -1); |
---|
218 | if (annotationTypeId != -1) experiment.addExperimentalFactor(AnnotationType.getById(dc, annotationTypeId)); |
---|
219 | } |
---|
220 | |
---|
221 | // OnSave extensions |
---|
222 | invoker.render(OnSaveRenderer.ON_SAVE); |
---|
223 | dc.commit(); |
---|
224 | invoker.render(OnSaveRenderer.ON_COMMIT); |
---|
225 | } |
---|
226 | catch (Exception ex) |
---|
227 | { |
---|
228 | invoker.render(OnSaveRenderer.onRollback(ex)); |
---|
229 | throw ex; |
---|
230 | } |
---|
231 | finally |
---|
232 | { |
---|
233 | cc.removeObject("item"); |
---|
234 | } |
---|
235 | } |
---|
236 | else if ("DeleteItem".equals(cmd)) |
---|
237 | { |
---|
238 | // Delete a single item and then return to the view page |
---|
239 | dc = sc.newDbControl(); |
---|
240 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
241 | RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), true); |
---|
242 | dc.commit(); |
---|
243 | redirect = viewPage; |
---|
244 | } |
---|
245 | else if ("DeleteItems".equals(cmd)) |
---|
246 | { |
---|
247 | // Delete all selected items on the list page |
---|
248 | dc = sc.newDbControl(); |
---|
249 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
250 | int numTotal = cc.getSelected().size(); |
---|
251 | int[] numRemoved = RemovableUtil.removeRecursively(dc, itemType, cc.getSelected(), true); |
---|
252 | numTotal += numRemoved[1]; |
---|
253 | dc.commit(); |
---|
254 | if (numTotal != numRemoved[0]) |
---|
255 | { |
---|
256 | message = (numRemoved[0] == 0 ? "No" : "Only "+numRemoved[0]+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
---|
257 | } |
---|
258 | redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : ""); |
---|
259 | } |
---|
260 | else if ("RestoreItem".equals(cmd)) |
---|
261 | { |
---|
262 | // Restore a single item and then return to the view page |
---|
263 | dc = sc.newDbControl(); |
---|
264 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
265 | RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), false); |
---|
266 | dc.commit(); |
---|
267 | redirect = viewPage; |
---|
268 | } |
---|
269 | else if ("RestoreItems".equals(cmd)) |
---|
270 | { |
---|
271 | // Restore all selected items on the list page |
---|
272 | dc = sc.newDbControl(); |
---|
273 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
274 | int numTotal = cc.getSelected().size(); |
---|
275 | int[] numRemoved = RemovableUtil.removeRecursively(dc, itemType, cc.getSelected(), false); |
---|
276 | numTotal += numRemoved[1]; |
---|
277 | dc.commit(); |
---|
278 | if (numTotal != numRemoved[0]) |
---|
279 | { |
---|
280 | message = (numRemoved[0] == 0 ? "No" : "Only "+numRemoved[0]+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
---|
281 | } |
---|
282 | redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : ""); |
---|
283 | } |
---|
284 | else if ("ShareItem".equals(cmd)) |
---|
285 | { |
---|
286 | // Display a popup window for sharing a single item |
---|
287 | dc = sc.newDbControl(); |
---|
288 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
289 | MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId())); |
---|
290 | dc.close(); |
---|
291 | cc.setObject("MultiPermissions", permissions); |
---|
292 | redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
293 | } |
---|
294 | else if ("ShareItems".equals(cmd)) |
---|
295 | { |
---|
296 | // Display a popup window for sharing all selected items on the list page |
---|
297 | dc = sc.newDbControl(); |
---|
298 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
299 | MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected()); |
---|
300 | dc.close(); |
---|
301 | cc.setObject("MultiPermissions", permissions); |
---|
302 | redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
303 | } |
---|
304 | else if ("SetOwnerOfItem".equals(cmd)) |
---|
305 | { |
---|
306 | // Change owner of items selected on a list page |
---|
307 | dc = sc.newDbControl(); |
---|
308 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
309 | OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId()); |
---|
310 | cc.setObject("OwnedItems", Collections.singleton(item)); |
---|
311 | redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
312 | } |
---|
313 | else if ("SetOwnerOfItems".equals(cmd)) |
---|
314 | { |
---|
315 | // Change owner of items selected on a list page |
---|
316 | dc = sc.newDbControl(); |
---|
317 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
318 | Set<OwnedItem> items = new HashSet<OwnedItem>(); |
---|
319 | for (Integer id : cc.getSelected()) |
---|
320 | { |
---|
321 | if (id != null) items.add((OwnedItem)itemType.getById(dc, id)); |
---|
322 | } |
---|
323 | dc.close(); |
---|
324 | cc.setObject("OwnedItems", items); |
---|
325 | redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
326 | } |
---|
327 | else if ("ExportItems".equals(cmd)) |
---|
328 | { |
---|
329 | // Run an export plugin in a list context |
---|
330 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
331 | final ItemQuery<Experiment> query = Experiment.getQuery(); |
---|
332 | dc = sc.newDbControl(); |
---|
333 | cc.configureQuery(dc, query, true); |
---|
334 | dc.close(); |
---|
335 | cc.setQuery(query); |
---|
336 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+experiments"; |
---|
337 | } |
---|
338 | else if ("ExportItem".equals(cmd)) |
---|
339 | { |
---|
340 | // Run an export plugin in single-item context |
---|
341 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
342 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+experiment"; |
---|
343 | } |
---|
344 | else if ("ImportItems".equals(cmd)) |
---|
345 | { |
---|
346 | // Run an import plugin in a list context |
---|
347 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
348 | final ItemQuery<Experiment> query = Experiment.getQuery(); |
---|
349 | dc = sc.newDbControl(); |
---|
350 | cc.configureQuery(dc, query, true); |
---|
351 | dc.close(); |
---|
352 | cc.setQuery(query); |
---|
353 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+experiments"; |
---|
354 | } |
---|
355 | else if ("ImportItem".equals(cmd)) |
---|
356 | { |
---|
357 | // Run an import plugin in single-item context |
---|
358 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
359 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+experiment"; |
---|
360 | } |
---|
361 | else if ("RunListPlugin".equals(cmd)) |
---|
362 | { |
---|
363 | // Run another plugin in a list context |
---|
364 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
365 | final ItemQuery<Experiment> query = Experiment.getQuery(); |
---|
366 | dc = sc.newDbControl(); |
---|
367 | cc.configureQuery(dc, query, true); |
---|
368 | dc.close(); |
---|
369 | cc.setQuery(query); |
---|
370 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
---|
371 | } |
---|
372 | else if ("RunPlugin".equals(cmd)) |
---|
373 | { |
---|
374 | // Run another plugin in single-item context |
---|
375 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
376 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
---|
377 | } |
---|
378 | else if ("AutoInherit".equals(cmd)) |
---|
379 | { |
---|
380 | Integer[] annotationTypeIds = Values.getInt(request.getParameterValues("autoinherit")); |
---|
381 | int numInherited = 0; |
---|
382 | int numRawBioAssays = 0; |
---|
383 | if (annotationTypeIds.length > 0) |
---|
384 | { |
---|
385 | dc = sc.newDbControl(); |
---|
386 | SimpleProgressReporter progress = new SimpleProgressReporter(null); |
---|
387 | sc.setSessionSetting("progress.autoinherit", progress); |
---|
388 | Experiment exp = Experiment.getById(dc, Values.getInt(itemId)); |
---|
389 | List<AnnotationType> annotationTypes = new ArrayList<AnnotationType>(annotationTypeIds.length); |
---|
390 | for (int atId : annotationTypeIds) |
---|
391 | { |
---|
392 | annotationTypes.add(AnnotationType.getById(dc, atId)); |
---|
393 | } |
---|
394 | ItemQuery<RawBioAssay> query = exp.getRawBioAssays(); |
---|
395 | query.include(Include.ALL); |
---|
396 | query.setItemPermission(Permission.WRITE); |
---|
397 | SnapshotManager manager = new SnapshotManager(); |
---|
398 | List<RawBioAssay> all = query.list(dc); |
---|
399 | int total = all.size(); |
---|
400 | int done = 0; |
---|
401 | for (RawBioAssay rba : all) |
---|
402 | { |
---|
403 | progress.display(10+(90 * done) / total, "Processing <i>" + rba.getName() + "</i>..."); |
---|
404 | ++done; |
---|
405 | int inherited = rba.getAnnotationSet().autoInherit(dc, annotationTypes, manager, false); |
---|
406 | numInherited += inherited; |
---|
407 | if (inherited > 0) numRawBioAssays++; |
---|
408 | } |
---|
409 | message = numInherited + " annotation(s) inherited by " + numRawBioAssays + " raw bioassay(s)"; |
---|
410 | progress.display(100, message); |
---|
411 | dc.commit(); |
---|
412 | } |
---|
413 | redirect = viewPage; |
---|
414 | } |
---|
415 | else if ("CloneReporters".equals(cmd)) |
---|
416 | { |
---|
417 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
---|
418 | final int maxRecent = Base.getMaxRecent(sc); |
---|
419 | |
---|
420 | dc = sc.newDbControl(); |
---|
421 | ReporterCloneTemplate template = ReporterCloneTemplate.getById(dc, Values.getInt(request.getParameter("reporterclonetemplate_id"))); |
---|
422 | cc.setRecent(template, maxRecent); |
---|
423 | |
---|
424 | Experiment exp = Experiment.getById(dc, Values.getInt(itemId)); |
---|
425 | |
---|
426 | PluginDefinition clonePlugin = PluginDefinition.getByClassName(dc, CloneReportersPlugin.class.getName()); |
---|
427 | Job cloneJob = Job.getNew(dc, clonePlugin, null, exp); |
---|
428 | cloneJob.setName("Cloning reporters using template '" + template.getName() + "'"); |
---|
429 | cloneJob.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
430 | cloneJob.setParameterValue("template", "Reporter clone template", null, |
---|
431 | new ItemParameterType<ReporterCloneTemplate>(ReporterCloneTemplate.class, null), template); |
---|
432 | dc.saveItem(cloneJob); |
---|
433 | dc.commit(); |
---|
434 | |
---|
435 | redirect = "../jobs/index.jsp?ID=" + ID + "&cmd=ViewItem&item_id="+cloneJob.getId(); |
---|
436 | } |
---|
437 | else if ("RemoveClonedReporters".equals(cmd)) |
---|
438 | { |
---|
439 | |
---|
440 | dc = sc.newDbControl(); |
---|
441 | Experiment exp = Experiment.getById(dc, Values.getInt(itemId)); |
---|
442 | ReporterCloneBatcher batcher = exp.getReporterCloneBatcher(dc); |
---|
443 | batcher.dropClonedReporters(); |
---|
444 | dc.commit(); |
---|
445 | |
---|
446 | message = "The cloned reporter annotations has been removed"; |
---|
447 | |
---|
448 | } |
---|
449 | else |
---|
450 | { |
---|
451 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
452 | } |
---|
453 | } |
---|
454 | finally |
---|
455 | { |
---|
456 | if (dc != null) dc.close(); |
---|
457 | } |
---|
458 | |
---|
459 | if (forward != null) |
---|
460 | { |
---|
461 | pageContext.forward(forward); |
---|
462 | } |
---|
463 | else if (redirect != null) |
---|
464 | { |
---|
465 | response.sendRedirect(redirect); |
---|
466 | } |
---|
467 | else if (message == null) |
---|
468 | { |
---|
469 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
470 | } |
---|
471 | else |
---|
472 | { |
---|
473 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
474 | } |
---|
475 | %> |
---|
476 | |
---|