Changeset 5985


Ignore:
Timestamp:
Feb 24, 2012, 11:01:01 AM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #1605: Inherit annotations from a child path

Implemented support in the "Item overview" functionality for biomaterial items and physical bioassays. Each loader implementation need to handle this case in the loadReverseChildNodes() method which should create PROPERTY-type nodes for the child items that have an item subtype with the pushAnnotations flag set. The downwards path of that branch will then be followed even though the main direction is going upwards.

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

Legend:

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

    r5815 r5985  
    3737import net.sf.basedb.core.DerivedBioAssay;
    3838import net.sf.basedb.core.Extract;
     39import net.sf.basedb.core.ItemSubtype;
    3940import net.sf.basedb.core.PermissionDeniedException;
    4041import net.sf.basedb.core.Presets;
     
    4647import net.sf.basedb.core.SessionControl;
    4748import net.sf.basedb.core.RawBioAssay;
     49import net.sf.basedb.core.Subtypable;
    4850import net.sf.basedb.core.Type;
    4951import net.sf.basedb.core.query.Expressions;
     
    283285    if (item.equals(node.getItem())) return node;
    284286    return node.getFirstParent(new BasicItemFilter(item));
     287  }
     288 
     289  /**
     290    Add a restriction to the query that limit the returned result to those items
     291    that has a subtype with the {@link ItemSubtype#getPushAnnotations()} flag set.
     292    @since 3.1
     293  */
     294  public static void restrictToPushAnnotationSubtypes(ItemQuery<? extends Subtypable> query)
     295  {
     296    query.join(Hql.innerJoin("itemSubtype", "sbt"));
     297    query.restrict(Restrictions.eq(Hql.property("sbt", "pushAnnotations"), Expressions.bool(true)));
    285298  }
    286299 
  • trunk/src/core/net/sf/basedb/util/overview/loader/BioSourceLoader.java

    r5663 r5985  
    2525import net.sf.basedb.core.DbControl;
    2626import net.sf.basedb.core.Item;
     27import net.sf.basedb.core.ItemSubtype;
    2728import net.sf.basedb.core.PermissionDeniedException;
    2829import net.sf.basedb.core.Sample;
     
    105106    getNodeLoader(context, Item.SAMPLE).createForwardNode(dc, context, bioSourceNode);
    106107  }
     108 
     109  /**
     110    A biosource usually don't have any reverse child nodes. The exception is
     111    child samples that have a subtype with the {@link ItemSubtype#getPushAnnotations()} flag set.
     112    @since 3.1
     113  */
     114  @Override
     115  protected void loadReverseChildNodes(DbControl dc, OverviewContext context, Node bioSourceNode)
     116  {
     117    if (bioSourceNode.getChildNodeDirection() == ChildNodeDirection.REVERSE)
     118    {
     119      // Only if we are moving in the reverse direction (eg. not when the biosource is a root node)
     120      getNodeLoader(context, Item.SAMPLE).createPropertyNode(dc, context, bioSourceNode);
     121    }
     122  }
    107123  // ---------------------------------------
    108124 
  • trunk/src/core/net/sf/basedb/util/overview/loader/ExtractLoader.java

    r5807 r5985  
    2525import net.sf.basedb.core.DerivedBioAssay;
    2626import net.sf.basedb.core.Extract;
     27import net.sf.basedb.core.ItemSubtype;
    2728import net.sf.basedb.core.PermissionDeniedException;
    2829import net.sf.basedb.core.PhysicalBioAssay;
     
    8384    if (parentType == Item.SAMPLE)
    8485    {
    85       returnNode = createForwardNode((Sample)parentNode.getItem(dc), dc, context, parentNode);
     86      returnNode = createForwardNode((Sample)parentNode.getItem(dc), dc, context, parentNode, false);
    8687    }
    8788    else if (parentType == Item.EXTRACT)
    8889    {
    89       returnNode = createForwardNode((Extract)parentNode.getItem(dc), dc, context, parentNode);
     90      returnNode = createForwardNode((Extract)parentNode.getItem(dc), dc, context, parentNode, false);
    9091    }
    9192    return returnNode;
     
    135136    return returnNode;
    136137  }
     138 
     139  /**
     140    A property node is created when moving in the reverse direction so that we
     141    can load child extracts+physical bioassays with the {@link ItemSubtype#getPushAnnotations()}
     142    flag set. The parent node should be a sample or extract node.
     143    @since 3.1
     144  */
     145  @Override
     146  public Node createPropertyNode(DbControl dc, OverviewContext context, Node parentNode)
     147  {
     148    Node returnNode = null;
     149    Item parentType = parentNode.getItemType();
     150    if (parentType == Item.SAMPLE)
     151    {
     152      returnNode = createForwardNode((Sample)parentNode.getItem(dc), dc, context, parentNode, true);
     153    }
     154    else if (parentType == Item.EXTRACT)
     155    {
     156      returnNode = createForwardNode((Extract)parentNode.getItem(dc), dc, context, parentNode, true);
     157    }
     158    return returnNode;
     159  }
    137160  // --------------------------------
    138161  /*
     
    175198 
    176199  /**
    177     Load either the parent sample or extract(s).
     200    Load either the parent sample or extract(s) and child extracts+physical bioassays
     201    with a subtype that has {@link ItemSubtype#getPushAnnotations()} flag set.
    178202    @see ExtractLoader#createReverseNode(DbControl, OverviewContext, Node)
    179203    @see SampleLoader#createReverseNode(DbControl, OverviewContext, Node)
     
    190214    {
    191215      getNodeLoader(context, Item.SAMPLE).createReverseNode(dc, context, extractNode);
     216    }
     217    if (extractNode.getChildNodeDirection() == ChildNodeDirection.REVERSE)
     218    {
     219      // Only if we are moving in the reverse direction (eg. not when the extract is a root node)
     220      getNodeLoader(context, Item.EXTRACT).createPropertyNode(dc, context, extractNode);
     221      getNodeLoader(context, Item.PHYSICALBIOASSAY).createPropertyNode(dc, context, extractNode);
    192222    }
    193223  }
     
    333363    sample as their parent.
    334364  */
    335   private Node createForwardNode(Sample sample, DbControl dc, OverviewContext context, Node parentNode)
     365  private Node createForwardNode(Sample sample, DbControl dc, OverviewContext context, Node parentNode,
     366    boolean onlyPushAnnotationTypes)
    336367  {
    337368    NodeFactory<Extract> nf = getNodeFactory(dc, context);
    338369    Node folderNode = null;
    339370    ItemQuery<Extract> query = context.initQuery(sample.getExtracts(), "name");
     371    if (onlyPushAnnotationTypes) OverviewUtil.restrictToPushAnnotationSubtypes(query);
    340372    ItemResultIterator<Extract> it = query.iterate(dc);
    341373    while (it.hasNext())
     
    354386  /**
    355387    Create forward-loading extract nodes for the (pooled) extract that has a given
    356     extract among their parents.
    357   */
    358   private Node createForwardNode(Extract parentExtract, DbControl dc, OverviewContext context, Node parentNode)
     388    extract among their parents. If the parent node is a forward-loading node all child
     389    nodes are loaded, otherwise only child nodes that have an item with a subtype that
     390    has {@link ItemSubtype#getPushAnnotations()} set.
     391  */
     392  private Node createForwardNode(Extract parentExtract, DbControl dc, OverviewContext context, Node parentNode,
     393    boolean onlyPushAnnotationTypes)
    359394  {
    360395    NodeFactory<Extract> nf = getNodeFactory(dc, context);
    361396    Node folderNode = null;
    362397    ItemQuery<Extract> query = context.initQuery(parentExtract.getChildExtracts(), "name");
     398    if (onlyPushAnnotationTypes) OverviewUtil.restrictToPushAnnotationSubtypes(query);
    363399    ItemResultIterator<Extract> it = query.iterate(dc);
    364400    while (it.hasNext())
  • trunk/src/core/net/sf/basedb/util/overview/loader/PhysicalBioAssayLoader.java

    r5748 r5985  
    2626import net.sf.basedb.core.DerivedBioAssay;
    2727import net.sf.basedb.core.Extract;
     28import net.sf.basedb.core.ItemSubtype;
    2829import net.sf.basedb.core.PhysicalBioAssay;
    2930import net.sf.basedb.core.Item;
     
    3435import net.sf.basedb.util.overview.NodeAttribute;
    3536import net.sf.basedb.util.overview.OverviewContext;
     37import net.sf.basedb.util.overview.OverviewUtil;
    3638import net.sf.basedb.util.overview.cache.IndexedCacheKey;
    3739import net.sf.basedb.util.overview.filter.HasAttributeFilter;
     
    8486    if (parentType == Item.EXTRACT)
    8587    {
    86       returnNode = createForwardNode((Extract)parentNode.getItem(dc), dc, context, parentNode);
     88      returnNode = createForwardNode((Extract)parentNode.getItem(dc), dc, context, parentNode, false);
    8789    }
    8890    else if (parentType == Item.ARRAYSLIDE)
     
    128130    return bioAssayNode;
    129131  }
     132 
     133  /**
     134    A property node is created when moving in the reverse direction so that we
     135    can load child physical bioassays with the {@link ItemSubtype#getPushAnnotations()}
     136    flag set. The parent node should be an extract node.
     137    @since 3.1
     138  */
     139  @Override
     140  public Node createPropertyNode(DbControl dc, OverviewContext context, Node parentNode)
     141  {
     142    Node returnNode = null;
     143    Item parentType = parentNode.getItemType();
     144    if (parentType == Item.EXTRACT)
     145    {
     146      returnNode = createForwardNode((Extract)parentNode.getItem(dc), dc, context, parentNode, true);
     147    }
     148    return returnNode;
     149  }
    130150  // --------------------------------------
    131151  /*
     
    199219    that has a given extract as a source.
    200220  */
    201   private Node createForwardNode(Extract extract, DbControl dc, OverviewContext context, Node parentNode)
     221  private Node createForwardNode(Extract extract, DbControl dc, OverviewContext context, Node parentNode,
     222    boolean onlyPushAnnotationTypes)
    202223  {
    203224    NodeFactory<PhysicalBioAssay> nf = getNodeFactory(dc, context);
    204225    Node folderNode = null;
    205226    ItemQuery<PhysicalBioAssay> query = context.initQuery(extract.getPhysicalBioAssays(), "name");
     227    if (onlyPushAnnotationTypes) OverviewUtil.restrictToPushAnnotationSubtypes(query);
    206228    ItemResultIterator<PhysicalBioAssay> it = query.iterate(dc);
    207229    while (it.hasNext())
  • trunk/src/core/net/sf/basedb/util/overview/loader/SampleLoader.java

    r5807 r5985  
    3030import net.sf.basedb.core.ItemQuery;
    3131import net.sf.basedb.core.ItemResultIterator;
     32import net.sf.basedb.core.ItemSubtype;
    3233import net.sf.basedb.core.MeasuredBioMaterial;
    3334import net.sf.basedb.core.PermissionDeniedException;
     
    7980    if (parentType == Item.BIOSOURCE)
    8081    {
    81       returnNode = createForwardNode((BioSource)parentNode.getItem(dc), dc, context, parentNode);
     82      returnNode = createForwardNode((BioSource)parentNode.getItem(dc), dc, context, parentNode, false);
    8283    }
    8384    else if (parentType == Item.SAMPLE)
    8485    {
    85       returnNode = createForwardNode((Sample)parentNode.getItem(dc), dc, context, parentNode);
     86      returnNode = createForwardNode((Sample)parentNode.getItem(dc), dc, context, parentNode, false);
    8687    }
    8788    return returnNode;
     
    118119    return returnNode;
    119120  }
     121 
     122  /**
     123    A property node is created when moving in the reverse direction so that we
     124    can load child samples+extracts with the {@link ItemSubtype#getPushAnnotations()}
     125    flag set. The parent node should be a biosource or sample node.
     126    @since 3.1
     127  */
     128  @Override
     129  public Node createPropertyNode(DbControl dc, OverviewContext context, Node parentNode)
     130  {
     131    Node returnNode = null;
     132    Item parentType = parentNode.getItemType();
     133    if (parentType == Item.BIOSOURCE)
     134    {
     135      returnNode = createForwardNode((BioSource)parentNode.getItem(dc), dc, context, parentNode, true);
     136    }
     137    else if (parentType == Item.SAMPLE)
     138    {
     139      returnNode = createForwardNode((Sample)parentNode.getItem(dc), dc, context, parentNode, true);
     140    }
     141    return returnNode;
     142  }
    120143  // --------------------------------
    121144  /*
     
    153176  /**
    154177    If the sample is a pooled sample, loads the parent samples that
    155     it was pooled from. Otherwise load the parent biosource.
     178    it was pooled from. Otherwise load the parent biosource. Also load
     179    any child samples or extracts that have a subtype with the
     180    {@link ItemSubtype#getPushAnnotations()} flag set.
    156181    @see SampleLoader#createReverseNode(DbControl, OverviewContext, Node)
    157182    @see BioSourceLoader#createReverseNode(DbControl, OverviewContext, Node)
     
    168193    {
    169194      getNodeLoader(context, Item.BIOSOURCE).createReverseNode(dc, context, sampleNode);
     195    }
     196    if (sampleNode.getChildNodeDirection() == ChildNodeDirection.REVERSE)
     197    {
     198      // Only if we are moving in the reverse direction (eg. not when the sample is a root node)
     199      getNodeLoader(context, Item.SAMPLE).createPropertyNode(dc, context, sampleNode);
     200      getNodeLoader(context, Item.EXTRACT).createPropertyNode(dc, context, sampleNode);
    170201    }
    171202  }
     
    238269    biosource as their parent.
    239270  */
    240   private Node createForwardNode(BioSource bioSource, DbControl dc, OverviewContext context, Node parentNode)
     271  private Node createForwardNode(BioSource bioSource, DbControl dc, OverviewContext context, Node parentNode,
     272    boolean onlyPushAnnotationTypes)
    241273  {
    242274    NodeFactory<Sample> nf = getNodeFactory(dc, context);
    243275    Node folderNode = null;
    244276    ItemQuery<Sample> query = context.initQuery(bioSource.getSamples(), "name");
     277    if (onlyPushAnnotationTypes) OverviewUtil.restrictToPushAnnotationSubtypes(query);
    245278    ItemResultIterator<Sample> it = query.iterate(dc);
    246279    while (it.hasNext())
     
    261294    sample as their parent.
    262295  */
    263   private Node createForwardNode(Sample parentSample, DbControl dc, OverviewContext context, Node parentNode)
     296  private Node createForwardNode(Sample parentSample, DbControl dc, OverviewContext context, Node parentNode,
     297    boolean onlyPushAnnotationTypes)
    264298  {
    265299    NodeFactory<Sample> nf = getNodeFactory(dc, context);
    266300    Node folderNode = null;
    267301    ItemQuery<Sample> query = context.initQuery(parentSample.getChildSamples(), "name");
     302    if (onlyPushAnnotationTypes) OverviewUtil.restrictToPushAnnotationSubtypes(query);
    268303    ItemResultIterator<Sample> it = query.iterate(dc);
    269304    while (it.hasNext())
Note: See TracChangeset for help on using the changeset viewer.