Changeset 6456


Ignore:
Timestamp:
May 9, 2014, 11:21:36 AM (8 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1806: Fail to load upstream extracts from physical bioassays when inheriting annotations

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

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/MeasuredBioMaterial.java

    r6357 r6456  
    2424package net.sf.basedb.core;
    2525
     26import java.util.Collection;
    2627import java.util.Collections;
    2728import java.util.Date;
     29import java.util.HashSet;
    2830import java.util.Map;
    2931import java.util.Set;
     
    3638import net.sf.basedb.core.log.ChangeType;
    3739import net.sf.basedb.core.log.LoggingInterceptor;
     40import net.sf.basedb.core.query.Expressions;
     41import net.sf.basedb.core.query.Hql;
     42import net.sf.basedb.core.query.Restrictions;
    3843import net.sf.basedb.util.EqualsHelper;
     44import net.sf.basedb.util.collections.BasicItemToIdTransformer;
    3945
    4046/**
     
    189195    throws BaseException
    190196  {
     197    return getAnnotatableParents(null);
     198  }
     199  // -------------------------------------------
     200
     201  /**
     202    Get the annotable parents, possible only a given set of specific parents items.
     203    @param parents If not null or empty, only include the given parent items (for pooled items only)
     204    @since 3.3
     205  */
     206  public Set<Annotatable> getAnnotatableParents(Collection<? extends MeasuredBioMaterial> parents)
     207    throws BaseException
     208  {
    191209    Set<Annotatable> annotatable = super.getAnnotatableParents();
    192210    try
     
    200218        ItemQuery<? extends BioMaterial> query = getCreationEvent().getSources();
    201219        query.include(Include.ALL);
     220        if (parents != null && parents.size() > 0)
     221        {
     222          query.restrict(Restrictions.in(Hql.property("id"), Expressions.parameter("parents")));
     223          Set<Integer> parentIds = new HashSet<Integer>();
     224          new BasicItemToIdTransformer().transform(parents, parentIds);
     225          query.setParameter("parents", parentIds, Type.INT);
     226        }
    202227        annotatable.addAll(query.list(getDbControl()));
    203228      }
     
    211236    return annotatable;
    212237  }
    213   // -------------------------------------------
    214 
    215  
     238
    216239  /*
    217240    From the Subtypable interface
  • trunk/src/core/net/sf/basedb/util/AnnotationUtil.java

    r6124 r6456  
    3939import net.sf.basedb.core.PhysicalBioAssay;
    4040import net.sf.basedb.core.RawBioAssay;
     41import net.sf.basedb.util.biomaterial.ChildrenTransformer;
     42import net.sf.basedb.util.extensions.events.AllEventsFilter;
    4143import net.sf.basedb.util.filter.Filter;
    4244
     
    115117      {
    116118        // ...and queue the parents items for processing...
    117         unprocessed.addAll(toProcess.getAnnotatableParentWrappers());
     119        unprocessed.addAll(toProcess.getAnnotatableParentWrappers(dc));
    118120      }
    119121    }
     
    170172    private final Annotatable item;
    171173    private final Set<Extract> extractsInChain;
     174    private Set<Extract> allChildExtractsInChain;
    172175    private final AnnotatableWrapper chain;
    173176    private final Cache cache;
     
    181184      this.extract = getExtract(item);
    182185      this.extractsInChain = loadExtracts();
     186      this.allChildExtractsInChain = null;
    183187    }
    184188   
     
    190194      this.extract = getExtract(item);
    191195      this.extractsInChain = loadExtracts();
     196      this.allChildExtractsInChain = chain.allChildExtractsInChain;
    192197    }
    193198   
     
    233238      Get all annotatable parents wrapped inside AnnotatableWrapper:s
    234239    */
    235     Set<AnnotatableWrapper> getAnnotatableParentWrappers()
     240    Set<AnnotatableWrapper> getAnnotatableParentWrappers(DbControl dc)
    236241      throws BaseException
    237242    {
     
    247252        if (item instanceof PhysicalBioAssay)
    248253        {
    249           parents = ((PhysicalBioAssay)item).getAnnotatableParents(0, extractsInChain);
     254          allChildExtractsInChain = new HashSet<Extract>();
     255          if (extractsInChain.size() > 0)
     256          {
     257            // Only load parents that eventually lead up to one of the extracts in the chain
     258            ChildrenTransformer<Extract> transformer = new ChildrenTransformer<Extract>(dc, true, Extract.getQuery());
     259            transformer.transform(extractsInChain, allChildExtractsInChain);
     260          }
     261          parents = ((PhysicalBioAssay)item).getAnnotatableParents(0, allChildExtractsInChain);
     262        }
     263        else if (item instanceof Extract)
     264        {
     265          if (extractsInChain.contains(item))
     266          {
     267            // When we have reached one of the items in the chain, we no longed need to restrict the loading of parent items
     268            allChildExtractsInChain = null;
     269          }
     270          parents = ((Extract)item).getAnnotatableParents(allChildExtractsInChain);
    250271        }
    251272        else
Note: See TracChangeset for help on using the changeset viewer.