Ignore:
Timestamp:
Aug 24, 2009, 11:19:37 AM (13 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1360: Existing annotatation on an item may not be visible/editable in some cases

This should make sure that all existing annotations can be viewed and edited. The problem with the "Unhandled item: ANNOTATION..." will be fixed as part of #1361.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/common/annotations/list_annotations.jsp

    r5055 r5074  
    4343  import="net.sf.basedb.clients.web.Base"
    4444  import="net.sf.basedb.clients.web.util.HTML"
     45  import="net.sf.basedb.util.NameableComparator"
    4546  import="net.sf.basedb.util.formatter.Formatter"
    4647  import="net.sf.basedb.util.formatter.PrefixSuffixFormatter"
     
    4849  import="net.sf.basedb.util.Values"
    4950  import="java.util.List"
     51  import="java.util.Set"
     52  import="java.util.HashSet"
     53  import="java.util.TreeSet"
     54  import="java.util.Map"
     55  import="java.util.HashMap"
    5056%>
    5157<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    6066final DbControl dc = sc.newDbControl();
    6167
     68Set<AnnotationType> annotationTypes = null;
     69Set<AnnotationType> protocolParameters = null;
     70Map<AnnotationType, Annotation> existing = null;
     71
    6272try
    6373{
    6474  final Annotatable item = (Annotatable)itemType.getById(dc, itemId);
     75  final boolean writePermission = item.hasPermission(Permission.WRITE);
     76
    6577  ItemQuery<AnnotationType> annotationTypeQuery = null;
    6678  String message = null;
    6779  boolean isProxy = item instanceof AnnotatableProxy;
    6880
     81  // Load all annotation types that are possible for this item type
    6982  if (isProxy)
    7083  {
     
    7790    annotationTypeQuery = Base.getAnnotationTypesQuery(itemType, false);
    7891  }
    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);
     92  annotationTypes = new TreeSet<AnnotationType>(new NameableComparator(false));
     93  annotationTypes.addAll(annotationTypeQuery.list(dc));
    9394
    9495  final AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null;
     
    9697  if (as != null)
    9798  {
     99    // Load the existing annotations on the item
     100    existing = new HashMap<AnnotationType, Annotation>();
     101    List<Annotation> annotations = as.getAnnotations().list(dc);
     102    for (Annotation a : annotations)
     103    {
     104      try
     105      {
     106        existing.put(a.getAnnotationType(), a);
     107      }
     108      catch (PermissionDeniedException ex)
     109      {}
     110    }
     111    annotationTypes.addAll(existing.keySet());
     112   
     113    // Load inherited annotations
    98114    ItemQuery<Annotation> inheritedQuery = as.getAllInheritedAnnotations();
    99115    // Need FETCH JOIN because Postgres don't like the DISTINCT keyword
     
    104120    inheritedAnnotations = inheritedQuery.list(dc);
    105121  }
    106 %>
     122 
     123  // Load the possible protocol parameters
     124  Protocol protocol = null;
     125  boolean readProtocol = true;
     126  try
     127  {
     128    protocol = item.getProtocol();
     129  }
     130  catch (PermissionDeniedException ex)
     131  {
     132    readProtocol = false;
     133  }
     134  ItemQuery<AnnotationType> parameterQuery = Base.getProtocolParametersQuery(protocol);
     135  if (parameterQuery != null)
     136  {
     137    protocolParameters = new HashSet<AnnotationType>(parameterQuery.list(dc));
     138    annotationTypes.removeAll(protocolParameters);
     139  }
     140  %>
    107141  <base:page type="include">
    108142  <base:body>
     
    168202              for (AnnotationType at : annotationTypes)
    169203              {
    170                 Annotation a = as != null && as.hasAnnotation(at) ? as.getAnnotation(at) : null;
     204                Annotation a = existing != null ? existing.get(at) : null;
    171205                List<?> values = null;
    172206                Formatter formatter = null;
     
    252286                for (AnnotationType at : protocolParameters)
    253287                {
    254                   Annotation a = as != null && as.hasAnnotation(at) ? as.getAnnotation(at) : null;
     288                  Annotation a = existing != null ? existing.get(at) : null;
    255289                  Formatter formatter = null;
    256290                  List<?> values = null;
Note: See TracChangeset for help on using the changeset viewer.