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 pageEncoding="UTF-8" session="false" |
---|
26 | import="net.sf.basedb.core.SessionControl" |
---|
27 | import="net.sf.basedb.core.DbControl" |
---|
28 | import="net.sf.basedb.core.Item" |
---|
29 | import="net.sf.basedb.core.ItemContext" |
---|
30 | import="net.sf.basedb.core.Type" |
---|
31 | import="net.sf.basedb.core.ItemQuery" |
---|
32 | import="net.sf.basedb.core.ItemList" |
---|
33 | import="net.sf.basedb.core.BasicItem" |
---|
34 | import="net.sf.basedb.core.Listable" |
---|
35 | import="net.sf.basedb.core.query.Restrictions" |
---|
36 | import="net.sf.basedb.core.query.Expressions" |
---|
37 | import="net.sf.basedb.core.query.Hql" |
---|
38 | import="net.sf.basedb.core.query.Orders" |
---|
39 | import="net.sf.basedb.core.MultiPermissions" |
---|
40 | import="net.sf.basedb.core.Permission" |
---|
41 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
42 | import="net.sf.basedb.clients.web.Base" |
---|
43 | import="net.sf.basedb.clients.web.WebException" |
---|
44 | import="net.sf.basedb.util.ShareableUtil" |
---|
45 | import="net.sf.basedb.util.RemovableUtil" |
---|
46 | import="net.sf.basedb.util.Values" |
---|
47 | import="net.sf.basedb.clients.web.util.HTML" |
---|
48 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
49 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
50 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
51 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
52 | import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer" |
---|
53 | import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil" |
---|
54 | import="java.util.Arrays" |
---|
55 | import="java.util.Collections" |
---|
56 | import="java.util.Set" |
---|
57 | import="java.util.HashSet" |
---|
58 | %> |
---|
59 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
60 | <%! |
---|
61 | private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,itemSubtype,description"); |
---|
62 | |
---|
63 | private static void registerExportUtils(ItemContext cc) |
---|
64 | { |
---|
65 | Item memberType = cc.getItemType(); |
---|
66 | } |
---|
67 | %> |
---|
68 | <% |
---|
69 | final int listId = Values.getInt(request.getParameter("list_id")); |
---|
70 | final String subContext = "listmembers."+listId; |
---|
71 | |
---|
72 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
73 | final String ID = sc.getId(); |
---|
74 | final String cmd = request.getParameter("cmd"); |
---|
75 | final String root = request.getContextPath()+"/"; |
---|
76 | final String mode = request.getParameter("mode"); |
---|
77 | final String callback = request.getParameter("callback"); |
---|
78 | final String listPage = "list_members.jsp?ID="+ID |
---|
79 | +"&list_id="+listId |
---|
80 | +(mode == null ? "" : "&mode="+mode) |
---|
81 | +(callback == null ? "" : "&callback="+callback); |
---|
82 | |
---|
83 | String forward = null; |
---|
84 | String redirect = null; |
---|
85 | String message = null; |
---|
86 | DbControl dc = null; |
---|
87 | try |
---|
88 | { |
---|
89 | dc = sc.newDbControl(); |
---|
90 | final ItemList list = ItemList.getById(dc, listId); |
---|
91 | final Item itemType = list.getMemberType(); |
---|
92 | |
---|
93 | if (cmd == null || "List".equals(cmd)) |
---|
94 | { |
---|
95 | // Display the list page without updatinging the current context |
---|
96 | Base.getAndSetCurrentContext(sc, itemType, subContext, (PageContext)null, defaultContext, true); |
---|
97 | redirect = listPage; |
---|
98 | } |
---|
99 | else if ("UpdateContext".equals(cmd)) |
---|
100 | { |
---|
101 | // Display the list page after updating the current context from the request parameters |
---|
102 | Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
---|
103 | redirect = listPage; |
---|
104 | } |
---|
105 | else if ("LoadContext".equals(cmd)) |
---|
106 | { |
---|
107 | // Display the list page after loading a saved context |
---|
108 | int contextId = Values.getInt(request.getParameter("context")); |
---|
109 | Base.loadContext(sc, contextId, defaultContext); |
---|
110 | redirect = listPage; |
---|
111 | } |
---|
112 | else if ("ExportItems".equals(cmd)) |
---|
113 | { |
---|
114 | // Run an export plugin in a list context |
---|
115 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
---|
116 | registerExportUtils(cc); |
---|
117 | final ItemQuery<? extends Listable> query = list.getMembers(); |
---|
118 | dc = sc.newDbControl(); |
---|
119 | cc.configureQuery(dc, query, true); |
---|
120 | cc.setQuery(query); |
---|
121 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
---|
122 | ExtensionsInvoker listInvoker = ListColumnUtil.useExtensions(jspContext); |
---|
123 | listInvoker.render(new ListColumnExportRenderer(cc)); |
---|
124 | dc.close(); |
---|
125 | redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&subcontext="+subContext+"&title=Export+list+members"; |
---|
126 | } |
---|
127 | else if ("ImportItems".equals(cmd)) |
---|
128 | { |
---|
129 | // Run an import plugin in a list context |
---|
130 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
---|
131 | final ItemQuery<? extends Listable> query = list.getMembers(); |
---|
132 | cc.configureQuery(dc, query, true); |
---|
133 | cc.setQuery(query); |
---|
134 | dc.close(); |
---|
135 | redirect = "../../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&subcontext="+subContext+"&title=Import+list+members"; |
---|
136 | } |
---|
137 | else if ("RunListPlugin".equals(cmd)) |
---|
138 | { |
---|
139 | // Run another plugin in a list context |
---|
140 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
---|
141 | final ItemQuery<? extends BasicItem> query = list.getMembers(); |
---|
142 | cc.configureQuery(dc, query, true); |
---|
143 | cc.setQuery(query); |
---|
144 | dc.close(); |
---|
145 | redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&subcontext="+subContext+"&main_type=OTHER&title=Run+plugin"; |
---|
146 | } |
---|
147 | else if ("AddMembers".equals(cmd)) |
---|
148 | { |
---|
149 | ItemContext memberContext = sc.getCurrentContext(itemType); |
---|
150 | final ItemQuery<? extends Listable> query = list.getAllItems(); |
---|
151 | memberContext.configureQuery(dc, query, true); |
---|
152 | String which = request.getParameter("which"); |
---|
153 | if ("selected".equals(which)) |
---|
154 | { |
---|
155 | query.setFirstResult(0); |
---|
156 | query.setMaxResults(-1); |
---|
157 | Integer[] itemIds = Values.getInt(request.getParameter("items").split(",")); |
---|
158 | query.restrict( |
---|
159 | Restrictions.in( |
---|
160 | Hql.property("id"), |
---|
161 | Expressions.parameter("selectedItems") |
---|
162 | ) |
---|
163 | ); |
---|
164 | query.setParameter("selectedItems", Arrays.asList(itemIds), Type.INT); |
---|
165 | } |
---|
166 | else if ("all".equals(which)) |
---|
167 | { |
---|
168 | query.setFirstResult(0); |
---|
169 | query.setMaxResults(-1); |
---|
170 | } |
---|
171 | int count = list.add(query.iterate(dc)); |
---|
172 | dc.commit(); |
---|
173 | message = count + " members added to list"; |
---|
174 | } |
---|
175 | else if ("RemoveMembers".equals(cmd)) |
---|
176 | { |
---|
177 | // Delete all selected items on the list page |
---|
178 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
---|
179 | for (int itemId : cc.getSelected()) |
---|
180 | { |
---|
181 | list.remove((Listable)itemType.getById(dc, itemId)); |
---|
182 | } |
---|
183 | dc.commit(); |
---|
184 | redirect = listPage; |
---|
185 | } |
---|
186 | |
---|
187 | else |
---|
188 | { |
---|
189 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
190 | } |
---|
191 | } |
---|
192 | finally |
---|
193 | { |
---|
194 | if (dc != null) dc.close(); |
---|
195 | } |
---|
196 | |
---|
197 | if (forward != null) |
---|
198 | { |
---|
199 | sc.setSessionSetting("alert-message", message); |
---|
200 | pageContext.forward(forward); |
---|
201 | } |
---|
202 | else if (redirect != null) |
---|
203 | { |
---|
204 | sc.setSessionSetting("alert-message", message); |
---|
205 | response.sendRedirect(redirect); |
---|
206 | } |
---|
207 | else if (message == null) |
---|
208 | { |
---|
209 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
210 | } |
---|
211 | else |
---|
212 | { |
---|
213 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
214 | } |
---|
215 | %> |
---|
216 | |
---|