Changeset 6455
- Timestamp:
- May 9, 2014, 10:31:05 AM (9 years ago)
- 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 21 21 */ 22 22 package net.sf.basedb.util.overview; 23 24 import java.util.Set; 23 25 24 26 import net.sf.basedb.core.Extract; … … 45 47 */ 46 48 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>>(); 47 57 48 58 -
trunk/src/core/net/sf/basedb/util/overview/filter/HasAttributeFilter.java
r5748 r6455 28 28 /** 29 29 A filter implementation that checks if a value for a given attribute 30 exists inon a node. It will evaluate to true for all {@link Node}:s that30 exists on a node. It will evaluate to true for all {@link Node}:s that 31 31 has a value for a specific attribute. 32 32 … … 40 40 41 41 private final NodeAttribute<?> attribute; 42 private final Object value; 42 43 43 44 /** … … 48 49 public HasAttributeFilter(NodeAttribute<?> attribute) 49 50 { 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 { 50 63 this.attribute = attribute; 64 this.value = value; 51 65 } 52 66 … … 58 72 public boolean evaluate(Node node) 59 73 { 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 } 61 82 } 62 83 // ----------------------------- -
trunk/src/core/net/sf/basedb/util/overview/loader/ExtractLoader.java
r6125 r6455 43 43 import net.sf.basedb.core.query.Hql; 44 44 import net.sf.basedb.core.query.Restrictions; 45 import net.sf.basedb.util.biomaterial.ChildrenTransformer; 46 import net.sf.basedb.util.collections.BasicItemToIdTransformer; 45 47 import net.sf.basedb.util.overview.Fix; 46 48 import net.sf.basedb.util.overview.NodeAttribute; … … 53 55 import net.sf.basedb.util.overview.Node; 54 56 import net.sf.basedb.util.overview.node.NodeFactory; 55 import net.sf.basedb.util.query.MultiQueryIterator;56 57 57 58 /** … … 254 255 ItemQuery<Extract> query = (ItemQuery<Extract>)context.initQuery( 255 256 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 256 277 ItemResultIterator<Extract> it = query.iterate(dc); 257 278 int numExtracts = 0; … … 316 337 317 338 ItemQuery<Extract> query = context.initQuery(bioAssay.getExtracts(0), "name"); 318 ItemQuery<Extract> extraQuery = null;319 320 339 // If we have followed this path from derived bioassays that has specified an 321 340 // 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); 334 350 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); 341 356 while (it.hasNext()) 342 357 { … … 348 363 createItemNode(nf, extract, extract, false, folderNode, ChildNodeDirection.REVERSE); 349 364 } 350 postValidateFolder(nf, folderNode, bioAssayNode, extract Ids.size() > 0);365 postValidateFolder(nf, folderNode, bioAssayNode, extracts.size() > 0); 351 366 return folderNode; 352 367 } … … 459 474 } 460 475 461 private Set< Integer> getExtractChain(Node node)476 private Set<Extract> getExtractChain(Node node) 462 477 { 463 478 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()); 465 480 for (Node n : nodesWithExtract) 466 481 { 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; 470 496 } 471 497
Note: See TracChangeset
for help on using the changeset viewer.