1 | <%-- $Id: index.jsp 6278 2013-05-24 10:41:55Z 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 import="net.sf.basedb.core.Listable"%> |
---|
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.ItemContext" |
---|
31 | import="net.sf.basedb.core.Type" |
---|
32 | import="net.sf.basedb.core.ItemQuery" |
---|
33 | import="net.sf.basedb.core.ItemResultIterator" |
---|
34 | import="net.sf.basedb.core.ItemList" |
---|
35 | import="net.sf.basedb.core.BasicItem" |
---|
36 | import="net.sf.basedb.core.Sample" |
---|
37 | import="net.sf.basedb.core.Extract" |
---|
38 | import="net.sf.basedb.core.PhysicalBioAssay" |
---|
39 | import="net.sf.basedb.core.BioPlateEventType" |
---|
40 | import="net.sf.basedb.core.OwnedItem" |
---|
41 | import="net.sf.basedb.core.query.Restrictions" |
---|
42 | import="net.sf.basedb.core.query.Expressions" |
---|
43 | import="net.sf.basedb.core.query.Hql" |
---|
44 | import="net.sf.basedb.core.query.Orders" |
---|
45 | import="net.sf.basedb.core.MultiPermissions" |
---|
46 | import="net.sf.basedb.core.Permission" |
---|
47 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
48 | import="net.sf.basedb.clients.web.Base" |
---|
49 | import="net.sf.basedb.clients.web.WebException" |
---|
50 | import="net.sf.basedb.util.ShareableUtil" |
---|
51 | import="net.sf.basedb.util.RemovableUtil" |
---|
52 | import="net.sf.basedb.util.Values" |
---|
53 | import="net.sf.basedb.clients.web.util.HTML" |
---|
54 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
55 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
56 | import="net.sf.basedb.util.formatter.NameableFormatter" |
---|
57 | import="net.sf.basedb.util.formatter.WellCoordinateFormatter" |
---|
58 | import="net.sf.basedb.util.formatter.ItemTypeFormatter" |
---|
59 | import="net.sf.basedb.clients.web.plugins.BioMaterialEventSourceFormatter" |
---|
60 | import="net.sf.basedb.clients.web.plugins.ItemQueryLoader" |
---|
61 | import="net.sf.basedb.clients.web.plugins.ParentBioMaterialEventSourceLoader" |
---|
62 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
63 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
64 | import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer" |
---|
65 | import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil" |
---|
66 | import="java.util.Arrays" |
---|
67 | import="java.util.Collections" |
---|
68 | import="java.util.Set" |
---|
69 | import="java.util.HashSet" |
---|
70 | %> |
---|
71 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
72 | <%! |
---|
73 | private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,itemSubtype,description"); |
---|
74 | |
---|
75 | private static void registerExportUtils(ItemContext cc) |
---|
76 | { |
---|
77 | Item memberType = cc.getItemType(); |
---|
78 | if (memberType == Item.BIOSOURCE) |
---|
79 | { |
---|
80 | // Register formatters |
---|
81 | cc.setObject("export.formatter.&children(name)", new NameableFormatter()); |
---|
82 | |
---|
83 | // Register dataloaders |
---|
84 | String bioSourceParameter = "bioSource"; |
---|
85 | final ItemQuery<Sample> sampleQuery = Sample.getQuery(); |
---|
86 | sampleQuery.include(cc.getInclude()); |
---|
87 | sampleQuery.restrict(Restrictions.eq(Hql.property("parent"), Expressions.parameter(bioSourceParameter))); |
---|
88 | sampleQuery.order(Orders.asc(Hql.property("name"))); |
---|
89 | cc.setObject("export.dataloader.&children(name)", new ItemQueryLoader(sampleQuery, bioSourceParameter)); |
---|
90 | } |
---|
91 | else if (memberType == Item.SAMPLE) |
---|
92 | { |
---|
93 | // Register formatters |
---|
94 | cc.setObject("export.formatter.bioWell.row", new WellCoordinateFormatter(true)); |
---|
95 | cc.setObject("export.formatter.bioWell.column", new WellCoordinateFormatter(false)); |
---|
96 | cc.setObject("export.formatter.&creationEvent.sources(bioMaterial.name)", new BioMaterialEventSourceFormatter()); |
---|
97 | cc.setObject("export.formatter.&childCreationEvents(event.bioMaterial.name)", new NameableFormatter()); |
---|
98 | cc.setObject("export.formatter.&children(name)", new NameableFormatter()); |
---|
99 | cc.setObject("export.formatter.parentType", new ItemTypeFormatter()); |
---|
100 | |
---|
101 | // Register dataloaders |
---|
102 | String sampleParameter = "sample"; |
---|
103 | |
---|
104 | // Child extracts |
---|
105 | ItemQuery<Extract> extractQuery = Extract.getQuery(); |
---|
106 | extractQuery.include(cc.getInclude()); |
---|
107 | extractQuery.restrict(Restrictions.eq(Hql.property("parent"), Expressions.parameter(sampleParameter))); |
---|
108 | extractQuery.order(Orders.asc(Hql.property("name"))); |
---|
109 | cc.setObject("export.dataloader.&children(name)", new ItemQueryLoader(extractQuery, sampleParameter)); |
---|
110 | |
---|
111 | // Child samples |
---|
112 | ItemQuery<Sample> childSamplesQuery = Sample.getQuery(); |
---|
113 | childSamplesQuery.join(Hql.innerJoin("creationEvent", "ce")); |
---|
114 | childSamplesQuery.join(Hql.innerJoin("ce", "sources", "src")); |
---|
115 | childSamplesQuery.restrict(Restrictions.eq(Hql.property("src", "bioMaterial"), Expressions.parameter(sampleParameter))); |
---|
116 | childSamplesQuery.order(Orders.asc(Hql.property("name"))); |
---|
117 | childSamplesQuery.include(cc.getInclude()); |
---|
118 | cc.setObject("export.dataloader.&childCreationEvents(event.bioMaterial.name)", new ItemQueryLoader(childSamplesQuery, sampleParameter)); |
---|
119 | |
---|
120 | // Parent samples |
---|
121 | cc.setObject("export.dataloader.&creationEvent.sources(bioMaterial.name)", new ParentBioMaterialEventSourceLoader()); |
---|
122 | } |
---|
123 | else if (memberType == Item.EXTRACT) |
---|
124 | { |
---|
125 | cc.setObject("export.formatter.bioWell.row", new WellCoordinateFormatter(true)); |
---|
126 | cc.setObject("export.formatter.bioWell.column", new WellCoordinateFormatter(false)); |
---|
127 | cc.setObject("export.formatter.&children(name)", new NameableFormatter()); |
---|
128 | cc.setObject("export.formatter.&creationEvent.sources(bioMaterial.name)", new BioMaterialEventSourceFormatter()); |
---|
129 | cc.setObject("export.formatter.&childCreationEvents(event.physicalBioAssay.name)", new NameableFormatter()); |
---|
130 | cc.setObject("export.formatter.&childCreationEvents(event.bioMaterial.name)", new NameableFormatter()); |
---|
131 | cc.setObject("export.formatter.parentType", new ItemTypeFormatter()); |
---|
132 | |
---|
133 | String restrictionParameter = "extract"; |
---|
134 | |
---|
135 | // Physical bioassays |
---|
136 | ItemQuery<PhysicalBioAssay> bioAssayQuery = PhysicalBioAssay.getQuery(); |
---|
137 | bioAssayQuery.join(Hql.innerJoin("creationEvent", "ce")); |
---|
138 | bioAssayQuery.join(Hql.innerJoin("ce", "sources", "src")); |
---|
139 | bioAssayQuery.restrict(Restrictions.eq(Hql.property("src", "bioMaterial"), Expressions.parameter(restrictionParameter))); |
---|
140 | bioAssayQuery.order(Orders.asc(Hql.property("name"))); |
---|
141 | bioAssayQuery.include(cc.getInclude()); |
---|
142 | cc.setObject("export.dataloader.&childCreationEvents(event.physicalBioAssay.name)", new ItemQueryLoader(bioAssayQuery, restrictionParameter)); |
---|
143 | |
---|
144 | // Child extracts |
---|
145 | ItemQuery<Extract> childExtractsQuery = Extract.getQuery(); |
---|
146 | childExtractsQuery.join(Hql.innerJoin("creationEvent", "ce")); |
---|
147 | childExtractsQuery.join(Hql.innerJoin("ce", "sources", "src")); |
---|
148 | childExtractsQuery.restrict(Restrictions.eq(Hql.property("src", "bioMaterial"), Expressions.parameter(restrictionParameter))); |
---|
149 | childExtractsQuery.order(Orders.asc(Hql.property("name"))); |
---|
150 | childExtractsQuery.include(cc.getInclude()); |
---|
151 | cc.setObject("export.dataloader.&childCreationEvents(event.bioMaterial.name)", new ItemQueryLoader(childExtractsQuery, restrictionParameter)); |
---|
152 | |
---|
153 | // Parent items |
---|
154 | cc.setObject("export.dataloader.&creationEvent.sources(bioMaterial.name)", new ParentBioMaterialEventSourceLoader()); |
---|
155 | } |
---|
156 | } |
---|
157 | %> |
---|
158 | <% |
---|
159 | final int listId = Values.getInt(request.getParameter("list_id")); |
---|
160 | final String subContext = "listmembers."+listId; |
---|
161 | |
---|
162 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
163 | final String ID = sc.getId(); |
---|
164 | final String cmd = request.getParameter("cmd"); |
---|
165 | final String root = request.getContextPath()+"/"; |
---|
166 | final String mode = request.getParameter("mode"); |
---|
167 | final String callback = request.getParameter("callback"); |
---|
168 | final String listPage = "list_members.jsp?ID="+ID |
---|
169 | +"&list_id="+listId |
---|
170 | +(mode == null ? "" : "&mode="+mode) |
---|
171 | +(callback == null ? "" : "&callback="+callback); |
---|
172 | |
---|
173 | String forward = null; |
---|
174 | String redirect = null; |
---|
175 | String message = null; |
---|
176 | DbControl dc = null; |
---|
177 | try |
---|
178 | { |
---|
179 | dc = sc.newDbControl(); |
---|
180 | final ItemList list = ItemList.getById(dc, listId); |
---|
181 | final Item itemType = list.getMemberType(); |
---|
182 | |
---|
183 | if (cmd == null || "List".equals(cmd)) |
---|
184 | { |
---|
185 | // Display the list page without updatinging the current context |
---|
186 | Base.getAndSetCurrentContext(sc, itemType, subContext, (PageContext)null, defaultContext, true); |
---|
187 | redirect = listPage; |
---|
188 | } |
---|
189 | else if ("UpdateContext".equals(cmd)) |
---|
190 | { |
---|
191 | // Display the list page after updating the current context from the request parameters |
---|
192 | Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
---|
193 | redirect = listPage; |
---|
194 | } |
---|
195 | else if ("LoadContext".equals(cmd)) |
---|
196 | { |
---|
197 | // Display the list page after loading a saved context |
---|
198 | int contextId = Values.getInt(request.getParameter("context")); |
---|
199 | Base.loadContext(sc, contextId, defaultContext); |
---|
200 | redirect = listPage; |
---|
201 | } |
---|
202 | else if ("ExportItems".equals(cmd)) |
---|
203 | { |
---|
204 | // Run an export plugin in a list context |
---|
205 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
---|
206 | registerExportUtils(cc); |
---|
207 | final ItemQuery<? extends Listable> query = list.getMembers(); |
---|
208 | dc = sc.newDbControl(); |
---|
209 | cc.configureQuery(dc, query, true); |
---|
210 | cc.setQuery(query); |
---|
211 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
---|
212 | ExtensionsInvoker listInvoker = ListColumnUtil.useExtensions(jspContext); |
---|
213 | listInvoker.render(new ListColumnExportRenderer(cc)); |
---|
214 | dc.close(); |
---|
215 | redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&subcontext="+subContext+"&title=Export+list+members"; |
---|
216 | } |
---|
217 | else if ("ImportItems".equals(cmd)) |
---|
218 | { |
---|
219 | // Run an import plugin in a list context |
---|
220 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
---|
221 | final ItemQuery<? extends Listable> query = list.getMembers(); |
---|
222 | cc.configureQuery(dc, query, true); |
---|
223 | cc.setQuery(query); |
---|
224 | dc.close(); |
---|
225 | redirect = "../../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&subcontext="+subContext+"&title=Import+list+members"; |
---|
226 | } |
---|
227 | else if ("RunListPlugin".equals(cmd)) |
---|
228 | { |
---|
229 | // Run another plugin in a list context |
---|
230 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
---|
231 | final ItemQuery<? extends BasicItem> query = list.getMembers(); |
---|
232 | cc.configureQuery(dc, query, true); |
---|
233 | cc.setQuery(query); |
---|
234 | dc.close(); |
---|
235 | redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&subcontext="+subContext+"&main_type=OTHER&title=Run+plugin"; |
---|
236 | } |
---|
237 | else |
---|
238 | { |
---|
239 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
240 | } |
---|
241 | } |
---|
242 | finally |
---|
243 | { |
---|
244 | if (dc != null) dc.close(); |
---|
245 | } |
---|
246 | |
---|
247 | if (forward != null) |
---|
248 | { |
---|
249 | sc.setSessionSetting("alert-message", message); |
---|
250 | pageContext.forward(forward); |
---|
251 | } |
---|
252 | else if (redirect != null) |
---|
253 | { |
---|
254 | sc.setSessionSetting("alert-message", message); |
---|
255 | response.sendRedirect(redirect); |
---|
256 | } |
---|
257 | else if (message == null) |
---|
258 | { |
---|
259 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
260 | } |
---|
261 | else |
---|
262 | { |
---|
263 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
264 | } |
---|
265 | %> |
---|
266 | |
---|