1 | <%-- $Id: list_annotations.jsp 4064 2007-12-14 13:31:33Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2006 Jari Hakkinen, 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 2 |
---|
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 this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | ------------------------------------------------------------------ |
---|
23 | |
---|
24 | @author Nicklas |
---|
25 | @version 2.0 |
---|
26 | --%> |
---|
27 | <%@ page 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.Permission" |
---|
32 | import="net.sf.basedb.core.AnnotationType" |
---|
33 | import="net.sf.basedb.core.Protocol" |
---|
34 | import="net.sf.basedb.core.AnnotationSet" |
---|
35 | import="net.sf.basedb.core.Annotation" |
---|
36 | import="net.sf.basedb.core.Annotatable" |
---|
37 | import="net.sf.basedb.core.AnnotatableProxy" |
---|
38 | import="net.sf.basedb.core.Nameable" |
---|
39 | import="net.sf.basedb.core.ItemQuery" |
---|
40 | import="net.sf.basedb.core.ItemResultList" |
---|
41 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
42 | import="net.sf.basedb.core.query.Orders" |
---|
43 | import="net.sf.basedb.core.query.Hql" |
---|
44 | import="net.sf.basedb.clients.web.Base" |
---|
45 | import="net.sf.basedb.clients.web.util.HTML" |
---|
46 | import="net.sf.basedb.util.formatter.Formatter" |
---|
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 | <h4 class="docked">Primary annotations</h4> |
---|
143 | <tbl:table |
---|
144 | id="annotations" |
---|
145 | clazz="itemlist" |
---|
146 | columns="all" |
---|
147 | > |
---|
148 | <tbl:columndef |
---|
149 | id="annotation" |
---|
150 | title="Annotation" |
---|
151 | /> |
---|
152 | <tbl:columndef |
---|
153 | id="values" |
---|
154 | title="Values" |
---|
155 | /> |
---|
156 | <tbl:columndef |
---|
157 | id="description" |
---|
158 | title="Description" |
---|
159 | /> |
---|
160 | <tbl:data> |
---|
161 | <tbl:columns> |
---|
162 | </tbl:columns> |
---|
163 | <tbl:rows> |
---|
164 | <% |
---|
165 | for (AnnotationType at : annotationTypes) |
---|
166 | { |
---|
167 | Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType()); |
---|
168 | List<?> values = as == null || !as.hasAnnotation(at) ? |
---|
169 | null : as.getAnnotation(at).getValues(); |
---|
170 | if (values != null || !at.isRemoved()) |
---|
171 | { |
---|
172 | %> |
---|
173 | <tbl:row> |
---|
174 | <tbl:cell column="annotation"><base:icon |
---|
175 | image="deleted.gif" |
---|
176 | tooltip="This item has been scheduled for deletion" |
---|
177 | visible="<%=at.isRemoved()%>" |
---|
178 | /><%=Base.getLinkedName(ID, at, false, true)%></tbl:cell> |
---|
179 | <tbl:cell column="values"><%=values == null || values.size() == 0 ? "<i>- no values -</i>" : Values.getString(values, ", ", true, formatter)%> |
---|
180 | <% |
---|
181 | if (writePermission) |
---|
182 | { |
---|
183 | %>: <base:icon image="edit.gif" |
---|
184 | onclick="<%="editAnnotation("+at.getId()+")"%>" |
---|
185 | tooltip="Modify the values of this annotation" /> |
---|
186 | <% |
---|
187 | } |
---|
188 | %> |
---|
189 | </tbl:cell> |
---|
190 | <tbl:cell column="description"><%=HTML.encodeTags(at.getDescription())%></tbl:cell> |
---|
191 | </tbl:row> |
---|
192 | <% |
---|
193 | } |
---|
194 | } |
---|
195 | %> |
---|
196 | </tbl:rows> |
---|
197 | </tbl:data> |
---|
198 | </tbl:table> |
---|
199 | <br> |
---|
200 | <% |
---|
201 | } |
---|
202 | %> |
---|
203 | |
---|
204 | <% |
---|
205 | if (protocolParameters != null ) |
---|
206 | { |
---|
207 | if (protocolParameters.size() == 0) |
---|
208 | { |
---|
209 | %> |
---|
210 | <h4>Protocol parameters</h4> |
---|
211 | No protocol parameters has been defined for the protocol |
---|
212 | <%=Base.getLinkedName(ID, protocol, !readProtocol, true)%> |
---|
213 | (or you don't have permission to view them). |
---|
214 | <% |
---|
215 | } |
---|
216 | else |
---|
217 | { |
---|
218 | %> |
---|
219 | <h4 class="docked">Protocol parameters for: |
---|
220 | <%=Base.getLinkedName(ID, protocol, !readProtocol, true)%></h4> |
---|
221 | <tbl:table |
---|
222 | id="parameters" |
---|
223 | clazz="itemlist" |
---|
224 | columns="all" |
---|
225 | > |
---|
226 | <tbl:columndef |
---|
227 | id="parameter" |
---|
228 | title="Parameter" |
---|
229 | /> |
---|
230 | <tbl:columndef |
---|
231 | id="values" |
---|
232 | title="Values" |
---|
233 | /> |
---|
234 | <tbl:columndef |
---|
235 | id="description" |
---|
236 | title="Description" |
---|
237 | /> |
---|
238 | <tbl:data> |
---|
239 | <tbl:columns> |
---|
240 | </tbl:columns> |
---|
241 | <tbl:rows> |
---|
242 | <% |
---|
243 | for (AnnotationType at : protocolParameters) |
---|
244 | { |
---|
245 | Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType()); |
---|
246 | List<?> values = as == null || !as.hasAnnotation(at) ? |
---|
247 | null : as.getAnnotation(at).getValues(); |
---|
248 | if (values != null || !at.isRemoved()) |
---|
249 | { |
---|
250 | %> |
---|
251 | <tbl:row> |
---|
252 | <tbl:cell column="parameter"><base:icon |
---|
253 | image="deleted.gif" |
---|
254 | tooltip="This item has been scheduled for deletion" |
---|
255 | visible="<%=at.isRemoved()%>" |
---|
256 | /><%=Base.getLinkedName(ID, at, false, true)%></tbl:cell> |
---|
257 | <tbl:cell column="values"> |
---|
258 | <%=values == null || values.size() == 0 ? "<i>- no values -</i>" : Values.getString(values, ", ", true, formatter)%> |
---|
259 | <% |
---|
260 | if (writePermission) |
---|
261 | { |
---|
262 | %>: <base:icon image="edit.gif" |
---|
263 | onclick="<%="editAnnotation("+at.getId()+")"%>" |
---|
264 | tooltip="Modify the values of this protocol parameter" /> |
---|
265 | <% |
---|
266 | } |
---|
267 | %> |
---|
268 | </tbl:cell> |
---|
269 | <tbl:cell column="description"><%=HTML.encodeTags(at.getDescription())%></tbl:cell> |
---|
270 | </tbl:row> |
---|
271 | <% |
---|
272 | } |
---|
273 | } |
---|
274 | %> |
---|
275 | </tbl:rows> |
---|
276 | </tbl:data> |
---|
277 | </tbl:table> |
---|
278 | <br> |
---|
279 | <% |
---|
280 | } |
---|
281 | } |
---|
282 | %> |
---|
283 | |
---|
284 | <% |
---|
285 | if (!isProxy) |
---|
286 | { |
---|
287 | if (inheritedAnnotations == null || inheritedAnnotations.size() == 0) |
---|
288 | { |
---|
289 | %> |
---|
290 | <h4>Inherited annotations and protocol parameters</h4> |
---|
291 | No annotations are inherited by this item. |
---|
292 | <% |
---|
293 | } |
---|
294 | else |
---|
295 | { |
---|
296 | %> |
---|
297 | <h4 class="docked">Inherited annotations and protocol parameters</h4> |
---|
298 | <tbl:table |
---|
299 | id="inheritedAnnotations" |
---|
300 | clazz="itemlist" |
---|
301 | columns="all" |
---|
302 | > |
---|
303 | <tbl:columndef |
---|
304 | id="annotation" |
---|
305 | title="Annotation" |
---|
306 | /> |
---|
307 | <tbl:columndef |
---|
308 | id="item" |
---|
309 | title="From item" |
---|
310 | /> |
---|
311 | <tbl:columndef |
---|
312 | id="values" |
---|
313 | title="Values" |
---|
314 | /> |
---|
315 | <tbl:columndef |
---|
316 | id="description" |
---|
317 | title="Description" |
---|
318 | /> |
---|
319 | <tbl:data> |
---|
320 | <tbl:columns> |
---|
321 | </tbl:columns> |
---|
322 | <tbl:rows> |
---|
323 | <% |
---|
324 | String denied = "<i>- denied -</i>"; |
---|
325 | for (Annotation a : inheritedAnnotations) |
---|
326 | { |
---|
327 | AnnotationType at = null; |
---|
328 | int annotationTypeId = 0; |
---|
329 | String name = denied; |
---|
330 | String description = ""; |
---|
331 | boolean writeInherited = false; |
---|
332 | String icon = "joust/annotation.gif"; |
---|
333 | Formatter formatter = FormatterFactory.getTypeFormatter(sc, a.getValueType()); |
---|
334 | try |
---|
335 | { |
---|
336 | at = a.getAnnotationType(); |
---|
337 | annotationTypeId = at.getId(); |
---|
338 | name = HTML.encodeTags(at.getName()); |
---|
339 | if (at.isRemoved()) |
---|
340 | { |
---|
341 | icon = "deleted.gif"; |
---|
342 | } |
---|
343 | else if (at.isProtocolParameter()) |
---|
344 | { |
---|
345 | icon = "parameter.gif"; |
---|
346 | } |
---|
347 | description = HTML.encodeTags(at.getDescription()); |
---|
348 | } |
---|
349 | catch (PermissionDeniedException ex) |
---|
350 | {} |
---|
351 | Nameable aItem = null; |
---|
352 | try |
---|
353 | { |
---|
354 | aItem = (Nameable)a.getAnnotationSet().getItem(); |
---|
355 | writeInherited = aItem.hasPermission(Permission.WRITE); |
---|
356 | } |
---|
357 | catch (PermissionDeniedException ex) |
---|
358 | {} |
---|
359 | List<?> values = a.getValues(); |
---|
360 | %> |
---|
361 | <tbl:row> |
---|
362 | <tbl:cell column="annotation"><base:icon image="<%=icon%>" /> <%=Base.getLinkedName(ID, at, at == null, true)%></tbl:cell> |
---|
363 | <tbl:cell column="item"><%=Base.getLinkedName(ID, aItem, aItem == null, true)%><%=aItem != null ? " ["+aItem.getType()+"]" : ""%></tbl:cell> |
---|
364 | <tbl:cell column="values"> |
---|
365 | <%=values == null || values.size() == 0 ? |
---|
366 | "<i>- no values -</i>" : Values.getString(values, ", ", true, formatter)%> |
---|
367 | <% |
---|
368 | if (writeInherited && aItem != null) |
---|
369 | { |
---|
370 | %>: <base:icon image="edit.gif" |
---|
371 | onclick="<%="editInheritedAnnotation('"+aItem.getType().name()+"', "+aItem.getId()+", "+at.getId()+")"%>" |
---|
372 | tooltip="Modify the values of this annotation" /> |
---|
373 | <% |
---|
374 | } |
---|
375 | %> |
---|
376 | </tbl:cell> |
---|
377 | <tbl:cell column="description"><%=description%></tbl:cell> |
---|
378 | </tbl:row> |
---|
379 | <% |
---|
380 | } |
---|
381 | %> |
---|
382 | </tbl:rows> |
---|
383 | </tbl:data> |
---|
384 | </tbl:table> |
---|
385 | <base:icon image="joust/annotation.gif" /> = Annotation, |
---|
386 | <base:icon image="parameter.gif" /> = Protocol parameter |
---|
387 | <% |
---|
388 | } |
---|
389 | } |
---|
390 | %> |
---|
391 | |
---|
392 | </base:body> |
---|
393 | </base:page> |
---|
394 | <% |
---|
395 | } |
---|
396 | finally |
---|
397 | { |
---|
398 | if (dc != null) dc.close(); |
---|
399 | } |
---|
400 | |
---|
401 | %> |
---|