source: trunk/www/common/overview/info.jsp @ 5132

Last change on this file since 5132 was 5132, checked in by Nicklas Nordborg, 13 years ago

References #1404: Use cached annotations in "item overview"

This should fix the ticket. But there are so many different error-handling cases to test that I want to keep it open a bit more...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 15.0 KB
Line 
1<%-- $Id: info.jsp 5132 2009-10-14 11:55:03Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2009 Nicklas Nordborg
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<%@ page session="false"
23  import="net.sf.basedb.core.SessionControl"
24  import="net.sf.basedb.core.DbControl"
25  import="net.sf.basedb.core.Project"
26  import="net.sf.basedb.core.Item"
27  import="net.sf.basedb.core.BasicItem"
28  import="net.sf.basedb.core.Nameable"
29  import="net.sf.basedb.core.Annotatable"
30  import="net.sf.basedb.core.AnnotationSet"
31  import="net.sf.basedb.core.AnnotationType"
32  import="net.sf.basedb.core.Annotation"
33  import="net.sf.basedb.core.Protocol"
34  import="net.sf.basedb.core.FileStoreEnabled"
35  import="net.sf.basedb.core.FileSetMember"
36  import="net.sf.basedb.core.File"
37  import="net.sf.basedb.core.DataFileType"
38  import="net.sf.basedb.core.ItemContext"
39  import="net.sf.basedb.core.Permission"
40  import="net.sf.basedb.core.PermissionDeniedException"
41  import="net.sf.basedb.core.ItemNotFoundException"
42  import="net.sf.basedb.core.snapshot.SnapshotManager"
43  import="net.sf.basedb.core.snapshot.AnnotationSetSnapshot"
44  import="net.sf.basedb.core.snapshot.AnnotationSnapshot"
45  import="net.sf.basedb.core.snapshot.AnnotationTypeFilter"
46  import="net.sf.basedb.core.snapshot.AnnotationFilter"
47  import="net.sf.basedb.clients.web.Base"
48  import="net.sf.basedb.clients.web.util.HTML"
49  import="net.sf.basedb.util.Values"
50  import="net.sf.basedb.util.NestedIterator"
51  import="net.sf.basedb.util.overview.GenericOverview"
52  import="net.sf.basedb.util.overview.OverviewUtil"
53  import="net.sf.basedb.util.overview.Node"
54  import="net.sf.basedb.util.overview.ValidationOptions"
55  import="net.sf.basedb.util.overview.Validator"
56  import="net.sf.basedb.util.overview.Severity"
57  import="net.sf.basedb.util.overview.Failure"
58  import="net.sf.basedb.util.overview.Fix"
59  import="java.util.ArrayList"
60  import="java.util.List"
61  import="java.util.LinkedList"
62  import="java.util.Iterator"
63  import="java.util.Collection"
64  import="java.util.Collections"
65%>
66<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
67<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
68<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
69<%!
70private String getPath(String ID, Node node)
71{
72  Node parent = node.getParent();
73  if (parent == null) return "";
74  String path = getPath(ID, parent);
75  if (parent.getNodeType() == Node.Type.FOLDER)
76  {
77    //path += "/" + HTML.encodeTags(parent.getTitle());
78  }
79  else
80  {
81    BasicItem item = parent.getItem();
82    if (path.length() > 0)
83    {
84      path += "<img src=\"../../images/submenu.gif\" style=\"padding: 0px 4px 5px 6px;\" >";
85    }
86    path += Base.getLink(ID, parent.getTitle(), item.getType(), item.getId(), item.hasPermission(Permission.WRITE));
87//    path += "<a href=\"javascript:Main.editItem('" + item.getType().name() + "', " + item.getId() +
88//      ")\" title=\"Edit this item\" style=\"padding-right: 4px; white-space: nowrap;\">" + HTML.encodeTags(parent.getTitle()) + "</a>";
89  }
90  return path;
91}
92%>
93<%
94final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
95final String ID = sc.getId();
96final float scale = Base.getScale(sc);
97final DbControl dc = sc.newDbControl();
98try
99{
100  final GenericOverview overview = OverviewUtil.getCurrentOverview(sc);
101  final SnapshotManager snapshotManager = overview.getSnapshotManager();
102  final AnnotationTypeFilter annotationTypeFilter = new AnnotationTypeFilter();
103  final AnnotationFilter annotationFilter = new AnnotationFilter();
104  ValidationOptions options = overview.getValidationOptions();
105  String nodeId = request.getParameter("nodeId");
106  Boolean showFailures = Values.getBoolean(request.getParameter("show_failures"), false);
107  Node node = overview.getNode(nodeId);
108  if (node == null) node = overview.getRootNode();
109
110  BasicItem item = node.getItem();
111  List<Failure> failures = overview.getFailures();
112  if (failures == null) failures = new LinkedList<Failure>();
113  %>
114  <base:page title="" type="popup">
115  <base:head scripts="" styles="newjoust.css">
116  <script language="JavaScript">
117  function editItem(itemType, itemId, extraUrl)
118  {
119    Main.viewOrEditItem('<%=ID%>', itemType, itemId, true, extraUrl);
120  }
121  function editAnnotation(itemType, itemId, annotationTypeId)
122  {
123    var url = getRoot() + 'common/annotations/annotate.jsp?ID=<%=ID%>';
124    url += '&item_type=' + itemType;
125    url += '&item_id=' + itemId;
126    url += '&annotationtype_id='+annotationTypeId;
127    url += '&standalone=1';
128    Main.openPopup(url, 'EditAnnotation', 700, 460);
129  }
130  function editInheritedAnnotation(itemType, itemId, annotationTypeId)
131  {
132    var url = getRoot() + 'common/annotations/inherit.jsp?ID=<%=ID%>';
133    url += '&item_type='+itemType;
134    url += '&item_id='+itemId;
135    url += '&annotationtype_id='+annotationTypeId;
136    url += '&standalone=1';
137    Main.openPopup(url, 'EditAnnotation', 700, 460);
138  }
139  function editDataFile(itemType, itemId)
140  {
141    Main.viewOrEditItem('<%=ID%>', itemType, itemId, true, '&tab=datafiles');
142  }
143  </script>
144  </base:head>
145
146    <base:body>
147      <table class="form">
148      <tr>
149        <td class="prompt">Path</td>
150        <td><%=getPath(ID, node)%></td>
151      </tr>
152      <%
153      if (item instanceof FileSetMember)
154      {
155        FileSetMember member = null;
156        boolean notFound = false;
157        try
158        { 
159          member = FileSetMember.getById(dc, item.getId());
160        }
161        catch (ItemNotFoundException ex)
162        {
163          notFound = true;
164        }
165        File file = null;
166        DataFileType dft = null;
167        boolean deniedFile = false;
168        boolean deniedFileType = false;
169        if (member != null)
170        {
171          try
172          {
173            file = member.getFile();
174          }
175          catch (PermissionDeniedException ex)
176          {
177            deniedFile = true;
178          }
179          try
180          {
181            dft = member.getDataFileType();
182          }
183          catch (PermissionDeniedException ex)
184          {
185            deniedFileType = true;
186          }
187        }
188        if (dft != null || file != null)
189        {
190          %>
191          <tr>
192            <td class="prompt">
193              <%=dft == null ? "Data file" : HTML.encodeTags(dft.getName())%>
194            </td>
195            <td>
196              <%=Base.getLinkedFile(ID, file, deniedFile, true, true, "../../")%>
197            </td>
198          </tr>
199          <%
200        }
201        else
202        {
203          %>
204          <tr>
205          <td class="prompt"><%=HTML.encodeTags(node.getTitle())%></td>
206          <td>
207            <%=notFound ? "<i>- not found -</i>" : "<i>- denied -</i>"%>
208          </td>
209          </tr>
210          <%
211        }
212      }
213      else
214      {
215        %>
216        <tr>
217          <td class="prompt"><%=node.getNodeType() == Node.Type.FOLDER ? 
218            "Folder" : item != null ? item.getType().toString() : "Item"%></td>
219          <td>
220            <%
221            if (item != null)
222            {
223              %>
224              <%=Base.getLink(ID, node.getTitle(), item.getType(),item.getId(), item.hasPermission(Permission.WRITE))%>
225              <%
226            }
227            else
228            {
229              %>
230              <%=HTML.encodeTags(node.getTitle())%>
231              <%
232            }
233            %>
234          </td>
235        </tr>
236        <%
237      }
238      %>
239      <tr>
240        <td class="prompt">Errors (children)</td>
241        <%
242        if (showFailures)
243        {
244        %>
245          <td><%=node.getNumErrors()+node.getChildErrors()%> (<%=node.getChildErrors()%>)</td>
246        <%
247        }
248        else
249        {       
250        %>
251          <td><i>- n/a -</i></td>
252        <%
253        }
254        %>
255      </tr>
256      <tr>
257        <td class="prompt">Warnings (children)</td>
258        <%
259        if (showFailures)
260        {
261        %>
262          <td><%=node.getNumWarnings()+node.getChildWarnings()%> (<%=node.getChildWarnings()%>)</td>
263        <%
264        }
265        else
266        {       
267        %>
268          <td><i>- n/a -</i></td>
269        <%
270        }
271        %>
272      </tr>
273      <%
274      if (item instanceof Nameable)
275      {
276        Nameable nameable = (Nameable)item;
277        %>
278        <tr>
279          <td class="prompt">Description</td>
280          <td><%=HTML.niceFormat(nameable.getDescription())%></td>
281        </tr>
282        <%
283      }
284      %>
285      </table>
286      <p>
287     
288      <%
289      List<AnnotationSnapshot> annotations = new LinkedList<AnnotationSnapshot>();
290      String annotationsTitle = "";
291      Annotatable annotatable = null;
292      if (item instanceof Annotation)
293      {
294        Annotation a = (Annotation)item;
295        dc.reattachItem(a, false);
296        AnnotationSetSnapshot snapshot = snapshotManager.getSnapshot(dc, a.getAnnotationSet().getId());
297        annotationFilter.setAnnotationType(a);
298        annotations.addAll(snapshotManager.findAnnotations(dc, snapshot, annotationFilter, true));
299       
300        // Find the annotatable parent node
301        Node parentNode = node;
302        while (parentNode != null)
303        {
304          BasicItem parentItem = parentNode.getItem();
305          if (parentItem instanceof Annotatable)
306          {
307            annotatable = (Annotatable)parentItem;
308            break;
309          }
310          parentNode = parentNode.getParent();
311        }
312        annotationsTitle = "Annotation values";
313      }
314      else if (item instanceof AnnotationType)
315      {
316        // Find the annotatable parent
317        Node parentNode = node;
318        while (parentNode != null)
319        {
320          BasicItem parentItem = parentNode.getItem();
321          if (parentItem instanceof Annotatable && !(parentItem instanceof Protocol))
322          {
323            annotatable = (Annotatable)parentItem;
324            dc.reattachItem((BasicItem)annotatable, false);
325            if (annotatable.isAnnotated())
326            {
327              annotationTypeFilter.setAnnotationType((AnnotationType)item);
328              annotations.addAll(snapshotManager.findAnnotations(dc, annotatable, annotationTypeFilter, true));
329            }
330            annotationsTitle = "Annotation values";
331            break;
332          }
333          parentNode = parentNode.getParent();
334        }
335      }
336      else if (item instanceof Annotatable)
337      {
338        annotationsTitle = "Annotations &amp; protocol parameters";
339        annotatable = (Annotatable)item;
340        if (annotatable.isAnnotated())
341        {
342          dc.reattachItem((BasicItem)annotatable, false);
343          annotations.addAll(snapshotManager.findAnnotations(dc, annotatable, null, true));
344        }
345      }
346      if (annotations != null && annotations.size() > 0)
347      {
348        %>
349        <h4><%=annotationsTitle%></h4>
350        <table border=0 cellspacing=0 cellpadding=0>
351        <%
352        for (AnnotationSnapshot snapshot : annotations)
353        {
354          Annotation a = snapshot.getAnnotation(dc);
355          String unitSymbol = a.hasUnit() ? "&nbsp;" + a.getUnitSymbol(null) : "";
356          AnnotationType at = null;
357          Annotatable annotationOwner = null;
358          try
359          {
360            at = snapshot.getAnnotationType(dc);
361          }
362          catch (Throwable t)
363          {}
364          try
365          {
366            annotationOwner = snapshot.getItem(dc);
367          }
368          catch (Throwable t)
369          {}
370          String icon = at != null && at.isProtocolParameter() ? 
371              "parameter.gif" : "joust/annotation.gif";
372          String editLink = null;
373          String editTooltip = null;
374          if (annotatable != null && annotatable.hasPermission(Permission.WRITE) && at != null)
375          {
376            if (annotatable.equals(annotationOwner))
377            {
378              editLink = "editAnnotation('" + annotatable.getType().name() + "', " + annotatable.getId() + ", " + at.getId() + ")";
379              editTooltip = "Edit the values of this annotation";
380            }
381            else
382            {
383              editLink = "editInheritedAnnotation('" + annotatable.getType().name() + "', " + annotatable.getId() + ", " + at.getId() + ")";
384              editTooltip = "Inherit this annotation from another item";
385            }
386          }
387          %>
388          <tr>
389            <td><base:icon visible="<%=icon != null%>" image="<%=icon%>" />&nbsp;</td>
390            <td>
391              <%
392              if (at != null)
393              {
394                %>
395                <%=Base.getLinkedName(ID, at, false, true)%>
396                <%
397              }
398              else
399              {
400                %>
401                <%=a.getValueType() %>
402                <%
403              }
404              %>
405            </td>
406            <td>
407              <%
408              if (annotationOwner != null && !annotationOwner.equals(annotatable))
409              {
410                String ownerName = annotationOwner instanceof Nameable ?
411                    ((Nameable)annotationOwner).getName() : annotationOwner.toString();
412                %>
413                <base:icon image="bullet.gif" tooltip="Annotation is inherited from" />
414                <%=Base.getLink(ID, ownerName, annotationOwner.getType(), annotationOwner.getId(), annotationOwner.hasPermission(Permission.WRITE)) %>
415                <%
416              }
417              %>
418            </td>
419            <td><base:icon image="bullet.gif" /></td>
420            <td><%=Values.getString(a.getValues(null), ", ", true)%><%=unitSymbol%></td>
421            <td>&nbsp;
422              <%
423              if (editLink != null)
424              {
425                %><base:icon image="edit.gif" onclick="<%=editLink%>" 
426                  tooltip="<%=editTooltip%>" />
427                <%
428              }
429              %>
430            </td>
431          </tr>
432          <%
433        }
434        %>
435        </table>
436        <%
437      }     
438      if (showFailures)
439      {
440        %>
441        <h4>Failure details</h4>     
442        <table>
443        <%
444        int numFailures = 0;
445        for (Failure failure : failures)
446        {
447          Validator validator = failure.getValidator();
448          Severity severity = options.getSeverity(validator);
449          if (failure.getNode() == node && severity != Severity.IGNORE)
450          {
451            numFailures++;
452            List<Fix> fixes = failure.getFixes();
453            %>
454            <tr>
455              <td><base:icon image="<%=severity == Severity.ERROR ? 
456                "error.gif" : "warning.gif"%>" /></td>
457              <td><b><%=HTML.encodeTags(failure.getMessage())%></b></td>
458            </tr>
459            <tr>
460              <td style="border-bottom: 1px dotted #999999;"></td>
461              <td style="border-bottom: 1px dotted #999999;">
462                <%=HTML.encodeTags(validator.getDescription())%><br>
463                <%
464                if (fixes != null && fixes.size() > 0)
465                {
466                  for (Fix fix : fixes)
467                  {
468                    if (fix == null) continue;
469                    BasicItem fixItem = fix.getItem();
470                    if (fixItem.hasPermission(Permission.WRITE))
471                    {
472                      String fixIt = "";
473                      if (fix.isAnnotationFix())
474                      {
475                        AnnotationType at = fix.getAnnotationType();
476                        if (fix.isFromInherited())
477                        {
478                          fixIt = "editInheritedAnnotation('" + fixItem.getType().name() + "', " + 
479                            fixItem.getId() + ", " + at.getId() + ")";
480                        }
481                        else
482                        {
483                          fixIt = "editAnnotation('" + fixItem.getType().name() + "', " + 
484                            fixItem.getId() + ", " + at.getId() + ")";
485                        }
486                      }
487                      else if (fix.isDataFileFix())
488                      {
489                        FileSetMember member = fix.getFileSetMember();
490                        fixIt = "editDataFile('" + fixItem.getType().name() + "', " + 
491                          fixItem.getId() + ")";
492                      }
493                      else
494                      {
495                        fixIt = "editItem('" + fixItem.getType().name() + "', " + 
496                          fixItem.getId() + ")";
497                      }
498                      %>
499                      <base:icon image="fixit.png" 
500                        style="padding-bottom: 4px;" /><a href="javascript:<%=fixIt%>"
501                        title="Edit this item to fix the problem"><%=HTML.encodeTags(fix.getMessage())%></a><br>
502                      <%
503                    }
504                  }
505                }
506                %>
507              </td>
508            </tr>
509            <%
510          }
511        }
512        %>
513        </table>
514        <%
515        if (numFailures == 0)
516        {
517          %>
518          No validation failures on this item
519          <%
520        }       
521      }
522      %>
523    </base:body>
524  </base:page>
525  <%
526}
527finally
528{
529  if (dc != null) dc.close();
530}
531%>
Note: See TracBrowser for help on using the repository browser.