2396 |
19 Jun 06 |
nicklas |
1 |
<%-- $Id$ |
2396 |
19 Jun 06 |
nicklas |
2 |
------------------------------------------------------------------ |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2006 Nicklas Nordborg |
2396 |
19 Jun 06 |
nicklas |
4 |
|
2396 |
19 Jun 06 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
2396 |
19 Jun 06 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
2396 |
19 Jun 06 |
nicklas |
7 |
|
2396 |
19 Jun 06 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
2396 |
19 Jun 06 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
4476 |
05 Sep 08 |
jari |
10 |
as published by the Free Software Foundation; either version 3 |
2396 |
19 Jun 06 |
nicklas |
11 |
of the License, or (at your option) any later version. |
2396 |
19 Jun 06 |
nicklas |
12 |
|
2396 |
19 Jun 06 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
2396 |
19 Jun 06 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2396 |
19 Jun 06 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2396 |
19 Jun 06 |
nicklas |
16 |
GNU General Public License for more details. |
2396 |
19 Jun 06 |
nicklas |
17 |
|
2396 |
19 Jun 06 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
4510 |
11 Sep 08 |
jari |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
2396 |
19 Jun 06 |
nicklas |
20 |
------------------------------------------------------------------ |
2396 |
19 Jun 06 |
nicklas |
21 |
|
2396 |
19 Jun 06 |
nicklas |
22 |
@author Nicklas |
2396 |
19 Jun 06 |
nicklas |
23 |
@version 2.0 |
2396 |
19 Jun 06 |
nicklas |
24 |
--%> |
5426 |
24 Sep 10 |
nicklas |
25 |
<%@ page pageEncoding="UTF-8" session="false" |
2396 |
19 Jun 06 |
nicklas |
26 |
import="net.sf.basedb.core.SessionControl" |
2396 |
19 Jun 06 |
nicklas |
27 |
import="net.sf.basedb.core.DbControl" |
2396 |
19 Jun 06 |
nicklas |
28 |
import="net.sf.basedb.core.Item" |
2396 |
19 Jun 06 |
nicklas |
29 |
import="net.sf.basedb.core.Include" |
2396 |
19 Jun 06 |
nicklas |
30 |
import="net.sf.basedb.core.AnyToAny" |
6282 |
27 May 13 |
nicklas |
31 |
import="net.sf.basedb.core.BasicItem" |
2396 |
19 Jun 06 |
nicklas |
32 |
import="net.sf.basedb.core.ItemQuery" |
2396 |
19 Jun 06 |
nicklas |
33 |
import="net.sf.basedb.core.ItemResultIterator" |
2396 |
19 Jun 06 |
nicklas |
34 |
import="net.sf.basedb.core.Permission" |
2396 |
19 Jun 06 |
nicklas |
35 |
import="net.sf.basedb.core.ItemContext" |
2396 |
19 Jun 06 |
nicklas |
36 |
import="net.sf.basedb.core.MultiPermissions" |
2396 |
19 Jun 06 |
nicklas |
37 |
import="net.sf.basedb.core.PermissionDeniedException" |
2396 |
19 Jun 06 |
nicklas |
38 |
import="net.sf.basedb.core.ItemAlreadyExistsException" |
2396 |
19 Jun 06 |
nicklas |
39 |
import="net.sf.basedb.util.RemovableUtil" |
2396 |
19 Jun 06 |
nicklas |
40 |
import="net.sf.basedb.util.ShareableUtil" |
2396 |
19 Jun 06 |
nicklas |
41 |
import="net.sf.basedb.clients.web.Base" |
2396 |
19 Jun 06 |
nicklas |
42 |
import="net.sf.basedb.clients.web.WebException" |
2753 |
20 Oct 06 |
nicklas |
43 |
import="net.sf.basedb.util.Values" |
2396 |
19 Jun 06 |
nicklas |
44 |
import="net.sf.basedb.clients.web.util.HTML" |
2396 |
19 Jun 06 |
nicklas |
45 |
import="java.util.Enumeration" |
2396 |
19 Jun 06 |
nicklas |
46 |
import="java.util.Set" |
2396 |
19 Jun 06 |
nicklas |
47 |
import="java.util.HashSet" |
2396 |
19 Jun 06 |
nicklas |
48 |
import="java.util.List" |
2396 |
19 Jun 06 |
nicklas |
49 |
import="java.util.ArrayList" |
2396 |
19 Jun 06 |
nicklas |
50 |
import="java.util.Collections" |
2396 |
19 Jun 06 |
nicklas |
51 |
%> |
2396 |
19 Jun 06 |
nicklas |
52 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
2396 |
19 Jun 06 |
nicklas |
53 |
<%! |
2396 |
19 Jun 06 |
nicklas |
54 |
private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,description"); |
2396 |
19 Jun 06 |
nicklas |
55 |
private static final Item itemType = Item.ANYTOANY; |
2396 |
19 Jun 06 |
nicklas |
56 |
%> |
2396 |
19 Jun 06 |
nicklas |
57 |
<% |
2396 |
19 Jun 06 |
nicklas |
58 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
2396 |
19 Jun 06 |
nicklas |
59 |
final String ID = sc.getId(); |
2396 |
19 Jun 06 |
nicklas |
60 |
final String cmd = request.getParameter("cmd"); |
2396 |
19 Jun 06 |
nicklas |
61 |
final String root = request.getContextPath()+"/"; |
2396 |
19 Jun 06 |
nicklas |
62 |
final String mode = request.getParameter("mode"); |
2396 |
19 Jun 06 |
nicklas |
63 |
final String callback = request.getParameter("callback"); |
2396 |
19 Jun 06 |
nicklas |
64 |
final String itemId = request.getParameter("item_id"); |
2396 |
19 Jun 06 |
nicklas |
65 |
final String listPage = "list_anytoany.jsp?ID="+ID |
2396 |
19 Jun 06 |
nicklas |
66 |
+(mode == null ? "" : "&mode="+mode) |
2396 |
19 Jun 06 |
nicklas |
67 |
+(callback == null ? "" : "&callback="+callback) |
2396 |
19 Jun 06 |
nicklas |
68 |
+(itemId == null ? "" : "&item_id="+itemId); |
2396 |
19 Jun 06 |
nicklas |
69 |
final String editPage = "edit_anytoany.jsp?ID="+ID; |
2396 |
19 Jun 06 |
nicklas |
70 |
|
2396 |
19 Jun 06 |
nicklas |
71 |
String forward = null; |
2396 |
19 Jun 06 |
nicklas |
72 |
String redirect = null; |
2396 |
19 Jun 06 |
nicklas |
73 |
String message = null; |
2396 |
19 Jun 06 |
nicklas |
74 |
DbControl dc = null; |
2396 |
19 Jun 06 |
nicklas |
75 |
|
2396 |
19 Jun 06 |
nicklas |
76 |
try |
2396 |
19 Jun 06 |
nicklas |
77 |
{ |
2396 |
19 Jun 06 |
nicklas |
78 |
if ("ViewItem".equals(cmd)) |
2396 |
19 Jun 06 |
nicklas |
79 |
{ |
2396 |
19 Jun 06 |
nicklas |
80 |
// Display the view page for a single item |
2396 |
19 Jun 06 |
nicklas |
81 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2396 |
19 Jun 06 |
nicklas |
82 |
forward = editPage; |
2396 |
19 Jun 06 |
nicklas |
83 |
} |
2396 |
19 Jun 06 |
nicklas |
84 |
else if ("EditItem".equals(cmd)) |
2396 |
19 Jun 06 |
nicklas |
85 |
{ |
2396 |
19 Jun 06 |
nicklas |
86 |
// Display the edit page for a single item (should be opened in a popup) |
2396 |
19 Jun 06 |
nicklas |
87 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2396 |
19 Jun 06 |
nicklas |
88 |
redirect = editPage; |
2396 |
19 Jun 06 |
nicklas |
89 |
} |
6285 |
30 May 13 |
nicklas |
90 |
else if ("NewItem".equals(cmd)) |
6285 |
30 May 13 |
nicklas |
91 |
{ |
6285 |
30 May 13 |
nicklas |
92 |
// Display the edit page for a new item (should be opened in a popup) |
6285 |
30 May 13 |
nicklas |
93 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6285 |
30 May 13 |
nicklas |
94 |
cc.setId(0); |
6285 |
30 May 13 |
nicklas |
95 |
forward = editPage; |
6285 |
30 May 13 |
nicklas |
96 |
} |
2396 |
19 Jun 06 |
nicklas |
97 |
else if ("UpdateItem".equals(cmd)) |
2396 |
19 Jun 06 |
nicklas |
98 |
{ |
2396 |
19 Jun 06 |
nicklas |
99 |
// Update the properties on an item (will close the popup) |
2396 |
19 Jun 06 |
nicklas |
100 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
6285 |
30 May 13 |
nicklas |
101 |
final int maxRecent = Base.getMaxRecent(sc); |
7954 |
12 May 21 |
nicklas |
102 |
dc = sc.newDbControl(":Edit "+itemType); |
2396 |
19 Jun 06 |
nicklas |
103 |
|
7605 |
26 Feb 19 |
nicklas |
104 |
AnyToAny anyToAny = cc.getObject("item"); |
2396 |
19 Jun 06 |
nicklas |
105 |
if (anyToAny == null) |
2396 |
19 Jun 06 |
nicklas |
106 |
{ |
6285 |
30 May 13 |
nicklas |
107 |
Item fromType = Item.valueOf(request.getParameter("from_type")); |
6285 |
30 May 13 |
nicklas |
108 |
int fromId = Values.getInt(request.getParameter("from_id")); |
6285 |
30 May 13 |
nicklas |
109 |
BasicItem from = fromType.getById(dc, fromId); |
6285 |
30 May 13 |
nicklas |
110 |
|
6285 |
30 May 13 |
nicklas |
111 |
Item toType = Item.valueOf(request.getParameter("to_type")); |
6285 |
30 May 13 |
nicklas |
112 |
int toId = Values.getInt(request.getParameter("to_id")); |
6285 |
30 May 13 |
nicklas |
113 |
BasicItem to = toType.getById(dc, toId); |
6285 |
30 May 13 |
nicklas |
114 |
|
6285 |
30 May 13 |
nicklas |
115 |
cc.setRecent("toTypes", toType.name(), maxRecent); |
6285 |
30 May 13 |
nicklas |
116 |
|
6285 |
30 May 13 |
nicklas |
117 |
String name = Values.getStringOrNull(request.getParameter("name")); |
6285 |
30 May 13 |
nicklas |
118 |
|
6285 |
30 May 13 |
nicklas |
119 |
anyToAny = AnyToAny.getNew(dc, from, to, name, false); |
6285 |
30 May 13 |
nicklas |
120 |
dc.saveItem(anyToAny); |
6285 |
30 May 13 |
nicklas |
121 |
message = "Link created"; |
2396 |
19 Jun 06 |
nicklas |
122 |
} |
2396 |
19 Jun 06 |
nicklas |
123 |
else |
2396 |
19 Jun 06 |
nicklas |
124 |
{ |
5060 |
19 Aug 09 |
nicklas |
125 |
dc.reattachItem(anyToAny, false); |
6285 |
30 May 13 |
nicklas |
126 |
|
6285 |
30 May 13 |
nicklas |
127 |
anyToAny.setName(Values.getStringOrNull(request.getParameter("name"))); |
6285 |
30 May 13 |
nicklas |
128 |
int toId = Values.getInt(request.getParameter("to_id"), -1); |
6285 |
30 May 13 |
nicklas |
129 |
if (toId >= 0) // < 0 = denied or unchanged |
6285 |
30 May 13 |
nicklas |
130 |
{ |
6285 |
30 May 13 |
nicklas |
131 |
BasicItem to = anyToAny.getToType().getById(dc, toId); |
6285 |
30 May 13 |
nicklas |
132 |
anyToAny.setTo(to); |
6285 |
30 May 13 |
nicklas |
133 |
} |
6285 |
30 May 13 |
nicklas |
134 |
|
6285 |
30 May 13 |
nicklas |
135 |
message = "Link updated"; |
2396 |
19 Jun 06 |
nicklas |
136 |
} |
2396 |
19 Jun 06 |
nicklas |
137 |
|
2396 |
19 Jun 06 |
nicklas |
138 |
anyToAny.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
6285 |
30 May 13 |
nicklas |
139 |
anyToAny.setUsingTo(Values.getBoolean(request.getParameter("block_removal"))); |
6282 |
27 May 13 |
nicklas |
140 |
|
2396 |
19 Jun 06 |
nicklas |
141 |
dc.commit(); |
2396 |
19 Jun 06 |
nicklas |
142 |
cc.removeObject("item"); |
2396 |
19 Jun 06 |
nicklas |
143 |
} |
6284 |
30 May 13 |
nicklas |
144 |
else if ("DeleteItems".equals(cmd)) |
6284 |
30 May 13 |
nicklas |
145 |
{ |
7954 |
12 May 21 |
nicklas |
146 |
dc = sc.newDbControl(":Delete "+itemType); |
6284 |
30 May 13 |
nicklas |
147 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
6284 |
30 May 13 |
nicklas |
148 |
int numTotal = cc.getSelected().size(); |
6284 |
30 May 13 |
nicklas |
149 |
int numDeleted = RemovableUtil.delete(dc, itemType, cc.getSelected()); |
6284 |
30 May 13 |
nicklas |
150 |
dc.commit(); |
6284 |
30 May 13 |
nicklas |
151 |
if (numTotal != numDeleted) |
6284 |
30 May 13 |
nicklas |
152 |
{ |
6284 |
30 May 13 |
nicklas |
153 |
message = (numDeleted == 0 ? "No" : "Only "+numDeleted+" of "+numTotal) + " items could be unlinked, because you have no DELETE permission"; |
6284 |
30 May 13 |
nicklas |
154 |
} |
6284 |
30 May 13 |
nicklas |
155 |
else |
6284 |
30 May 13 |
nicklas |
156 |
{ |
6284 |
30 May 13 |
nicklas |
157 |
message = numDeleted + " items unlinked"; |
6284 |
30 May 13 |
nicklas |
158 |
} |
6284 |
30 May 13 |
nicklas |
159 |
} |
2396 |
19 Jun 06 |
nicklas |
160 |
else |
2396 |
19 Jun 06 |
nicklas |
161 |
{ |
2396 |
19 Jun 06 |
nicklas |
162 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
2396 |
19 Jun 06 |
nicklas |
163 |
} |
2396 |
19 Jun 06 |
nicklas |
164 |
} |
2396 |
19 Jun 06 |
nicklas |
165 |
finally |
2396 |
19 Jun 06 |
nicklas |
166 |
{ |
2396 |
19 Jun 06 |
nicklas |
167 |
if (dc != null) dc.close(); |
2396 |
19 Jun 06 |
nicklas |
168 |
} |
2396 |
19 Jun 06 |
nicklas |
169 |
|
2396 |
19 Jun 06 |
nicklas |
170 |
if (forward != null) |
2396 |
19 Jun 06 |
nicklas |
171 |
{ |
6192 |
31 Oct 12 |
nicklas |
172 |
sc.setSessionSetting("alert-message", message); |
2396 |
19 Jun 06 |
nicklas |
173 |
pageContext.forward(forward); |
2396 |
19 Jun 06 |
nicklas |
174 |
} |
2396 |
19 Jun 06 |
nicklas |
175 |
else if (redirect != null) |
2396 |
19 Jun 06 |
nicklas |
176 |
{ |
6192 |
31 Oct 12 |
nicklas |
177 |
sc.setSessionSetting("alert-message", message); |
2396 |
19 Jun 06 |
nicklas |
178 |
response.sendRedirect(redirect); |
2396 |
19 Jun 06 |
nicklas |
179 |
} |
2396 |
19 Jun 06 |
nicklas |
180 |
else if (message == null) |
2396 |
19 Jun 06 |
nicklas |
181 |
{ |
2396 |
19 Jun 06 |
nicklas |
182 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
2396 |
19 Jun 06 |
nicklas |
183 |
} |
2396 |
19 Jun 06 |
nicklas |
184 |
else |
2396 |
19 Jun 06 |
nicklas |
185 |
{ |
2396 |
19 Jun 06 |
nicklas |
186 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
2396 |
19 Jun 06 |
nicklas |
187 |
} |
2396 |
19 Jun 06 |
nicklas |
188 |
%> |
2396 |
19 Jun 06 |
nicklas |
189 |
|