Changeset 4559
- Timestamp:
- Oct 3, 2008, 4:23:49 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/MeasuredBioMaterial.java
r4517 r4559 27 27 28 28 import net.sf.basedb.core.data.MeasuredBioMaterialData; 29 import net.sf.basedb.core.query.Expressions; 30 import net.sf.basedb.core.query.Hql; 31 import net.sf.basedb.core.query.Restrictions; 29 32 30 33 /** … … 292 295 return BioMaterialEvent.getQuery(this); 293 296 } 297 298 /** 299 Get a query that returns all events where this biomaterial 300 has been used as a source. 301 @return An {@link ItemQuery} object 302 @since 2.9 303 */ 304 public ItemQuery<BioMaterialEvent> getPoolingEvents() 305 { 306 ItemQuery<BioMaterialEvent> query = new ItemQuery<BioMaterialEvent>(BioMaterialEvent.class, null); 307 query.setDistinct(true); // Otherwise, the join to sources can result in one copy for each source 308 query.joinPermanent(Hql.leftJoin("sources", "src")); 309 query.joinPermanent(Hql.leftJoin("bioMaterial", "bm")); 310 query.restrictPermanent( 311 Restrictions.and( 312 Restrictions.eq( 313 Hql.index("src", null), 314 Hql.entity(this) 315 ), 316 Restrictions.eq( 317 Hql.property("bm", "pooled"), 318 Expressions.integer(1) 319 ), 320 Restrictions.eq( 321 Hql.property("eventType"), 322 Expressions.integer(BioMaterialEvent.Type.CREATION.getValue()) 323 ) 324 ) 325 ); 326 return query; 327 } 294 328 } 295 -
trunk/src/test/TestExtract.java
r4514 r4559 60 60 test_list_sources(id3, 1); // The sample 61 61 test_list_sources(id4, 3); // The three id, id2 and id3 extracts 62 test_list_pooledChildren(id2, 1); 62 63 63 64 if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); … … 401 402 } 402 403 } 403 404 static void test_list_pooledChildren(int extractId, int expectedResults) 405 { 406 if (extractId == 0) return; 407 DbControl dc = null; 408 try 409 { 410 dc = TestUtil.getDbControl(); 411 Extract e = Extract.getById(dc, extractId); 412 ItemResultList<BioMaterialEvent> ev = e.getPoolingEvents().list(dc); 413 414 for (int i=0; i<ev.size(); i++) 415 { 416 write_item(i, (Extract)ev.get(i).getBioMaterial()); 417 } 418 if (expectedResults >= 0 && expectedResults != ev.size()) 419 { 420 throw new BaseException("Expected "+expectedResults+" results, not "+ev.size()); 421 } 422 write("--List pools from extract OK ("+ev.size()+")"); 423 } 424 catch (Throwable ex) 425 { 426 write("--List pools for extract FAILED"); 427 ex.printStackTrace(); 428 ok = false; 429 } 430 finally 431 { 432 if (dc != null) dc.close(); 433 } 434 } 404 435 } -
trunk/src/test/TestLabeledExtract.java
r4514 r4559 60 60 test_list_sources(id3, 1); // The extract 61 61 test_list_sources(id4, 3); // The three id, id2 and id3 labeled extracts 62 test_list_pooledChildren(id2, 1); 62 63 test_list_hybridizations(id, 0); 63 64 … … 440 441 } 441 442 } 442 443 444 static void test_list_pooledChildren(int labeledExtractId, int expectedResults) 445 { 446 if (labeledExtractId == 0) return; 447 DbControl dc = null; 448 try 449 { 450 dc = TestUtil.getDbControl(); 451 LabeledExtract le = LabeledExtract.getById(dc, labeledExtractId); 452 ItemResultList<BioMaterialEvent> ev = le.getPoolingEvents().list(dc); 453 454 for (int i=0; i<ev.size(); i++) 455 { 456 write_item(i, (LabeledExtract)ev.get(i).getBioMaterial()); 457 } 458 if (expectedResults >= 0 && expectedResults != ev.size()) 459 { 460 throw new BaseException("Expected "+expectedResults+" results, not "+ev.size()); 461 } 462 write("--List pools from labeledExtract OK ("+ev.size()+")"); 463 } 464 catch (Throwable ex) 465 { 466 write("--List pools for labeled extract FAILED"); 467 ex.printStackTrace(); 468 ok = false; 469 } 470 finally 471 { 472 if (dc != null) dc.close(); 473 } 474 } 443 475 } -
trunk/src/test/TestSample.java
r4514 r4559 59 59 write_sources_header(); 60 60 test_list_sources(id4, 3); // The three id, id2 and id3 samples 61 test_list_pooledChildren(id2, 1); 61 62 62 63 // Standard test: Delete … … 400 401 } 401 402 } 402 403 static void test_list_pooledChildren(int sampleId, int expectedResults) 404 { 405 if (sampleId == 0) return; 406 DbControl dc = null; 407 try 408 { 409 dc = TestUtil.getDbControl(); 410 Sample s = Sample.getById(dc, sampleId); 411 ItemResultList<BioMaterialEvent> ev = s.getPoolingEvents().list(dc); 412 413 for (int i=0; i<ev.size(); i++) 414 { 415 write_item(i, (Sample)ev.get(i).getBioMaterial()); 416 } 417 if (expectedResults >= 0 && expectedResults != ev.size()) 418 { 419 throw new BaseException("Expected "+expectedResults+" results, not "+ev.size()); 420 } 421 write("--List pools from sample OK ("+ev.size()+")"); 422 } 423 catch (Throwable ex) 424 { 425 write("--List pools for sample FAILED"); 426 ex.printStackTrace(); 427 ok = false; 428 } 429 finally 430 { 431 if (dc != null) dc.close(); 432 } 433 } 403 434 } -
trunk/www/biomaterials/extracts/view_extract.jsp
r4539 r4559 388 388 389 389 // Extracts this item is pooled in. 390 Set<ItemProxy> childSet = extract.getUsingItems(); 391 List<Extract> childExtracts = new ArrayList<Extract>(); 392 for (ItemProxy itemProxy : childSet) 393 { 394 if (Item.EXTRACT.equals(itemProxy.getType())) 395 { 396 childExtracts.add((Extract)itemProxy.getItem(dc)); 397 } 398 } 399 if (childExtracts.size() == 0) 390 ItemQuery<BioMaterialEvent> poolingQuery = extract.getPoolingEvents(); 391 ItemResultList<BioMaterialEvent> poolingEvents = poolingQuery.list(dc); 392 if (poolingEvents.size() == 0) 400 393 { 401 394 %> … … 434 427 <tbl:rows> 435 428 <% 436 for ( Extract e : childExtracts)429 for (BioMaterialEvent poolEvt : poolingEvents) 437 430 { 438 BioMaterialEvent poolEvent = e.getCreationEvent();439 ItemQuery<Extract> extractsQuery = (ItemQuery<Extract>)poolEvent.getSources();431 ItemQuery<Extract> extractsQuery = (ItemQuery<Extract>)poolEvt.getSources(); 432 Extract child = (Extract)poolEvt.getBioMaterial(); 440 433 extractsQuery.include(Include.ALL); 441 434 extractsQuery.order(Orders.asc(Hql.property("name"))); … … 447 440 image="deleted.gif" 448 441 tooltip="This item has been scheduled for deletion" 449 visible="<%= e.isRemoved()%>"442 visible="<%=child.isRemoved()%>" 450 443 /> 451 <%=Base.getLinkedName(ID, e, false, true)%>444 <%=Base.getLinkedName(ID, child, false, true)%> 452 445 </tbl:cell> 453 <tbl:cell column="quantity"><%=Values.formatNumber( e.getOriginalQuantity(), 2)%></tbl:cell>446 <tbl:cell column="quantity"><%=Values.formatNumber(child.getOriginalQuantity(), 2)%></tbl:cell> 454 447 <tbl:cell column="parents"> 455 448 <% … … 462 455 else 463 456 out.write(Base.getLinkedName(ID, parent, false, true)); 464 out.write("[" + Values.formatNumber(poolEv ent.getUsedQuantity(parent), 2) + "µg]");457 out.write("[" + Values.formatNumber(poolEvt.getUsedQuantity(parent), 2) + "µg]"); 465 458 separator = ", "; 466 459 } 467 460 %> 468 461 </tbl:cell> 469 <tbl:cell column="description"><%=HTML.encodeTags( e.getDescription())%></tbl:cell>462 <tbl:cell column="description"><%=HTML.encodeTags(child.getDescription())%></tbl:cell> 470 463 </tbl:row> 471 464 <% -
trunk/www/biomaterials/labeledextracts/view_labeledextract.jsp
r4510 r4559 39 39 import="net.sf.basedb.core.Protocol" 40 40 import="net.sf.basedb.core.User" 41 import="net.sf.basedb.core.ItemProxy" 41 42 import="net.sf.basedb.core.ItemQuery" 42 43 import="net.sf.basedb.core.ItemResultIterator" 43 44 import="net.sf.basedb.core.ItemResultList" 44 45 import="net.sf.basedb.core.Include" 46 import="net.sf.basedb.core.MeasuredBioMaterial" 45 47 import="net.sf.basedb.core.MultiPermissions" 46 48 import="net.sf.basedb.core.query.Orders" … … 57 59 import="net.sf.basedb.util.formatter.Formatter" 58 60 import="net.sf.basedb.clients.web.formatter.FormatterFactory" 61 import="java.util.ArrayList" 59 62 import="java.util.Collections" 60 63 import="java.util.Date" … … 387 390 <% 388 391 } 392 393 // Pooled item this labeled extract is used in. 394 ItemQuery<BioMaterialEvent> poolingQuery = extract.getPoolingEvents(); 395 ItemResultList<BioMaterialEvent> poolingEvents = poolingQuery.list(dc); 396 if (poolingEvents.size() == 0) 397 { 398 %> 399 <h4>Pooled in labeled extracts</h4> 400 No labeled extracts have been pooled from this labeled extract 401 (or, you don't have permission to view them). 402 <% 403 } 404 else 405 { 406 %> 407 <h4 class="docked">Pooled in labeled extracts</h4> 408 <tbl:table 409 id="poolChilds" 410 clazz="itemlist" 411 columns="all" 412 > 413 <tbl:columndef 414 id="name" 415 title="Name" 416 /> 417 <tbl:columndef 418 id="quantity" 419 title="Original quantity (µg)" 420 /> 421 <tbl:columndef 422 id="parents" 423 title="Used labeled extracts [quantity]" 424 /> 425 <tbl:columndef 426 id="description" 427 title="Description" 428 /> 429 <tbl:data> 430 <tbl:columns></tbl:columns> 431 <tbl:rows> 432 <% 433 for (BioMaterialEvent poolEvt : poolingEvents) 434 { 435 LabeledExtract ch = (LabeledExtract)poolEvt.getBioMaterial(); 436 ItemQuery<LabeledExtract> extractsQuery = (ItemQuery<LabeledExtract>)poolEvt.getSources(); 437 extractsQuery.include(Include.ALL); 438 extractsQuery.order(Orders.asc(Hql.property("name"))); 439 ItemResultList<LabeledExtract> parentExtracts = extractsQuery.list(dc); 440 %> 441 <tbl:row> 442 <tbl:cell column="name"> 443 <base:icon 444 image="deleted.gif" 445 tooltip="This item has been scheduled for deletion" 446 visible="<%=ch.isRemoved() %>" 447 /> 448 <%=Base.getLinkedName(ID, ch, false, true)%> 449 </tbl:cell> 450 <tbl:cell column="quantity"><%=Values.formatNumber(ch.getOriginalQuantity(), 2)%></tbl:cell> 451 <tbl:cell column="parents"> 452 <% 453 String separator = ""; 454 for (LabeledExtract parent : parentExtracts) 455 { 456 out.write(separator); 457 if (parent.equals(extract)) 458 out.write(HTML.encodeTags(parent.getName())); 459 else 460 out.write(Base.getLinkedName(ID, parent, false, true)); 461 out.write("[" + Values.formatNumber(poolEvt.getUsedQuantity(parent), 2) + "µg]"); 462 separator = ", "; 463 } 464 %> 465 </tbl:cell> 466 <tbl:cell column="description"><%=HTML.encodeTags(ch.getDescription())%></tbl:cell> 467 </tbl:row> 468 <% 469 } 470 %> 471 </tbl:rows> 472 </tbl:data> 473 </tbl:table> 474 <% 475 } 476 389 477 ItemQuery<Hybridization> hybridizationQuery = extract.getHybridizations(); 390 478 hybridizationQuery.include(Include.ALL); -
trunk/www/biomaterials/samples/view_sample.jsp
r4539 r4559 373 373 374 374 // Samples this item is pooled in. 375 Set<ItemProxy> childSet = sample.getUsingItems(); 376 List<Sample> childSamples = new ArrayList<Sample>(); 377 for (ItemProxy itemProxy : childSet) 378 { 379 if (Item.SAMPLE.equals(itemProxy.getType())) 380 { 381 childSamples.add((Sample)itemProxy.getItem(dc)); 382 } 383 } 384 if (childSamples.size() == 0) 375 ItemQuery<BioMaterialEvent> poolingQuery = sample.getPoolingEvents(); 376 ItemResultList<BioMaterialEvent> poolingEvents = poolingQuery.list(dc); 377 if (poolingEvents.size() == 0) 385 378 { 386 379 %> … … 419 412 <tbl:rows> 420 413 <% 421 for ( Sample s : childSamples)414 for (BioMaterialEvent poolingEvt : poolingEvents) 422 415 { 423 BioMaterialEvent poolEvent = s.getCreationEvent();424 ItemQuery<Sample> samplesQuery = (ItemQuery<Sample>)pool Event.getSources();416 Sample child = (Sample)poolingEvt.getBioMaterial(); 417 ItemQuery<Sample> samplesQuery = (ItemQuery<Sample>)poolingEvt.getSources(); 425 418 samplesQuery.include(Include.ALL); 426 419 samplesQuery.order(Orders.asc(Hql.property("name"))); … … 432 425 image="deleted.gif" 433 426 tooltip="This item has been scheduled for deletion" 434 visible="<%= s.isRemoved()%>"427 visible="<%=child.isRemoved()%>" 435 428 /> 436 <%=Base.getLinkedName(ID, s, false, true)%>429 <%=Base.getLinkedName(ID, child, false, true)%> 437 430 </tbl:cell> 438 <tbl:cell column="quantity"><%=Values.formatNumber( s.getOriginalQuantity(), 2)%></tbl:cell>431 <tbl:cell column="quantity"><%=Values.formatNumber(child.getOriginalQuantity(), 2)%></tbl:cell> 439 432 <tbl:cell column="parents"> 440 433 <% … … 447 440 else 448 441 out.write(Base.getLinkedName(ID, parent, false, true)); 449 out.write("[" + Values.formatNumber(pool Event.getUsedQuantity(parent), 2) + "µg]");442 out.write("[" + Values.formatNumber(poolingEvt.getUsedQuantity(parent), 2) + "µg]"); 450 443 separator = ", "; 451 444 } 452 445 %> 453 446 </tbl:cell> 454 <tbl:cell column="description"><%=HTML.encodeTags( s.getDescription())%></tbl:cell>447 <tbl:cell column="description"><%=HTML.encodeTags(child.getDescription())%></tbl:cell> 455 448 </tbl:row> 456 449 <%
Note: See TracChangeset
for help on using the changeset viewer.