6742 |
17 Feb 15 |
nicklas |
1 |
<%-- $Id$ |
6742 |
17 Feb 15 |
nicklas |
2 |
------------------------------------------------------------------ |
6742 |
17 Feb 15 |
nicklas |
Copyright (C) 2015 Nicklas Nordborg |
6742 |
17 Feb 15 |
nicklas |
4 |
|
6742 |
17 Feb 15 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
6742 |
17 Feb 15 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
6742 |
17 Feb 15 |
nicklas |
7 |
|
6742 |
17 Feb 15 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
6742 |
17 Feb 15 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
6742 |
17 Feb 15 |
nicklas |
10 |
as published by the Free Software Foundation; either version 3 |
6742 |
17 Feb 15 |
nicklas |
11 |
of the License, or (at your option) any later version. |
6742 |
17 Feb 15 |
nicklas |
12 |
|
6742 |
17 Feb 15 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
6742 |
17 Feb 15 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
6742 |
17 Feb 15 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6742 |
17 Feb 15 |
nicklas |
16 |
GNU General Public License for more details. |
6742 |
17 Feb 15 |
nicklas |
17 |
|
6742 |
17 Feb 15 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
6742 |
17 Feb 15 |
nicklas |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
6742 |
17 Feb 15 |
nicklas |
20 |
------------------------------------------------------------------ |
6742 |
17 Feb 15 |
nicklas |
21 |
|
6742 |
17 Feb 15 |
nicklas |
22 |
@author Nicklas |
6742 |
17 Feb 15 |
nicklas |
23 |
--%> |
6742 |
17 Feb 15 |
nicklas |
24 |
<%@ page pageEncoding="UTF-8" session="false" |
6742 |
17 Feb 15 |
nicklas |
25 |
import="net.sf.basedb.core.SessionControl" |
6742 |
17 Feb 15 |
nicklas |
26 |
import="net.sf.basedb.core.DbControl" |
6742 |
17 Feb 15 |
nicklas |
27 |
import="net.sf.basedb.core.Item" |
6742 |
17 Feb 15 |
nicklas |
28 |
import="net.sf.basedb.core.Type" |
6742 |
17 Feb 15 |
nicklas |
29 |
import="net.sf.basedb.core.Include" |
6742 |
17 Feb 15 |
nicklas |
30 |
import="net.sf.basedb.core.ItemList" |
6771 |
16 Mar 15 |
nicklas |
31 |
import="net.sf.basedb.core.ItemList.SynchronizeOption" |
6753 |
20 Feb 15 |
nicklas |
32 |
import="net.sf.basedb.core.RawDataTypes" |
6753 |
20 Feb 15 |
nicklas |
33 |
import="net.sf.basedb.core.ItemSubtype" |
6742 |
17 Feb 15 |
nicklas |
34 |
import="net.sf.basedb.core.ItemQuery" |
6742 |
17 Feb 15 |
nicklas |
35 |
import="net.sf.basedb.core.Permission" |
6742 |
17 Feb 15 |
nicklas |
36 |
import="net.sf.basedb.core.ItemContext" |
6770 |
13 Mar 15 |
nicklas |
37 |
import="net.sf.basedb.core.SyncFilter" |
6770 |
13 Mar 15 |
nicklas |
38 |
import="net.sf.basedb.core.SyncFilter.SourceItemTransform" |
6742 |
17 Feb 15 |
nicklas |
39 |
import="net.sf.basedb.core.ItemResultIterator" |
6742 |
17 Feb 15 |
nicklas |
40 |
import="net.sf.basedb.core.ItemQuery" |
6742 |
17 Feb 15 |
nicklas |
41 |
import="net.sf.basedb.core.MultiPermissions" |
6742 |
17 Feb 15 |
nicklas |
42 |
import="net.sf.basedb.core.OwnedItem" |
6750 |
19 Feb 15 |
nicklas |
43 |
import="net.sf.basedb.core.Listable" |
6795 |
24 Mar 15 |
nicklas |
44 |
import="net.sf.basedb.core.SimpleProgressReporter" |
6742 |
17 Feb 15 |
nicklas |
45 |
import="net.sf.basedb.core.PermissionDeniedException" |
6742 |
17 Feb 15 |
nicklas |
46 |
import="net.sf.basedb.core.ItemAlreadyExistsException" |
6742 |
17 Feb 15 |
nicklas |
47 |
import="net.sf.basedb.core.query.Restrictions" |
6742 |
17 Feb 15 |
nicklas |
48 |
import="net.sf.basedb.core.query.Hql" |
6742 |
17 Feb 15 |
nicklas |
49 |
import="net.sf.basedb.core.query.Expressions" |
6928 |
04 Jun 15 |
nicklas |
50 |
import="net.sf.basedb.util.ChainedProgressReporter" |
6742 |
17 Feb 15 |
nicklas |
51 |
import="net.sf.basedb.util.RemovableUtil" |
6742 |
17 Feb 15 |
nicklas |
52 |
import="net.sf.basedb.util.ShareableUtil" |
6742 |
17 Feb 15 |
nicklas |
53 |
import="net.sf.basedb.util.OwnableUtil" |
6742 |
17 Feb 15 |
nicklas |
54 |
import="net.sf.basedb.clients.web.Base" |
6742 |
17 Feb 15 |
nicklas |
55 |
import="net.sf.basedb.clients.web.WebException" |
6742 |
17 Feb 15 |
nicklas |
56 |
import="net.sf.basedb.util.Values" |
6742 |
17 Feb 15 |
nicklas |
57 |
import="net.sf.basedb.clients.web.util.HTML" |
6742 |
17 Feb 15 |
nicklas |
58 |
import="net.sf.basedb.core.plugin.GuiContext" |
6742 |
17 Feb 15 |
nicklas |
59 |
import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
6742 |
17 Feb 15 |
nicklas |
60 |
import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
6742 |
17 Feb 15 |
nicklas |
61 |
import="net.sf.basedb.clients.web.extensions.JspContext" |
6742 |
17 Feb 15 |
nicklas |
62 |
import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
7604 |
25 Feb 19 |
nicklas |
63 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveAction" |
6742 |
17 Feb 15 |
nicklas |
64 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer" |
6742 |
17 Feb 15 |
nicklas |
65 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer" |
7604 |
25 Feb 19 |
nicklas |
66 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnAction" |
6742 |
17 Feb 15 |
nicklas |
67 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil" |
6742 |
17 Feb 15 |
nicklas |
68 |
import="java.util.Enumeration" |
6742 |
17 Feb 15 |
nicklas |
69 |
import="java.util.Set" |
6742 |
17 Feb 15 |
nicklas |
70 |
import="java.util.HashSet" |
6742 |
17 Feb 15 |
nicklas |
71 |
import="java.util.List" |
6742 |
17 Feb 15 |
nicklas |
72 |
import="java.util.ArrayList" |
6742 |
17 Feb 15 |
nicklas |
73 |
import="java.util.Collections" |
6742 |
17 Feb 15 |
nicklas |
74 |
import="java.util.Arrays" |
6742 |
17 Feb 15 |
nicklas |
75 |
%> |
6742 |
17 Feb 15 |
nicklas |
76 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
6742 |
17 Feb 15 |
nicklas |
77 |
<%! |
6742 |
17 Feb 15 |
nicklas |
78 |
private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,memberType,size,description"); |
6742 |
17 Feb 15 |
nicklas |
79 |
private static final Item itemType = Item.ITEMLIST; |
6795 |
24 Mar 15 |
nicklas |
80 |
|
6795 |
24 Mar 15 |
nicklas |
81 |
private static class ReSyncList |
6795 |
24 Mar 15 |
nicklas |
82 |
implements Runnable |
6795 |
24 Mar 15 |
nicklas |
83 |
{ |
6795 |
24 Mar 15 |
nicklas |
84 |
|
6795 |
24 Mar 15 |
nicklas |
85 |
private final SessionControl sc; |
6795 |
24 Mar 15 |
nicklas |
86 |
private final int listId; |
6928 |
04 Jun 15 |
nicklas |
87 |
private final Integer[] depending; |
6795 |
24 Mar 15 |
nicklas |
88 |
private final SynchronizeOption syncOption; |
6795 |
24 Mar 15 |
nicklas |
89 |
private final boolean applySubtypeFilter; |
6795 |
24 Mar 15 |
nicklas |
90 |
|
6928 |
04 Jun 15 |
nicklas |
91 |
ReSyncList(ItemList list, Integer[] depending, SynchronizeOption syncOption, boolean applySubtypeFilter) |
6795 |
24 Mar 15 |
nicklas |
92 |
{ |
6795 |
24 Mar 15 |
nicklas |
93 |
this.sc = list.getSessionControl(); |
6795 |
24 Mar 15 |
nicklas |
94 |
this.listId = list.getId(); |
6928 |
04 Jun 15 |
nicklas |
95 |
this.depending = depending; |
6795 |
24 Mar 15 |
nicklas |
96 |
this.syncOption = syncOption; |
6795 |
24 Mar 15 |
nicklas |
97 |
this.applySubtypeFilter = applySubtypeFilter; |
6795 |
24 Mar 15 |
nicklas |
98 |
} |
6795 |
24 Mar 15 |
nicklas |
99 |
|
6795 |
24 Mar 15 |
nicklas |
100 |
public void run() |
6795 |
24 Mar 15 |
nicklas |
101 |
{ |
6795 |
24 Mar 15 |
nicklas |
102 |
SimpleProgressReporter progress = new SimpleProgressReporter(null); |
6928 |
04 Jun 15 |
nicklas |
103 |
ChainedProgressReporter master = null; |
6795 |
24 Mar 15 |
nicklas |
104 |
sc.setSessionSetting("progress.resync-itemlist-"+listId, progress); |
6928 |
04 Jun 15 |
nicklas |
105 |
DbControl dc = null; |
6795 |
24 Mar 15 |
nicklas |
106 |
try |
6795 |
24 Mar 15 |
nicklas |
107 |
{ |
6928 |
04 Jun 15 |
nicklas |
108 |
|
6928 |
04 Jun 15 |
nicklas |
109 |
if (depending != null && depending.length > 0) |
6928 |
04 Jun 15 |
nicklas |
110 |
{ |
6928 |
04 Jun 15 |
nicklas |
111 |
master = new ChainedProgressReporter(progress); |
6928 |
04 Jun 15 |
nicklas |
112 |
float step = 100f / (1+depending.length); // Divide 100% into equal parts for each list |
6928 |
04 Jun 15 |
nicklas |
113 |
int index = 0; |
6928 |
04 Jun 15 |
nicklas |
114 |
|
6928 |
04 Jun 15 |
nicklas |
115 |
for (int i = depending.length - 1; i >= 0; i--) |
6928 |
04 Jun 15 |
nicklas |
116 |
{ |
6928 |
04 Jun 15 |
nicklas |
117 |
// Work backwards since the last ones are the "deepest" children |
7954 |
12 May 21 |
nicklas |
118 |
dc = sc.newDbControl(":Re-sync depending item list"); |
6928 |
04 Jun 15 |
nicklas |
119 |
ItemList list = ItemList.getById(dc, depending[i]); |
6795 |
24 Mar 15 |
nicklas |
120 |
|
6928 |
04 Jun 15 |
nicklas |
121 |
master.setRange((int)(index*step), (int)((index+1)*step)); |
6928 |
04 Jun 15 |
nicklas |
122 |
index++; |
6928 |
04 Jun 15 |
nicklas |
123 |
master.setMessagePrefix(list.getName() + ": "); |
6928 |
04 Jun 15 |
nicklas |
124 |
|
6928 |
04 Jun 15 |
nicklas |
125 |
list.resyncFilter(dc, syncOption, applySubtypeFilter, master); |
6928 |
04 Jun 15 |
nicklas |
126 |
dc.commit(); |
6928 |
04 Jun 15 |
nicklas |
127 |
} |
6928 |
04 Jun 15 |
nicklas |
128 |
|
6928 |
04 Jun 15 |
nicklas |
129 |
master.setRange((int)(100-step), 100); |
6928 |
04 Jun 15 |
nicklas |
130 |
master.setMessagePrefix(null); |
6928 |
04 Jun 15 |
nicklas |
131 |
} |
6928 |
04 Jun 15 |
nicklas |
132 |
|
7954 |
12 May 21 |
nicklas |
133 |
dc = sc.newDbControl(":Re-sync item list"); |
6795 |
24 Mar 15 |
nicklas |
134 |
ItemList list = ItemList.getById(dc, listId); |
6928 |
04 Jun 15 |
nicklas |
135 |
if (master != null) master.setMessagePrefix(list.getName() + ": "); |
6846 |
10 Apr 15 |
nicklas |
136 |
int membersBefore = list.getSize(); |
6928 |
04 Jun 15 |
nicklas |
137 |
int membersAfter = list.resyncFilter(dc, syncOption, applySubtypeFilter, master != null ? master : progress); |
6846 |
10 Apr 15 |
nicklas |
138 |
progress.display(99, "Committing to database..."); |
6795 |
24 Mar 15 |
nicklas |
139 |
dc.commit(); |
6846 |
10 Apr 15 |
nicklas |
140 |
progress.display(100, "List synchronized successfully; " + membersAfter + " members ("+membersBefore+")"); |
6795 |
24 Mar 15 |
nicklas |
141 |
} |
6795 |
24 Mar 15 |
nicklas |
142 |
catch (Throwable t) |
6795 |
24 Mar 15 |
nicklas |
143 |
{ |
6795 |
24 Mar 15 |
nicklas |
144 |
progress.display(100, t.getMessage()); |
6795 |
24 Mar 15 |
nicklas |
145 |
progress.setError(t); |
6796 |
24 Mar 15 |
nicklas |
146 |
t.printStackTrace(System.out); |
6795 |
24 Mar 15 |
nicklas |
147 |
} |
6795 |
24 Mar 15 |
nicklas |
148 |
finally |
6795 |
24 Mar 15 |
nicklas |
149 |
{ |
6795 |
24 Mar 15 |
nicklas |
150 |
if (dc != null) dc.close(); |
6795 |
24 Mar 15 |
nicklas |
151 |
} |
6795 |
24 Mar 15 |
nicklas |
152 |
} |
6795 |
24 Mar 15 |
nicklas |
153 |
} |
6742 |
17 Feb 15 |
nicklas |
154 |
%> |
6742 |
17 Feb 15 |
nicklas |
155 |
<% |
6742 |
17 Feb 15 |
nicklas |
156 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
6742 |
17 Feb 15 |
nicklas |
157 |
final String ID = sc.getId(); |
6742 |
17 Feb 15 |
nicklas |
158 |
final String cmd = request.getParameter("cmd"); |
6742 |
17 Feb 15 |
nicklas |
159 |
final String root = request.getContextPath()+"/"; |
6742 |
17 Feb 15 |
nicklas |
160 |
final String mode = request.getParameter("mode"); |
6742 |
17 Feb 15 |
nicklas |
161 |
final String callback = request.getParameter("callback"); |
6742 |
17 Feb 15 |
nicklas |
162 |
final String itemId = request.getParameter("item_id"); |
6742 |
17 Feb 15 |
nicklas |
163 |
final String listPage = "list_lists.jsp?ID="+ID |
6742 |
17 Feb 15 |
nicklas |
164 |
+(mode == null ? "" : "&mode="+mode) |
6742 |
17 Feb 15 |
nicklas |
165 |
+(callback == null ? "" : "&callback="+callback) |
6742 |
17 Feb 15 |
nicklas |
166 |
+(itemId == null ? "" : "&item_id="+itemId); |
6742 |
17 Feb 15 |
nicklas |
167 |
final String viewPage = "view_list.jsp?ID="+ID; |
6742 |
17 Feb 15 |
nicklas |
168 |
final String editPage = "edit_list.jsp?ID="+ID; |
6742 |
17 Feb 15 |
nicklas |
169 |
|
6742 |
17 Feb 15 |
nicklas |
170 |
String forward = null; |
6742 |
17 Feb 15 |
nicklas |
171 |
String redirect = null; |
6742 |
17 Feb 15 |
nicklas |
172 |
String message = null; |
6742 |
17 Feb 15 |
nicklas |
173 |
DbControl dc = null; |
6742 |
17 Feb 15 |
nicklas |
174 |
|
6742 |
17 Feb 15 |
nicklas |
175 |
try |
6742 |
17 Feb 15 |
nicklas |
176 |
{ |
6742 |
17 Feb 15 |
nicklas |
177 |
if (cmd == null || "List".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
178 |
{ |
6742 |
17 Feb 15 |
nicklas |
179 |
// Display the list page without updatinging the current context |
6742 |
17 Feb 15 |
nicklas |
180 |
Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true); |
6742 |
17 Feb 15 |
nicklas |
181 |
redirect = listPage; |
6742 |
17 Feb 15 |
nicklas |
182 |
} |
6742 |
17 Feb 15 |
nicklas |
183 |
else if ("UpdateContext".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
184 |
{ |
6742 |
17 Feb 15 |
nicklas |
185 |
// Display the list page after updating the current context from the request parameters |
6742 |
17 Feb 15 |
nicklas |
186 |
Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
187 |
redirect = listPage; |
6742 |
17 Feb 15 |
nicklas |
188 |
} |
6742 |
17 Feb 15 |
nicklas |
189 |
else if ("LoadContext".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
190 |
{ |
6742 |
17 Feb 15 |
nicklas |
191 |
// Display the list page after loading a saved context |
6742 |
17 Feb 15 |
nicklas |
192 |
int contextId = Values.getInt(request.getParameter("context")); |
6742 |
17 Feb 15 |
nicklas |
193 |
Base.loadContext(sc, contextId, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
194 |
redirect = listPage; |
6742 |
17 Feb 15 |
nicklas |
195 |
} |
6742 |
17 Feb 15 |
nicklas |
196 |
|
6742 |
17 Feb 15 |
nicklas |
197 |
else if ("ViewItem".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
198 |
{ |
6742 |
17 Feb 15 |
nicklas |
199 |
// Display the view page for a single item |
6742 |
17 Feb 15 |
nicklas |
200 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
201 |
forward = viewPage; |
6742 |
17 Feb 15 |
nicklas |
202 |
} |
6742 |
17 Feb 15 |
nicklas |
203 |
else if ("EditItem".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
204 |
{ |
6742 |
17 Feb 15 |
nicklas |
205 |
// Display the edit page for a single item (should be opened in a popup) |
6742 |
17 Feb 15 |
nicklas |
206 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
207 |
redirect = editPage; |
6742 |
17 Feb 15 |
nicklas |
208 |
} |
6742 |
17 Feb 15 |
nicklas |
209 |
else if ("NewItem".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
210 |
{ |
6742 |
17 Feb 15 |
nicklas |
211 |
// Display the edit page for a new item (should be opened in a popup) |
6742 |
17 Feb 15 |
nicklas |
212 |
if (!sc.hasPermission(Permission.CREATE, itemType)) |
6742 |
17 Feb 15 |
nicklas |
213 |
{ |
6742 |
17 Feb 15 |
nicklas |
214 |
throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
6742 |
17 Feb 15 |
nicklas |
215 |
} |
6742 |
17 Feb 15 |
nicklas |
216 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
217 |
cc.setId(0); |
6742 |
17 Feb 15 |
nicklas |
218 |
forward = editPage; |
6742 |
17 Feb 15 |
nicklas |
219 |
} |
6742 |
17 Feb 15 |
nicklas |
220 |
else if ("UpdateItem".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
221 |
{ |
6742 |
17 Feb 15 |
nicklas |
222 |
// Update the properties on an item (will close the popup) |
6742 |
17 Feb 15 |
nicklas |
223 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
7954 |
12 May 21 |
nicklas |
224 |
dc = sc.newDbControl(":Edit "+itemType); |
7605 |
26 Feb 19 |
nicklas |
225 |
ItemList list = cc.getObject("item"); |
6803 |
25 Mar 15 |
nicklas |
226 |
|
6742 |
17 Feb 15 |
nicklas |
227 |
if (list == null) |
6742 |
17 Feb 15 |
nicklas |
228 |
{ |
6742 |
17 Feb 15 |
nicklas |
229 |
Item memberType = Item.valueOf(request.getParameter("memberType")); |
6742 |
17 Feb 15 |
nicklas |
230 |
list = ItemList.getNew(dc, memberType); |
7813 |
19 May 20 |
nicklas |
231 |
if (Values.getBoolean(request.getParameter("private"))) |
7813 |
19 May 20 |
nicklas |
232 |
{ |
7813 |
19 May 20 |
nicklas |
233 |
list.setProjectKey(null); |
7813 |
19 May 20 |
nicklas |
234 |
list.setItemKey(null); |
7813 |
19 May 20 |
nicklas |
235 |
} |
6742 |
17 Feb 15 |
nicklas |
236 |
dc.saveItem(list); |
6803 |
25 Mar 15 |
nicklas |
237 |
|
6803 |
25 Mar 15 |
nicklas |
238 |
int cloneId = Values.getInt(request.getParameter("clone_id")); |
6803 |
25 Mar 15 |
nicklas |
239 |
if (cloneId > 0) |
6803 |
25 Mar 15 |
nicklas |
240 |
{ |
6803 |
25 Mar 15 |
nicklas |
241 |
ItemList cloneFrom = ItemList.getById(dc, cloneId); |
6803 |
25 Mar 15 |
nicklas |
242 |
list.copySyncFiltersAndMembers(dc, cloneFrom); |
6803 |
25 Mar 15 |
nicklas |
243 |
} |
6742 |
17 Feb 15 |
nicklas |
244 |
message = "List created"; |
6742 |
17 Feb 15 |
nicklas |
245 |
} |
6742 |
17 Feb 15 |
nicklas |
246 |
else |
6742 |
17 Feb 15 |
nicklas |
247 |
{ |
6742 |
17 Feb 15 |
nicklas |
248 |
dc.reattachItem(list, false); |
6742 |
17 Feb 15 |
nicklas |
249 |
message = "List updated"; |
6742 |
17 Feb 15 |
nicklas |
250 |
} |
6742 |
17 Feb 15 |
nicklas |
251 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.ITEMLIST), list); |
7604 |
25 Feb 19 |
nicklas |
252 |
ExtensionsInvoker<OnSaveAction> invoker = EditUtil.useOnSaveExtensions(jspContext); |
6742 |
17 Feb 15 |
nicklas |
253 |
try |
6742 |
17 Feb 15 |
nicklas |
254 |
{ |
6742 |
17 Feb 15 |
nicklas |
255 |
list.setName(Values.getStringOrNull(request.getParameter("name"))); |
6742 |
17 Feb 15 |
nicklas |
256 |
list.setExternalId(Values.getStringOrNull(request.getParameter("external_id"))); |
6742 |
17 Feb 15 |
nicklas |
257 |
list.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
6786 |
19 Mar 15 |
nicklas |
258 |
list.setDisableManualMembers(Values.getBoolean(request.getParameter("disableManual"), false)); |
6786 |
19 Mar 15 |
nicklas |
259 |
list.setDisableSyncFilters(Values.getBoolean(request.getParameter("disableSyncFilters"), false)); |
6753 |
20 Feb 15 |
nicklas |
260 |
if (list.getMemberType() == Item.RAWBIOASSAY) |
6753 |
20 Feb 15 |
nicklas |
261 |
{ |
6753 |
20 Feb 15 |
nicklas |
262 |
list.setRawDataType(RawDataTypes.getRawDataType(request.getParameter("rawdatatype"))); |
6753 |
20 Feb 15 |
nicklas |
263 |
} |
6753 |
20 Feb 15 |
nicklas |
264 |
else |
6753 |
20 Feb 15 |
nicklas |
265 |
{ |
6753 |
20 Feb 15 |
nicklas |
266 |
int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1); |
6753 |
20 Feb 15 |
nicklas |
267 |
ItemSubtype subtype = null; |
6753 |
20 Feb 15 |
nicklas |
268 |
if (subtypeId >= 0) // < 0 = denied or unchanged |
6753 |
20 Feb 15 |
nicklas |
269 |
{ |
6753 |
20 Feb 15 |
nicklas |
270 |
if (subtypeId > 0) subtype = ItemSubtype.getById(dc, subtypeId); |
6753 |
20 Feb 15 |
nicklas |
271 |
list.setItemSubtype(subtype); |
6753 |
20 Feb 15 |
nicklas |
272 |
} |
6753 |
20 Feb 15 |
nicklas |
273 |
} |
6742 |
17 Feb 15 |
nicklas |
274 |
|
6742 |
17 Feb 15 |
nicklas |
275 |
// Annotations tab |
6742 |
17 Feb 15 |
nicklas |
276 |
Base.updateAnnotations(dc, list, list, request); |
6742 |
17 Feb 15 |
nicklas |
277 |
|
6750 |
19 Feb 15 |
nicklas |
278 |
if (!list.isInDatabase()) |
6750 |
19 Feb 15 |
nicklas |
279 |
{ |
6750 |
19 Feb 15 |
nicklas |
280 |
// Add individual items from selected from a list page |
6750 |
19 Feb 15 |
nicklas |
281 |
String source = request.getParameter("source"); |
6750 |
19 Feb 15 |
nicklas |
282 |
if (source != null) |
6750 |
19 Feb 15 |
nicklas |
283 |
{ |
6750 |
19 Feb 15 |
nicklas |
284 |
String subContext = Values.getString(request.getParameter("subContext"), ""); |
6768 |
10 Mar 15 |
nicklas |
285 |
boolean useSyncFilter = false; |
6768 |
10 Mar 15 |
nicklas |
286 |
ItemContext filterContext = sc.getCurrentContext(list.getMemberType(), subContext); |
7605 |
26 Feb 19 |
nicklas |
287 |
ItemQuery<? extends Listable> query = filterContext.getQuery(); |
6750 |
19 Feb 15 |
nicklas |
288 |
if ("all".equals(source)) |
6750 |
19 Feb 15 |
nicklas |
289 |
{ |
7747 |
16 Sep 19 |
nicklas |
290 |
useSyncFilter = Values.getBoolean(request.getParameter("syncFilter")) && filterContext.getNumPropertyFilters() > 0; |
6750 |
19 Feb 15 |
nicklas |
291 |
query.setFirstResult(0); |
6750 |
19 Feb 15 |
nicklas |
292 |
query.setMaxResults(-1); |
6770 |
13 Mar 15 |
nicklas |
293 |
if (useSyncFilter) |
6770 |
13 Mar 15 |
nicklas |
294 |
{ |
6770 |
13 Mar 15 |
nicklas |
295 |
SyncFilter sf = list.newSyncFilter(dc); |
6770 |
13 Mar 15 |
nicklas |
296 |
sf.setName("Origin"); |
6770 |
13 Mar 15 |
nicklas |
297 |
sf.setSyncContext(filterContext, SourceItemTransform.NONE); |
6770 |
13 Mar 15 |
nicklas |
298 |
dc.saveItem(sf); |
6786 |
19 Mar 15 |
nicklas |
299 |
|
6795 |
24 Mar 15 |
nicklas |
300 |
list.resyncFilter(dc, SynchronizeOption.ADD_ONLY, false, null); |
6770 |
13 Mar 15 |
nicklas |
301 |
} |
6750 |
19 Feb 15 |
nicklas |
302 |
} |
6750 |
19 Feb 15 |
nicklas |
303 |
else if ("selected".equals(source)) |
6750 |
19 Feb 15 |
nicklas |
304 |
{ |
6750 |
19 Feb 15 |
nicklas |
305 |
query.setFirstResult(0); |
6750 |
19 Feb 15 |
nicklas |
306 |
query.setMaxResults(-1); |
6750 |
19 Feb 15 |
nicklas |
307 |
Integer[] itemIds = Values.getInt(request.getParameter("items").split(",")); |
6750 |
19 Feb 15 |
nicklas |
308 |
query.restrict( |
6750 |
19 Feb 15 |
nicklas |
309 |
Restrictions.in( |
6750 |
19 Feb 15 |
nicklas |
310 |
Hql.property("id"), |
6750 |
19 Feb 15 |
nicklas |
311 |
Expressions.parameter("selectedItems") |
6750 |
19 Feb 15 |
nicklas |
312 |
) |
6750 |
19 Feb 15 |
nicklas |
313 |
); |
6750 |
19 Feb 15 |
nicklas |
314 |
query.setParameter("selectedItems", Arrays.asList(itemIds), Type.INT); |
6750 |
19 Feb 15 |
nicklas |
315 |
} |
6750 |
19 Feb 15 |
nicklas |
316 |
// else -- no modifications to the query mean that we only get the current page |
6750 |
19 Feb 15 |
nicklas |
317 |
|
7834 |
26 Jun 20 |
nicklas |
318 |
if (!useSyncFilter) list.add(query); |
6750 |
19 Feb 15 |
nicklas |
319 |
} |
6750 |
19 Feb 15 |
nicklas |
320 |
|
6750 |
19 Feb 15 |
nicklas |
321 |
message = "List created with " + list.getSize() + " item(s)"; |
6750 |
19 Feb 15 |
nicklas |
322 |
} |
6750 |
19 Feb 15 |
nicklas |
323 |
|
6750 |
19 Feb 15 |
nicklas |
324 |
|
6742 |
17 Feb 15 |
nicklas |
325 |
// OnSave extensions |
6742 |
17 Feb 15 |
nicklas |
326 |
invoker.render(OnSaveRenderer.ON_SAVE); |
6742 |
17 Feb 15 |
nicklas |
327 |
dc.commit(); |
6742 |
17 Feb 15 |
nicklas |
328 |
invoker.render(OnSaveRenderer.ON_COMMIT); |
6742 |
17 Feb 15 |
nicklas |
329 |
} |
6742 |
17 Feb 15 |
nicklas |
330 |
catch (Exception ex) |
6742 |
17 Feb 15 |
nicklas |
331 |
{ |
6742 |
17 Feb 15 |
nicklas |
332 |
invoker.render(OnSaveRenderer.onRollback(ex)); |
6742 |
17 Feb 15 |
nicklas |
333 |
throw ex; |
6742 |
17 Feb 15 |
nicklas |
334 |
} |
6742 |
17 Feb 15 |
nicklas |
335 |
finally |
6742 |
17 Feb 15 |
nicklas |
336 |
{ |
6742 |
17 Feb 15 |
nicklas |
337 |
cc.removeObject("item"); |
6742 |
17 Feb 15 |
nicklas |
338 |
} |
6742 |
17 Feb 15 |
nicklas |
339 |
} |
6771 |
16 Mar 15 |
nicklas |
340 |
else if ("ReSync".equals(cmd)) |
6768 |
10 Mar 15 |
nicklas |
341 |
{ |
7954 |
12 May 21 |
nicklas |
342 |
dc = sc.newDbControl(":Re-sync item list"); |
6768 |
10 Mar 15 |
nicklas |
343 |
ItemList list = ItemList.getById(dc, Values.getInt(itemId)); |
6771 |
16 Mar 15 |
nicklas |
344 |
|
6771 |
16 Mar 15 |
nicklas |
345 |
SynchronizeOption syncOption = SynchronizeOption.valueOf(request.getParameter("syncoption")); |
6771 |
16 Mar 15 |
nicklas |
346 |
boolean subtypeFilter = Values.getBoolean(request.getParameter("subtype")); |
6771 |
16 Mar 15 |
nicklas |
347 |
boolean rawDataTypeFilter = Values.getBoolean(request.getParameter("rawdatatype")); |
6928 |
04 Jun 15 |
nicklas |
348 |
|
6928 |
04 Jun 15 |
nicklas |
349 |
Integer[] depending = Values.getInt(request.getParameterValues("depending")); |
6928 |
04 Jun 15 |
nicklas |
350 |
Runnable resync = new ReSyncList(list, depending, syncOption, subtypeFilter || rawDataTypeFilter); |
6768 |
10 Mar 15 |
nicklas |
351 |
dc.commit(); |
6795 |
24 Mar 15 |
nicklas |
352 |
|
6795 |
24 Mar 15 |
nicklas |
353 |
Thread t = new Thread(resync); |
6795 |
24 Mar 15 |
nicklas |
354 |
t.start(); |
6795 |
24 Mar 15 |
nicklas |
355 |
redirect = "../../common/progress_reporter.jsp?ID="+ID+ |
7432 |
08 Dec 17 |
nicklas |
356 |
"&progress=resync-itemlist-"+list.getId()+"¬ify_opener=btnResync&title=" + HTML.urlEncode("Synchronizing: " + list.getName()); |
6768 |
10 Mar 15 |
nicklas |
357 |
} |
6742 |
17 Feb 15 |
nicklas |
358 |
else if ("DeleteItem".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
359 |
{ |
6742 |
17 Feb 15 |
nicklas |
360 |
// Delete a single item and then return to the view page |
7954 |
12 May 21 |
nicklas |
361 |
dc = sc.newDbControl(":Delete "+itemType); |
6742 |
17 Feb 15 |
nicklas |
362 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
363 |
RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true); |
6742 |
17 Feb 15 |
nicklas |
364 |
dc.commit(); |
6742 |
17 Feb 15 |
nicklas |
365 |
redirect = viewPage; |
6742 |
17 Feb 15 |
nicklas |
366 |
} |
6742 |
17 Feb 15 |
nicklas |
367 |
else if ("DeleteItems".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
368 |
{ |
6742 |
17 Feb 15 |
nicklas |
369 |
// Delete all selected items on the list page |
7954 |
12 May 21 |
nicklas |
370 |
dc = sc.newDbControl(":Delete "+itemType); |
6742 |
17 Feb 15 |
nicklas |
371 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
372 |
int numTotal = cc.getSelected().size(); |
6742 |
17 Feb 15 |
nicklas |
373 |
int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true); |
6742 |
17 Feb 15 |
nicklas |
374 |
dc.commit(); |
6742 |
17 Feb 15 |
nicklas |
375 |
if (numTotal != numRemoved) |
6742 |
17 Feb 15 |
nicklas |
376 |
{ |
6742 |
17 Feb 15 |
nicklas |
377 |
message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
6742 |
17 Feb 15 |
nicklas |
378 |
} |
6742 |
17 Feb 15 |
nicklas |
379 |
redirect = listPage; |
6742 |
17 Feb 15 |
nicklas |
380 |
} |
6742 |
17 Feb 15 |
nicklas |
381 |
else if ("RestoreItem".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
382 |
{ |
6742 |
17 Feb 15 |
nicklas |
383 |
// Restore a single item and then return to the view page |
7954 |
12 May 21 |
nicklas |
384 |
dc = sc.newDbControl(":Restore "+itemType); |
6742 |
17 Feb 15 |
nicklas |
385 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
386 |
RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false); |
6742 |
17 Feb 15 |
nicklas |
387 |
dc.commit(); |
6742 |
17 Feb 15 |
nicklas |
388 |
redirect = viewPage; |
6742 |
17 Feb 15 |
nicklas |
389 |
} |
6742 |
17 Feb 15 |
nicklas |
390 |
else if ("RestoreItems".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
391 |
{ |
6742 |
17 Feb 15 |
nicklas |
392 |
// Restore all selected items on the list page |
7954 |
12 May 21 |
nicklas |
393 |
dc = sc.newDbControl(":Restore "+itemType); |
6742 |
17 Feb 15 |
nicklas |
394 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
395 |
int numTotal = cc.getSelected().size(); |
6742 |
17 Feb 15 |
nicklas |
396 |
int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false); |
6742 |
17 Feb 15 |
nicklas |
397 |
dc.commit(); |
6742 |
17 Feb 15 |
nicklas |
398 |
if (numTotal != numRemoved) |
6742 |
17 Feb 15 |
nicklas |
399 |
{ |
6742 |
17 Feb 15 |
nicklas |
400 |
message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
6742 |
17 Feb 15 |
nicklas |
401 |
} |
6742 |
17 Feb 15 |
nicklas |
402 |
redirect = listPage; |
6742 |
17 Feb 15 |
nicklas |
403 |
} |
6742 |
17 Feb 15 |
nicklas |
404 |
else if ("ShareItem".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
405 |
{ |
6742 |
17 Feb 15 |
nicklas |
406 |
// Display a popup window for sharing a single item |
7954 |
12 May 21 |
nicklas |
407 |
dc = sc.newDbControl(":Share "+itemType); |
6742 |
17 Feb 15 |
nicklas |
408 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
409 |
MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId())); |
6742 |
17 Feb 15 |
nicklas |
410 |
dc.close(); |
6742 |
17 Feb 15 |
nicklas |
411 |
cc.setObject("MultiPermissions", permissions); |
6742 |
17 Feb 15 |
nicklas |
412 |
redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
6742 |
17 Feb 15 |
nicklas |
413 |
} |
6742 |
17 Feb 15 |
nicklas |
414 |
else if ("ShareItems".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
415 |
{ |
6742 |
17 Feb 15 |
nicklas |
416 |
// Display a popup window for sharing all selected items on the list page |
7954 |
12 May 21 |
nicklas |
417 |
dc = sc.newDbControl(":Share "+itemType); |
6742 |
17 Feb 15 |
nicklas |
418 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
419 |
MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected()); |
6742 |
17 Feb 15 |
nicklas |
420 |
dc.close(); |
6742 |
17 Feb 15 |
nicklas |
421 |
cc.setObject("MultiPermissions", permissions); |
6742 |
17 Feb 15 |
nicklas |
422 |
redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
6742 |
17 Feb 15 |
nicklas |
423 |
} |
6742 |
17 Feb 15 |
nicklas |
424 |
else if ("SetOwnerOfItem".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
425 |
{ |
6742 |
17 Feb 15 |
nicklas |
426 |
// Change owner of items selected on a list page |
7954 |
12 May 21 |
nicklas |
427 |
dc = sc.newDbControl(":Set owner of "+itemType); |
6742 |
17 Feb 15 |
nicklas |
428 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
429 |
OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId()); |
6742 |
17 Feb 15 |
nicklas |
430 |
cc.setObject("OwnedItems", Collections.singleton(item)); |
6742 |
17 Feb 15 |
nicklas |
431 |
redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
6742 |
17 Feb 15 |
nicklas |
432 |
} |
6742 |
17 Feb 15 |
nicklas |
433 |
else if ("SetOwnerOfItems".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
434 |
{ |
6742 |
17 Feb 15 |
nicklas |
435 |
// Change owner of items selected on a list page |
7954 |
12 May 21 |
nicklas |
436 |
dc = sc.newDbControl(":Set owner of "+itemType); |
6742 |
17 Feb 15 |
nicklas |
437 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
438 |
Set<OwnedItem> items = new HashSet<OwnedItem>(); |
6742 |
17 Feb 15 |
nicklas |
439 |
for (Integer id : cc.getSelected()) |
6742 |
17 Feb 15 |
nicklas |
440 |
{ |
6742 |
17 Feb 15 |
nicklas |
441 |
if (id != null) items.add((OwnedItem)itemType.getById(dc, id)); |
6742 |
17 Feb 15 |
nicklas |
442 |
} |
6742 |
17 Feb 15 |
nicklas |
443 |
dc.close(); |
6742 |
17 Feb 15 |
nicklas |
444 |
cc.setObject("OwnedItems", items); |
6742 |
17 Feb 15 |
nicklas |
445 |
redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
6742 |
17 Feb 15 |
nicklas |
446 |
} |
6742 |
17 Feb 15 |
nicklas |
447 |
else if ("ExportItems".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
448 |
{ |
6742 |
17 Feb 15 |
nicklas |
449 |
// Run an export plugin in a list context |
6742 |
17 Feb 15 |
nicklas |
450 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
451 |
final ItemQuery<ItemList> query = ItemList.getQuery(); |
7954 |
12 May 21 |
nicklas |
452 |
dc = sc.newDbControl(":Export "+itemType); |
7914 |
23 Feb 21 |
nicklas |
453 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
454 |
cc.configureQuery(dc, query, jspContext, true); |
6742 |
17 Feb 15 |
nicklas |
455 |
dc.close(); |
6742 |
17 Feb 15 |
nicklas |
456 |
cc.setQuery(query); |
6742 |
17 Feb 15 |
nicklas |
457 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+item+lists"; |
6742 |
17 Feb 15 |
nicklas |
458 |
} |
6742 |
17 Feb 15 |
nicklas |
459 |
else if ("ExportItem".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
460 |
{ |
6742 |
17 Feb 15 |
nicklas |
461 |
// Run an export plugin in single-item context |
6742 |
17 Feb 15 |
nicklas |
462 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
463 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+item+list"; |
6742 |
17 Feb 15 |
nicklas |
464 |
} |
6742 |
17 Feb 15 |
nicklas |
465 |
else if ("ImportItems".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
466 |
{ |
6742 |
17 Feb 15 |
nicklas |
467 |
// Run an import plugin in a list context |
6742 |
17 Feb 15 |
nicklas |
468 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
469 |
final ItemQuery<ItemList> query = ItemList.getQuery(); |
7954 |
12 May 21 |
nicklas |
470 |
dc = sc.newDbControl(":Import "+itemType); |
7914 |
23 Feb 21 |
nicklas |
471 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
472 |
cc.configureQuery(dc, query, jspContext, true); |
6742 |
17 Feb 15 |
nicklas |
473 |
cc.setQuery(query); |
7604 |
25 Feb 19 |
nicklas |
474 |
ExtensionsInvoker<ListColumnAction<ItemList,?>> listInvoker = ListColumnUtil.useExtensions(jspContext); |
7604 |
25 Feb 19 |
nicklas |
475 |
listInvoker.render(new ListColumnExportRenderer<ItemList>(cc)); |
6742 |
17 Feb 15 |
nicklas |
476 |
dc.close(); |
6742 |
17 Feb 15 |
nicklas |
477 |
redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+item+lists"; |
6742 |
17 Feb 15 |
nicklas |
478 |
} |
6742 |
17 Feb 15 |
nicklas |
479 |
else if ("ImportItem".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
480 |
{ |
6742 |
17 Feb 15 |
nicklas |
481 |
// Run an import plugin in single-item context |
6742 |
17 Feb 15 |
nicklas |
482 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
483 |
redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+item+list"; |
6742 |
17 Feb 15 |
nicklas |
484 |
} |
6742 |
17 Feb 15 |
nicklas |
485 |
else if ("RunListPlugin".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
486 |
{ |
6742 |
17 Feb 15 |
nicklas |
487 |
// Run another plugin in a list context |
6742 |
17 Feb 15 |
nicklas |
488 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
489 |
final ItemQuery<ItemList> query = ItemList.getQuery(); |
7954 |
12 May 21 |
nicklas |
490 |
dc = sc.newDbControl(":Run plugin "+itemType); |
7914 |
23 Feb 21 |
nicklas |
491 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
492 |
cc.configureQuery(dc, query, jspContext, true); |
6742 |
17 Feb 15 |
nicklas |
493 |
dc.close(); |
6742 |
17 Feb 15 |
nicklas |
494 |
cc.setQuery(query); |
6742 |
17 Feb 15 |
nicklas |
495 |
redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
6742 |
17 Feb 15 |
nicklas |
496 |
} |
6742 |
17 Feb 15 |
nicklas |
497 |
else if ("RunPlugin".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
498 |
{ |
6742 |
17 Feb 15 |
nicklas |
499 |
// Run another plugin in single-item context |
6742 |
17 Feb 15 |
nicklas |
500 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6742 |
17 Feb 15 |
nicklas |
501 |
redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
6742 |
17 Feb 15 |
nicklas |
502 |
} |
6742 |
17 Feb 15 |
nicklas |
503 |
else if ("MergeItem".equals(cmd)) |
6742 |
17 Feb 15 |
nicklas |
504 |
{ |
6742 |
17 Feb 15 |
nicklas |
505 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
7954 |
12 May 21 |
nicklas |
506 |
dc = sc.newDbControl(":Merge item lists"); |
7605 |
26 Feb 19 |
nicklas |
507 |
ItemList itemList = cc.getObject("item"); |
6742 |
17 Feb 15 |
nicklas |
508 |
dc.reattachItem(itemList, false); |
6742 |
17 Feb 15 |
nicklas |
509 |
|
6742 |
17 Feb 15 |
nicklas |
510 |
String mergeType = request.getParameter("mergeType"); |
6742 |
17 Feb 15 |
nicklas |
511 |
String sourceMerge = request.getParameter("sourceMerge"); |
6742 |
17 Feb 15 |
nicklas |
512 |
|
6742 |
17 Feb 15 |
nicklas |
513 |
String[] sourceListIds = Values.getString(request.getParameter("+ITEMLIST")).split(","); |
6742 |
17 Feb 15 |
nicklas |
514 |
List<ItemList> sourceLists = new ArrayList<ItemList>(sourceListIds.length); |
6742 |
17 Feb 15 |
nicklas |
515 |
for (int i = 0; i < sourceListIds.length; ++i) |
6742 |
17 Feb 15 |
nicklas |
516 |
{ |
6742 |
17 Feb 15 |
nicklas |
517 |
int listId = Values.getInt(sourceListIds[i], -1); |
6742 |
17 Feb 15 |
nicklas |
518 |
if (listId != -1) sourceLists.add(ItemList.getById(dc, listId)); |
6742 |
17 Feb 15 |
nicklas |
519 |
} |
6742 |
17 Feb 15 |
nicklas |
520 |
|
6742 |
17 Feb 15 |
nicklas |
521 |
int numAdded = 0; |
6742 |
17 Feb 15 |
nicklas |
522 |
int numRemoved = 0; |
6742 |
17 Feb 15 |
nicklas |
523 |
if ("union".equals(mergeType)) |
6742 |
17 Feb 15 |
nicklas |
524 |
{ |
6742 |
17 Feb 15 |
nicklas |
525 |
if ("union".equals(sourceMerge)) |
6742 |
17 Feb 15 |
nicklas |
526 |
{ |
6742 |
17 Feb 15 |
nicklas |
527 |
numAdded = itemList.addUnion(sourceLists); |
6742 |
17 Feb 15 |
nicklas |
528 |
} |
6742 |
17 Feb 15 |
nicklas |
529 |
else if ("intersection".equals(sourceMerge)) |
6742 |
17 Feb 15 |
nicklas |
530 |
{ |
6742 |
17 Feb 15 |
nicklas |
531 |
numAdded = itemList.addIntersection(sourceLists); |
6742 |
17 Feb 15 |
nicklas |
532 |
} |
6742 |
17 Feb 15 |
nicklas |
533 |
message = numAdded + " items added to this list"; |
6742 |
17 Feb 15 |
nicklas |
534 |
} |
6742 |
17 Feb 15 |
nicklas |
535 |
else if ("intersection".equals(mergeType)) |
6742 |
17 Feb 15 |
nicklas |
536 |
{ |
6742 |
17 Feb 15 |
nicklas |
537 |
if ("union".equals(sourceMerge)) |
6742 |
17 Feb 15 |
nicklas |
538 |
{ |
6742 |
17 Feb 15 |
nicklas |
539 |
numRemoved = itemList.retainUnion(sourceLists); |
6742 |
17 Feb 15 |
nicklas |
540 |
} |
6742 |
17 Feb 15 |
nicklas |
541 |
else if ("intersection".equals(sourceMerge)) |
6742 |
17 Feb 15 |
nicklas |
542 |
{ |
6742 |
17 Feb 15 |
nicklas |
543 |
numRemoved = itemList.retainIntersection(sourceLists); |
6742 |
17 Feb 15 |
nicklas |
544 |
} |
6742 |
17 Feb 15 |
nicklas |
545 |
message = numRemoved + " items removed from this list"; |
6742 |
17 Feb 15 |
nicklas |
546 |
} |
6742 |
17 Feb 15 |
nicklas |
547 |
else if ("complement".equals(mergeType)) |
6742 |
17 Feb 15 |
nicklas |
548 |
{ |
6742 |
17 Feb 15 |
nicklas |
549 |
if ("union".equals(sourceMerge)) |
6742 |
17 Feb 15 |
nicklas |
550 |
{ |
6742 |
17 Feb 15 |
nicklas |
551 |
numRemoved = itemList.removeUnion(sourceLists); |
6742 |
17 Feb 15 |
nicklas |
552 |
} |
6742 |
17 Feb 15 |
nicklas |
553 |
else if ("intersection".equals(sourceMerge)) |
6742 |
17 Feb 15 |
nicklas |
554 |
{ |
6742 |
17 Feb 15 |
nicklas |
555 |
numRemoved = itemList.removeIntersection(sourceLists); |
6742 |
17 Feb 15 |
nicklas |
556 |
} |
6742 |
17 Feb 15 |
nicklas |
557 |
message = numRemoved + " items removed from this list"; |
6742 |
17 Feb 15 |
nicklas |
558 |
} |
6742 |
17 Feb 15 |
nicklas |
559 |
dc.commit(); |
6742 |
17 Feb 15 |
nicklas |
560 |
} |
7813 |
19 May 20 |
nicklas |
561 |
else if ("AddMembers".equals(cmd)) |
7813 |
19 May 20 |
nicklas |
562 |
{ |
7954 |
12 May 21 |
nicklas |
563 |
dc = sc.newDbControl(":Add items to item list"); |
7813 |
19 May 20 |
nicklas |
564 |
ItemList list = ItemList.getById(dc, Values.getInt(itemId)); |
7813 |
19 May 20 |
nicklas |
565 |
String subContext = Values.getString(request.getParameter("subContext"), ""); |
7813 |
19 May 20 |
nicklas |
566 |
final int maxRecent = Base.getMaxRecent(sc); |
7813 |
19 May 20 |
nicklas |
567 |
|
7813 |
19 May 20 |
nicklas |
568 |
ItemContext memberContext = sc.getCurrentContext(list.getMemberType(), subContext); |
7813 |
19 May 20 |
nicklas |
569 |
memberContext.setRecent(Item.ITEMLIST, list, "AddMembers", maxRecent); |
7813 |
19 May 20 |
nicklas |
570 |
ItemQuery<? extends Listable> query = memberContext.getQuery(); |
7813 |
19 May 20 |
nicklas |
571 |
String source = request.getParameter("source"); |
7813 |
19 May 20 |
nicklas |
572 |
if ("all".equals(source)) |
7813 |
19 May 20 |
nicklas |
573 |
{ |
7813 |
19 May 20 |
nicklas |
574 |
query.setFirstResult(0); |
7813 |
19 May 20 |
nicklas |
575 |
query.setMaxResults(-1); |
7813 |
19 May 20 |
nicklas |
576 |
} |
7813 |
19 May 20 |
nicklas |
577 |
else if ("selected".equals(source)) |
7813 |
19 May 20 |
nicklas |
578 |
{ |
7813 |
19 May 20 |
nicklas |
579 |
query.setFirstResult(0); |
7813 |
19 May 20 |
nicklas |
580 |
query.setMaxResults(-1); |
7813 |
19 May 20 |
nicklas |
581 |
Integer[] itemIds = Values.getInt(request.getParameter("items").split(",")); |
7813 |
19 May 20 |
nicklas |
582 |
query.restrict( |
7813 |
19 May 20 |
nicklas |
583 |
Restrictions.in( |
7813 |
19 May 20 |
nicklas |
584 |
Hql.property("id"), |
7813 |
19 May 20 |
nicklas |
585 |
Expressions.parameter("selectedItems") |
7813 |
19 May 20 |
nicklas |
586 |
) |
7813 |
19 May 20 |
nicklas |
587 |
); |
7813 |
19 May 20 |
nicklas |
588 |
query.setParameter("selectedItems", Arrays.asList(itemIds), Type.INT); |
7813 |
19 May 20 |
nicklas |
589 |
} |
7813 |
19 May 20 |
nicklas |
590 |
// else -- no modifications to the query mean that we only get the current page |
7813 |
19 May 20 |
nicklas |
591 |
|
7834 |
26 Jun 20 |
nicklas |
592 |
int count = list.add(query); |
7813 |
19 May 20 |
nicklas |
593 |
dc.commit(); |
7813 |
19 May 20 |
nicklas |
594 |
message = count + " members added to list"; |
7813 |
19 May 20 |
nicklas |
595 |
} |
6742 |
17 Feb 15 |
nicklas |
596 |
else |
6742 |
17 Feb 15 |
nicklas |
597 |
{ |
6742 |
17 Feb 15 |
nicklas |
598 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
6742 |
17 Feb 15 |
nicklas |
599 |
} |
6742 |
17 Feb 15 |
nicklas |
600 |
} |
6742 |
17 Feb 15 |
nicklas |
601 |
finally |
6742 |
17 Feb 15 |
nicklas |
602 |
{ |
6742 |
17 Feb 15 |
nicklas |
603 |
if (dc != null) dc.close(); |
6742 |
17 Feb 15 |
nicklas |
604 |
} |
6742 |
17 Feb 15 |
nicklas |
605 |
|
6742 |
17 Feb 15 |
nicklas |
606 |
if (forward != null) |
6742 |
17 Feb 15 |
nicklas |
607 |
{ |
6742 |
17 Feb 15 |
nicklas |
608 |
sc.setSessionSetting("alert-message", message); |
6742 |
17 Feb 15 |
nicklas |
609 |
pageContext.forward(forward); |
6742 |
17 Feb 15 |
nicklas |
610 |
} |
6742 |
17 Feb 15 |
nicklas |
611 |
else if (redirect != null) |
6742 |
17 Feb 15 |
nicklas |
612 |
{ |
6742 |
17 Feb 15 |
nicklas |
613 |
sc.setSessionSetting("alert-message", message); |
6742 |
17 Feb 15 |
nicklas |
614 |
response.sendRedirect(redirect); |
6742 |
17 Feb 15 |
nicklas |
615 |
} |
6742 |
17 Feb 15 |
nicklas |
616 |
else if (message == null) |
6742 |
17 Feb 15 |
nicklas |
617 |
{ |
6742 |
17 Feb 15 |
nicklas |
618 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
6742 |
17 Feb 15 |
nicklas |
619 |
} |
6742 |
17 Feb 15 |
nicklas |
620 |
else |
6742 |
17 Feb 15 |
nicklas |
621 |
{ |
6742 |
17 Feb 15 |
nicklas |
622 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
6742 |
17 Feb 15 |
nicklas |
623 |
} |
6742 |
17 Feb 15 |
nicklas |
624 |
%> |
6742 |
17 Feb 15 |
nicklas |
625 |
|