Changeset 6455


Ignore:
Timestamp:
May 9, 2014, 10:31:05 AM (8 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1805: Item overview fail to load upstream extracts from physical bioassays

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

Legend:

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

    r5748 r6455  
    2121*/
    2222package net.sf.basedb.util.overview;
     23
     24import java.util.Set;
    2325
    2426import net.sf.basedb.core.Extract;
     
    4547  */
    4648  public static NodeAttribute<Extract> EXTRACT = new NodeAttribute<Extract>();
     49 
     50  /**
     51    Store the ID values of extracts that should be followed on
     52    upstream paths as long as the current extract is not among
     53    one of the given parent extracts.
     54    @since 3.3
     55  */
     56  public static NodeAttribute<Set<Integer>> EXTRACT_PATH = new NodeAttribute<Set<Integer>>();
    4757
    4858 
  • trunk/src/core/net/sf/basedb/util/overview/filter/HasAttributeFilter.java

    r5748 r6455  
    2828/**
    2929  A filter implementation that checks if a value for a given attribute
    30   existsin on a node. It will evaluate to true for all {@link Node}:s that
     30  exists on a node. It will evaluate to true for all {@link Node}:s that
    3131  has a value for a specific attribute.
    3232
     
    4040 
    4141  private final NodeAttribute<?> attribute;
     42  private final Object value;
    4243 
    4344  /**
     
    4849  public HasAttributeFilter(NodeAttribute<?> attribute)
    4950  {
     51    this(attribute, null);
     52  }
     53 
     54  /**
     55    Create a filter that finds nodes that has a specific value for the given
     56    attribute.
     57    @param attribute The attribute to check
     58    @param value The value that must match
     59    @since 3.3
     60  */
     61  public HasAttributeFilter(NodeAttribute<?> attribute, Object value)
     62  {
    5063    this.attribute = attribute;
     64    this.value = value;
    5165  }
    5266
     
    5872  public boolean evaluate(Node node)
    5973  {
    60     return node.hasAttribute(attribute);
     74    if (value == null)
     75    {
     76      return node.hasAttribute(attribute);
     77    }
     78    else
     79    {
     80      return value.equals(node.getAttribute(attribute));
     81    }
    6182  }
    6283  // -----------------------------
  • trunk/src/core/net/sf/basedb/util/overview/loader/ExtractLoader.java

    r6125 r6455  
    4343import net.sf.basedb.core.query.Hql;
    4444import net.sf.basedb.core.query.Restrictions;
     45import net.sf.basedb.util.biomaterial.ChildrenTransformer;
     46import net.sf.basedb.util.collections.BasicItemToIdTransformer;
    4547import net.sf.basedb.util.overview.Fix;
    4648import net.sf.basedb.util.overview.NodeAttribute;
     
    5355import net.sf.basedb.util.overview.Node;
    5456import net.sf.basedb.util.overview.node.NodeFactory;
    55 import net.sf.basedb.util.query.MultiQueryIterator;
    5657
    5758/**
     
    254255    ItemQuery<Extract> query = (ItemQuery<Extract>)context.initQuery(
    255256        product.getCreationEvent().getSources(), "name");
     257   
     258    // Check if we are follwing a specific paths of extracts due to DerivedBioAssay.getExtract
     259    Node extractPath = parentNode.getFirstParent(new HasAttributeFilter(NodeAttribute.EXTRACT_PATH));
     260    if (extractPath != null)
     261    {
     262      // Yes, we are following a specific paths of extracts...
     263      // Is the parent item still on the path?
     264      if (extractPath.getAttribute(NodeAttribute.EXTRACT_PATH).contains(product.getId()))
     265      {
     266        // Yes, but is the parent item one of the specified extract on a DerivedBioassay?
     267        if (parentNode.getFirstParent(new HasAttributeFilter(NodeAttribute.EXTRACT, product)) == null)
     268        {
     269          // No, so we have not found the 'exit' extract
     270          // and we must only load extracts that are part of the path
     271          query.restrict(Restrictions.in(Hql.property("id"), Expressions.parameter("extracts")));
     272          query.setParameter("extracts", extractPath.getAttribute(NodeAttribute.EXTRACT_PATH), Type.INT);
     273        }
     274      }
     275    }
     276   
    256277    ItemResultIterator<Extract> it = query.iterate(dc);
    257278    int numExtracts = 0;
     
    316337
    317338    ItemQuery<Extract> query = context.initQuery(bioAssay.getExtracts(0), "name");
    318     ItemQuery<Extract> extraQuery = null;
    319 
    320339    // If we have followed this path from derived bioassays that has specified an
    321340    // extract we should only load the same extracts when following the path upstreams
    322     // We look for both
    323     Set<Integer> extractIds = getExtractChain(bioAssayNode);
    324     if (extractIds.size() > 0)
    325     {
    326       query.restrict(
    327         Restrictions.in(Hql.property("id"), Expressions.parameter("extracts"))
    328         );
    329       query.setParameter("extracts", extractIds, Type.INT);
    330 
    331       extraQuery = context.initQuery(bioAssay.getExtracts(0), "name");
    332       extraQuery.join(Hql.leftJoin("creationEvent", "cevt"));
    333       extraQuery.join(Hql.leftJoin("cevt", "sources", "sss", null, false));
     341    Set<Extract> extracts = getExtractChain(bioAssayNode);
     342    if (extracts.size() > 0)
     343    {
     344      // Since we don't know exactly how far upstreams the given extrcts are we
     345      // must first find all child items (recursively)
     346      Set<Integer> allChildren = getAllChildren(dc, extracts);
     347      // We keep the set of all child extracts since we need that later
     348      // when moving up the parent chain (see createPooledReverseNode)
     349      bioAssayNode.setAttribute(NodeAttribute.EXTRACT_PATH, allChildren);
    334350     
    335       extraQuery.restrict(
    336         Restrictions.in(Hql.property("sss", "bioMaterial"), Expressions.parameter("extracts"))
    337         );
    338       extraQuery.setParameter("extracts", extractIds, Type.INT);
    339     }
    340     Iterator<Extract> it = MultiQueryIterator.get(dc, query, extraQuery);
     351      // An we must of course limit the extracts on this level also
     352      query.restrict(Restrictions.in(Hql.property("id"), Expressions.parameter("extracts")));
     353      query.setParameter("extracts", allChildren, Type.INT);
     354    }
     355    Iterator<Extract> it = query.iterate(dc);
    341356    while (it.hasNext())
    342357    {
     
    348363      createItemNode(nf, extract, extract, false, folderNode, ChildNodeDirection.REVERSE);
    349364    }
    350     postValidateFolder(nf, folderNode, bioAssayNode, extractIds.size() > 0);
     365    postValidateFolder(nf, folderNode, bioAssayNode, extracts.size() > 0);
    351366    return folderNode;
    352367  }
     
    459474  }
    460475 
    461   private Set<Integer> getExtractChain(Node node)
     476  private Set<Extract> getExtractChain(Node node)
    462477  {
    463478    List<Node> nodesWithExtract = node.findAll(new HasAttributeFilter(NodeAttribute.EXTRACT));
    464     Set<Integer> extractIds = new HashSet<Integer>(nodesWithExtract.size());
     479    Set<Extract> extracts = new HashSet<Extract>(nodesWithExtract.size());
    465480    for (Node n : nodesWithExtract)
    466481    {
    467       extractIds.add(n.getAttribute(NodeAttribute.EXTRACT).getId());
    468     }
    469     return extractIds;
     482      extracts.add(n.getAttribute(NodeAttribute.EXTRACT));
     483    }
     484    return extracts;
     485  }
     486 
     487  private Set<Integer> getAllChildren(DbControl dc, Set<Extract> parents)
     488  {
     489    Set<Extract> all = new HashSet<Extract>();
     490    ChildrenTransformer<Extract> transformer = new ChildrenTransformer<Extract>(dc, true, Extract.getQuery());
     491    transformer.transform(parents, all);
     492    BasicItemToIdTransformer idTransformer = new BasicItemToIdTransformer();
     493    Set<Integer> allIds = new HashSet<Integer>(all.size());
     494    idTransformer.transform(all, allIds);
     495    return allIds;
    470496  }
    471497 
Note: See TracChangeset for help on using the changeset viewer.