Changeset 7302


Ignore:
Timestamp:
Mar 1, 2017, 2:22:26 PM (5 years ago)
Author:
Nicklas Nordborg
Message:

References #2058: Item overview is not working when going from extract to derived bioassay

This should hopefully fix the second problem with back-links going to a parent extract higher up in the overview tree. The same fix was needed for both derived and raw bioassays.

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

Legend:

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

    r7301 r7302  
    4040import net.sf.basedb.core.query.Hql;
    4141import net.sf.basedb.core.query.Restrictions;
     42import net.sf.basedb.util.listable.ExtractToParentExtractTransformer;
     43import net.sf.basedb.util.listable.SourceItemTransformer;
     44import net.sf.basedb.util.listable.TransformContext;
    4245import net.sf.basedb.util.overview.Fix;
    4346import net.sf.basedb.util.overview.Node;
     
    211214    if (extractIds.size() > 0)
    212215    {
     216      // Since we don't know exactly how far upstreams the given extracts are we
     217      // must first find all parent items (recursively)
     218      Set<Integer> allParents = getAllExtractParents(dc, extractIds);
     219     
    213220      query.restrict(
    214221        Restrictions.or(
     
    216223          Restrictions.in(Hql.property("extract"), Expressions.parameter("extracts"))
    217224        ));
    218       query.setParameter("extracts", extractIds, Type.INT);
     225      query.setParameter("extracts", allParents, Type.INT);
    219226    }
    220227
     
    250257    if (extractIds.size() > 0)
    251258    {
     259      // Since we don't know exactly how far upstreams the given extracts are we
     260      // must first find all parent items (recursively)
     261      Set<Integer> allParents = getAllExtractParents(dc, extractIds);
     262     
    252263      query.restrict(
    253264        Restrictions.or(
     
    255266          Restrictions.in(Hql.property("extract"), Expressions.parameter("extracts"))
    256267        ));
    257       query.setParameter("extracts", extractIds, Type.INT);
     268      query.setParameter("extracts", allParents, Type.INT);
    258269    }
    259270
     
    399410  }
    400411 
     412  private Set<Integer> getAllExtractParents(DbControl dc, Set<Integer> extracts)
     413  {
     414    SourceItemTransformer transformer = new ExtractToParentExtractTransformer(true);
     415    return transformer.transform(new TransformContext(dc), extracts);
     416  }
     417
     418 
    401419}
  • trunk/src/core/net/sf/basedb/util/overview/loader/RawBioAssayLoader.java

    r6755 r7302  
    2222package net.sf.basedb.util.overview.loader;
    2323
     24
     25import java.util.HashSet;
     26import java.util.List;
     27import java.util.Set;
    2428
    2529import net.sf.basedb.core.DbControl;
     
    3236import net.sf.basedb.core.ItemResultIterator;
    3337import net.sf.basedb.core.RawBioAssay;
     38import net.sf.basedb.core.Type;
     39import net.sf.basedb.core.query.Expressions;
    3440import net.sf.basedb.core.query.Hql;
    3541import net.sf.basedb.core.query.Restrictions;
     42import net.sf.basedb.util.listable.ExtractToParentExtractTransformer;
     43import net.sf.basedb.util.listable.SourceItemTransformer;
     44import net.sf.basedb.util.listable.TransformContext;
    3645import net.sf.basedb.util.overview.Node;
    3746import net.sf.basedb.util.overview.NodeAttribute;
     
    194203    ItemQuery<RawBioAssay> query = context.initQuery(bioAssay.getRawBioAssays(), "name");
    195204
    196     // If there is an extract node in the parent chain we should only load
    197     // raw bioassays with the same or a null extract
    198     Node extractNode = bioAssayNode.getFirstNode(new ItemTypeFilter(Item.EXTRACT));
    199     Extract extract = null;
    200     if (extractNode != null)
    201     {
    202       extract = (Extract)extractNode.getItem();
    203       query.restrict(Restrictions.or(
    204           Restrictions.eq(Hql.property("parentExtract"), Hql.entity(extract)),
    205           Restrictions.eq(Hql.property("parentExtract"), null))
    206         );
    207     }
    208    
     205    // We should only load derived bioassays that has a null extract or an
     206    // extract that is found in the parent chain
     207    Set<Integer> extractIds = getExtractChain(bioAssayNode);
     208    if (extractIds.size() > 0)
     209    {
     210      // Since we don't know exactly how far upstreams the given extracts are we
     211      // must first find all parent items (recursively)
     212      Set<Integer> allParents = getAllExtractParents(dc, extractIds);
     213     
     214      query.restrict(
     215        Restrictions.or(
     216          Restrictions.eq(Hql.property("parentExtract"), null),
     217          Restrictions.in(Hql.property("parentExtract"), Expressions.parameter("extracts"))
     218        ));
     219      query.setParameter("extracts", allParents, Type.INT);
     220    }
     221 
    209222    ItemResultIterator<RawBioAssay> it = query.iterate(dc);
    210223    while (it.hasNext())
     
    243256  }
    244257 
     258  private Set<Integer> getExtractChain(Node node)
     259  {
     260    List<Node> extractNodes = node.findAll(new ItemTypeFilter(Item.EXTRACT));
     261    Set<Integer> extractIds = new HashSet<Integer>(extractNodes.size());
     262    for (Node n : extractNodes)
     263    {
     264      extractIds.add(n.getItem().getId());
     265    }
     266    return extractIds;
     267  }
     268 
     269  private Set<Integer> getAllExtractParents(DbControl dc, Set<Integer> extracts)
     270  {
     271    SourceItemTransformer transformer = new ExtractToParentExtractTransformer(true);
     272    return transformer.transform(new TransformContext(dc), extracts);
     273  }
     274
    245275}
Note: See TracChangeset for help on using the changeset viewer.