1 | <%-- $Id: list_annotations.jsp 5055 2009-08-18 11:56:36Z martin $ |
---|
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 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.ItemQuery" |
---|
39 | import="net.sf.basedb.core.ItemResultList" |
---|
40 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
41 | import="net.sf.basedb.core.query.Orders" |
---|
42 | import="net.sf.basedb.core.query.Hql" |
---|
43 | import="net.sf.basedb.clients.web.Base" |
---|
44 | import="net.sf.basedb.clients.web.util.HTML" |
---|
45 | import="net.sf.basedb.util.formatter.Formatter" |
---|
46 | import="net.sf.basedb.util.formatter.PrefixSuffixFormatter" |
---|
47 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
48 | import="net.sf.basedb.util.Values" |
---|
49 | import="java.util.List" |
---|
50 | %> |
---|
51 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
52 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
53 | |
---|
54 | <% |
---|
55 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
56 | final String ID = sc.getId(); |
---|
57 | final Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
58 | final int itemId = Values.getInt(request.getParameter("item_id")); |
---|
59 | final float scale = Base.getScale(sc); |
---|
60 | final DbControl dc = sc.newDbControl(); |
---|
61 | |
---|
62 | try |
---|
63 | { |
---|
64 | final Annotatable item = (Annotatable)itemType.getById(dc, itemId); |
---|
65 | ItemQuery<AnnotationType> annotationTypeQuery = null; |
---|
66 | String message = null; |
---|
67 | boolean isProxy = item instanceof AnnotatableProxy; |
---|
68 | |
---|
69 | if (isProxy) |
---|
70 | { |
---|
71 | AnnotatableProxy proxy = (AnnotatableProxy)item; |
---|
72 | annotationTypeQuery = Base.getAnnotationTypesQuery(proxy); |
---|
73 | message = proxy.getAnnotationMessage(); |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | annotationTypeQuery = Base.getAnnotationTypesQuery(itemType, false); |
---|
78 | } |
---|
79 | final List<AnnotationType> annotationTypes = annotationTypeQuery.list(dc); |
---|
80 | Protocol protocol = null; |
---|
81 | boolean readProtocol = true; |
---|
82 | try |
---|
83 | { |
---|
84 | protocol = item.getProtocol(); |
---|
85 | } |
---|
86 | catch (PermissionDeniedException ex) |
---|
87 | { |
---|
88 | readProtocol = false; |
---|
89 | } |
---|
90 | final List<AnnotationType> protocolParameters = protocol == null ? |
---|
91 | null : Base.getProtocolParametersQuery(protocol).list(dc); |
---|
92 | final boolean writePermission = item.hasPermission(Permission.WRITE); |
---|
93 | |
---|
94 | final AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null; |
---|
95 | ItemResultList<Annotation> inheritedAnnotations = null; |
---|
96 | if (as != null) |
---|
97 | { |
---|
98 | ItemQuery<Annotation> inheritedQuery = as.getAllInheritedAnnotations(); |
---|
99 | // Need FETCH JOIN because Postgres don't like the DISTINCT keyword |
---|
100 | // if we sort on a non-selected column See ticket #731 |
---|
101 | inheritedQuery.join(Hql.innerJoin(null, "annotationType", "at", true)); |
---|
102 | inheritedQuery.order(Orders.asc(Hql.property("annotationSet"))); |
---|
103 | inheritedQuery.order(Orders.asc(Hql.property("at", "name"))); |
---|
104 | inheritedAnnotations = inheritedQuery.list(dc); |
---|
105 | } |
---|
106 | %> |
---|
107 | <base:page type="include"> |
---|
108 | <base:body> |
---|
109 | <script language="JavaScript"> |
---|
110 | function editAnnotation(annotationTypeId) |
---|
111 | { |
---|
112 | var url = getRoot() + 'common/annotations/annotate.jsp?ID=<%=ID%>'; |
---|
113 | url += '&item_type=<%=itemType.name()%>'; |
---|
114 | url += '&item_id=<%=itemId%>'; |
---|
115 | url += '&annotationtype_id='+annotationTypeId; |
---|
116 | url += '&standalone=1'; |
---|
117 | Main.openPopup(url, 'EditAnnotation', 700, 460); |
---|
118 | } |
---|
119 | function editInheritedAnnotation(itemType, itemId, annotationTypeId) |
---|
120 | { |
---|
121 | var url = getRoot() + 'common/annotations/annotate.jsp?ID=<%=ID%>'; |
---|
122 | url += '&item_type='+itemType; |
---|
123 | url += '&item_id='+itemId; |
---|
124 | url += '&annotationtype_id='+annotationTypeId; |
---|
125 | url += '&standalone=1'; |
---|
126 | Main.openPopup(url, 'EditAnnotation', 700, 460); |
---|
127 | } |
---|
128 | </script> |
---|
129 | <% |
---|
130 | if (annotationTypes.size() == 0) |
---|
131 | { |
---|
132 | %> |
---|
133 | <h4>Primary annotations</h4> |
---|
134 | No annotation types has been defined for this type of item |
---|
135 | (or you don't have permission to view them). |
---|
136 | <% |
---|
137 | } |
---|
138 | else |
---|
139 | { |
---|
140 | %> |
---|
141 | <%=message == null ? "" : message%> |
---|
142 | <base:section |
---|
143 | id="primaryAnnotations" |
---|
144 | title="<%="Primary annotations (" + annotationTypes.size() + ")"%>" |
---|
145 | > |
---|
146 | <tbl:table |
---|
147 | id="annotations" |
---|
148 | clazz="itemlist" |
---|
149 | columns="all" |
---|
150 | > |
---|
151 | <tbl:columndef |
---|
152 | id="annotation" |
---|
153 | title="Annotation" |
---|
154 | /> |
---|
155 | <tbl:columndef |
---|
156 | id="values" |
---|
157 | title="Values" |
---|
158 | /> |
---|
159 | <tbl:columndef |
---|
160 | id="description" |
---|
161 | title="Description" |
---|
162 | /> |
---|
163 | <tbl:data> |
---|
164 | <tbl:columns> |
---|
165 | </tbl:columns> |
---|
166 | <tbl:rows> |
---|
167 | <% |
---|
168 | for (AnnotationType at : annotationTypes) |
---|
169 | { |
---|
170 | Annotation a = as != null && as.hasAnnotation(at) ? as.getAnnotation(at) : null; |
---|
171 | List<?> values = null; |
---|
172 | Formatter formatter = null; |
---|
173 | if (a != null) |
---|
174 | { |
---|
175 | values = a.getValues(null); |
---|
176 | formatter = FormatterFactory.getAnnotationFormatter(sc, a, null); |
---|
177 | } |
---|
178 | if (values != null || !at.isRemoved()) |
---|
179 | { |
---|
180 | %> |
---|
181 | <tbl:row> |
---|
182 | <tbl:cell column="annotation"><base:icon |
---|
183 | image="deleted.gif" |
---|
184 | tooltip="This item has been scheduled for deletion" |
---|
185 | visible="<%=at.isRemoved()%>" |
---|
186 | /><%=Base.getLinkedName(ID, at, false, true)%></tbl:cell> |
---|
187 | <tbl:cell column="values"><%=values == null || values.size() == 0 ? "<i>- no values -</i>" : Values.getString(values, ", ", true, formatter)%> |
---|
188 | <% |
---|
189 | if (writePermission) |
---|
190 | { |
---|
191 | %>: <base:icon image="edit.gif" |
---|
192 | onclick="<%="editAnnotation("+at.getId()+")"%>" |
---|
193 | tooltip="Modify the values of this annotation" /> |
---|
194 | <% |
---|
195 | } |
---|
196 | %> |
---|
197 | </tbl:cell> |
---|
198 | <tbl:cell column="description"><%=HTML.encodeTags(at.getDescription())%></tbl:cell> |
---|
199 | </tbl:row> |
---|
200 | <% |
---|
201 | } |
---|
202 | } |
---|
203 | %> |
---|
204 | </tbl:rows> |
---|
205 | </tbl:data> |
---|
206 | </tbl:table> |
---|
207 | <br> |
---|
208 | </base:section> |
---|
209 | <% |
---|
210 | } |
---|
211 | if (protocolParameters != null ) |
---|
212 | { |
---|
213 | if (protocolParameters.size() == 0) |
---|
214 | { |
---|
215 | %> |
---|
216 | <h4>Protocol parameters</h4> |
---|
217 | No protocol parameters has been defined for the protocol |
---|
218 | <%=Base.getLinkedName(ID, protocol, !readProtocol, true)%> |
---|
219 | (or you don't have permission to view them). |
---|
220 | <% |
---|
221 | } |
---|
222 | else |
---|
223 | { |
---|
224 | %> |
---|
225 | <base:section |
---|
226 | id="parameterSection" |
---|
227 | title="<%="Protocol parameters for: " + |
---|
228 | Base.getLinkedName(ID, protocol, !readProtocol, true) + " (" + protocolParameters.size() + ")"%>" |
---|
229 | > |
---|
230 | <tbl:table |
---|
231 | id="parameters" |
---|
232 | clazz="itemlist" |
---|
233 | columns="all" |
---|
234 | > |
---|
235 | <tbl:columndef |
---|
236 | id="parameter" |
---|
237 | title="Parameter" |
---|
238 | /> |
---|
239 | <tbl:columndef |
---|
240 | id="values" |
---|
241 | title="Values" |
---|
242 | /> |
---|
243 | <tbl:columndef |
---|
244 | id="description" |
---|
245 | title="Description" |
---|
246 | /> |
---|
247 | <tbl:data> |
---|
248 | <tbl:columns> |
---|
249 | </tbl:columns> |
---|
250 | <tbl:rows> |
---|
251 | <% |
---|
252 | for (AnnotationType at : protocolParameters) |
---|
253 | { |
---|
254 | Annotation a = as != null && as.hasAnnotation(at) ? as.getAnnotation(at) : null; |
---|
255 | Formatter formatter = null; |
---|
256 | List<?> values = null; |
---|
257 | if (a != null) |
---|
258 | { |
---|
259 | values = a.getValues(null); |
---|
260 | formatter = FormatterFactory.getAnnotationFormatter(sc, a, null); |
---|
261 | } |
---|
262 | if (values != null || !at.isRemoved()) |
---|
263 | { |
---|
264 | %> |
---|
265 | <tbl:row> |
---|
266 | <tbl:cell column="parameter"><base:icon |
---|
267 | image="deleted.gif" |
---|
268 | tooltip="This item has been scheduled for deletion" |
---|
269 | visible="<%=at.isRemoved()%>" |
---|
270 | /><%=Base.getLinkedName(ID, at, false, true)%></tbl:cell> |
---|
271 | <tbl:cell column="values"> |
---|
272 | <%=values == null || values.size() == 0 ? "<i>- no values -</i>" : Values.getString(values, ", ", true, formatter)%> |
---|
273 | <% |
---|
274 | if (writePermission) |
---|
275 | { |
---|
276 | %>: <base:icon image="edit.gif" |
---|
277 | onclick="<%="editAnnotation("+at.getId()+")"%>" |
---|
278 | tooltip="Modify the values of this protocol parameter" /> |
---|
279 | <% |
---|
280 | } |
---|
281 | %> |
---|
282 | </tbl:cell> |
---|
283 | <tbl:cell column="description"><%=HTML.encodeTags(at.getDescription())%></tbl:cell> |
---|
284 | </tbl:row> |
---|
285 | <% |
---|
286 | } |
---|
287 | } |
---|
288 | %> |
---|
289 | </tbl:rows> |
---|
290 | </tbl:data> |
---|
291 | </tbl:table> |
---|
292 | <br> |
---|
293 | </base:section> |
---|
294 | <% |
---|
295 | } |
---|
296 | } |
---|
297 | %> |
---|
298 | |
---|
299 | <% |
---|
300 | if (!isProxy) |
---|
301 | { |
---|
302 | if (inheritedAnnotations == null || inheritedAnnotations.size() == 0) |
---|
303 | { |
---|
304 | %> |
---|
305 | <h4>Inherited annotations and protocol parameters</h4> |
---|
306 | No annotations are inherited by this item. |
---|
307 | <% |
---|
308 | } |
---|
309 | else |
---|
310 | { |
---|
311 | %> |
---|
312 | <base:section |
---|
313 | id="inherited" |
---|
314 | title="<%="Inherited annotations and protocol parameters (" + inheritedAnnotations.size() + ")"%>" |
---|
315 | > |
---|
316 | <tbl:table |
---|
317 | id="inheritedAnnotations" |
---|
318 | clazz="itemlist" |
---|
319 | columns="all" |
---|
320 | > |
---|
321 | <tbl:columndef |
---|
322 | id="annotation" |
---|
323 | title="Annotation" |
---|
324 | /> |
---|
325 | <tbl:columndef |
---|
326 | id="item" |
---|
327 | title="From item" |
---|
328 | /> |
---|
329 | <tbl:columndef |
---|
330 | id="values" |
---|
331 | title="Values" |
---|
332 | /> |
---|
333 | <tbl:columndef |
---|
334 | id="description" |
---|
335 | title="Description" |
---|
336 | /> |
---|
337 | <tbl:data> |
---|
338 | <tbl:columns> |
---|
339 | </tbl:columns> |
---|
340 | <tbl:rows> |
---|
341 | <% |
---|
342 | String denied = "<i>- denied -</i>"; |
---|
343 | for (Annotation a : inheritedAnnotations) |
---|
344 | { |
---|
345 | AnnotationType at = null; |
---|
346 | int annotationTypeId = 0; |
---|
347 | String name = denied; |
---|
348 | String description = ""; |
---|
349 | boolean writeInherited = false; |
---|
350 | String icon = "joust/annotation.gif"; |
---|
351 | Formatter formatter = FormatterFactory.getAnnotationFormatter(sc, a, null); |
---|
352 | try |
---|
353 | { |
---|
354 | at = a.getAnnotationType(); |
---|
355 | annotationTypeId = at.getId(); |
---|
356 | name = HTML.encodeTags(at.getName()); |
---|
357 | if (at.isRemoved()) |
---|
358 | { |
---|
359 | icon = "deleted.gif"; |
---|
360 | } |
---|
361 | else if (at.isProtocolParameter()) |
---|
362 | { |
---|
363 | icon = "parameter.gif"; |
---|
364 | } |
---|
365 | description = HTML.encodeTags(at.getDescription()); |
---|
366 | } |
---|
367 | catch (PermissionDeniedException ex) |
---|
368 | {} |
---|
369 | Nameable aItem = null; |
---|
370 | try |
---|
371 | { |
---|
372 | aItem = (Nameable)a.getAnnotationSet().getItem(); |
---|
373 | writeInherited = aItem.hasPermission(Permission.WRITE); |
---|
374 | } |
---|
375 | catch (PermissionDeniedException ex) |
---|
376 | {} |
---|
377 | List<?> values = a.getValues(null); |
---|
378 | %> |
---|
379 | <tbl:row> |
---|
380 | <tbl:cell column="annotation"><base:icon image="<%=icon%>" /> <%=Base.getLinkedName(ID, at, at == null, true)%></tbl:cell> |
---|
381 | <tbl:cell column="item"><%=Base.getLinkedName(ID, aItem, aItem == null, true)%><%=aItem != null ? " ["+aItem.getType()+"]" : ""%></tbl:cell> |
---|
382 | <tbl:cell column="values"> |
---|
383 | <%=values == null || values.size() == 0 ? |
---|
384 | "<i>- no values -</i>" : Values.getString(values, ", ", true, formatter)%> |
---|
385 | <% |
---|
386 | if (writeInherited && aItem != null) |
---|
387 | { |
---|
388 | %>: <base:icon image="edit.gif" |
---|
389 | onclick="<%="editInheritedAnnotation('"+aItem.getType().name()+"', "+aItem.getId()+", "+at.getId()+")"%>" |
---|
390 | tooltip="Modify the values of this annotation" /> |
---|
391 | <% |
---|
392 | } |
---|
393 | %> |
---|
394 | </tbl:cell> |
---|
395 | <tbl:cell column="description"><%=description%></tbl:cell> |
---|
396 | </tbl:row> |
---|
397 | <% |
---|
398 | } |
---|
399 | %> |
---|
400 | </tbl:rows> |
---|
401 | </tbl:data> |
---|
402 | </tbl:table> |
---|
403 | </base:section> |
---|
404 | <base:icon image="joust/annotation.gif" /> = Annotation, |
---|
405 | <base:icon image="parameter.gif" /> = Protocol parameter |
---|
406 | <% |
---|
407 | } |
---|
408 | } |
---|
409 | %> |
---|
410 | |
---|
411 | </base:body> |
---|
412 | </base:page> |
---|
413 | <% |
---|
414 | } |
---|
415 | finally |
---|
416 | { |
---|
417 | if (dc != null) dc.close(); |
---|
418 | } |
---|
419 | |
---|
420 | %> |
---|