1 | <%-- $Id: list_files.jsp 5698 2011-08-15 11:57:00Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
---|
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.0 |
---|
24 | --%> |
---|
25 | <%@page import="net.sf.basedb.core.Subtypable"%> |
---|
26 | <%@page import="net.sf.basedb.core.ItemSubtype"%> |
---|
27 | <%@ page pageEncoding="UTF-8" session="false" |
---|
28 | import="net.sf.basedb.core.SessionControl" |
---|
29 | import="net.sf.basedb.core.DbControl" |
---|
30 | import="net.sf.basedb.core.Item" |
---|
31 | import="net.sf.basedb.core.ItemContext" |
---|
32 | import="net.sf.basedb.core.Permission" |
---|
33 | import="net.sf.basedb.core.Platform" |
---|
34 | import="net.sf.basedb.core.PlatformVariant" |
---|
35 | import="net.sf.basedb.core.PlatformFileType" |
---|
36 | import="net.sf.basedb.core.DataFileType" |
---|
37 | import="net.sf.basedb.core.FileSet" |
---|
38 | import="net.sf.basedb.core.FileSetMember" |
---|
39 | import="net.sf.basedb.core.File" |
---|
40 | import="net.sf.basedb.core.FileStoreEnabled" |
---|
41 | import="net.sf.basedb.core.Nameable" |
---|
42 | import="net.sf.basedb.core.ItemQuery" |
---|
43 | import="net.sf.basedb.core.ItemResultList" |
---|
44 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
45 | import="net.sf.basedb.core.query.Orders" |
---|
46 | import="net.sf.basedb.core.query.Expressions" |
---|
47 | import="net.sf.basedb.core.query.Restrictions" |
---|
48 | import="net.sf.basedb.core.query.Hql" |
---|
49 | import="net.sf.basedb.util.NameableComparator" |
---|
50 | import="net.sf.basedb.clients.web.Base" |
---|
51 | import="net.sf.basedb.clients.web.util.HTML" |
---|
52 | import="net.sf.basedb.util.formatter.Formatter" |
---|
53 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
54 | import="net.sf.basedb.util.Values" |
---|
55 | import="java.util.Map" |
---|
56 | import="java.util.Set" |
---|
57 | import="java.util.HashSet" |
---|
58 | import="java.util.HashMap" |
---|
59 | import="java.util.List" |
---|
60 | import="java.util.LinkedList" |
---|
61 | import="java.util.Collection" |
---|
62 | %> |
---|
63 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
64 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
65 | <%! |
---|
66 | |
---|
67 | private static class DataFile |
---|
68 | { |
---|
69 | final DataFileType type; |
---|
70 | final FileSetMember member; |
---|
71 | final FileStoreEnabled parent; |
---|
72 | DataFile(DataFileType type, FileSetMember member, FileStoreEnabled parent) |
---|
73 | { |
---|
74 | this.type = type; |
---|
75 | this.member = member; |
---|
76 | this.parent = parent; |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | %> |
---|
81 | <% |
---|
82 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
83 | final String ID = sc.getId(); |
---|
84 | final Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
85 | final int itemId = Values.getInt(request.getParameter("item_id")); |
---|
86 | final float scale = Base.getScale(sc); |
---|
87 | final DbControl dc = sc.newDbControl(); |
---|
88 | final ItemContext cc = sc.getCurrentContext(itemType); |
---|
89 | final String root = request.getContextPath() + "/"; |
---|
90 | |
---|
91 | try |
---|
92 | { |
---|
93 | final FileStoreEnabled item = (FileStoreEnabled)itemType.getById(dc, itemId); |
---|
94 | final FileSet fileSet = item.hasFileSet() ? item.getFileSet() : null; |
---|
95 | Collection<FileSet> parents = null; |
---|
96 | try |
---|
97 | { |
---|
98 | parents = item.getParentFileSets(); |
---|
99 | } |
---|
100 | catch (Throwable t) |
---|
101 | {} |
---|
102 | |
---|
103 | Platform platform = null; |
---|
104 | PlatformVariant variant = null; |
---|
105 | ItemSubtype subtype = null; |
---|
106 | try |
---|
107 | { |
---|
108 | platform = item.getPlatform(); |
---|
109 | variant = item.getVariant(); |
---|
110 | } |
---|
111 | catch (Throwable t) |
---|
112 | {} |
---|
113 | if (item instanceof Subtypable) |
---|
114 | { |
---|
115 | try |
---|
116 | { |
---|
117 | subtype = ((Subtypable)item).getItemSubtype(); |
---|
118 | } |
---|
119 | catch (Throwable t) |
---|
120 | {} |
---|
121 | } |
---|
122 | |
---|
123 | // Load member file types |
---|
124 | List<DataFile> members = new LinkedList<DataFile>(); |
---|
125 | Set<DataFileType> existing = new HashSet<DataFileType>(); |
---|
126 | if (fileSet != null) |
---|
127 | { |
---|
128 | ItemQuery<FileSetMember> query = fileSet.getMembers(); |
---|
129 | for (FileSetMember member : query.list(dc)) |
---|
130 | { |
---|
131 | DataFileType dft = null; |
---|
132 | try |
---|
133 | { |
---|
134 | dft = member.getDataFileType(); |
---|
135 | existing.add(dft); |
---|
136 | } |
---|
137 | catch (Throwable t) |
---|
138 | {} |
---|
139 | members.add(new DataFile(dft, member, null)); |
---|
140 | } |
---|
141 | } |
---|
142 | int numMembers = members.size(); |
---|
143 | if (parents != null && !parents.isEmpty()) |
---|
144 | { |
---|
145 | for (FileSet pFileSet : parents) |
---|
146 | { |
---|
147 | try |
---|
148 | { |
---|
149 | FileStoreEnabled parent = pFileSet.getItem(); |
---|
150 | for (FileSetMember pMember : pFileSet.getMembers().list(dc)) |
---|
151 | { |
---|
152 | DataFileType dft = null; |
---|
153 | try |
---|
154 | { |
---|
155 | dft = pMember.getDataFileType(); |
---|
156 | } |
---|
157 | catch (Throwable t) |
---|
158 | {} |
---|
159 | members.add(new DataFile(dft, pMember, parent)); |
---|
160 | } |
---|
161 | } |
---|
162 | catch (Throwable t) |
---|
163 | {} |
---|
164 | } |
---|
165 | } |
---|
166 | int numParents = members.size() - numMembers; |
---|
167 | |
---|
168 | |
---|
169 | // Load platform file types |
---|
170 | Map<DataFileType, PlatformFileType> platformFileTypes = |
---|
171 | new HashMap<DataFileType, PlatformFileType>(); |
---|
172 | if (platform != null) |
---|
173 | { |
---|
174 | ItemQuery<PlatformFileType> query = platform.getFileTypes(variant, variant == null); |
---|
175 | for (PlatformFileType pft : query.list(dc)) |
---|
176 | { |
---|
177 | DataFileType dft = null; |
---|
178 | try |
---|
179 | { |
---|
180 | dft = pft.getDataFileType(); |
---|
181 | platformFileTypes.put(dft, pft); |
---|
182 | if (dft.getItemType() == itemType && !existing.contains(dft)) |
---|
183 | { |
---|
184 | members.add(new DataFile(dft, null, null)); |
---|
185 | } |
---|
186 | } |
---|
187 | catch (Throwable t) |
---|
188 | {} |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | // Load subtype-related file types |
---|
193 | if (subtype != null) |
---|
194 | { |
---|
195 | ItemQuery<DataFileType> query = subtype.getDataFileTypes(); |
---|
196 | for (DataFileType dft : query.list(dc)) |
---|
197 | { |
---|
198 | if (!existing.contains(dft)) |
---|
199 | { |
---|
200 | members.add(new DataFile(dft, null, null)); |
---|
201 | } |
---|
202 | } |
---|
203 | } |
---|
204 | %> |
---|
205 | <base:page type="include"> |
---|
206 | <base:body> |
---|
207 | <script language="JavaScript"> |
---|
208 | </script> |
---|
209 | <% |
---|
210 | if (members.size() == 0) |
---|
211 | { |
---|
212 | %> |
---|
213 | <h4>Data files</h4> |
---|
214 | No files have been added to this item |
---|
215 | (or you don't have permission to view them). |
---|
216 | <% |
---|
217 | } |
---|
218 | else |
---|
219 | { |
---|
220 | %> |
---|
221 | <base:section |
---|
222 | id="datafiles" |
---|
223 | title="<%="Data files (" + (numMembers + numParents) +")"%>" |
---|
224 | context="<%=cc%>"> |
---|
225 | <tbl:table |
---|
226 | id="datafiles" |
---|
227 | clazz="itemlist" |
---|
228 | columns="all" |
---|
229 | > |
---|
230 | <tbl:columndef |
---|
231 | id="type" |
---|
232 | title="Type" |
---|
233 | /> |
---|
234 | <tbl:columndef |
---|
235 | id="file" |
---|
236 | title="File" |
---|
237 | /> |
---|
238 | <tbl:columndef |
---|
239 | id="required" |
---|
240 | title="Required" |
---|
241 | /> |
---|
242 | <tbl:columndef |
---|
243 | id="validation" |
---|
244 | title="Validation" |
---|
245 | /> |
---|
246 | <tbl:data> |
---|
247 | <tbl:columns> |
---|
248 | </tbl:columns> |
---|
249 | <tbl:rows> |
---|
250 | <% |
---|
251 | for (DataFile dataFile : members) |
---|
252 | { |
---|
253 | FileSetMember member = dataFile.member; |
---|
254 | DataFileType dft = dataFile.type; |
---|
255 | FileStoreEnabled parent = dataFile.parent; |
---|
256 | Boolean validFile = null; |
---|
257 | String validationMessage = ""; |
---|
258 | boolean readFile = true; |
---|
259 | File file = null; |
---|
260 | boolean readDataFileType = true; |
---|
261 | if (member != null) |
---|
262 | { |
---|
263 | try |
---|
264 | { |
---|
265 | file = member.getFile(); |
---|
266 | } |
---|
267 | catch (PermissionDeniedException ex) |
---|
268 | { |
---|
269 | readFile = false; |
---|
270 | } |
---|
271 | try |
---|
272 | { |
---|
273 | dft = member.getDataFileType(); |
---|
274 | } |
---|
275 | catch (PermissionDeniedException ex) |
---|
276 | { |
---|
277 | readDataFileType = false; |
---|
278 | } |
---|
279 | } |
---|
280 | PlatformFileType pft = platformFileTypes.get(dft); |
---|
281 | boolean isRequired = pft == null ? false : pft.isRequired(); |
---|
282 | boolean isPartOfPlatform = pft != null || (subtype != null && subtype.isAssociatedDataFileType(dft)); |
---|
283 | String icon = null; |
---|
284 | if (member == null) |
---|
285 | { |
---|
286 | if (isRequired) |
---|
287 | { |
---|
288 | icon = "warning.gif"; |
---|
289 | validationMessage = "Missing a required file"; |
---|
290 | } |
---|
291 | } |
---|
292 | else |
---|
293 | { |
---|
294 | validFile = member.isValid(); |
---|
295 | if (Boolean.FALSE.equals(validFile)) |
---|
296 | { |
---|
297 | validationMessage = HTML.encodeTags(member.getErrorMessage()); |
---|
298 | icon = "error.gif"; |
---|
299 | } |
---|
300 | else if (!isPartOfPlatform) |
---|
301 | { |
---|
302 | icon = "warning.gif"; |
---|
303 | if (platform != null) |
---|
304 | { |
---|
305 | validationMessage = "This file is not part of the <i>" + HTML.encodeTags(platform.getName()) + "</i> platform"; |
---|
306 | } |
---|
307 | else if (subtype != null) |
---|
308 | { |
---|
309 | validationMessage = "This file is not part of the <i>" + HTML.encodeTags(subtype.getName()) + "</i> subtype"; |
---|
310 | } |
---|
311 | } |
---|
312 | else if (Boolean.TRUE.equals(validFile)) |
---|
313 | { |
---|
314 | if (member.getErrorMessage() != null) |
---|
315 | { |
---|
316 | validationMessage = HTML.encodeTags(member.getErrorMessage()); |
---|
317 | icon = "warning.gif"; |
---|
318 | } |
---|
319 | else |
---|
320 | { |
---|
321 | validationMessage = "Ok"; |
---|
322 | icon = "ok.gif"; |
---|
323 | } |
---|
324 | } |
---|
325 | else |
---|
326 | { |
---|
327 | validationMessage = "<i>- not validated -</i>"; |
---|
328 | } |
---|
329 | } |
---|
330 | %> |
---|
331 | <tbl:row> |
---|
332 | <tbl:cell column="type"><base:icon |
---|
333 | image="deleted.gif" |
---|
334 | tooltip="This item has been scheduled for deletion" |
---|
335 | visible="<%=dft != null && dft.isRemoved()%>" |
---|
336 | /><%=Base.getLinkedName(ID, dft, !readDataFileType, true)%></tbl:cell> |
---|
337 | <tbl:cell column="file"><base:icon |
---|
338 | image="deleted.gif" |
---|
339 | tooltip="This item has been scheduled for deletion" |
---|
340 | visible="<%=file != null && file.isRemoved()%>" |
---|
341 | /> |
---|
342 | <%=Base.getLinkedFile(ID, file, !readFile, true, true, root)%> |
---|
343 | <% |
---|
344 | if (parent != null) |
---|
345 | { |
---|
346 | %> |
---|
347 | <i>(inherited from <%=Base.getLinkedName(ID, (Nameable)parent, false, true)%>)</i> |
---|
348 | <% |
---|
349 | } |
---|
350 | %> |
---|
351 | </tbl:cell> |
---|
352 | <tbl:cell column="required"><%=isRequired ? "yes" : "no" %></tbl:cell> |
---|
353 | <tbl:cell column="validation"> |
---|
354 | <base:icon image="<%=icon%>" visible="<%=icon != null %>" /> |
---|
355 | <%=validationMessage %> |
---|
356 | </tbl:cell> |
---|
357 | </tbl:row> |
---|
358 | <% |
---|
359 | } |
---|
360 | %> |
---|
361 | </tbl:rows> |
---|
362 | </tbl:data> |
---|
363 | </tbl:table> |
---|
364 | </base:section> |
---|
365 | <% |
---|
366 | } |
---|
367 | %> |
---|
368 | |
---|
369 | </base:body> |
---|
370 | </base:page> |
---|
371 | <% |
---|
372 | } |
---|
373 | finally |
---|
374 | { |
---|
375 | if (dc != null) dc.close(); |
---|
376 | } |
---|
377 | |
---|
378 | %> |
---|