Changeset 7860


Ignore:
Timestamp:
Oct 20, 2020, 3:30:21 PM (14 months ago)
Author:
Nicklas Nordborg
Message:

References #2224: Files should be annotatable

Annotation validation in the "Item overview" failed for any-to-any items (and probably also file set items) since we need to use the target item to get to the annotations.

Location:
trunk/src/core/net/sf/basedb/util/overview
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/util/overview/loader/AnnotationLoader.java

    r7859 r7860  
    5555{
    5656
     57  /**
     58    Get the annotatable item from the node. This is in most cases
     59    the {@link Node#getItem()} item, but can also be the target
     60    item of an {@link AnyToAny} node or the file of a {@link FileSetMember}
     61    node.
     62    @since 3.17
     63  */
     64  public static Annotatable getAnnotatableFromNode(DbControl dc, Node node)
     65  {
     66    Annotatable annotatable = null;
     67    Item nodeType = node.getItemType();
     68    try
     69    {
     70      if (nodeType == Item.ANYTOANY)
     71      {
     72        // The parent item is the 'to' target of the any-to-any
     73        AnyToAny any = (AnyToAny)node.getItem(dc);
     74        annotatable = (Annotatable)any.getTo();
     75      }
     76      else if (nodeType == Item.FILESETMEMBER)
     77      {
     78        // The parent item is the 'file' item
     79        FileSetMember member = (FileSetMember)node.getItem(dc);
     80        annotatable = member.getFile();
     81      }
     82      else
     83      {
     84        annotatable = (Annotatable)node.getItem(dc);
     85      }
     86    }
     87    catch (PermissionDeniedException ex)
     88    {}
     89    return annotatable;
     90  }
     91 
    5792  public AnnotationLoader()
    5893  {
     
    68103  {
    69104    NodeFactory<Annotation> nf = getNodeFactory(dc, context);
    70     Annotatable parent = null;
    71     Item parentNodeType = parentNode.getItemType();
    72     try
    73     {
    74       if (parentNodeType == Item.ANYTOANY)
    75       {
    76         // The parent item is the 'to' target of the any-to-any
    77         AnyToAny any = (AnyToAny)parentNode.getItem(dc);
    78         parent = (Annotatable)any.getTo();
    79       }
    80       else if (parentNodeType == Item.FILESETMEMBER)
    81       {
    82         // The parent item is the 'file' item
    83         FileSetMember member = (FileSetMember)parentNode.getItem(dc);
    84         parent = member.getFile();
    85       }
    86       else
    87       {
    88         parent = (Annotatable)parentNode.getItem(dc);
    89       }
    90     }
    91     catch (PermissionDeniedException ex)
    92     {}
     105    Annotatable parent = getAnnotatableFromNode(dc, parentNode);
    93106
    94107    Node folderNode = null;
  • trunk/src/core/net/sf/basedb/util/overview/validator/AnnotationValidator.java

    r6960 r7860  
    4848import net.sf.basedb.util.overview.Validator;
    4949import net.sf.basedb.util.overview.filter.ItemTypeFilter;
     50import net.sf.basedb.util.overview.loader.AnnotationLoader;
    5051
    5152/**
     
    8889    super.postValidate(dc, context, node, parentNode);
    8990    if (parentNode.getNodeType() == Node.Type.FOLDER) parentNode = parentNode.getParent();
    90     Annotatable parent = (Annotatable)parentNode.getItem(dc);
    91     Item parentItemType = parentNode.getItemType();
     91    Annotatable parent = AnnotationLoader.getAnnotatableFromNode(dc, parentNode);
     92    if (parent == null) return;
     93   
     94    Item parentItemType = parent.getType();
    9295   
    9396    Annotation a = (Annotation)node.getItem(dc);
     
    221224  {
    222225    super.postValidateFolder(dc, context, folderNode, parentNode);
    223     Annotatable parent = (Annotatable)parentNode.getItem(dc);
     226    Annotatable parent = AnnotationLoader.getAnnotatableFromNode(dc, parentNode);
     227    if (parent == null) return;
     228    Item parentItemType = parent.getType();
    224229   
    225230    // Check for 'Required by MIAME' annotations and duplicates
    226     Set<AnnotationType> miame = OverviewUtil.getMiameAnnotationTypes(dc, context, parentNode.getItemType());
     231    Set<AnnotationType> miame = OverviewUtil.getMiameAnnotationTypes(dc, context, parentItemType);
    227232    Set<AnnotationType> all = new HashSet<AnnotationType>();
    228233    Map<AnnotationType, Annotation> duplicates = new HashMap<AnnotationType, Annotation>();
     
    249254        context.createFailure(Validator.ANNOTATION_INHERIT_MULTIPLE, parentNode,
    250255          "Duplicate annotations of type '" + dup.getKey().getName() + "'",
    251           new Fix("Modify annotations", parentNode.getItem(), dup.getValue())
     256          new Fix("Modify annotations", (BasicItem)parent, dup.getValue())
    252257        );
    253258      }
Note: See TracChangeset for help on using the changeset viewer.