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