1 | <%-- $Id: list_annotations.jsp 5984 2012-02-24 07:33:47Z 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.Permission" |
---|
30 | import="net.sf.basedb.core.AnnotationType" |
---|
31 | import="net.sf.basedb.core.Protocol" |
---|
32 | import="net.sf.basedb.core.AnnotationSet" |
---|
33 | import="net.sf.basedb.core.Annotation" |
---|
34 | import="net.sf.basedb.core.Annotatable" |
---|
35 | import="net.sf.basedb.core.AnnotatableProxy" |
---|
36 | import="net.sf.basedb.core.Unit" |
---|
37 | import="net.sf.basedb.core.Nameable" |
---|
38 | import="net.sf.basedb.core.Subtypable" |
---|
39 | import="net.sf.basedb.core.ItemSubtype" |
---|
40 | import="net.sf.basedb.core.ItemQuery" |
---|
41 | import="net.sf.basedb.core.ItemResultList" |
---|
42 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
43 | import="net.sf.basedb.core.query.Orders" |
---|
44 | import="net.sf.basedb.core.query.Hql" |
---|
45 | import="net.sf.basedb.core.snapshot.AnnotationSetSnapshot" |
---|
46 | import="net.sf.basedb.core.snapshot.AnnotationSnapshot" |
---|
47 | import="net.sf.basedb.core.snapshot.SnapshotManager" |
---|
48 | import="net.sf.basedb.clients.web.Base" |
---|
49 | import="net.sf.basedb.clients.web.util.HTML" |
---|
50 | import="net.sf.basedb.util.NameableComparator" |
---|
51 | import="net.sf.basedb.util.formatter.Formatter" |
---|
52 | import="net.sf.basedb.util.formatter.PrefixSuffixFormatter" |
---|
53 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
54 | import="net.sf.basedb.util.Values" |
---|
55 | import="java.util.ArrayList" |
---|
56 | import="java.util.List" |
---|
57 | import="java.util.Set" |
---|
58 | import="java.util.HashSet" |
---|
59 | import="java.util.TreeSet" |
---|
60 | import="java.util.Map" |
---|
61 | import="java.util.HashMap" |
---|
62 | %> |
---|
63 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
64 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
65 | |
---|
66 | <% |
---|
67 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
68 | final String ID = sc.getId(); |
---|
69 | final Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
70 | final int itemId = Values.getInt(request.getParameter("item_id")); |
---|
71 | final float scale = Base.getScale(sc); |
---|
72 | final DbControl dc = sc.newDbControl(); |
---|
73 | |
---|
74 | Set<AnnotationType> annotationTypes = null; |
---|
75 | Set<AnnotationType> protocolParameters = null; |
---|
76 | Map<AnnotationType, AnnotationSnapshot> existing = null; |
---|
77 | |
---|
78 | try |
---|
79 | { |
---|
80 | final Annotatable item = (Annotatable)itemType.getById(dc, itemId); |
---|
81 | final boolean writePermission = item.hasPermission(Permission.WRITE); |
---|
82 | final SnapshotManager manager = new SnapshotManager(); |
---|
83 | |
---|
84 | ItemQuery<AnnotationType> annotationTypeQuery = null; |
---|
85 | String message = null; |
---|
86 | boolean isProxy = item instanceof AnnotatableProxy; |
---|
87 | |
---|
88 | // Load all annotation types that are possible for this item type |
---|
89 | if (isProxy) |
---|
90 | { |
---|
91 | AnnotatableProxy proxy = (AnnotatableProxy)item; |
---|
92 | annotationTypeQuery = Base.getAnnotationTypesQuery(proxy); |
---|
93 | message = proxy.getAnnotationMessage(); |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | annotationTypeQuery = Base.getAnnotationTypesQuery(itemType, false); |
---|
98 | } |
---|
99 | annotationTypes = new TreeSet<AnnotationType>(new NameableComparator(false)); |
---|
100 | annotationTypes.addAll(annotationTypeQuery.list(dc)); |
---|
101 | |
---|
102 | final AnnotationSetSnapshot snapshot = item.isAnnotated() ? |
---|
103 | manager.getSnapshot(dc, item.getAnnotationSet().getId()) : null; |
---|
104 | List<AnnotationSnapshot> inheritedAnnotations = null; |
---|
105 | if (snapshot != null) |
---|
106 | { |
---|
107 | // Load the existing primary and inherited annotations |
---|
108 | existing = new HashMap<AnnotationType, AnnotationSnapshot>(); |
---|
109 | inheritedAnnotations = new ArrayList<AnnotationSnapshot>(); |
---|
110 | for (AnnotationSnapshot a : manager.findAnnotations(dc, snapshot, null, true)) |
---|
111 | { |
---|
112 | try |
---|
113 | { |
---|
114 | AnnotationType at = a.getAnnotationType(dc); |
---|
115 | if (!a.isInherited()) |
---|
116 | { |
---|
117 | existing.put(a.getAnnotationType(dc), a); |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | inheritedAnnotations.add(a); |
---|
122 | } |
---|
123 | } |
---|
124 | catch (PermissionDeniedException ex) |
---|
125 | {} |
---|
126 | } |
---|
127 | annotationTypes.addAll(existing.keySet()); |
---|
128 | } |
---|
129 | |
---|
130 | // Load the possible protocol parameters |
---|
131 | Protocol protocol = null; |
---|
132 | boolean readProtocol = true; |
---|
133 | try |
---|
134 | { |
---|
135 | protocol = item.getProtocol(); |
---|
136 | } |
---|
137 | catch (PermissionDeniedException ex) |
---|
138 | { |
---|
139 | readProtocol = false; |
---|
140 | } |
---|
141 | ItemQuery<AnnotationType> parameterQuery = Base.getProtocolParametersQuery(protocol); |
---|
142 | if (parameterQuery != null) |
---|
143 | { |
---|
144 | protocolParameters = new HashSet<AnnotationType>(parameterQuery.list(dc)); |
---|
145 | annotationTypes.removeAll(protocolParameters); |
---|
146 | } |
---|
147 | %> |
---|
148 | <base:page type="include"> |
---|
149 | <base:body> |
---|
150 | <script language="JavaScript"> |
---|
151 | function editAnnotation(annotationTypeId) |
---|
152 | { |
---|
153 | var url = getRoot() + 'common/annotations/annotate.jsp?ID=<%=ID%>'; |
---|
154 | url += '&item_type=<%=itemType.name()%>'; |
---|
155 | url += '&item_id=<%=itemId%>'; |
---|
156 | url += '&annotationtype_id='+annotationTypeId; |
---|
157 | url += '&standalone=1'; |
---|
158 | Main.openPopup(url, 'EditAnnotation', 750, 500); |
---|
159 | } |
---|
160 | function editInheritedAnnotation(itemType, itemId, annotationTypeId) |
---|
161 | { |
---|
162 | var url = getRoot() + 'common/annotations/annotate.jsp?ID=<%=ID%>'; |
---|
163 | url += '&item_type='+itemType; |
---|
164 | url += '&item_id='+itemId; |
---|
165 | url += '&annotationtype_id='+annotationTypeId; |
---|
166 | url += '&standalone=1'; |
---|
167 | Main.openPopup(url, 'EditAnnotation', 750, 500); |
---|
168 | } |
---|
169 | </script> |
---|
170 | <% |
---|
171 | if (message != null) |
---|
172 | { |
---|
173 | %> |
---|
174 | <div class="messagecontainer note"><%=message%></div> |
---|
175 | <% |
---|
176 | } |
---|
177 | %> |
---|
178 | <base:section |
---|
179 | id="primaryAnnotations" |
---|
180 | title="<%="Primary annotations (" + annotationTypes.size() + ")"%>" |
---|
181 | > |
---|
182 | <% |
---|
183 | if (annotationTypes.size() == 0) |
---|
184 | { |
---|
185 | %> |
---|
186 | <div class="messagecontainer note"> |
---|
187 | No annotation types has been defined for this type of item |
---|
188 | (or you don't have permission to view them). |
---|
189 | </div> |
---|
190 | <% |
---|
191 | } |
---|
192 | else |
---|
193 | { |
---|
194 | %> |
---|
195 | <tbl:table |
---|
196 | id="annotations" |
---|
197 | columns="all" |
---|
198 | > |
---|
199 | <tbl:columndef |
---|
200 | id="annotation" |
---|
201 | title="Annotation" |
---|
202 | /> |
---|
203 | <tbl:columndef |
---|
204 | id="values" |
---|
205 | title="Values" |
---|
206 | /> |
---|
207 | <tbl:columndef |
---|
208 | id="description" |
---|
209 | title="Description" |
---|
210 | /> |
---|
211 | <tbl:data> |
---|
212 | <tbl:headers> |
---|
213 | <tbl:headerrow> |
---|
214 | <tbl:columnheaders /> |
---|
215 | </tbl:headerrow> |
---|
216 | </tbl:headers> |
---|
217 | <tbl:rows> |
---|
218 | <% |
---|
219 | for (AnnotationType at : annotationTypes) |
---|
220 | { |
---|
221 | AnnotationSnapshot a = existing != null ? existing.get(at) : null; |
---|
222 | List<?> values = null; |
---|
223 | Formatter formatter = null; |
---|
224 | if (a != null) |
---|
225 | { |
---|
226 | Annotation ann = a.getAnnotation(dc); |
---|
227 | values = a.getValues(ann.getUnitConverter(null), ann.getValueType()); |
---|
228 | formatter = FormatterFactory.getAnnotationFormatter(sc, ann, null); |
---|
229 | } |
---|
230 | if (values != null || !at.isRemoved()) |
---|
231 | { |
---|
232 | %> |
---|
233 | <tbl:row> |
---|
234 | <tbl:cell column="annotation"><base:icon |
---|
235 | image="deleted.png" |
---|
236 | tooltip="This item has been scheduled for deletion" |
---|
237 | visible="<%=at.isRemoved()%>" |
---|
238 | /><%=Base.getLinkedName(ID, at, false, true)%></tbl:cell> |
---|
239 | <tbl:cell column="values"><%=values == null || values.size() == 0 ? "<i>- no values -</i>" : Values.getString(values, ", ", true, formatter)%> |
---|
240 | <% |
---|
241 | if (writePermission) |
---|
242 | { |
---|
243 | %>: <base:icon image="edit.png" |
---|
244 | onclick="<%="editAnnotation("+at.getId()+")"%>" |
---|
245 | tooltip="Modify the values of this annotation" /> |
---|
246 | <% |
---|
247 | } |
---|
248 | %> |
---|
249 | </tbl:cell> |
---|
250 | <tbl:cell column="description"><%=HTML.encodeTags(at.getDescription())%></tbl:cell> |
---|
251 | </tbl:row> |
---|
252 | <% |
---|
253 | } |
---|
254 | } |
---|
255 | %> |
---|
256 | </tbl:rows> |
---|
257 | </tbl:data> |
---|
258 | </tbl:table> |
---|
259 | <% |
---|
260 | } |
---|
261 | %> |
---|
262 | </base:section> |
---|
263 | |
---|
264 | <% |
---|
265 | if (protocolParameters != null) |
---|
266 | { |
---|
267 | %> |
---|
268 | <base:section |
---|
269 | id="parameterSection" |
---|
270 | title="<%="Protocol parameters for " + HTML.encodeTags(protocol.getName()) + |
---|
271 | " (" + protocolParameters.size() + ")"%>" |
---|
272 | > |
---|
273 | <% |
---|
274 | if (protocolParameters.size() == 0) |
---|
275 | { |
---|
276 | %> |
---|
277 | <div class="messagecontainer note"> |
---|
278 | No protocol parameters has been defined for the protocol |
---|
279 | <%=Base.getLinkedName(ID, protocol, !readProtocol, true)%> |
---|
280 | (or you don't have permission to view them). |
---|
281 | </div> |
---|
282 | <% |
---|
283 | } |
---|
284 | else |
---|
285 | { |
---|
286 | %> |
---|
287 | <tbl:table |
---|
288 | id="parameters" |
---|
289 | columns="all" |
---|
290 | > |
---|
291 | <tbl:columndef |
---|
292 | id="parameter" |
---|
293 | title="Parameter" |
---|
294 | /> |
---|
295 | <tbl:columndef |
---|
296 | id="values" |
---|
297 | title="Values" |
---|
298 | /> |
---|
299 | <tbl:columndef |
---|
300 | id="description" |
---|
301 | title="Description" |
---|
302 | /> |
---|
303 | <tbl:data> |
---|
304 | <tbl:headers> |
---|
305 | <tbl:headerrow> |
---|
306 | <tbl:columnheaders /> |
---|
307 | </tbl:headerrow> |
---|
308 | </tbl:headers> |
---|
309 | <tbl:rows> |
---|
310 | <% |
---|
311 | for (AnnotationType at : protocolParameters) |
---|
312 | { |
---|
313 | AnnotationSnapshot a = existing != null ? existing.get(at) : null; |
---|
314 | Formatter formatter = null; |
---|
315 | List<?> values = null; |
---|
316 | if (a != null) |
---|
317 | { |
---|
318 | Annotation ann = a.getAnnotation(dc); |
---|
319 | values = a.getValues(ann.getUnitConverter(null), ann.getValueType()); |
---|
320 | formatter = FormatterFactory.getAnnotationFormatter(sc, ann, null); |
---|
321 | } |
---|
322 | if (values != null || !at.isRemoved()) |
---|
323 | { |
---|
324 | %> |
---|
325 | <tbl:row> |
---|
326 | <tbl:cell column="parameter"><base:icon |
---|
327 | image="deleted.png" |
---|
328 | tooltip="This item has been scheduled for deletion" |
---|
329 | visible="<%=at.isRemoved()%>" |
---|
330 | /><%=Base.getLinkedName(ID, at, false, true)%></tbl:cell> |
---|
331 | <tbl:cell column="values"> |
---|
332 | <%=values == null || values.size() == 0 ? "<i>- no values -</i>" : Values.getString(values, ", ", true, formatter)%> |
---|
333 | <% |
---|
334 | if (writePermission) |
---|
335 | { |
---|
336 | %>: <base:icon image="edit.png" |
---|
337 | onclick="<%="editAnnotation("+at.getId()+")"%>" |
---|
338 | tooltip="Modify the values of this protocol parameter" /> |
---|
339 | <% |
---|
340 | } |
---|
341 | %> |
---|
342 | </tbl:cell> |
---|
343 | <tbl:cell column="description"><%=HTML.encodeTags(at.getDescription())%></tbl:cell> |
---|
344 | </tbl:row> |
---|
345 | <% |
---|
346 | } |
---|
347 | } |
---|
348 | %> |
---|
349 | </tbl:rows> |
---|
350 | </tbl:data> |
---|
351 | </tbl:table> |
---|
352 | <% |
---|
353 | } |
---|
354 | %> |
---|
355 | </base:section> |
---|
356 | <% |
---|
357 | } |
---|
358 | %> |
---|
359 | <% |
---|
360 | if (!isProxy) |
---|
361 | { |
---|
362 | int numInherited = inheritedAnnotations == null ? 0 : inheritedAnnotations.size(); |
---|
363 | %> |
---|
364 | <base:section |
---|
365 | id="inherited" |
---|
366 | title="<%="Inherited annotations and protocol parameters (" + numInherited + ")"%>" |
---|
367 | > |
---|
368 | <% |
---|
369 | if (numInherited == 0) |
---|
370 | { |
---|
371 | %> |
---|
372 | <div class="messagecontainer note"> |
---|
373 | No annotations are inherited by this item. |
---|
374 | (or you don't have permission to view them). |
---|
375 | </div> |
---|
376 | <% |
---|
377 | } |
---|
378 | else |
---|
379 | { |
---|
380 | %> |
---|
381 | <tbl:table |
---|
382 | id="inheritedAnnotations" |
---|
383 | columns="all" |
---|
384 | > |
---|
385 | <tbl:columndef |
---|
386 | id="annotation" |
---|
387 | title="Annotation" |
---|
388 | /> |
---|
389 | <tbl:columndef |
---|
390 | id="item" |
---|
391 | title="From item" |
---|
392 | /> |
---|
393 | <tbl:columndef |
---|
394 | id="values" |
---|
395 | title="Values" |
---|
396 | /> |
---|
397 | <tbl:columndef |
---|
398 | id="description" |
---|
399 | title="Description" |
---|
400 | /> |
---|
401 | <tbl:data> |
---|
402 | <tbl:headers> |
---|
403 | <tbl:headerrow> |
---|
404 | <tbl:columnheaders /> |
---|
405 | </tbl:headerrow> |
---|
406 | </tbl:headers> |
---|
407 | <tbl:rows> |
---|
408 | <% |
---|
409 | for (AnnotationSnapshot a : inheritedAnnotations) |
---|
410 | { |
---|
411 | Annotation ann = a.getAnnotation(dc); |
---|
412 | AnnotationType at = a.getAnnotationType(dc); |
---|
413 | String name = HTML.encodeTags(at.getName()); |
---|
414 | String description = HTML.encodeTags(at.getDescription()); |
---|
415 | boolean writeInherited = false; |
---|
416 | String icon = "joust/annotation.gif"; |
---|
417 | if (at.isRemoved()) |
---|
418 | { |
---|
419 | icon = "deleted.png"; |
---|
420 | } |
---|
421 | else if (at.isProtocolParameter()) |
---|
422 | { |
---|
423 | icon = "parameter.png"; |
---|
424 | } |
---|
425 | List<?> values = a.getValues(ann.getUnitConverter(null), ann.getValueType()); |
---|
426 | Formatter formatter = FormatterFactory.getAnnotationFormatter(sc, ann, null); |
---|
427 | Nameable aItem = null; |
---|
428 | String fromType = a.getItemType().toString(); |
---|
429 | try |
---|
430 | { |
---|
431 | aItem = (Nameable)a.getItem(dc); |
---|
432 | writeInherited = aItem.hasPermission(Permission.WRITE); |
---|
433 | } |
---|
434 | catch (PermissionDeniedException ex) |
---|
435 | {} |
---|
436 | if (aItem instanceof Subtypable) |
---|
437 | { |
---|
438 | try |
---|
439 | { |
---|
440 | ItemSubtype subtype = ((Subtypable)aItem).getItemSubtype(); |
---|
441 | if (subtype != null) fromType = subtype.getName(); |
---|
442 | } |
---|
443 | catch (PermissionDeniedException ex) |
---|
444 | {} |
---|
445 | } %> |
---|
446 | <tbl:row> |
---|
447 | <tbl:cell column="annotation"><base:icon image="<%=icon%>" /><%=Base.getLinkedName(ID, at, at == null, true)%></tbl:cell> |
---|
448 | <tbl:cell column="item"><%=Base.getLinkedName(ID, aItem, aItem == null, true)%><%=aItem != null ? " <span class=\"itemsubtype\">("+fromType+")</span>" : ""%></tbl:cell> |
---|
449 | <tbl:cell column="values"> |
---|
450 | <%=values == null || values.size() == 0 ? |
---|
451 | "<i>- no values -</i>" : Values.getString(values, ", ", true, formatter)%> |
---|
452 | <% |
---|
453 | if (writeInherited && aItem != null) |
---|
454 | { |
---|
455 | %>: <base:icon image="edit.png" |
---|
456 | onclick="<%="editInheritedAnnotation('"+aItem.getType().name()+"', "+aItem.getId()+", "+at.getId()+")"%>" |
---|
457 | tooltip="Modify the values of this annotation" /> |
---|
458 | <% |
---|
459 | } |
---|
460 | %> |
---|
461 | </tbl:cell> |
---|
462 | <tbl:cell column="description"><%=description%></tbl:cell> |
---|
463 | </tbl:row> |
---|
464 | <% |
---|
465 | } |
---|
466 | %> |
---|
467 | </tbl:rows> |
---|
468 | </tbl:data> |
---|
469 | </tbl:table> |
---|
470 | <base:icon image="joust/annotation.gif" /> = Annotation, |
---|
471 | <base:icon image="parameter.png" /> = Protocol parameter |
---|
472 | <% |
---|
473 | } |
---|
474 | %> |
---|
475 | </base:section> |
---|
476 | <% |
---|
477 | } |
---|
478 | %> |
---|
479 | </base:body> |
---|
480 | </base:page> |
---|
481 | <% |
---|
482 | } |
---|
483 | finally |
---|
484 | { |
---|
485 | if (dc != null) dc.close(); |
---|
486 | } |
---|
487 | |
---|
488 | %> |
---|