Changeset 6090
- Timestamp:
- Aug 22, 2012, 1:36:15 PM (11 years ago)
- Location:
- trunk/src/core/net/sf/basedb/util/overview
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/util/overview/Node.java
r6046 r6090 286 286 287 287 /** 288 Find all nodes in the parent chain that matches the given 289 filter. 290 @param filter The filter to use for matching nodes 291 @return A list with the matched nodes in the order they matched 292 @since 3.2 293 */ 294 public List<Node> findAll(Filter<? super Node> filter) 295 { 296 List<Node> result = new LinkedList<Node>(); 297 Node current = this; 298 while (current != null) 299 { 300 if (filter.evaluate(current)) result.add(current); 301 current = current.getParent(); 302 } 303 return result; 304 } 305 306 /** 288 307 Get all child nodes of this node. May return null or an empty 289 308 list if this node has no children. -
trunk/src/core/net/sf/basedb/util/overview/loader/DerivedBioAssayLoader.java
r5807 r6090 21 21 */ 22 22 package net.sf.basedb.util.overview.loader; 23 24 import java.util.HashSet; 25 import java.util.List; 26 import java.util.Set; 23 27 24 28 import net.sf.basedb.core.DbControl; … … 31 35 import net.sf.basedb.core.PhysicalBioAssay; 32 36 import net.sf.basedb.core.RawBioAssay; 37 import net.sf.basedb.core.Type; 38 import net.sf.basedb.core.query.Expressions; 33 39 import net.sf.basedb.core.query.Hql; 34 40 import net.sf.basedb.core.query.Restrictions; 41 import net.sf.basedb.util.overview.Fix; 35 42 import net.sf.basedb.util.overview.Node; 36 43 import net.sf.basedb.util.overview.NodeAttribute; 37 44 import net.sf.basedb.util.overview.OverviewContext; 38 import net.sf.basedb.util.overview. cache.IndexedCacheKey;39 import net.sf.basedb.util.overview. filter.HasAttributeFilter;45 import net.sf.basedb.util.overview.OverviewUtil; 46 import net.sf.basedb.util.overview.Validator; 40 47 import net.sf.basedb.util.overview.filter.ItemTypeFilter; 41 48 import net.sf.basedb.util.overview.node.ChildNodeDirection; … … 66 73 { 67 74 Node node = super.createRootNode(dc, context, item); 68 Extract extract = findExtract(null,item);75 Extract extract = getExtract(item); 69 76 if (extract != null) node.setAttribute(NodeAttribute.EXTRACT, extract); 70 77 return node; … … 184 191 ItemQuery<DerivedBioAssay> query = context.initQuery(bioAssay.getRootDerivedBioAssays(), "name"); 185 192 186 // If there is an extract node in the parent chain we should only load 187 // derived bioassays with the same or a null extract 188 Node extractNode = bioAssayNode.getFirstNode(new ItemTypeFilter(Item.EXTRACT)); 189 Extract extract = null; 190 if (extractNode != null) 191 { 192 extract = (Extract)extractNode.getItem(); 193 query.restrict(Restrictions.or( 194 Restrictions.eq(Hql.property("extract"), Hql.entity(extract)), 195 Restrictions.eq(Hql.property("extract"), null)) 196 ); 197 } 193 // We should only load derived bioassays that has a null extract or an 194 // extract that is found in the parent chain 195 Set<Integer> extractIds = getExtractChain(bioAssayNode); 196 if (extractIds.size() > 0) 197 { 198 query.restrict( 199 Restrictions.or( 200 Restrictions.eq(Hql.property("extract"), null), 201 Restrictions.in(Hql.property("extract"), Expressions.parameter("extracts")) 202 )); 203 query.setParameter("extracts", extractIds, Type.INT); 204 } 205 198 206 ItemResultIterator<DerivedBioAssay> it = query.iterate(dc); 199 207 while (it.hasNext()) … … 204 212 folderNode = new Node("bioassays", "Bioassays", bioAssayNode, ChildNodeDirection.FORWARD); 205 213 } 206 Object cacheKey = new IndexedCacheKey(bioAssay, extract);214 Object cacheKey = extractIds.size() > 0 ? null : child; 207 215 createItemNode(nf, child, cacheKey, false, folderNode, ChildNodeDirection.FORWARD); 208 216 } … … 222 230 ItemQuery<DerivedBioAssay> query = context.initQuery(parent.getChildren(), "name"); 223 231 224 // If there is an extract node in the parent chain we should only load225 // derived bioassays with the same or a null extract226 Node extractNode = parentNode.getFirstNode(new ItemTypeFilter(Item.EXTRACT));227 Extract extract = null;228 if (extractNode != null)229 {230 extract = (Extract)extractNode.getItem();231 query.restrict(Restrictions.or(232 Restrictions. eq(Hql.property("extract"), Hql.entity(extract)),233 Restrictions.eq(Hql.property("extract"), null))234 232 // We should only load derived bioassays that has a null extract or an 233 // extract that is found in the parent chain 234 Set<Integer> extractIds = getExtractChain(parentNode); 235 if (extractIds.size() > 0) 236 { 237 query.restrict( 238 Restrictions.or( 239 Restrictions.eq(Hql.property("extract"), null), 240 Restrictions.in(Hql.property("extract"), Expressions.parameter("extracts")) 241 )); 242 query.setParameter("extracts", extractIds, Type.INT); 235 243 } 236 244 … … 243 251 folderNode = new Node("bioassays", "Child bioassays", parentNode, ChildNodeDirection.FORWARD); 244 252 } 245 Object cacheKey = new IndexedCacheKey(child, extract);253 Object cacheKey = extractIds.size() > 0 ? null : child; 246 254 createItemNode(nf, child, cacheKey, false, folderNode, ChildNodeDirection.FORWARD); 247 255 } … … 263 271 { 264 272 bioAssay = raw.getParentBioAssay(); 265 // We must clone/set the EXTRACT attribute so that upstream loaders273 // We must set the EXTRACT attribute so that upstream loaders 266 274 // follow the correct path when reaching the biomaterials section 267 if (bioAssay != null) 268 { 269 extract = findExtract(rawNode, bioAssay); 270 } 275 if (bioAssay != null) extract = getExtract(bioAssay); 271 276 } 272 277 catch (PermissionDeniedException ex) … … 274 279 denied = true; 275 280 } 276 Object cacheKey = new IndexedCacheKey(bioAssay, extract); 277 Node bioAssayNode = createItemNode(nf, bioAssay, cacheKey, denied, 281 Node bioAssayNode = createItemNode(nf, bioAssay, null, denied, 278 282 rawNode, ChildNodeDirection.REVERSE); 279 283 if (extract != null && bioAssayNode != null) … … 291 295 { 292 296 NodeFactory<DerivedBioAssay> nf = getNodeFactory(dc, context); 293 DerivedBioAssay bioAssay = null; 297 298 ItemQuery<DerivedBioAssay> query = context.initQuery(child.getParents(), "name"); 299 List<DerivedBioAssay> parents = query.list(dc); 300 301 Node folderNode = null; 302 Node bioAssayNode = null; 303 if (parents.size() > 1) 304 { 305 folderNode = new Node("parents", "Parents", childNode, ChildNodeDirection.REVERSE); 306 } 307 308 for (DerivedBioAssay dba : parents) 309 { 310 // We need to handle circular references inline because 311 // we can never require that a validator implementation handles this 312 Node circularNode = OverviewUtil.getCircularRef(childNode, dba); 313 if (circularNode != null) 314 { 315 context.createFailure(Validator.CIRCULAR_REFERENCE, childNode, 316 "Circular reference to '" + dba.getName() + "'", 317 new Fix("Modify parents of '" + child.getName() + "'", child), 318 new Fix("Modify parents of '" + dba.getName() + "'", dba) 319 ); 320 } 321 else 322 { 323 Extract extract = getExtract(dba); 324 bioAssayNode = createItemNode(nf, dba, null, false, folderNode == null ? childNode : folderNode, ChildNodeDirection.REVERSE); 325 if (extract != null && bioAssayNode != null) 326 { 327 bioAssayNode.setAttribute(NodeAttribute.EXTRACT, extract); 328 } 329 } 330 } 331 postValidateFolder(nf, folderNode, childNode, bioAssayNode == null); 332 return folderNode == null ? bioAssayNode : folderNode; 333 } 334 335 /** 336 Get the extract that is associated with the current derived bioassay 337 @return The extract or null if none was found 338 */ 339 private Extract getExtract(DerivedBioAssay bioAssay) 340 { 294 341 Extract extract = null; 295 boolean denied = false;296 342 try 297 343 { 298 bioAssay = child.getParent(); 299 // We must clone/set the EXTRACT attribute so that upstream loaders 300 // follow the correct path when reaching the biomaterials section 301 extract = findExtract(childNode, bioAssay); 344 extract = bioAssay.getExtract(); 302 345 } 303 346 catch (PermissionDeniedException ex) 304 { 305 denied = true; 306 } 307 308 Object cacheKey = new IndexedCacheKey(bioAssay, extract); 309 Node bioAssayNode = createItemNode(nf, bioAssay, cacheKey, denied, 310 childNode, ChildNodeDirection.REVERSE); 311 if (extract != null && bioAssayNode != null) 312 { 313 bioAssayNode.setAttribute(NodeAttribute.EXTRACT, extract); 314 } 315 return bioAssayNode; 316 } 317 318 /** 319 Try to locate the extract we are following by first 320 checking if the node or any of it's parents have a 321 {@link NodeAttribute#EXTRACT} attribute set. If not we 322 check if the current bioassay has an extract. 323 @return The extract or null if none was found 324 */ 325 private Extract findExtract(Node node, DerivedBioAssay bioAssay) 326 { 327 Extract extract = null; 328 Node nodeWithExtract = node == null ? 329 null : node.getFirstNode(new HasAttributeFilter(NodeAttribute.EXTRACT)); 330 if (nodeWithExtract != null) 331 { 332 extract = nodeWithExtract.getAttribute(NodeAttribute.EXTRACT); 333 } 334 else 335 { 336 try 337 { 338 extract = bioAssay.getExtract(); 339 } 340 catch (PermissionDeniedException ex) 341 {} 342 } 347 {} 343 348 return extract; 344 349 } 350 351 private Set<Integer> getExtractChain(Node node) 352 { 353 List<Node> extractNodes = node.findAll(new ItemTypeFilter(Item.EXTRACT)); 354 Set<Integer> extractIds = new HashSet<Integer>(extractNodes.size()); 355 for (Node n : extractNodes) 356 { 357 extractIds.add(n.getItem().getId()); 358 } 359 return extractIds; 360 } 361 345 362 } -
trunk/src/core/net/sf/basedb/util/overview/loader/ExtractLoader.java
r6043 r6090 21 21 */ 22 22 package net.sf.basedb.util.overview.loader; 23 24 import java.util.HashSet; 25 import java.util.List; 26 import java.util.Set; 23 27 24 28 import net.sf.basedb.core.BioMaterialList; … … 34 38 import net.sf.basedb.core.RawBioAssay; 35 39 import net.sf.basedb.core.Sample; 40 import net.sf.basedb.core.Type; 36 41 import net.sf.basedb.core.query.Expressions; 37 42 import net.sf.basedb.core.query.Hql; … … 307 312 Node folderNode = null; 308 313 NodeFactory<Extract> nf = getNodeFactory(dc, context); 309 310 // If we have followed this path from an item that has specified an extract 311 // we should only load that extract when following the path upstreams 312 Extract extract = null; 313 Node nodeWithExtract = bioAssayNode.getFirstNode(new HasAttributeFilter(NodeAttribute.EXTRACT)); 314 if (nodeWithExtract != null) 315 { 316 extract = nodeWithExtract.getAttribute(NodeAttribute.EXTRACT); 317 } 318 314 319 315 ItemQuery<Extract> query = context.initQuery(bioAssay.getExtracts(0), "name"); 320 if (extract != null) 321 { 322 query.restrict(Restrictions.eq(Hql.property("id"), Expressions.integer(extract.getId()))); 316 317 // If we have followed this path from derived bioassays that has specified an 318 // extract we should only load the same extracts when following the path upstreams 319 Set<Integer> extractIds = getExtractChain(bioAssayNode); 320 if (extractIds.size() > 0) 321 { 322 query.restrict( 323 Restrictions.in(Hql.property("id"), Expressions.parameter("extracts")) 324 ); 325 query.setParameter("extracts", extractIds, Type.INT); 323 326 } 324 327 ItemResultIterator<Extract> it = query.iterate(dc); 325 328 while (it.hasNext()) 326 329 { 327 extract = it.next();330 Extract extract = it.next(); 328 331 if (folderNode == null) 329 332 { … … 332 335 createItemNode(nf, extract, extract, false, folderNode, ChildNodeDirection.REVERSE); 333 336 } 334 postValidateFolder(nf, folderNode, bioAssayNode, nodeWithExtract == null);337 postValidateFolder(nf, folderNode, bioAssayNode, extractIds.size() > 0); 335 338 return folderNode; 336 339 } … … 442 445 443 446 } 447 448 private Set<Integer> getExtractChain(Node node) 449 { 450 List<Node> nodesWithExtract = node.findAll(new HasAttributeFilter(NodeAttribute.EXTRACT)); 451 Set<Integer> extractIds = new HashSet<Integer>(nodesWithExtract.size()); 452 for (Node n : nodesWithExtract) 453 { 454 extractIds.add(n.getAttribute(NodeAttribute.EXTRACT).getId()); 455 } 456 return extractIds; 457 } 458 444 459 } -
trunk/src/core/net/sf/basedb/util/overview/loader/PhysicalBioAssayLoader.java
r5985 r6090 21 21 */ 22 22 package net.sf.basedb.util.overview.loader; 23 24 import java.util.List; 23 25 24 26 import net.sf.basedb.core.ArraySlide; … … 33 35 import net.sf.basedb.core.PermissionDeniedException; 34 36 import net.sf.basedb.util.overview.Node; 35 import net.sf.basedb.util.overview.NodeAttribute;36 37 import net.sf.basedb.util.overview.OverviewContext; 37 38 import net.sf.basedb.util.overview.OverviewUtil; 38 39 import net.sf.basedb.util.overview.cache.IndexedCacheKey; 39 import net.sf.basedb.util.overview.filter.HasAttributeFilter;40 40 import net.sf.basedb.util.overview.node.ChildNodeDirection; 41 41 import net.sf.basedb.util.overview.node.NameableNameGenerator; … … 103 103 { 104 104 NodeFactory<PhysicalBioAssay> nf = getNodeFactory(dc, context); 105 PhysicalBioAssay bioAssay = null; 106 Extract extract = null; 107 boolean denied = false; 108 try 109 { 110 DerivedBioAssay bas = (DerivedBioAssay)derivedBioAssayNode.getItem(dc); 111 bioAssay = bas.getPhysicalBioAssay(); 112 // We must clone/set the EXTRACT attribute so that upstream loaders 113 // follow the correct path when reaching the biomaterials section 114 Node nodeWithExtract = derivedBioAssayNode.getFirstNode(new HasAttributeFilter(NodeAttribute.EXTRACT)); 115 if (nodeWithExtract != null) 116 { 117 extract = nodeWithExtract.getAttribute(NodeAttribute.EXTRACT); 118 } 119 } 120 catch (PermissionDeniedException ex) 121 { 122 denied = true; 123 } 124 Object cacheKey = new IndexedCacheKey(bioAssay, extract); 125 Node bioAssayNode = createItemNode(nf, bioAssay, cacheKey, denied, derivedBioAssayNode, ChildNodeDirection.REVERSE); 126 if (extract != null && bioAssayNode != null) 127 { 128 bioAssayNode.setAttribute(NodeAttribute.EXTRACT, extract); 129 } 130 return bioAssayNode; 105 DerivedBioAssay dba = (DerivedBioAssay)derivedBioAssayNode.getItem(dc); 106 107 ItemQuery<PhysicalBioAssay> query = context.initQuery(dba.getPhysicalBioAssays(), "name"); 108 List<PhysicalBioAssay> parents = query.list(dc); 109 110 Node folderNode = null; 111 Node bioAssayNode = null; 112 if (parents.size() > 1) 113 { 114 folderNode = new Node("parents", "Physical bioassays", derivedBioAssayNode, ChildNodeDirection.REVERSE); 115 } 116 117 for (PhysicalBioAssay pba : parents) 118 { 119 bioAssayNode = createItemNode(nf, pba, null, false, folderNode == null ? derivedBioAssayNode : folderNode, ChildNodeDirection.REVERSE); 120 } 121 postValidateFolder(nf, folderNode, derivedBioAssayNode, bioAssayNode == null); 122 return folderNode == null ? bioAssayNode : folderNode; 131 123 } 132 124 … … 230 222 { 231 223 PhysicalBioAssay bioAssay = it.next(); 232 int position = bioAssay.getCreationEvent().getEventSource(extract).getPosition(); 233 Object cacheKey = position == 0 ? bioAssay : new IndexedCacheKey(bioAssay, position); 224 Object cacheKey = new IndexedCacheKey(bioAssay, extract); 234 225 if (folderNode == null) 235 226 { -
trunk/src/core/net/sf/basedb/util/overview/validator/DerivedBioAssayValidator.java
r5807 r6090 111 111 } 112 112 } 113 113 /* 114 114 // Check that parent items make sense 115 115 DerivedBioAssay bioAssay = (DerivedBioAssay)node.getItem(dc); … … 158 158 } 159 159 } 160 */ 160 161 } 161 162
Note: See TracChangeset
for help on using the changeset viewer.