Changeset 5663
- Timestamp:
- Jun 22, 2011, 4:03:17 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 35 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/plugins/ParentBioMaterialLoader.java
r5384 r5663 22 22 package net.sf.basedb.clients.web.plugins; 23 23 24 import net.sf.basedb.core.BioMaterial; 24 25 import net.sf.basedb.core.DbControl; 25 26 import net.sf.basedb.core.Include; … … 48 49 Object parents = null; 49 50 DbControl dc = item.getDbControl(); 50 if (item. isPooled())51 if (item.getParentType() == null) 51 52 { 52 ItemQuery<? extends MeasuredBioMaterial> pooledQuery = item.getCreationEvent().getSources(); 53 pooledQuery.include(Include.ALL); 54 parents = pooledQuery.list(dc); 53 // No parents 55 54 } 56 else 55 else if (item.hasSingleParent()) 57 56 { 58 57 try … … 63 62 {} 64 63 } 64 else 65 { 66 ItemQuery<? extends BioMaterial> pooledQuery = item.getCreationEvent().getSources(); 67 pooledQuery.include(Include.ALL); 68 parents = pooledQuery.list(dc); 69 } 65 70 return parents; 66 71 } -
trunk/src/clients/web/net/sf/basedb/clients/web/taglib/Button.java
r4937 r5663 175 175 defaultImages.put("remove", "remove.png"); 176 176 defaultImages.put("browse", "browse.png"); 177 defaultImages.put("select", "select.png"); 177 178 } 178 179 … … 316 317 if (!isDisabled()) 317 318 { 318 sb.append(" onmouseover=\"this.className='").append(getClazz()).append("_hover';\"");319 sb.append(" onmouseout=\"this.className='").append(getClazz()).append("';\"");319 //sb.append(" onmouseover=\"this.className='").append(getClazz()).append("_hover';\""); 320 //sb.append(" onmouseout=\"this.className='").append(getClazz()).append("';\""); 320 321 } 321 322 } … … 332 333 theImage = page.getRoot() + "images/" + theImage; 333 334 } 334 sb.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td >");335 sb.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"width: 20px;\">"); 335 336 sb.append("<img src=\"").append(theImage).append("\""); 336 337 sb.append(" border=\"0\">"); 337 sb.append("</td><td >");338 sb.append("</td><td style=\"text-align: left;\">"); 338 339 } 339 340 sb.append(getTitle()); -
trunk/src/clients/web/net/sf/basedb/clients/web/taglib/Select.java
r5629 r5663 59 59 clazz=... 60 60 style=... 61 buttonclass=... 62 buttonstyle=... 63 buttontitle=... 64 buttonicon=... 61 65 required=true|false 62 66 current=... … … 111 115 </tr> 112 116 <tr> 117 <td>buttonclass</td> 118 <td>buttonclass</td> 119 <td>no</td> 120 <td> 121 The value if this attribute goes directly into the standard HTML 122 <code>class</code> attribute for the "Select" button part. This allows you to 123 apply different styles to the button. If the button is disabled "_disabled" is 124 appended to the class name. 125 </td> 126 </tr> 127 <tr> 128 <td>buttonstyle</td> 129 <td>-</td> 130 <td>no</td> 131 <td> 132 The value if this attribute goes directly into the standard HTML 133 <code>style</code> attribute for the "Select" button part. This allows you to 134 apply different styles to the button. 135 </td> 136 </tr> 137 <tr> 138 <td>buttontitle</td> 139 <td>Select</td> 140 <td>no</td> 141 <td> 142 The text on the "Select" button. 143 </td> 144 </tr> 145 <tr> 146 <td>buttonicon</td> 147 <td>select.png</td> 148 <td>no</td> 149 <td> 150 The icon to use on the "Select" button. 151 </td> 152 </tr> 153 <tr> 113 154 <td>required</td> 114 155 <td>false</td> … … 242 283 private String style = null; 243 284 285 private String buttonclass = "buttonclass"; 286 private String buttonstyle = null; 287 private String buttontitle = "Select…"; 288 private String buttonicon = "select.png"; 289 244 290 /** 245 291 If a value is required or not. … … 331 377 return style; 332 378 } 379 /** 380 @since 3.0 381 */ 382 public void setButtonclass(String clazz) 383 { 384 this.buttonclass = clazz; 385 } 386 /** 387 @since 3.0 388 */ 389 public String getButtonclass() 390 { 391 return buttonclass; 392 } 393 /** 394 @since 3.0 395 */ 396 public void setButtonstyle(String style) 397 { 398 this.buttonstyle = style; 399 } 400 /** 401 @since 3.0 402 */ 403 public String getButtonstyle() 404 { 405 return buttonstyle; 406 } 407 /** 408 @since 3.0 409 */ 410 public void setButtontitle(String title) 411 { 412 this.buttontitle = title; 413 } 414 /** 415 @since 3.0 416 */ 417 public String getButtontitle() 418 { 419 return buttontitle; 420 } 421 /** 422 @since 3.0 423 */ 424 public void setButtonicon(String icon) 425 { 426 this.buttonicon = icon; 427 } 428 /** 429 @since 3.0 430 */ 431 public String getButtonicon() 432 { 433 return buttonicon; 434 } 333 435 334 436 public void setRequired(boolean required) … … 454 556 { 455 557 if (!isVisible()) return SKIP_BODY; 456 //Page page = (Page)findAncestorWithClass(this, Page.class);558 Page page = (Page)findAncestorWithClass(this, Page.class); 457 559 458 560 tryGetDirectoryPath = true; … … 536 638 { 537 639 sb.append("<td>"); 538 sb.append("<div class=\" buttonclass").append(disabled ? "_disabled": "").append("\"");640 sb.append("<div class=\"").append(getButtonclass()).append(disabled ? "_disabled": "").append("\""); 539 641 if (!disabled) 540 642 { 541 sb.append(" onmouseover=\"this.className='buttonclass_hover';\" onmouseout=\"this.className='buttonclass';\"");643 //sb.append(" onmouseover=\"this.className='buttonclass_hover';\" onmouseout=\"this.className='buttonclass';\""); 542 644 sb.append(" onclick=\"").append(getOnselect()).append("\""); 543 645 } 544 sb.append("><div class=\"buttonclass_inner\">Select…</div></div>"); 646 if (getButtonstyle() != null) 647 { 648 sb.append("style=\"").append(getButtonstyle()).append("\""); 649 } 650 sb.append("><div class=\"").append(getButtonclass()).append("_inner\">"); 651 String buttonImg = getButtonicon(); 652 if (buttonImg != null) 653 { 654 if (!buttonImg.startsWith("/")) 655 { 656 buttonImg = page.getRoot() + "images/" + buttonImg; 657 } 658 sb.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"width: 20px;\">"); 659 sb.append("<img src=\"").append(buttonImg).append("\" border=\"0\"></td><td style=\"text-align: left;\">"); 660 } 661 sb.append(getButtontitle()); 662 if (buttonImg != null) 663 { 664 sb.append("</td></tr></table>"); 665 } 666 sb.append("</div></div>"); 545 667 sb.append("</td>\n"); 546 668 } -
trunk/src/core/common-queries.xml
r5652 r5663 1091 1091 FROM BioMaterialEventData bme 1092 1092 JOIN bme.sources src 1093 WHERE index(src)= :bioMaterial1093 WHERE src.bioMaterial = :bioMaterial 1094 1094 </sql> 1095 1095 <description> -
trunk/src/core/net/sf/basedb/core/BioMaterial.java
r5643 r5663 26 26 import net.sf.basedb.core.Transactional.Action; 27 27 import net.sf.basedb.core.data.BioMaterialData; 28 import net.sf.basedb.core.query.Hql; 29 import net.sf.basedb.core.query.Restrictions; 28 30 29 31 /** … … 167 169 */ 168 170 public abstract long countChildren(boolean pooled); 171 172 /** 173 Get a query returning all events where this biomaterial has been used 174 as a source item. 175 @return A special query 176 @since 3.0 177 */ 178 public SpecialQuery<BioMaterialEventSource> getChildCreationEvents() 179 { 180 SpecialQuery<BioMaterialEventSource> query = 181 new SpecialQuery<BioMaterialEventSource>(null, "BioMaterialEventSourceData", "es", 182 new BioMaterialEventSource.BioMaterialEventSourceTransformer()); 183 query.restrictPermanent(Restrictions.eq(Hql.property("es", "bioMaterial"), Hql.entity(this))); 184 return query; 185 } 169 186 170 187 } -
trunk/src/core/net/sf/basedb/core/BioMaterialEvent.java
r5662 r5663 331 331 332 332 DbControl dc = getDbControl(); 333 Subtypable parent = null; 334 ItemSubtype protocolSubtype = null; 335 ItemSubtype hardwareSubtype = null; 333 Subtypable createdItem = null; 336 334 String defaultProtocolId = null; 337 335 if (getEventType() == Type.BIOASSAY) 338 336 { 339 parent= getPhysicalBioAssay();337 createdItem = getPhysicalBioAssay(); 340 338 } 341 339 else 342 340 { 343 341 MeasuredBioMaterial bioMaterial = getBioMaterial(); 344 parent = bioMaterial; 345 Item parentType = parent.getType(); 346 if (bioMaterial.isPooled()) 347 { 348 defaultProtocolId = Protocol.POOLING; 349 } 350 else if (parentType == Item.SAMPLE) 342 createdItem = bioMaterial; 343 Item parentType = createdItem.getType(); 344 if (parentType == Item.SAMPLE) 351 345 { 352 346 defaultProtocolId = Protocol.SAMPLING; … … 357 351 } 358 352 } 359 protocolSubtype = ItemSubtype.getRelatedSubtype(dc, parent, Item.PROTOCOL, SystemItems.getId(defaultProtocolId)); 360 hardwareSubtype = ItemSubtype.getRelatedSubtype(dc, parent, Item.HARDWARE, 0); 361 362 if (!protocolHasBeenSet && protocolSubtype != null) 363 { 364 ProtocolData protocol = 365 (ProtocolData)activeProject.findDefaultData(Item.PROTOCOL, protocolSubtype.getData(), false); 366 if (protocol != null) getData().setProtocol(protocol); 367 protocolHasBeenSet = true; 368 } 369 if (!hardwareHasBeenSet && hardwareSubtype != null) 353 354 if (!protocolHasBeenSet) 355 { 356 ItemSubtype protocolSubtype = 357 ItemSubtype.getRelatedSubtype(dc, createdItem, Item.PROTOCOL, SystemItems.getId(defaultProtocolId)); 358 if (protocolSubtype != null) 359 { 360 ProtocolData protocol = 361 (ProtocolData)activeProject.findDefaultData(Item.PROTOCOL, protocolSubtype.getData(), false); 362 if (protocol != null) 363 { 364 getData().setProtocol(protocol); 365 protocolHasBeenSet = true; 366 } 367 } 368 } 369 if (!hardwareHasBeenSet) 370 370 { 371 371 HardwareData hardware = 372 (HardwareData)activeProject.findDefaultData(Item.HARDWARE, hardwareSubtype.getData(), false); 373 if (hardware != null) getData().setHardware(hardware); 374 hardwareHasBeenSet = true; 372 (HardwareData)activeProject.findDefaultRelatedData(dc, createdItem, Item.HARDWARE, false); 373 if (hardware != null) 374 { 375 getData().setHardware(hardware); 376 hardwareHasBeenSet = true; 377 } 375 378 } 376 379 } … … 618 621 619 622 /** 620 Add a biomaterial as a source to this event. If the given biomaterial 621 already is a source, the existing information is returned. 622 623 @param bioMaterial The biomaterial 623 Set a single parent item for this event. Any sources 624 that are currently associated with it are removed and 625 the used quantity is returned. 626 627 @param parent The parent biomaterial, or null to remove all parents 628 @since 3.0 629 */ 630 public BioMaterialEventSource setSource(BioMaterial parent) 631 { 632 checkPermission(Permission.RESTRICTED_WRITE); 633 if (parent != null) 634 { 635 parent.checkPermission(Permission.USE); 636 checkAllowedSource(parent, false); 637 } 638 clearSources(); 639 BioMaterialEventSource eventSource = null; 640 if (parent != null) 641 { 642 eventSource = addCheckedSource(parent); 643 } 644 return eventSource; 645 } 646 647 /** 648 Add a biomaterial as a source to this event. If the given 649 biomaterial already is a source, the existing information is 650 returned. If this event already has sources the new source 651 must be of the same type as the existing sources and the 652 produced biomaterial. 653 654 @param bioMaterial The biomaterial (null is not allowed) 624 655 @return A BioMaterialEventSource object 656 @since 3.0 625 657 */ 626 658 public BioMaterialEventSource addSource(BioMaterial bioMaterial) … … 629 661 if (bioMaterial == null) throw new InvalidUseOfNullException("bioMaterial"); 630 662 bioMaterial.checkPermission(Permission.USE); 631 checkAllowedSource(bioMaterial); 663 664 checkAllowedSource(bioMaterial, true); 632 665 return addCheckedSource(bioMaterial); 633 666 } … … 636 669 { 637 670 BioMaterialData bmData = (BioMaterialData)bioMaterial.getData(); 638 BioMaterialEventSourceData src = getData().getSources().get(bmData); 671 672 Map<BioMaterialData, BioMaterialEventSourceData> sources = getData().getSources(); 673 674 BioMaterialEventSourceData src = sources.get(bmData); 639 675 if (src == null) 640 676 { … … 642 678 src.setBioMaterial(bmData); 643 679 src.setEvent(this.getData()); 644 getData().getSources().put(bmData, src); 645 } 680 sources.put(bmData, src); 681 } 682 683 if (getData().getBioMaterial() != null) 684 { 685 // If the product is a biomaterial we may need to set parent + parent type 686 MeasuredBioMaterialData product = getData().getBioMaterial(); 687 if (sources.size() == 1) 688 { 689 // This is the first parent 690 product.setParentType(bioMaterial.getType().getValue()); 691 product.setParent(bmData); 692 } 693 else 694 { 695 // Clear if we get more than one parent 696 product.setParent(null); 697 } 698 } 699 646 700 return new BioMaterialEventSource(getDbControl(), src); 647 701 } … … 657 711 biomaterial is of another type 658 712 @throws BaseException If there is another error 713 @since 3.0 659 714 */ 660 715 public void removeSource(BioMaterial bioMaterial) … … 663 718 checkPermission(Permission.RESTRICTED_WRITE); 664 719 if (bioMaterial == null) throw new InvalidUseOfNullException("bioMaterial"); 665 checkAllowedSource(bioMaterial);666 720 BioMaterialData data = (BioMaterialData)bioMaterial.getData(); 667 BioMaterialEventSourceData src = getData().getSources().remove(data); 721 Map<BioMaterialData, BioMaterialEventSourceData> sources = getData().getSources(); 722 BioMaterialEventSourceData src = sources.remove(data); 723 724 if (sources.size() == 0) 725 { 726 if (getData().getBioMaterial() != null) 727 { 728 getData().getBioMaterial().setParentType(null); 729 } 730 } 731 668 732 if (src == null) return; 669 733 … … 680 744 681 745 /** 682 Check if the biomaterial is allowed as a source. It is allowed if: 683 <ul> 684 <li>This is a creation event 685 <li>The created biomaterial is pooled 686 <li>It is of the same type as the created biomaterial 687 <li>It is not the same item as the created biomaterial 688 </ul> 689 */ 690 private void checkAllowedSource(BioMaterial bioMaterial) 746 Check if the biomaterial is allowed as a source. 747 */ 748 private void checkAllowedSource(BioMaterial source, boolean forAdd) 691 749 throws PermissionDeniedException, InvalidDataException, BaseException 692 750 { 693 751 Type eventType = getEventType(); 752 Item sourceType = source.getType(); 694 753 switch (eventType) 695 754 { … … 700 759 case BIOASSAY: 701 760 { 702 if ( bioMaterial.getType()!= Item.EXTRACT)761 if (sourceType != Item.EXTRACT) 703 762 { 704 763 throw new InvalidDataException("The source for a physical bioassay must be an extract"); … … 708 767 case CREATION: 709 768 { 710 MeasuredBioMaterial parent = getBioMaterial(); 711 if (!parent.isPooled()) 769 MeasuredBioMaterial product = getBioMaterial(); 770 Item productType = product.getType(); 771 Item parentType = product.getParentType(); 772 773 if (forAdd && parentType != null) 712 774 { 713 throw new InvalidDataException("Non-pooled biomaterials can't have sources"); 775 if (parentType != sourceType) 776 { 777 throw new InvalidDataException("Can't add '" + source.getName() + "' (" + sourceType + 778 ") as parent since there is already a " + parentType + " parent"); 779 } 714 780 } 715 else if (bioMaterial.getType() != parent.getType()) 781 782 if (productType != sourceType) 716 783 { 717 throw new InvalidDataException("The source biomaterial must be of the same type as the produced biomaterial"); 784 if (productType == Item.EXTRACT && sourceType != Item.SAMPLE) 785 { 786 throw new InvalidDataException("The parent for an extract must be an extract or sample: " + source); 787 } 788 if (productType == Item.SAMPLE && sourceType != Item.BIOSOURCE) 789 { 790 throw new InvalidDataException("The parent for a sample must be a biosource or sample: " + source); 791 } 718 792 } 719 else if (bioMaterial.equals(parent)) 793 794 if (source.equals(product)) 720 795 { 721 throw new InvalidDataException("The source biomaterial cannot be the same as the produced biomaterial");796 throw new InvalidDataException("The parent biomaterial cannot be the same as the produced biomaterial: " + source); 722 797 } 723 798 break; … … 731 806 732 807 /** 733 Set a single source. This method is used for non-pooled biomaterial734 to specify the parent.735 @see Extract#setSample(Sample)736 */737 BioMaterialEventSource setSource(MeasuredBioMaterial bioMaterial)738 throws PermissionDeniedException, InvalidDataException739 {740 clearSources();741 return bioMaterial == null ? null : addCheckedSource(bioMaterial);742 }743 744 /**745 808 Clear the sources collection and return the used quantities to 746 809 the source biomaterials. 747 */ 748 void clearSources() 810 @since 3.0 811 */ 812 public void clearSources() 749 813 { 750 814 DbControl dc = getDbControl(); 751 for (BioMaterialEventSourceData src : getData().getSources().values()) 815 Map<BioMaterialData, BioMaterialEventSourceData> sources = getData().getSources(); 816 for (BioMaterialEventSourceData src : sources.values()) 752 817 { 753 818 BioMaterialData bioMaterial = src.getBioMaterial(); … … 759 824 dc.getHibernateSession().delete(src); 760 825 } 761 getData().getSources().clear(); 826 sources.clear(); 827 if (getData().getBioMaterial() != null) 828 { 829 getData().getBioMaterial().setParentType(null); 830 getData().getBioMaterial().setParent(null); 831 } 762 832 } 763 833 … … 780 850 @return An {@link ItemQuery} object 781 851 */ 782 public ItemQuery<? extends MeasuredBioMaterial> getSources()783 { 784 ItemQuery<? extends MeasuredBioMaterial> query = null;852 public ItemQuery<? extends BioMaterial> getSources() 853 { 854 ItemQuery<? extends BioMaterial> query = null; 785 855 MeasuredBioMaterialData bioMaterialData = getData().getBioMaterial(); 786 boolean pooled = bioMaterialData != null ? bioMaterialData.isPooled() : false; 787 Item parentType = Item.fromDataObject(bioMaterialData == null ? getData().getPhysicalBioAssay() : bioMaterialData); 856 Item parentType = null; 857 if (getEventType() == Type.BIOASSAY) 858 { 859 parentType = Item.EXTRACT; 860 } 861 else 862 { 863 Integer tmp = getData().getBioMaterial().getParentType(); 864 parentType = tmp != null ? Item.fromValue(tmp) : Item.fromDataObject(getData().getBioMaterial()); 865 } 788 866 switch (parentType) 789 867 { 868 case EXTRACT: 869 { 870 query = Extract.getQuery(); 871 break; 872 } 790 873 case SAMPLE: 791 874 { … … 793 876 break; 794 877 } 795 case EXTRACT: 796 { 797 if (pooled) 798 { 799 query = Extract.getQuery(); 800 } 801 else 802 { 803 query = Sample.getQuery(); 804 } 805 break; 806 } 807 case PHYSICALBIOASSAY: 808 { 809 query = Extract.getQuery(); 878 case BIOSOURCE: 879 { 880 query = BioSource.getQuery(); 810 881 break; 811 882 } -
trunk/src/core/net/sf/basedb/core/BioSource.java
r5357 r5663 185 185 { 186 186 Sample s= Sample.getNew(getDbControl()); 187 s. setBioSource(this);187 s.getCreationEvent().setSource(this); 188 188 return s; 189 189 } -
trunk/src/core/net/sf/basedb/core/Extract.java
r5662 r5663 28 28 29 29 import java.util.Set; 30 import java.util.HashSet;31 30 32 31 /** … … 143 142 { 144 143 return TYPE; 145 }146 // -------------------------------------------147 /*148 From the Annotatable interface149 -------------------------------------------150 */151 /**152 Get the sample or pooled extracts.153 */154 public Set<Annotatable> getAnnotatableParents()155 throws BaseException156 {157 Set<Annotatable> annotatable = new HashSet<Annotatable>();158 try159 {160 if (isPooled())161 {162 ItemQuery<? extends MeasuredBioMaterial> query = getCreationEvent().getSources();163 query.include(Include.ALL);164 annotatable.addAll(query.list(getDbControl()));165 }166 else if (getData().getParent() != null)167 {168 annotatable.add(getSample());169 }170 }171 catch (PermissionDeniedException ex)172 {}173 return annotatable;174 144 } 175 145 // ------------------------------------------- … … 228 198 // ------------------------------------------- 229 199 200 /** 201 Get the tag that has been applied to this extract in order 202 to be able to distinguish it from other extracts on a 203 physical bioassay. 204 @return A tag or null if the extract is not tagged 205 @since 3.0 206 */ 230 207 public Tag getTag() 231 208 { … … 233 210 } 234 211 212 /** 213 Set the tag that was applied to this extract in order 214 to be able to distinguish it from other extracts on a 215 physical bioassay. 216 @param tag The tag, or null if the extract is not tagged 217 @since 3.0 218 */ 235 219 public void setTag(Tag tag) 236 220 { … … 239 223 getData().setTag(tag == null ? null : tag.getData()); 240 224 } 241 242 /**243 Get the {@link Sample} that is the parent of this extract.244 @return A <code>Sample</code> object or null if this is a pooled or245 standalone extract246 @throws PermissionDeniedException If the logged in user doesn't have read247 permission for the sample248 @throws BaseException If there is another error249 */250 public Sample getSample()251 throws PermissionDeniedException, BaseException252 {253 return getDbControl().getItem(Sample.class, getData().getParent());254 }255 256 /**257 Set the {@link Sample} item that is the parent258 of this extract.259 @param sample The new <code>Sample</code> item260 @throws PermissionDeniedException If the logged in user doesn't have261 write permission for this extract or use permission for the sample262 @throws InvalidDataException If this is a pooled extract263 @throws BaseException If there is another error264 @since 3.0265 */266 public BioMaterialEventSource setSample(Sample sample)267 throws PermissionDeniedException, InvalidDataException, BaseException268 {269 checkPermission(Permission.WRITE);270 if (sample != null) sample.checkPermission(Permission.USE);271 if (isPooled())272 {273 throw new InvalidDataException("A pooled extract can't have a parent sample");274 }275 getData().setParent(sample == null ? null : sample.getData());276 return getCreationEvent().setSource(sample);277 }278 279 280 public BioMaterialEventSource setExtract(Extract extract)281 throws PermissionDeniedException, InvalidDataException, BaseException282 {283 checkPermission(Permission.WRITE);284 if (extract != null) extract.checkPermission(Permission.USE);285 286 getData().setPooled(true);287 getData().setParent(extract == null ? null : extract.getData());288 return getCreationEvent().setSource(extract);289 }290 291 225 292 226 /** … … 322 256 FROM BioMaterialEventData bme 323 257 JOIN bme.sources src 324 WHERE index(src)= :bioMaterial258 WHERE src.bioMaterial = :bioMaterial 325 259 */ 326 260 query.setEntity("bioMaterial", this.getData()); … … 330 264 /** 331 265 Count the number of child extracts. Since an extract 332 can 't have non-pooledchildren, this method always return333 0 if pooled= false.266 can only have other extracts as children, this method always return 267 0 if extractsOnly = false. 334 268 @since 2.16 335 269 */ 336 270 @Override 337 public long countChildren(boolean pooled)338 { 339 return pooled? countExtracts() : 0;271 public long countChildren(boolean extractsOnly) 272 { 273 return extractsOnly ? countExtracts() : 0; 340 274 } 341 275 -
trunk/src/core/net/sf/basedb/core/MeasuredBioMaterial.java
r5643 r5663 25 25 26 26 import java.util.Date; 27 import java.util.HashSet; 27 28 import java.util.Set; 28 29 … … 31 32 import net.sf.basedb.core.data.BioWellData; 32 33 import net.sf.basedb.core.data.MeasuredBioMaterialData; 33 import net.sf.basedb.core.query.Expressions;34 import net.sf.basedb.core.query.Hql;35 import net.sf.basedb.core.query.Restrictions;36 34 import net.sf.basedb.util.EqualsHelper; 37 35 … … 87 85 FROM BioMaterialEventData bme 88 86 JOIN bme.sources src 89 WHERE index(src)= :bioMaterial87 WHERE src.bioMaterial = :bioMaterial 90 88 */ 91 89 query.setEntity("bioMaterial", this.getData()); … … 110 108 FROM BioMaterialEventData bme 111 109 JOIN bme.sources src 112 WHERE index(src)= :bioMaterial110 WHERE src.bioMaterial = :bioMaterial 113 111 */ 114 112 query.setEntity("bioMaterial", this.getData()); … … 173 171 // ------------------------------------------- 174 172 /* 173 From the Annotatable interface 174 ------------------------------------------- 175 */ 176 /** 177 Get the biosource or pooled samples. 178 */ 179 public Set<Annotatable> getAnnotatableParents() 180 throws BaseException 181 { 182 Set<Annotatable> annotatable = new HashSet<Annotatable>(); 183 try 184 { 185 if (getData().getParent() != null) 186 { 187 annotatable.add(getParent()); 188 } 189 else if (getParentType() != null) 190 { 191 ItemQuery<? extends BioMaterial> query = getCreationEvent().getSources(); 192 query.include(Include.ALL); 193 annotatable.addAll(query.list(getDbControl())); 194 } 195 } 196 catch (PermissionDeniedException ex) 197 {} 198 return annotatable; 199 } 200 // ------------------------------------------- 201 202 203 /* 175 204 From the Subtypable interface 176 205 ----------------------------- … … 290 319 291 320 /** 292 Check if this biomaterial was created by pooling or not. 293 @return TRUE if pooled, FALSE otherwise. 294 */ 295 public boolean isPooled() 296 { 297 return getData().isPooled(); 298 } 299 300 /** 301 Specify if this biomaterial was created by pooling or not. Changing this property 302 also clears the parent biomaterial and the sources collection for the creation event. 303 @param pooled set to TRUE if pooled, FALSE otherwise. 304 @throws PermissionDeniedException If the logged in user doesn't have 305 write permission 306 @throws BaseException If there is another error 307 @see BioMaterialEvent#getSources() 308 */ 309 public void setPooled(boolean pooled) 310 throws PermissionDeniedException, BaseException 311 { 312 checkPermission(Permission.WRITE); 313 boolean current = getData().isPooled(); 314 if (current != pooled) 315 { 316 getCreationEvent().clearSources(); 317 getData().setParent(null); 318 getData().setPooled(pooled); 319 } 321 Get the item type of the parent biomaterial. The parent type 322 must be either the same type as the current biomaterial or "one 323 step up" in the Extract -- Sample -- BioSource chain. 324 @return The parent type, or null if the biomaterial doesn't have any parents 325 @since 3.0 326 */ 327 public Item getParentType() 328 { 329 Integer parentType = getData().getParentType(); 330 return parentType == null ? null : Item.fromValue(parentType); 331 } 332 333 /** 334 Get the parent biomaterial if there is a single parent item only. 335 @return The parent biomaterial or null if there is not exactly one 336 parent 337 @since 3.0 338 @see #hasSingleParent() 339 */ 340 public BioMaterial getParent() 341 { 342 return getDbControl().getItem(BioMaterial.class, getData().getParent()); 343 } 344 345 /** 346 Checks if this biomaterial has a single parent item or not. 347 @return TRUE if there is exactly one parent, FALSE if there are 348 0 or 2 or more parents 349 @since 3.0 350 @see #getParentType() 351 */ 352 public boolean hasSingleParent() 353 { 354 return getData().getParent() != null; 320 355 } 321 356 … … 355 390 { 356 391 return BioMaterialEvent.getQuery(this); 357 }358 359 /**360 Get a query that returns all events where this biomaterial361 has been used as a source.362 @return An {@link ItemQuery} object363 @since 2.9364 */365 public ItemQuery<BioMaterialEvent> getPoolingEvents()366 {367 ItemQuery<BioMaterialEvent> query = new ItemQuery<BioMaterialEvent>(BioMaterialEvent.class, null);368 query.setDistinct(true); // Otherwise, the join to sources can result in one copy for each source369 query.joinPermanent(Hql.leftJoin("sources", "src"));370 query.joinPermanent(Hql.leftJoin("bioMaterial", "bm"));371 query.restrictPermanent(372 Restrictions.and(373 Restrictions.eq(374 Hql.index("src", null),375 Hql.entity(this)376 ),377 Restrictions.eq(378 Hql.property("bm", "pooled"),379 Expressions.parameter("isPooled", true, Type.BOOLEAN)380 ),381 Restrictions.eq(382 Hql.property("eventType"),383 Expressions.integer(BioMaterialEvent.Type.CREATION.getValue())384 )385 )386 );387 return query;388 392 } 389 393 -
trunk/src/core/net/sf/basedb/core/Sample.java
r5662 r5663 28 28 29 29 import java.util.Set; 30 import java.util.HashSet;31 30 32 31 /** … … 130 129 { 131 130 return TYPE; 132 }133 // -------------------------------------------134 /*135 From the Annotatable interface136 -------------------------------------------137 */138 /**139 Get the biosource or pooled samples.140 */141 public Set<Annotatable> getAnnotatableParents()142 throws BaseException143 {144 Set<Annotatable> annotatable = new HashSet<Annotatable>();145 try146 {147 if (isPooled())148 {149 ItemQuery<? extends MeasuredBioMaterial> query = getCreationEvent().getSources();150 query.include(Include.ALL);151 annotatable.addAll(query.list(getDbControl()));152 }153 else if (getData().getParent() != null)154 {155 annotatable.add(getBioSource());156 }157 }158 catch (PermissionDeniedException ex)159 {}160 return annotatable;161 131 } 162 132 // ------------------------------------------- … … 216 186 217 187 /** 218 Get the {@link BioSource} that is the parent of this sample.219 @return A <code>BioSource</code> object or null if this is a pooled or220 standalone sample221 @throws PermissionDeniedException If the logged in user doesn't have read222 permission for the biosource223 @throws BaseException If there is another error224 */225 public BioSource getBioSource()226 throws PermissionDeniedException, BaseException227 {228 return getDbControl().getItem(BioSource.class, getData().getParent());229 }230 231 /**232 Set the {@link BioSource} item that is the parent233 of this sample.234 @param bioSource The parent <code>BioSource</code> item235 @throws PermissionDeniedException If the logged in user doesn't have236 write permission for this sample or use permission for the biosource237 @throws InvalidDataException If this is a pooled sample238 @throws BaseException If there is another error239 */240 public void setBioSource(BioSource bioSource)241 throws PermissionDeniedException, InvalidDataException242 {243 checkPermission(Permission.WRITE);244 if (bioSource != null) bioSource.checkPermission(Permission.USE);245 if (isPooled())246 {247 throw new InvalidDataException("A pooled sample can't have a parent biosource");248 }249 getData().setParent(bioSource == null ? null : bioSource.getData());250 }251 252 /**253 188 Create a new {@link Extract} from this sample. 254 189 @param usedQuantity The quantity used from this sample or null … … 281 216 { 282 217 Extract e = Extract.getNew(getDbControl(), master); 283 e. setSample(this).setUsedQuantity(usedQuantity);218 e.getCreationEvent().setSource(e).setUsedQuantity(usedQuantity); 284 219 return e; 285 220 } … … 366 301 /** 367 302 Count the number of child samples or extracts. 368 @param pooledTRUE = count child samples, FALSE = count child extracts303 @param samples TRUE = count child samples, FALSE = count child extracts 369 304 @since 2.16 370 305 */ 371 306 @Override 372 public long countChildren(boolean pooled)373 { 374 return pooled? countSamples() : countExtracts();307 public long countChildren(boolean samples) 308 { 309 return samples ? countSamples() : countExtracts(); 375 310 } 376 311 -
trunk/src/core/net/sf/basedb/core/data/MeasuredBioMaterialData.java
r5662 r5663 45 45 private BioMaterialData parent; 46 46 /** 47 Get the parent biomaterial. Used for non-pooled biomaterials. The 48 core must add logic to check that only a biomaterial of the parent 49 type is linked. 47 Get the parent biomaterial. Used when a biomaterial has a single parent item. 50 48 @hibernate.many-to-one column="`parent_id`" not-null="false" outer-join="false" 51 49 */ … … 87 85 } 88 86 89 private boolean pooled;87 private Integer parentType; 90 88 /** 91 If the biomaterial was created by pooling other biomaterials of the same type92 or not.93 @ hibernate.property column="`pooled`" type="boolean" not-null="false"89 Get the type of the parent item. Null if the biomaterial doesn't have any parents. 90 @hibernate.property column="`parent_type`" type="int" not-null="false" 91 @since 3.0 94 92 */ 95 public boolean isPooled()93 public Integer getParentType() 96 94 { 97 return p ooled;95 return parentType; 98 96 } 99 public void setP ooled(boolean pooled)97 public void setParentType(Integer parentType) 100 98 { 101 this.p ooled = pooled;99 this.parentType = parentType; 102 100 } 101 103 102 private BioMaterialEventData creationEvent; 104 103 /** -
trunk/src/core/net/sf/basedb/util/biomaterial/ChildrenTransformer.java
r5662 r5663 40 40 /** 41 41 Collection transformer that given a collection of biomaterials 42 finds all pooled children (of the same type).42 finds all children of the same type. 43 43 44 44 @author Nicklas 45 @ version 2.1045 @since 3.0 46 46 @base.modified $Date$ 47 47 */ 48 public class PooledChildrenTransformer<I extends MeasuredBioMaterial>48 public class ChildrenTransformer<I extends MeasuredBioMaterial> 49 49 implements CollectionTransformer<I, I> 50 50 { … … 54 54 private final boolean copySources; 55 55 56 public PooledChildrenTransformer(DbControl dc, boolean copySources, ItemQuery<I> query)56 public ChildrenTransformer(DbControl dc, boolean copySources, ItemQuery<I> query) 57 57 { 58 58 this.dc = dc; -
trunk/src/core/net/sf/basedb/util/biomaterial/ExtractToSampleTransformer.java
r4723 r5663 46 46 parents to the extract. If you want to follow pooled extracts up 47 47 to samples, you should combine this transformer 48 and a {@link P ooledParentsTransformer} with the help of a48 and a {@link ParentsTransformer} with the help of a 49 49 {@link MultiStepCollectionTransformer}. 50 50 -
trunk/src/core/net/sf/basedb/util/biomaterial/ListUtil.java
r5641 r5663 132 132 @param sourceItem The type of source items 133 133 @param destinationItem The type of destination items 134 @param pooled If pooled children/parentsshould be considered or not134 @param sameType If children/parents of the same type should be considered or not 135 135 @return A collection transformer (never null) 136 136 */ 137 137 @SuppressWarnings("unchecked") 138 public static CollectionTransformer createTransformer(DbControl dc, Item sourceItem, Item destinationItem, boolean pooled)138 public static CollectionTransformer createTransformer(DbControl dc, Item sourceItem, Item destinationItem, boolean sameType) 139 139 { 140 140 // The allowed item types … … 167 167 { 168 168 // Moving down 169 if ( pooled) transformers.add(new PooledChildrenTransformer<Sample>(dc, true, Sample.getQuery()));169 if (sameType) transformers.add(new ChildrenTransformer<Sample>(dc, true, Sample.getQuery())); 170 170 transformers.add(new SampleToExtractTransformer(dc)); 171 171 } … … 173 173 { 174 174 // Moving up 175 if ( pooled) transformers.add(new PooledParentsTransformer<Sample>(dc, true, Sample.getQuery()));175 if (sameType) transformers.add(new ParentsTransformer<Sample>(dc, true, Sample.getQuery())); 176 176 transformers.add(new SampleToBioSourceTransformer(dc)); 177 177 } … … 182 182 { 183 183 // Moving down 184 if ( pooled) transformers.add(new PooledChildrenTransformer<Extract>(dc, true, Extract.getQuery()));184 if (sameType) transformers.add(new ChildrenTransformer<Extract>(dc, true, Extract.getQuery())); 185 185 } 186 186 else 187 187 { 188 188 // Moving up 189 if ( pooled) transformers.add(new PooledParentsTransformer<Extract>(dc, true, Extract.getQuery()));189 if (sameType) transformers.add(new ParentsTransformer<Extract>(dc, true, Extract.getQuery())); 190 190 transformers.add(new ExtractToSampleTransformer(dc)); 191 191 } … … 201 201 } 202 202 203 if ( pooled&& destinationItem != Item.BIOSOURCE)203 if (sameType && destinationItem != Item.BIOSOURCE) 204 204 { 205 205 if (step == 1) 206 206 { 207 207 // Moving down 208 transformers.add(new PooledChildrenTransformer(dc, true, getQuery(destinationItem)));208 transformers.add(new ChildrenTransformer(dc, true, getQuery(destinationItem))); 209 209 } 210 210 else 211 211 { 212 212 // Moving up 213 transformers.add(new P ooledParentsTransformer(dc, true, getQuery(destinationItem)));213 transformers.add(new ParentsTransformer(dc, true, getQuery(destinationItem))); 214 214 } 215 215 } -
trunk/src/core/net/sf/basedb/util/biomaterial/ParentsTransformer.java
r5662 r5663 39 39 40 40 /** 41 Collection transformer that given a collection of (pooled)42 biomaterials finds all parents (of the same type).41 Collection transformer that given a collection of 42 biomaterials finds all parents of the same type 43 43 44 44 @author Nicklas 45 @ version 2.1045 @since 3.0 46 46 @base.modified $Date$ 47 47 */ 48 public class P ooledParentsTransformer<I extends MeasuredBioMaterial>48 public class ParentsTransformer<I extends MeasuredBioMaterial> 49 49 implements CollectionTransformer<I, I> 50 50 { … … 54 54 private final boolean copySources; 55 55 56 public P ooledParentsTransformer(DbControl dc, boolean copySources, ItemQuery<I> query)56 public ParentsTransformer(DbControl dc, boolean copySources, ItemQuery<I> query) 57 57 { 58 58 this.dc = dc; -
trunk/src/core/net/sf/basedb/util/biomaterial/SampleToBioSourceTransformer.java
r4723 r5663 46 46 parents to the samples. If you want to follow pooled samples up 47 47 to biosources, you should combine this transformer 48 and a {@link P ooledParentsTransformer} with the help of a48 and a {@link ParentsTransformer} with the help of a 49 49 {@link MultiStepCollectionTransformer}. 50 50 -
trunk/src/core/net/sf/basedb/util/biomaterial/SampleToExtractTransformer.java
r4723 r5663 45 45 children to the samples. If you want to include extracts that are 46 46 children to pooled samples, you should combine this transformer 47 with a {@link PooledChildrenTransformer} with the help of a47 with a {@link ChildrenTransformer} with the help of a 48 48 {@link MultiStepCollectionTransformer}. 49 49 -
trunk/src/core/net/sf/basedb/util/overview/loader/BioSourceLoader.java
r5500 r5663 68 68 { 69 69 Sample sample = (Sample)sampleNode.getItem(dc); 70 bioSource = sample.getBioSource();70 bioSource = (BioSource)sample.getParent(); 71 71 } 72 72 catch (PermissionDeniedException ex) -
trunk/src/core/net/sf/basedb/util/overview/loader/ExtractLoader.java
r5657 r5663 30 30 import net.sf.basedb.core.ItemQuery; 31 31 import net.sf.basedb.core.ItemResultIterator; 32 import net.sf.basedb.core.RawBioAssay;33 32 import net.sf.basedb.core.Sample; 34 33 import net.sf.basedb.util.overview.Fix; … … 106 105 else if (parentItem == Item.EXTRACT) 107 106 { 108 returnNode = createReverseNode((Extract)parentNode.getItem(dc), dc, context, parentNode); 107 Extract e = (Extract)parentNode.getItem(dc); 108 if (e.hasSingleParent()) 109 { 110 createSingleParentReverseNode(e, dc, context, parentNode); 111 } 112 else 113 { 114 returnNode = createPooledReverseNode(e, dc, context, parentNode); 115 } 109 116 } 110 117 else if (parentItem == Item.DERIVEDBIOASSAY) … … 160 167 { 161 168 Extract extract = (Extract)extractNode.getItem(); 162 if (extract. isPooled())169 if (extract.getParentType() == Item.EXTRACT) 163 170 { 164 171 getNodeLoader(context, Item.EXTRACT).createReverseNode(dc, context, extractNode); … … 175 182 */ 176 183 @SuppressWarnings("unchecked") 177 private Node create ReverseNode(Extract product, DbControl dc, OverviewContext context, Node parentNode)184 private Node createPooledReverseNode(Extract product, DbControl dc, OverviewContext context, Node parentNode) 178 185 { 179 186 NodeFactory<Extract> nf = getNodeFactory(dc, context); … … 212 219 213 220 /** 221 Create a reverse-loading extract node from an extract. Eg. the child node 222 is the extract that is the parent of the (non-pooled) extract. 223 */ 224 private Node createSingleParentReverseNode(Extract bioMaterial, DbControl dc, OverviewContext context, Node parentNode) 225 { 226 NodeFactory<Extract> nf = getNodeFactory(dc, context); 227 Extract extract = null; 228 boolean denied = false; 229 try 230 { 231 extract = (Extract)bioMaterial.getParent(); 232 } 233 catch (PermissionDeniedException ex) 234 { 235 denied = true; 236 } 237 Node sampleNode = createItemNode(nf, extract, extract, denied, 238 parentNode, ChildNodeDirection.REVERSE); 239 return sampleNode; 240 } 241 242 /** 214 243 Create reverse-loading extract nodes from a physical bioassay. Eg. the child nodes 215 244 are the extracts that has been used on a bioassay. -
trunk/src/core/net/sf/basedb/util/overview/loader/SampleLoader.java
r5500 r5663 21 21 */ 22 22 package net.sf.basedb.util.overview.loader; 23 24 import java.util.Iterator; 23 25 24 26 import net.sf.basedb.core.BioSource; … … 28 30 import net.sf.basedb.core.ItemQuery; 29 31 import net.sf.basedb.core.ItemResultIterator; 32 import net.sf.basedb.core.MeasuredBioMaterial; 30 33 import net.sf.basedb.core.PermissionDeniedException; 31 34 import net.sf.basedb.core.Sample; … … 99 102 if (parentType == Item.EXTRACT) 100 103 { 101 returnNode = create ReverseNode((Extract)parentNode.getItem(dc), dc, context, parentNode);104 returnNode = createSingleParentReverseNode((Extract)parentNode.getItem(dc), dc, context, parentNode); 102 105 } 103 106 else if (parentType == Item.SAMPLE) 104 107 { 105 returnNode = createReverseNode((Sample)parentNode.getItem(dc), dc, context, parentNode); 108 Sample s = (Sample)parentNode.getItem(dc); 109 if (s.hasSingleParent()) 110 { 111 createSingleParentReverseNode(s, dc, context, parentNode); 112 } 113 else 114 { 115 returnNode = createPooledReverseNode(s, dc, context, parentNode); 116 } 106 117 } 107 118 return returnNode; … … 150 161 { 151 162 Sample sample = (Sample)sampleNode.getItem(); 152 if (sample. isPooled())163 if (sample.getParentType() == Item.SAMPLE) 153 164 { 154 165 getNodeLoader(context, Item.SAMPLE).createReverseNode(dc, context, sampleNode); … … 162 173 163 174 /** 164 Create reverse-loading samples nodes of a pooled sample. Eg. the child nodes165 are the source samples that was pooled to create the given product.175 Create reverse-loading samples nodes of a sample with other sample(s) as parent items. 176 Eg. the child nodes are the source sample(s) that was used to create the given product. 166 177 */ 167 178 @SuppressWarnings("unchecked") 168 private Node create ReverseNode(Sample product, DbControl dc, OverviewContext context, Node parentNode)179 private Node createPooledReverseNode(Sample product, DbControl dc, OverviewContext context, Node parentNode) 169 180 { 170 181 NodeFactory<Sample> nf = getNodeFactory(dc, context); 171 182 Node folderNode = null; 172 183 ItemQuery<Sample> query = (ItemQuery<Sample>)context.initQuery(product.getCreationEvent().getSources(), "name"); 173 Ite mResultIterator<Sample> it = query.iterate(dc);184 Iterator<Sample> it = query.iterate(dc); 174 185 int numSamples = 0; 175 186 while (it.hasNext()) … … 202 213 203 214 /** 204 Create a reverse-loading sample node from an extract . Eg. the child node205 is the sample that is the parent of the (non-pooled) extract .206 */ 207 private Node create ReverseNode(Extract extract, DbControl dc, OverviewContext context, Node parentNode)215 Create a reverse-loading sample node from an extract or sample. Eg. the child node 216 is the sample that is the parent of the (non-pooled) extract/sample. 217 */ 218 private Node createSingleParentReverseNode(MeasuredBioMaterial bioMaterial, DbControl dc, OverviewContext context, Node parentNode) 208 219 { 209 220 NodeFactory<Sample> nf = getNodeFactory(dc, context); … … 212 223 try 213 224 { 214 sample = extract.getSample();225 sample = (Sample)bioMaterial.getParent(); 215 226 } 216 227 catch (PermissionDeniedException ex) -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ExtractImporter.java
r5662 r5663 202 202 if (pooledMapper != null) 203 203 { 204 extract.setPooled(Values.getBoolean(pooledMapper.getValue(data)));204 //extract.setPooled(Values.getBoolean(pooledMapper.getValue(data))); 205 205 } 206 206 … … 216 216 { 217 217 String nameOrId = protocolMapper.getValue(data); 218 ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, extract, Item.PROTOCOL, 219 SystemItems.getId(extract.isPooled() ? Protocol.POOLING : Protocol.EXTRACTION)); 218 ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, extract, Item.PROTOCOL, SystemItems.getId(Protocol.EXTRACTION)); 220 219 Protocol protocol = findProtocol(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type); 221 220 if (nameOrId == null || protocol != null) creationEvent.setProtocol(protocol); … … 233 232 } 234 233 } 234 /* 235 235 if (!extract.isPooled()) 236 236 { 237 */ 237 238 if (parentMapper != null) 238 239 { … … 244 245 if (nameOrId == null || sample != null) 245 246 { 246 BioMaterialEventSource evtSrc = extract. setSample(sample);247 BioMaterialEventSource evtSrc = extract.getCreationEvent().setSource(sample); 247 248 if (evtSrc != null) evtSrc.setUsedQuantity(usedQuantity); 248 249 } 249 250 } 251 /* 250 252 } 251 253 else … … 253 255 updateMultiLineItem(dc, extract, data, 0); 254 256 } 257 */ 255 258 } 256 259 … … 262 265 FlatFileParser.Data data, int multiLineNum) 263 266 { 264 if (parentMapper != null && extract.isPooled())267 if (parentMapper != null) // && extract.isPooled()) 265 268 { 266 269 String nameOrId = parentMapper.getValue(data); -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/LabeledExtractImporter.java
r5662 r5663 206 206 if (pooledMapper != null) 207 207 { 208 extract.setPooled(Values.getBoolean(pooledMapper.getValue(data)));208 //extract.setPooled(Values.getBoolean(pooledMapper.getValue(data))); 209 209 } 210 210 if (protocolMapper != null) 211 211 { 212 212 String nameOrId = protocolMapper.getValue(data); 213 ItemSubtype type = ItemSubtype.getById(dc, 214 SystemItems.getId(extract.isPooled() ? Protocol.POOLING : Protocol.LABELING)); 213 ItemSubtype type = ItemSubtype.getById(dc, SystemItems.getId(Protocol.LABELING)); 215 214 Protocol protocol = findProtocol(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type); 216 215 if (nameOrId == null || protocol != null) creationEvent.setProtocol(protocol); … … 237 236 } 238 237 } 238 /* 239 239 if (!extract.isPooled()) 240 240 { 241 */ 241 242 if (parentMapper != null) 242 243 { … … 247 248 if (nameOrId == null || parent != null) 248 249 { 249 BioMaterialEventSource evtSrc = extract. setExtract(parent);250 BioMaterialEventSource evtSrc = extract.getCreationEvent().setSource(parent); 250 251 if (evtSrc != null) evtSrc.setUsedQuantity(usedQuantity); 251 252 } 252 253 } 254 /* 253 255 } 254 256 else … … 256 258 updateMultiLineItem(dc, extract, data, 0); 257 259 } 260 */ 258 261 } 259 262 … … 265 268 FlatFileParser.Data data, int multiLineNum) 266 269 { 267 if (parentMapper != null && extract.isPooled())270 if (parentMapper != null) // && extract.isPooled()) 268 271 { 269 272 String nameOrId = parentMapper.getValue(data); -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/SampleImporter.java
r5662 r5663 297 297 if (pooledMapper != null) 298 298 { 299 sample.setPooled(Values.getBoolean(pooledMapper.getValue(data)));299 //sample.setPooled(Values.getBoolean(pooledMapper.getValue(data))); 300 300 } 301 301 if (protocolMapper != null) 302 302 { 303 303 String nameOrId = protocolMapper.getValue(data); 304 ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, sample, Item.PROTOCOL, 305 SystemItems.getId(sample.isPooled() ? Protocol.POOLING : Protocol.SAMPLING)); 304 ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, sample, Item.PROTOCOL, SystemItems.getId(Protocol.SAMPLING)); 306 305 Protocol protocol = findProtocol(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type); 307 306 if (nameOrId == null || protocol != null) creationEvent.setProtocol(protocol); … … 319 318 } 320 319 } 320 /* 321 321 if (!sample.isPooled()) 322 322 { 323 */ 323 324 if (parentMapper != null) 324 325 { … … 326 327 ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, sample, Item.BIOSOURCE, 0); 327 328 BioSource bioSource = findBioSource(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type); 328 if (nameOrId == null || bioSource != null) sample. setBioSource(bioSource);329 if (nameOrId == null || bioSource != null) sample.getCreationEvent().setSource(bioSource); 329 330 } 331 /* 330 332 } 331 333 else … … 333 335 updateMultiLineItem(dc, sample, data, 0); 334 336 } 337 */ 335 338 } 336 339 … … 342 345 FlatFileParser.Data data, int multiLineNum) 343 346 { 344 if (parentMapper != null && sample.isPooled())347 if (parentMapper != null) // && sample.isPooled()) 345 348 { 346 349 String nameOrId = parentMapper.getValue(data); -
trunk/src/test/TestExtract.java
r5662 r5663 23 23 */ 24 24 import net.sf.basedb.core.*; 25 25 import net.sf.basedb.core.query.ResultList; 26 import net.sf.basedb.util.biomaterial.ChildrenTransformer; 27 import net.sf.basedb.util.biomaterial.ExtractToSampleTransformer; 28 import net.sf.basedb.util.biomaterial.ParentsTransformer; 29 import net.sf.basedb.util.biomaterial.SampleToExtractTransformer; 30 31 import java.util.Collections; 26 32 import java.util.Date; 33 import java.util.LinkedHashSet; 27 34 import java.util.Set; 28 35 … … 47 54 int tagId = TestTag.test_create("Test", SystemItems.getId(Tag.LABEL), true); 48 55 int id = test_create(0, "Extract #1 (standalone)", 0, 0, true); 49 int id2 = test_create(sampleId, "Extract #2", 0, 0, false); 50 int id3 = test_create(id2, "Extract #3 (labeled)", SystemItems.getId(Extract.LABELED), tagId, false); 51 int id4 = test_create_pooled(id, id2, id3); 52 56 int id2 = test_create(sampleId, "Extract #2 (sample parent)", 0, 0, false); 57 int id3 = test_create(id, "Extract #3 (extract parent+labeled)", SystemItems.getId(Extract.LABELED), tagId, false); 58 int id4 = test_create_pooled("Extract #4 (pooled)", id, id2, id3); 59 60 53 61 test_load(id); 54 62 test_list(-1); … … 56 64 write_events_header(); 57 65 test_add_event(id, 100.0f); 58 test_list_events(id, 3); // creation event, pooling event forid4, and extra event66 test_list_events(id, 4); // creation event, create event for id3+id4, and extra event 59 67 60 write_sources_header(); 61 test_list_sources(id3, 1); // The sample 62 test_list_sources(id4, 3); // The three id, id2 and id3 extracts 63 test_list_pooledChildren(id2, 2); 64 68 write_parents_header(); 69 test_list_sources(id4, 3); // The three id, id2 and id3 samples 70 test_list_children(id, 2); // id3 and id4 71 72 // Transformers 73 test_childrenTransformer(id, 2); 74 test_parentsTransformer(id4, 3); 75 test_extractToSampleTransformer(id2, 1); 76 test_sampleToExtractTransformer(sampleId, 1); 77 78 65 79 if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); 66 80 // Standard test: Delete … … 94 108 { 95 109 BioMaterial parent = BioMaterial.getById(dc, parentId); 96 if (parent.getType() == Item.SAMPLE) 97 { 98 Sample s = (Sample)parent; 99 e.setSample(s).setUsedQuantity(200.0f); 100 } 101 else 102 { 103 e.setPooled(true); 104 e.getCreationEvent().addSource(parent).setUsedQuantity(200.0f); 105 } 110 BioMaterialEventSource evtSrc = e.getCreationEvent().setSource(parent); 111 evtSrc.setUsedQuantity(200.0f); 106 112 } 107 113 if (subtypeId > 0) … … 134 140 } 135 141 136 static int test_create_pooled( int... sourceIds)142 static int test_create_pooled(String name, int... sourceIds) 137 143 { 138 144 if (!TestUtil.hasPermission(Permission.CREATE, Item.EXTRACT)) return 0; … … 143 149 dc = TestUtil.getDbControl(); 144 150 Extract e = Extract.getNew(dc); 145 e.setName( "Test pooled extract");151 e.setName(name); 146 152 e.setDescription("Added at "+new Date()); 147 153 e.setExternalId("POOLED-455-EXTRACT"); 148 154 e.setOriginalQuantity(500.0f); 149 e.setPooled(true);150 155 BioMaterialEvent evt = e.getCreationEvent(); 151 156 for (int sourceId : sourceIds) … … 289 294 if (!TestUtil.getSilent()) 290 295 { 291 write(" \tID \tName \tSubtype\tDescription\tExternal id\tP ooled\tSample\tTag\tQuantity\tRemain");292 write("-- \t-- \t--------- \t-------\t-----------\t-----------\t------ \t------\t---\t--------\t------");296 write(" \tID \tName \tSubtype\tDescription\tExternal id\tParent type\tParent\tTag\tQuantity\tRemain"); 297 write("-- \t-- \t--------- \t-------\t-----------\t-----------\t-----------\t------\t---\t--------\t------"); 293 298 } 294 299 } … … 297 302 { 298 303 if (!TestUtil.getSilent()) System.out.println(i+":\t"+e.getId()+"\t"+e.getName()+"\t"+e.getItemSubtype()+"\t"+e.getDescription()+ 299 "\t"+e.getExternalId()+"\t"+e. isPooled()+"\t"+e.getSample()+"\t"+e.getTag()+"\t"+e.getOriginalQuantity()+"\t"+e.getRemainingQuantity());304 "\t"+e.getExternalId()+"\t"+e.getParentType()+"\t"+e.getParent()+"\t"+e.getTag()+"\t"+e.getOriginalQuantity()+"\t"+e.getRemainingQuantity()); 300 305 } 301 306 static void write_events_header() … … 318 323 if (!TestUtil.getSilent()) System.out.println(i+":\t"+h.getId()+"\t"+h.getName()+"\t"+h.getDescription()); 319 324 } 320 static void write_sources_header() 325 326 static void write_parents_header() 321 327 { 322 328 if (!TestUtil.getSilent()) 323 329 { 324 write(" \tID \tName \tDescription\tExternal id\tPooled\tQuantity\tRemain\tUsed"); 325 write("-- \t-- \t--------- \t-----------\t-----------\t------\t--------\t------\t----"); 326 } 327 } 330 write(" \tID \tName \tDescription\tExternal id\tQuantity\tRemain\tUsed"); 331 write("-- \t-- \t--------- \t-----------\t-----------\t--------\t------\t----"); 332 } 333 } 334 328 335 static void write_item(int i, MeasuredBioMaterial b, BioMaterialEvent evt) 329 336 throws BaseException 330 337 { 331 338 if (!TestUtil.getSilent()) System.out.println(i+":\t"+b.getId()+"\t"+b.getName()+"\t"+b.getDescription()+ 332 "\t"+b.getExternalId()+"\t"+b. isPooled()+"\t"+b.getOriginalQuantity()+"\t"+b.getRemainingQuantity()+339 "\t"+b.getExternalId()+"\t"+b.getParentType()+"\t"+b.getOriginalQuantity()+"\t"+b.getRemainingQuantity()+ 333 340 "\t"+evt.getUsedQuantity(b)); 334 341 } … … 402 409 } 403 410 } 404 411 405 412 static void test_list_sources(int extractId, int expectedResults) 406 413 { … … 412 419 Extract e = Extract.getById(dc, extractId); 413 420 BioMaterialEvent evt = e.getCreationEvent(); 414 ItemResultList<? extends MeasuredBioMaterial> l = evt.getSources().list(dc);421 ResultList<BioMaterialEventSource> l = evt.getEventSources().list(dc); 415 422 for (int i = 0; i<l.size(); i++) 416 423 { 417 write_item(i, l.get(i), evt);424 TestSample.write_item(i, l.get(i)); 418 425 } 419 426 if (expectedResults >= 0 && expectedResults != l.size()) … … 434 441 } 435 442 } 436 static void test_list_pooledChildren(int extractId, int expectedResults) 443 444 static void test_list_children(int extractId, int expectedResults) 437 445 { 438 446 if (extractId == 0) return; … … 442 450 dc = TestUtil.getDbControl(); 443 451 Extract e = Extract.getById(dc, extractId); 444 ItemResultList< BioMaterialEvent> ev = e.getPoolingEvents().list(dc);452 ItemResultList<Extract> ev = e.getChildExtracts().list(dc); 445 453 446 454 for (int i=0; i<ev.size(); i++) 447 455 { 448 write_item(i, (Extract)ev.get(i).getBioMaterial());456 write_item(i, ev.get(i)); 449 457 } 450 458 if (expectedResults >= 0 && expectedResults != ev.size()) … … 452 460 throw new BaseException("Expected "+expectedResults+" results, not "+ev.size()); 453 461 } 454 write("--List pools from extract OK ("+ev.size()+")"); 455 } 456 catch (Throwable ex) 457 { 458 write("--List pools for extract FAILED"); 459 ex.printStackTrace(); 460 ok = false; 461 } 462 finally 463 { 464 if (dc != null) dc.close(); 465 } 466 } 462 write("--List children for extract OK ("+ev.size()+")"); 463 } 464 catch (Throwable ex) 465 { 466 write("--List children for extract FAILED"); 467 ex.printStackTrace(); 468 ok = false; 469 } 470 finally 471 { 472 if (dc != null) dc.close(); 473 } 474 } 475 467 476 468 477 static void test_list_bioassays(int extractId, int expectedResults) … … 497 506 } 498 507 508 509 static void test_childrenTransformer(int extractId, int expectedResults) 510 { 511 if (extractId == 0) return; 512 DbControl dc = null; 513 try 514 { 515 dc = TestUtil.getDbControl(); 516 Extract e = Extract.getById(dc, extractId); 517 ChildrenTransformer<Extract> pct = new ChildrenTransformer<Extract>(dc, false, Extract.getQuery()); 518 Set<Extract> children = new LinkedHashSet<Extract>(); 519 pct.transform(Collections.singleton(e), children); 520 521 int i = 0; 522 for (Extract c : children) 523 { 524 write_item(i, c); 525 i++; 526 } 527 if (expectedResults >= 0 && expectedResults != children.size()) 528 { 529 throw new BaseException("Expected "+expectedResults+" results, not "+children.size()); 530 } 531 write("--List children for extract using transformer OK ("+children.size()+")"); 532 } 533 catch (Throwable ex) 534 { 535 write("--List children for extract using transformer FAILED"); 536 ex.printStackTrace(); 537 ok = false; 538 } 539 finally 540 { 541 if (dc != null) dc.close(); 542 } 543 } 544 545 static void test_parentsTransformer(int extractId, int expectedResults) 546 { 547 if (extractId == 0) return; 548 DbControl dc = null; 549 try 550 { 551 dc = TestUtil.getDbControl(); 552 Extract e = Extract.getById(dc, extractId); 553 ParentsTransformer<Extract> pct = new ParentsTransformer<Extract>(dc, false, Extract.getQuery()); 554 Set<Extract> parents = new LinkedHashSet<Extract>(); 555 pct.transform(Collections.singleton(e), parents); 556 557 int i = 0; 558 for (Extract c : parents) 559 { 560 write_item(i, c); 561 i++; 562 } 563 if (expectedResults >= 0 && expectedResults != parents.size()) 564 { 565 throw new BaseException("Expected "+expectedResults+" results, not "+parents.size()); 566 } 567 write("--List parents for extract using transformer OK ("+parents.size()+")"); 568 } 569 catch (Throwable ex) 570 { 571 write("--List parents for extract using transformer FAILED"); 572 ex.printStackTrace(); 573 ok = false; 574 } 575 finally 576 { 577 if (dc != null) dc.close(); 578 } 579 } 580 581 static void test_extractToSampleTransformer(int extractId, int expectedResults) 582 { 583 if (extractId == 0) return; 584 DbControl dc = null; 585 try 586 { 587 dc = TestUtil.getDbControl(); 588 Extract e = Extract.getById(dc, extractId); 589 ExtractToSampleTransformer pct = new ExtractToSampleTransformer(dc); 590 Set<Sample> parents = new LinkedHashSet<Sample>(); 591 pct.transform(Collections.singleton(e), parents); 592 593 int i = 0; 594 for (Sample c : parents) 595 { 596 TestSample.write_item(i, c); 597 i++; 598 } 599 if (expectedResults >= 0 && expectedResults != parents.size()) 600 { 601 throw new BaseException("Expected "+expectedResults+" results, not "+parents.size()); 602 } 603 write("--List sample for extract using transformer OK ("+parents.size()+")"); 604 } 605 catch (Throwable ex) 606 { 607 write("--List sample for extract using transformer FAILED"); 608 ex.printStackTrace(); 609 ok = false; 610 } 611 finally 612 { 613 if (dc != null) dc.close(); 614 } 615 } 616 617 static void test_sampleToExtractTransformer(int sampleId, int expectedResults) 618 { 619 if (sampleId == 0) return; 620 DbControl dc = null; 621 try 622 { 623 dc = TestUtil.getDbControl(); 624 Sample s = Sample.getById(dc, sampleId); 625 SampleToExtractTransformer pct = new SampleToExtractTransformer(dc); 626 Set<Extract> children = new LinkedHashSet<Extract>(); 627 pct.transform(Collections.singleton(s), children); 628 629 int i = 0; 630 for (Extract c : children) 631 { 632 write_item(i, c); 633 i++; 634 } 635 if (expectedResults >= 0 && expectedResults != children.size()) 636 { 637 throw new BaseException("Expected "+expectedResults+" results, not "+children.size()); 638 } 639 write("--List extracts for sample using transformer OK ("+children.size()+")"); 640 } 641 catch (Throwable ex) 642 { 643 write("--List extracts for sample using transformer FAILED"); 644 ex.printStackTrace(); 645 ok = false; 646 } 647 finally 648 { 649 if (dc != null) dc.close(); 650 } 651 } 652 653 499 654 } -
trunk/src/test/TestGenericOverview.java
r5657 r5663 100 100 int extract1 = TestExtract.test_create(sample1, "Extract GO #1", 0, 0, false); 101 101 int extract2 = TestExtract.test_create(sample2, "Extract GO #2", 0, 0, false); 102 int extractPooled = TestExtract.test_create_pooled( extract1, extract2);102 int extractPooled = TestExtract.test_create_pooled("Extract GO #3 (pooled)", extract1, extract2); 103 103 104 104 // Array design -
trunk/src/test/TestPhysicalBioAssay.java
r5662 r5663 251 251 StringBuilder sb = new StringBuilder(); 252 252 sb.append("["); 253 for ( MeasuredBioMaterial le : h.getCreationEvent().getSources().list(h.getDbControl()))253 for (BioMaterial le : h.getCreationEvent().getSources().list(h.getDbControl())) 254 254 { 255 255 sb.append(le.toString()); -
trunk/src/test/TestSample.java
r5662 r5663 23 23 */ 24 24 import net.sf.basedb.core.*; 25 import net.sf.basedb.util.biomaterial.PooledChildrenTransformer; 26 27 import java.util.ArrayList; 25 import net.sf.basedb.core.query.ResultList; 26 import net.sf.basedb.util.biomaterial.BioSourceToSampleTransformer; 27 import net.sf.basedb.util.biomaterial.ChildrenTransformer; 28 import net.sf.basedb.util.biomaterial.ParentsTransformer; 29 import net.sf.basedb.util.biomaterial.SampleToBioSourceTransformer; 30 28 31 import java.util.Collections; 29 32 import java.util.Date; 30 import java.util.Li st;33 import java.util.LinkedHashSet; 31 34 import java.util.Set; 32 35 … … 48 51 write_header(); 49 52 // Standard tests: create, load, list 50 int id = test_create(0, null, true);51 int id2 = test_create(0, null, false);52 53 53 int bioSourceId = TestBioSource.test_create(null, false); 54 int id3 = test_create(bioSourceId, null, false); 55 int id4 = test_create_pooled(id, id2, id3); 54 int id = test_create(0, "Sample #1 (standalone)", true); 55 int id2 = test_create(bioSourceId, "Sample #2 (biosource parent)", false); 56 int id3 = test_create(id, "Sample #3 (sample parent)", false); 57 int id4 = test_create_pooled("Sample #4 (pooled)", id, id2, id3); 56 58 57 59 test_load(id); … … 60 62 write_events_header(); 61 63 test_add_event(id, 100.0f); 62 test_list_events(id, 3); // creation event, pooling event forid4, and extra event64 test_list_events(id, 4); // creation event, create event for id3+id4, and extra event 63 65 64 write_ sources_header();66 write_parents_header(); 65 67 test_list_sources(id4, 3); // The three id, id2 and id3 samples 66 test_list_pooledChildren(id2, 1); 67 test_pooledChildrenTransformer(id2, 1); 68 test_list_children(id, 2); // id3 and id4 69 70 // Transformers 71 test_childrenTransformer(id, 2); 72 test_parentsTransformer(id4, 3); 73 test_sampleToBioSourceTransformer(id2, 1); 74 test_bioSourceToSampleTransformer(bioSourceId, 1); 68 75 69 76 // Standard test: Delete … … 79 86 } 80 87 81 static int test_create(int bioSourceId, String name, boolean setAll)88 static int test_create(int parentId, String name, boolean setAll) 82 89 { 83 90 if (!TestUtil.hasPermission(Permission.CREATE, Item.SAMPLE)) return 0; … … 95 102 s.setOriginalQuantity(500.0f); 96 103 } 97 if ( bioSourceId != 0)98 { 99 Bio Source bs = BioSource.getById(dc, bioSourceId);100 s. setBioSource(bs);101 s.setName( bs.getName() + ".s");104 if (parentId != 0) 105 { 106 BioMaterial parent = BioMaterial.getById(dc, parentId); 107 s.getCreationEvent().setSource(parent); 108 s.setName(parent.getName() + ".s"); 102 109 } 103 110 if (name != null) s.setName(name); … … 123 130 } 124 131 125 static int test_create_pooled( int... sourceIds)132 static int test_create_pooled(String name, int... sourceIds) 126 133 { 127 134 if (!TestUtil.hasPermission(Permission.CREATE, Item.SAMPLE)) return 0; … … 132 139 dc = TestUtil.getDbControl(); 133 140 Sample s = Sample.getNew(dc); 134 s.setName( "Test pooled sample");141 s.setName(name); 135 142 s.setDescription("Added at "+new Date()); 136 143 s.setExternalId("POOLED-455-SAMPLE"); 137 144 s.setOriginalQuantity(500.0f); 138 s.setPooled(true);139 145 BioMaterialEvent evt = s.getCreationEvent(); 140 146 for (int sourceId : sourceIds) … … 277 283 if (!TestUtil.getSilent()) 278 284 { 279 write(" \tID \tName \tDescription\tExternal id\t BioSource\tQuantity\tRemain");280 write("-- \t-- \t--------- \t-----------\t-----------\t------ ---\t--------\t------");285 write(" \tID \tName \tDescription\tExternal id\tParent\tQuantity\tRemain"); 286 write("-- \t-- \t--------- \t-----------\t-----------\t------\t--------\t------"); 281 287 } 282 288 } … … 285 291 { 286 292 if (!TestUtil.getSilent()) System.out.println(i+":\t"+s.getId()+"\t"+s.getName()+"\t"+s.getDescription()+ 287 "\t"+s.getExternalId()+"\t"+s.get BioSource()+"\t"+s.getOriginalQuantity()+"\t"+s.getRemainingQuantity());293 "\t"+s.getExternalId()+"\t"+s.getParent()+"\t"+s.getOriginalQuantity()+"\t"+s.getRemainingQuantity()); 288 294 } 289 295 static void write_events_header() … … 301 307 "\t"+evt.getEventDate()+"\t"+evt.getEntryDate()+"\t"+evt.getUsedQuantity(s)+"\t"+evt.getComment()); 302 308 } 303 static void write_sources_header() 309 310 static void write_parents_header() 304 311 { 305 312 if (!TestUtil.getSilent()) 306 313 { 307 write(" \tID \tName \tDescription\tExternal id\tPooled\tQuantity\tRemain\tUsed"); 308 write("-- \t-- \t--------- \t-----------\t-----------\t------\t--------\t------\t----"); 309 } 310 } 311 static void write_item(int i, MeasuredBioMaterial b, BioMaterialEvent evt) 314 write(" \tID \tName \tDescription\tExternal id\tQuantity\tRemain\tUsed"); 315 write("-- \t-- \t--------- \t-----------\t-----------\t--------\t------\t----"); 316 } 317 } 318 319 static void write_item(int i, BioMaterialEventSource evtSrc) 312 320 throws BaseException 313 321 { 314 if (!TestUtil.getSilent()) System.out.println(i+":\t"+b.getId()+"\t"+b.getName()+"\t"+b.getDescription()+ 315 "\t"+b.getExternalId()+"\t"+b.isPooled()+"\t"+b.getOriginalQuantity()+"\t"+b.getRemainingQuantity()+ 316 "\t"+evt.getUsedQuantity(b)); 322 if (!TestUtil.getSilent()) 323 { 324 MeasuredBioMaterial bm = (MeasuredBioMaterial)evtSrc.getBioMaterial(); 325 System.out.println(i+":\t"+bm.getId()+"\t"+bm.getName()+"\t"+bm.getDescription()+ 326 "\t"+bm.getExternalId()+"\t"+"\t"+bm.getOriginalQuantity()+"\t"+bm.getRemainingQuantity()+ 327 "\t"+evtSrc.getUsedQuantity()); 328 } 317 329 } 318 330 … … 395 407 Sample s = Sample.getById(dc, sampleId); 396 408 BioMaterialEvent evt = s.getCreationEvent(); 397 ItemResultList<? extends MeasuredBioMaterial> l = evt.getSources().list(dc);409 ResultList<BioMaterialEventSource> l = evt.getEventSources().list(dc); 398 410 for (int i = 0; i<l.size(); i++) 399 411 { 400 write_item(i, l.get(i) , evt);412 write_item(i, l.get(i)); 401 413 } 402 414 if (expectedResults >= 0 && expectedResults != l.size()) … … 417 429 } 418 430 } 419 static void test_list_pooledChildren(int sampleId, int expectedResults) 431 432 static void test_list_children(int sampleId, int expectedResults) 420 433 { 421 434 if (sampleId == 0) return; … … 425 438 dc = TestUtil.getDbControl(); 426 439 Sample s = Sample.getById(dc, sampleId); 427 ItemResultList< BioMaterialEvent> ev = s.getPoolingEvents().list(dc);440 ItemResultList<Sample> ev = s.getChildSamples().list(dc); 428 441 429 442 for (int i=0; i<ev.size(); i++) 430 443 { 431 write_item(i, (Sample)ev.get(i).getBioMaterial());444 write_item(i, ev.get(i)); 432 445 } 433 446 if (expectedResults >= 0 && expectedResults != ev.size()) … … 435 448 throw new BaseException("Expected "+expectedResults+" results, not "+ev.size()); 436 449 } 437 write("--List pools fromsample OK ("+ev.size()+")");438 } 439 catch (Throwable ex) 440 { 441 write("--List poolsfor sample FAILED");442 ex.printStackTrace(); 443 ok = false; 444 } 445 finally 446 { 447 if (dc != null) dc.close(); 448 } 449 } 450 451 static void test_ pooledChildrenTransformer(int sampleId, int expectedResults)450 write("--List children for sample OK ("+ev.size()+")"); 451 } 452 catch (Throwable ex) 453 { 454 write("--List children for sample FAILED"); 455 ex.printStackTrace(); 456 ok = false; 457 } 458 finally 459 { 460 if (dc != null) dc.close(); 461 } 462 } 463 464 static void test_childrenTransformer(int sampleId, int expectedResults) 452 465 { 453 466 if (sampleId == 0) return; … … 457 470 dc = TestUtil.getDbControl(); 458 471 Sample s = Sample.getById(dc, sampleId); 459 PooledChildrenTransformer<Sample> pct = new PooledChildrenTransformer<Sample>(dc, false, Sample.getQuery()); 460 List<Sample> children = new ArrayList<Sample>(); 461 int numAdded = pct.transform(Collections.singleton(s), children); 462 463 for (int i=0; i<children.size(); i++) 464 { 465 write_item(i, children.get(i)); 466 } 467 if (expectedResults >= 0 && expectedResults != numAdded && numAdded != children.size()) 468 { 469 throw new BaseException("Expected "+expectedResults+" results, not "+numAdded); 470 } 471 write("--List pools from sample using transformer OK ("+numAdded+")"); 472 } 473 catch (Throwable ex) 474 { 475 write("--List pools for sample using transformer FAILED"); 476 ex.printStackTrace(); 477 ok = false; 478 } 479 finally 480 { 481 if (dc != null) dc.close(); 482 } 483 } 484 472 ChildrenTransformer<Sample> pct = new ChildrenTransformer<Sample>(dc, false, Sample.getQuery()); 473 Set<Sample> children = new LinkedHashSet<Sample>(); 474 pct.transform(Collections.singleton(s), children); 475 476 int i = 0; 477 for (Sample c : children) 478 { 479 write_item(i, c); 480 i++; 481 } 482 if (expectedResults >= 0 && expectedResults != children.size()) 483 { 484 throw new BaseException("Expected "+expectedResults+" results, not "+children.size()); 485 } 486 write("--List children for sample using transformer OK ("+children.size()+")"); 487 } 488 catch (Throwable ex) 489 { 490 write("--List children for sample using transformer FAILED"); 491 ex.printStackTrace(); 492 ok = false; 493 } 494 finally 495 { 496 if (dc != null) dc.close(); 497 } 498 } 499 500 static void test_parentsTransformer(int sampleId, int expectedResults) 501 { 502 if (sampleId == 0) return; 503 DbControl dc = null; 504 try 505 { 506 dc = TestUtil.getDbControl(); 507 Sample s = Sample.getById(dc, sampleId); 508 ParentsTransformer<Sample> pct = new ParentsTransformer<Sample>(dc, false, Sample.getQuery()); 509 Set<Sample> parents = new LinkedHashSet<Sample>(); 510 pct.transform(Collections.singleton(s), parents); 511 512 int i = 0; 513 for (Sample c : parents) 514 { 515 write_item(i, c); 516 i++; 517 } 518 if (expectedResults >= 0 && expectedResults != parents.size()) 519 { 520 throw new BaseException("Expected "+expectedResults+" results, not "+parents.size()); 521 } 522 write("--List parents for sample using transformer OK ("+parents.size()+")"); 523 } 524 catch (Throwable ex) 525 { 526 write("--List parents for sample using transformer FAILED"); 527 ex.printStackTrace(); 528 ok = false; 529 } 530 finally 531 { 532 if (dc != null) dc.close(); 533 } 534 } 535 536 static void test_sampleToBioSourceTransformer(int sampleId, int expectedResults) 537 { 538 if (sampleId == 0) return; 539 DbControl dc = null; 540 try 541 { 542 dc = TestUtil.getDbControl(); 543 Sample s = Sample.getById(dc, sampleId); 544 SampleToBioSourceTransformer pct = new SampleToBioSourceTransformer(dc); 545 Set<BioSource> parents = new LinkedHashSet<BioSource>(); 546 pct.transform(Collections.singleton(s), parents); 547 548 int i = 0; 549 for (BioSource c : parents) 550 { 551 TestBioSource.write_item(i, c); 552 i++; 553 } 554 if (expectedResults >= 0 && expectedResults != parents.size()) 555 { 556 throw new BaseException("Expected "+expectedResults+" results, not "+parents.size()); 557 } 558 write("--List biosource for sample using transformer OK ("+parents.size()+")"); 559 } 560 catch (Throwable ex) 561 { 562 write("--List biosource for sample using transformer FAILED"); 563 ex.printStackTrace(); 564 ok = false; 565 } 566 finally 567 { 568 if (dc != null) dc.close(); 569 } 570 } 571 572 static void test_bioSourceToSampleTransformer(int bioSourceId, int expectedResults) 573 { 574 if (bioSourceId == 0) return; 575 DbControl dc = null; 576 try 577 { 578 dc = TestUtil.getDbControl(); 579 BioSource bs = BioSource.getById(dc, bioSourceId); 580 BioSourceToSampleTransformer pct = new BioSourceToSampleTransformer(dc); 581 Set<Sample> children = new LinkedHashSet<Sample>(); 582 pct.transform(Collections.singleton(bs), children); 583 584 int i = 0; 585 for (Sample c : children) 586 { 587 write_item(i, c); 588 i++; 589 } 590 if (expectedResults >= 0 && expectedResults != children.size()) 591 { 592 throw new BaseException("Expected "+expectedResults+" results, not "+children.size()); 593 } 594 write("--List sample for biosource using transformer OK ("+children.size()+")"); 595 } 596 catch (Throwable ex) 597 { 598 write("--List sample for biosource using transformer FAILED"); 599 ex.printStackTrace(); 600 ok = false; 601 } 602 finally 603 { 604 if (dc != null) dc.close(); 605 } 606 } 607 485 608 } -
trunk/src/test/net/sf/basedb/test/roles/UserTest.java
r5662 r5663 376 376 sample.setName(name); 377 377 sample.setOriginalQuantity(100.0f); 378 sample. setBioSource(bioSource);378 sample.getCreationEvent().setSource(bioSource); 379 379 sample.getCreationEvent().setProtocol(Util.findProtocol(dc, "Sampling A")); 380 380 dc.saveItem(sample); … … 398 398 extract.setName(name); 399 399 extract.setOriginalQuantity(100.0f); 400 extract. setSample(sample).setUsedQuantity(50.0f);400 extract.getCreationEvent().setSource(sample).setUsedQuantity(50.0f); 401 401 extract.getCreationEvent().setProtocol(Util.findProtocol(dc, "Extraction A")); 402 402 dc.saveItem(extract); … … 416 416 labeledExtract.setOriginalQuantity(100.0f); 417 417 labeledExtract.setTag(label); 418 labeledExtract.setPooled(true);419 418 labeledExtract.getCreationEvent().setProtocol(Util.findProtocol(dc, "Labeling A")); 420 labeledExtract.getCreationEvent(). addSource(extract).setUsedQuantity(50.0f);419 labeledExtract.getCreationEvent().setSource(extract).setUsedQuantity(50.0f); 421 420 dc.saveItem(labeledExtract); 422 421 return labeledExtract; -
trunk/www/WEB-INF/base.tld
r5650 r5663 383 383 </attribute> 384 384 <attribute> 385 <name>buttonclass</name> 386 <required>false</required> 387 <rtexprvalue>true</rtexprvalue> 388 </attribute> 389 <attribute> 390 <name>buttonstyle</name> 391 <required>false</required> 392 <rtexprvalue>true</rtexprvalue> 393 </attribute> 394 <attribute> 395 <name>buttontitle</name> 396 <required>false</required> 397 <rtexprvalue>true</rtexprvalue> 398 </attribute> 399 <attribute> 400 <name>buttonicon</name> 401 <required>false</required> 402 <rtexprvalue>true</rtexprvalue> 403 </attribute> 404 <attribute> 385 405 <name>required</name> 386 406 <required>false</required> -
trunk/www/biomaterials/biosources/view_biosource.jsp
r5643 r5663 307 307 { 308 308 %> 309 <h4> Samples</h4>309 <h4>Child samples</h4> 310 310 No samples have been created from this biosource 311 311 (or, you don't have permission to view them). … … 317 317 <base:section 318 318 id="sampleSection" 319 title="<%=" Samples (" + samples.size() + ")"%>"319 title="<%="Child samples (" + samples.size() + ")"%>" 320 320 context="<%=cc%>" 321 321 > … … 328 328 id="name" 329 329 title="Name" 330 /> 331 <tbl:columndef 332 id="type" 333 title="Type" 330 334 /> 331 335 <tbl:columndef … … 347 351 visible="<%=item.isRemoved()%>" 348 352 /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell> 353 <tbl:cell column="type"><base:propertyvalue item="<%=item%>" property="itemSubtype" /></tbl:cell> 349 354 <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell> 350 355 </tbl:row> -
trunk/www/biomaterials/events/view_event.jsp
r5642 r5663 31 31 import="net.sf.basedb.core.Permission" 32 32 import="net.sf.basedb.core.Plate" 33 import="net.sf.basedb.core.BioMaterial" 33 34 import="net.sf.basedb.core.BioMaterialEvent" 35 import="net.sf.basedb.core.BioMaterialEventSource" 34 36 import="net.sf.basedb.core.BioPlateEventParticipant" 35 37 import="net.sf.basedb.core.BioPlateEvent" … … 40 42 import="net.sf.basedb.core.PermissionDeniedException" 41 43 import="net.sf.basedb.core.ItemQuery" 44 import="net.sf.basedb.core.SpecialQuery" 42 45 import="net.sf.basedb.core.ItemResultList" 43 46 import="net.sf.basedb.core.Include" … … 45 48 import="net.sf.basedb.core.query.Orders" 46 49 import="net.sf.basedb.core.query.Hql" 50 import="net.sf.basedb.core.query.ResultList" 47 51 import="net.sf.basedb.core.plugin.GuiContext" 48 52 import="net.sf.basedb.core.plugin.Plugin" … … 277 281 <% 278 282 } 279 ItemQuery<? extends MeasuredBioMaterial> sourcesQuery = event.getSources(); 280 sourcesQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS); 281 sourcesQuery.order(Orders.asc(Hql.property("name"))); 282 ItemResultList<? extends MeasuredBioMaterial> sources = sourcesQuery.list(dc); 283 SpecialQuery<BioMaterialEventSource> sourcesQuery = event.getEventSources(); 284 sourcesQuery.order(Orders.asc(Hql.property("bioMaterial.name"))); 285 ResultList<BioMaterialEventSource> sources = sourcesQuery.list(dc); 283 286 %> 284 287 <tr> … … 286 289 <td> 287 290 <% 288 for ( MeasuredBioMaterial s: sources)291 for (BioMaterialEventSource evtSrc : sources) 289 292 { 290 Item sourceType = s.getType(); 293 BioMaterial source = null; 294 Item sourceType = null; 295 try 296 { 297 source = evtSrc.getBioMaterial(); 298 sourceType = source.getType(); 299 } 300 catch (PermissionDeniedException ex) 301 {} 291 302 %> 292 <%=HTML.encodeTags(s.getName())%> (<%=sourceType%>), 293 <%=Values.formatNumber(event.getUsedQuantity(s), 2, " µg")%> 303 <%=Base.getLinkedName(ID, source, source == null, true)%> 304 <%=sourceType != null ? "(" + sourceType + ")" : "" %> 305 <%=Values.formatNumber(evtSrc.getUsedQuantity(), 2, " µg")%> 294 306 <br> 295 307 <% -
trunk/www/biomaterials/lists/index.jsp
r5641 r5663 46 46 import="net.sf.basedb.util.ShareableUtil" 47 47 import="net.sf.basedb.util.OwnableUtil" 48 import="net.sf.basedb.util.biomaterial.BioSourceToSampleTransformer"49 import="net.sf.basedb.util.biomaterial.SampleToExtractTransformer"50 import="net.sf.basedb.util.biomaterial.PooledChildrenTransformer"51 48 import="net.sf.basedb.util.collections.CollectionTransformer" 52 49 import="net.sf.basedb.util.biomaterial.ListUtil" -
trunk/www/biomaterials/samples/edit_sample.jsp
r5650 r5663 29 29 import="net.sf.basedb.core.DbControl" 30 30 import="net.sf.basedb.core.Item" 31 import="net.sf.basedb.core.Type" 31 32 import="net.sf.basedb.core.ItemContext" 32 33 import="net.sf.basedb.core.SystemItems" … … 47 48 import="net.sf.basedb.core.query.Orders" 48 49 import="net.sf.basedb.core.query.Hql" 50 import="net.sf.basedb.core.query.Expressions" 51 import="net.sf.basedb.core.query.Restrictions" 49 52 import="net.sf.basedb.clients.web.Base" 50 53 import="net.sf.basedb.clients.web.util.HTML" … … 81 84 BioMaterialEvent creationEvent = null; 82 85 Date eventDate = null; 83 boolean isPooled = false;86 Item parentType = null; 84 87 String name = null; 85 88 boolean lockEventProperties = false; … … 138 141 } 139 142 int bioSourceId = Values.getInt(request.getParameter("biosource_id")); 143 int sampleId = Values.getInt(request.getParameter("sample_id")); 140 144 if (bioSourceId != 0) 141 145 { 142 146 currentBioSource = BioSource.getById(dc, bioSourceId); 143 isPooled = false;147 parentType = Item.BIOSOURCE; 144 148 name = currentBioSource.getName() + ".s" + (currentBioSource.countSamples() + 1); 149 } 150 else if (sampleId != 0) 151 { 152 parentType = Item.SAMPLE; 153 Sample s = Sample.getById(dc, sampleId); 154 name = s.getName() + ".s" + (s.countSamples()+1); 155 samplesQuery = Sample.getQuery(); 156 samplesQuery.restrict(Restrictions.eq(Hql.property("id"), Expressions.integer(sampleId))); 145 157 } 146 158 else if (Values.getBoolean(request.getParameter("pooled"))) 147 159 { 148 isPooled = true; 149 name = Values.getString(cc.getPropertyValue("name"),"New pooled sample"); 160 parentType = Item.SAMPLE; 161 name = Values.getString(cc.getPropertyValue("name"), "New pooled sample"); 162 samplesQuery = Sample.getQuery(); 163 samplesQuery.restrict(Restrictions.in(Hql.property("id"), Expressions.parameter("selected"))); 164 samplesQuery.setParameter("selected", cc.getSelected(), Type.INT); 150 165 } 151 166 else 152 167 { 153 isPooled = Values.getBoolean(cc.getPropertyValue("pooled"));154 168 name = Values.getString(cc.getPropertyValue("name"), "New sample"); 155 169 } … … 165 179 creationEvent = sample.getCreationEvent(); 166 180 eventDate = creationEvent.getEventDate(); 167 isPooled = sample.isPooled();181 parentType = sample.getParentType(); 168 182 name = sample.getName(); 169 183 lockEventProperties = !creationEvent.hasPermission(Permission.WRITE); … … 179 193 } 180 194 181 182 195 try 183 196 { … … 191 204 try 192 205 { 193 currentBioSource = sample.getBioSource(); 206 if (parentType == Item.BIOSOURCE) 207 { 208 currentBioSource = (BioSource)sample.getParent(); 209 } 194 210 } 195 211 catch (PermissionDeniedException ex) … … 213 229 } 214 230 215 // Query to retrieve pooled samples 216 samplesQuery = (ItemQuery<Sample>)creationEvent.getSources(); 217 samplesQuery.include(Include.ALL); 218 samplesQuery.order(Orders.asc(Hql.property("name"))); 231 // Query to retrieve parent samples 232 if (parentType == Item.SAMPLE) 233 { 234 samplesQuery = (ItemQuery<Sample>)creationEvent.getSources(); 235 } 219 236 } 220 237 … … 314 331 var frm = document.forms['sample']; 315 332 var parents = new Array(); 316 if (frm.p ooled[0].checked)333 if (frm.parentType[0].checked) 317 334 { 318 335 var bioSourceId = Math.abs(parseInt(frm.biosource_id[frm.biosource_id.selectedIndex].value)); … … 449 466 } 450 467 451 function p ooledOnClick()452 { 453 var frm = document.forms['sample']; 454 var isPooled = frm.pooled[1].checked455 frm.biosource_id.disabled = isPooled;456 frm.samples.disabled = ! isPooled;457 frm.used_quantity.disabled = ! isPooled;468 function parentTypeOnClick() 469 { 470 var frm = document.forms['sample']; 471 var useSamples = frm.parentType[1].checked 472 frm.biosource_id.disabled = useSamples; 473 frm.samples.disabled = !useSamples; 474 frm.used_quantity.disabled = !useSamples; 458 475 parentsChanged = true; 459 476 } … … 465 482 { 466 483 var frm = document.forms['sample']; 467 if (frm.pooled[1].checked)468 {469 alert('This is a pooled sample, which cannot have a biosource as it\'s parent');470 return;471 }472 473 484 var url = '../biosources/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone'; 474 485 url += '&callback=setBioSourceCallback&resetTemporary=1'; … … 492 503 list[1].text = name; 493 504 list.selectedIndex = 1; 505 506 frm.parentType[0].checked = true; 507 frm.parentType[1].checked = false; 508 parentTypeOnClick(); 494 509 parentsChanged = true; 495 510 } … … 498 513 { 499 514 var frm = document.forms['sample']; 500 if (!frm.pooled[1].checked)501 {502 alert('This is not a pooled sample');503 return;504 }505 506 515 var url = 'index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple'; 507 516 url += '&callback=addSampleCallback&resetTemporary=1'; … … 511 520 function addSampleCallback(sampleId, name) 512 521 { 522 var frm = document.forms['sample']; 513 523 var item = Link.getItem('S', sampleId); 514 524 if (!item) item = new Item('S', sampleId, name+' [-]', '', ''); 515 Link.addItem(document.forms['sample'].samples, item); 525 Link.addItem(frm.samples, item); 526 frm.parentType[0].checked = false; 527 frm.parentType[1].checked = true; 528 parentTypeOnClick(); 516 529 parentsChanged = true; 517 530 } … … 567 580 initBioWell(); 568 581 initSamples(); 569 p ooledOnClick();582 parentTypeOnClick(); 570 583 } 571 584 function initSamples() … … 573 586 var samples = document.forms['sample'].samples; 574 587 <% 575 if (sample != null && sample.isPooled()) 576 { 588 if (samplesQuery != null) 589 { 590 samplesQuery.include(Include.ALL); 591 samplesQuery.order(Orders.asc(Hql.property("name"))); 577 592 ItemResultList<Sample> samples = samplesQuery.list(dc); 578 593 for (Sample s : samples) 579 594 { 580 String usedQuantity = Values.formatNumber(creationEvent.getUsedQuantity(s), -1); 581 %> 582 Link.addNewItem(samples, new Item('S', <%=s.getId()%>, '<%=HTML.javaScriptEncode(s.getName())%> [<%=usedQuantity%> µg]', '<%=usedQuantity%>')); 583 <% 584 } 585 } 586 else if (sample == null && Values.getBoolean(request.getParameter("pooled"))) 587 { 588 for (int sid : cc.getSelected()) 589 { 590 Sample sampleToPool = Sample.getById(dc, sid); 591 %> 592 Link.addItem(samples, new Item('S', <%=sampleToPool.getId()%>, '<%=HTML.javaScriptEncode(sampleToPool.getName())%> [-]', '', '')); 593 <% 595 if (sample != null) 596 { 597 String usedQuantity = Values.formatNumber(creationEvent.getUsedQuantity(s), -1); 598 %> 599 Link.addNewItem(samples, new Item('S', <%=s.getId()%>, '<%=HTML.javaScriptEncode(s.getName())%> [<%=usedQuantity%> µg]', '<%=usedQuantity%>')); 600 <% 601 } 602 else 603 { 604 %> 605 Link.addItem(samples, new Item('S', <%=s.getId()%>, '<%=HTML.javaScriptEncode(s.getName())%> [-]', '', '')); 606 <% 607 } 594 608 } 595 609 } … … 755 769 <table class="form" cellspacing=0> 756 770 <tr> 757 <td class="prompt">P ooled</td>771 <td class="prompt">Parent type</td> 758 772 <td> 759 <input type="radio" name="pooled" value="0" onclick="pooledOnClick()" 760 <%=!isPooled ? "checked" : ""%> 761 >no 762 <input type="radio" name="pooled" value="1" onclick="pooledOnClick()" 763 <%=isPooled ? "checked" : ""%> 764 >yes 773 <input type="radio" name="parentType" id="parentType.biosource" 774 value="BIOSOURCE" onclick="parentTypeOnClick()" 775 <%=parentType != Item.SAMPLE ? "checked" : ""%> 776 ><label for="parentType.biosource">Biosource</label> 777 <input type="radio" name="parentType" id="parentType.sample" 778 value="SAMPLE" onclick="parentTypeOnClick()" 779 <%=parentType == Item.SAMPLE ? "checked" : ""%> 780 ><label for="parentType.sample">Sample</label> 765 781 </td> 766 782 </tr> … … 771 787 id="biosource_id" 772 788 clazz="selectionlist" 789 buttonstyle="width: 150px;" 790 buttonicon="add.png" 791 buttontitle="Select biosource…" 773 792 required="false" 774 793 current="<%=currentBioSource%>" … … 788 807 <tr valign="top"> 789 808 <td> 790 <select name="samples" size="5" multiple style="width: 20em;"809 <select name="samples" size="5" multiple class="selectionlist" 791 810 onchange="samplesOnChange()"> 792 </select> <br> 793 Used 794 <input <%=clazz%> type="text" name="used_quantity" value="" 795 size="12" maxlength="10" onkeypress="return Numbers.numberOnly(event)" 796 onkeyup="usedQuantityOnBlur();" 797 > (µg) 811 </select> 798 812 <input type="hidden" name="modifiedSamples" value=""> 799 813 <input type="hidden" name="removedSamples" value=""> 800 814 </td> 801 815 <td> 802 <table border="0" >803 <tr><td width="150"><base:button816 <table border="0" cellspacing="0" cellpadding="0"> 817 <tr><td style="padding: 1px 0px 4px 0px; width: 150px;"><base:button 804 818 onclick="addSamplesOnClick()" 805 819 title="Add samples…" 806 820 tooltip="Add samples" 807 821 /></td></tr> 808 <tr><td width="150"><base:button 822 <tr><td><base:button 823 style="width: 150px;" 809 824 onclick="removeOnClick()" 810 825 title="Remove" … … 817 832 </td> 818 833 </tr> 834 <tr> 835 <td class="subprompt">-</td> 836 <td>used quantity 837 <input <%=clazz%> type="text" name="used_quantity" value="" 838 size="12" maxlength="10" onkeypress="return Numbers.numberOnly(event)" 839 onkeyup="usedQuantityOnBlur();" 840 > (µg) 841 </td> 842 </tr> 819 843 </table> 820 844 </t:tab> -
trunk/www/biomaterials/samples/index.jsp
r5662 r5663 88 88 cc.setObject("export.formatter.bioWell.row", new WellCoordinateFormatter(true)); 89 89 cc.setObject("export.formatter.bioWell.column", new WellCoordinateFormatter(false)); 90 cc.setObject("export.formatter.&creationEvent.source BioMaterials(name)", new NameableFormatter());91 cc.setObject("export.formatter.& sourceEvents(event.bioMaterial.name)", new NameableFormatter());90 cc.setObject("export.formatter.&creationEvent.sources(bioMaterial.name)", new NameableFormatter()); 91 cc.setObject("export.formatter.&childCreationEvents(event.bioMaterial.name)", new NameableFormatter()); 92 92 cc.setObject("export.formatter.&children(name)", new NameableFormatter()); 93 93 … … 106 106 childSamplesQuery.join(Hql.innerJoin("creationEvent", "ce")); 107 107 childSamplesQuery.join(Hql.innerJoin("ce", "sources", "src")); 108 childSamplesQuery.restrict(Restrictions.eq(Hql. index("src", null), Expressions.parameter(sampleParameter)));108 childSamplesQuery.restrict(Restrictions.eq(Hql.property("src", "bioMaterial"), Expressions.parameter(sampleParameter))); 109 109 childSamplesQuery.order(Orders.asc(Hql.property("name"))); 110 110 childSamplesQuery.include(cc.getInclude()); 111 cc.setObject("export.dataloader.& sourceEvents(event.bioMaterial.name)", new ItemQueryLoader(childSamplesQuery, sampleParameter));111 cc.setObject("export.dataloader.&childCreationEvents(event.bioMaterial.name)", new ItemQueryLoader(childSamplesQuery, sampleParameter)); 112 112 113 113 // Parent samples 114 114 final ItemQuery<Sample> parentSamplesQuery = Sample.getQuery(); 115 parentSamplesQuery.join(Hql.innerJoin(" sourceEvents", "srcevt"));116 parentSamplesQuery.join(Hql.innerJoin(" srcevt", "event", "evt"));115 parentSamplesQuery.join(Hql.innerJoin("childCreationEvents", "cce")); 116 parentSamplesQuery.join(Hql.innerJoin("cce", "event", "evt")); 117 117 parentSamplesQuery.restrict(Restrictions.eq(Hql.property("evt", "bioMaterial"), Expressions.parameter(sampleParameter))); 118 118 parentSamplesQuery.order(Orders.asc(Hql.property("name"))); 119 119 parentSamplesQuery.include(cc.getInclude()); 120 cc.setObject("export.dataloader.&creationEvent.source BioMaterials(name)", new ItemQueryLoader(parentSamplesQuery, sampleParameter));120 cc.setObject("export.dataloader.&creationEvent.sources(bioMaterial.name)", new ItemQueryLoader(parentSamplesQuery, sampleParameter)); 121 121 } 122 122 %> … … 264 264 265 265 // Parents tab 266 sample.setPooled(Values.getBoolean(request.getParameter("pooled"))); 267 if (!sample.isPooled()) 266 //sample.setPooled(Values.getBoolean(request.getParameter("pooled"))); 267 Item parentType = Item.valueOf(request.getParameter("parentType")); 268 if (parentType == Item.BIOSOURCE) 268 269 { 269 270 int bioSourceId = Values.getInt(request.getParameter("biosource_id"), -1); … … 271 272 { 272 273 BioSource bs = bioSourceId == 0 ? null : BioSource.getById(dc, bioSourceId); 273 sample.setBioSource(bs);274 creationEvent.setSource(bs); 274 275 if (bs != null) cc.setRecent(bs, maxRecent); 275 276 } … … 277 278 else 278 279 { 280 if (sample.getParentType() != Item.SAMPLE) 281 { 282 creationEvent.clearSources(); 283 } 279 284 String[] modifiedSamples = Values.getString(request.getParameter("modifiedSamples")).split(","); 280 285 for (int i = 0; i < modifiedSamples.length; ++i) -
trunk/www/biomaterials/samples/list_samples.jsp
r5662 r5663 110 110 childSamplesQuery.join(Hql.innerJoin("creationEvent", "ce")); 111 111 childSamplesQuery.join(Hql.innerJoin("ce", "sources", "src")); 112 childSamplesQuery.restrict(Restrictions.eq(Hql. index("src", null), Hql.entityParameter("sample", Item.SAMPLE)));112 childSamplesQuery.restrict(Restrictions.eq(Hql.property("src", "bioMaterial"), Hql.entityParameter("sample", Item.SAMPLE))); 113 113 childSamplesQuery.order(Orders.asc(Hql.property("name"))); 114 114 childSamplesQuery.include(cc.getInclude()); … … 178 178 Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected); 179 179 } 180 function newSample(sampleId) 181 { 182 Main.viewOrEditItem('<%=ID%>', 'SAMPLE', 0, true, '&sample_id='+sampleId); 183 } 180 184 function newExtract(sampleId) 181 185 { … … 374 378 formatter="<%=dateFormatter%>" 375 379 /> 376 <tbl:columndef377 id="pooled"378 property="pooled"379 datatype="boolean"380 title="Pooled"381 sortable="true"382 filterable="true"383 exportable="true"384 />385 <tbl:columndef386 id="bioSource"387 title="Biosource"388 property="parent.name"389 datatype="string"390 sortable="true"391 filterable="true"392 exportable="true"393 />394 380 <tbl:columndef 395 381 id="parents" 396 title="Parent samples"382 title="Parent items" 397 383 property="&creationEvent.sources(bioMaterial.name)" 384 sortproperty="parent.name" 398 385 datatype="string" 399 386 filterable="true" 400 387 exportable="true" 388 sortable="true" 401 389 /> 402 390 <tbl:columndef … … 652 640 { 653 641 Sample item = samples.next(); 642 Item parentType = item.getParentType(); 654 643 BioMaterialEvent creationEvent = item.getCreationEvent(); 655 644 int itemId = item.getId(); … … 717 706 <tbl:cell column="originalQuantity"><%=Values.formatNumber(item.getOriginalQuantity(), 2)%></tbl:cell> 718 707 <tbl:cell column="remainingQuantity"><%=Values.formatNumber(item.getRemainingQuantity(), 2)%></tbl:cell> 719 <tbl:cell column="pooled"><%=item.isPooled()%></tbl:cell>720 708 <tbl:cell column="protocol" 721 709 ><base:propertyvalue … … 768 756 <tbl:cell column="eventDate" value="<%=creationEvent.getEventDate()%>" /> 769 757 <tbl:cell column="entryDate" value="<%=creationEvent.getEntryDate()%>" /> 770 <tbl:cell column="bioSource"><base:propertyvalue item="<%=item%>" property="parent"/></tbl:cell>771 758 <tbl:cell column="parents"> 772 759 <% 773 if (item.isPooled()) 760 if (item.hasSingleParent() || item.getParentType() == null) 761 { 762 %> 763 <base:propertyvalue item="<%=item%>" property="parent"/> 764 <% 765 } 766 else 774 767 { 775 768 String separator = ""; … … 788 781 separator = ", "; 789 782 } 790 791 783 } 792 784 %> … … 810 802 } 811 803 %> 804 <base:icon 805 image="add.png" 806 onclick="<%="newSample("+itemId+")"%>" 807 tooltip="Create new child sample" 808 visible="<%=mode.hasEditLink() && createPermission && usePermission %>" 809 /> 812 810 </tbl:cell> 813 811 <tbl:cell column="extracts"> -
trunk/www/biomaterials/samples/view_sample.jsp
r5662 r5663 133 133 Main.viewOrEditItem('<%=ID%>', 'EXTRACT', 0, true, '&sample_id=<%=itemId%>'); 134 134 } 135 function newSample() 136 { 137 Main.viewOrEditItem('<%=ID%>', 'SAMPLE', 0, true, '&sample_id=<%=itemId%>'); 138 } 135 139 function deleteItem() 136 140 { … … 234 238 <tbl:button 235 239 image="add.png" 240 onclick="newSample()" 241 title="New child sample…" 242 tooltip="Create a new child sample from this sample" 243 visible="<%=sc.hasPermission(Permission.CREATE, Item.SAMPLE) && usePermission%>" 244 /> 245 <tbl:button 246 image="add.png" 236 247 onclick="newExtract()" 237 title="New extract…"248 title="New child extract…" 238 249 tooltip="Create a new extract from this sample" 239 250 visible="<%=sc.hasPermission(Permission.CREATE, Item.EXTRACT) && usePermission%>" … … 312 323 <td><%=dateFormatter.format(creationEvent.getEntryDate())%></td> 313 324 </tr> 314 <%315 if (!sample.isPooled())316 {317 %>318 <tr>319 <td class="prompt">Biosource</td>320 <td><base:propertyvalue item="<%=sample%>" property="parent" /></td>321 </tr>322 <%323 }324 %>325 325 <tr> 326 326 <td class="prompt">Protocol</td> … … 367 367 368 368 <% 369 if (sample.isPooled()) 370 { 371 SpecialQuery<BioMaterialEventSource> sourceQuery = creationEvent.getEventSources(); 372 sourceQuery.order(Orders.asc(Hql.property("bioMaterial.name"))); 373 ResultList<BioMaterialEventSource> sources = sourceQuery.list(dc); 374 %> 375 <h4 class="docked">Pooled from samples</h4> 376 <tbl:table 377 id="pooled" 378 clazz="itemlist" 379 columns="all" 369 SpecialQuery<BioMaterialEventSource> sourceQuery = creationEvent.getEventSources(); 370 sourceQuery.order(Orders.asc(Hql.property("bioMaterial.name"))); 371 ResultList<BioMaterialEventSource> sources = sourceQuery.list(dc); 372 if (sources.size() == 0) 373 { 374 %> 375 <% 376 } 377 else 378 { 379 %> 380 <base:section 381 id="parentsSection" 382 title="<%="Parent items (" + sources.size() + ")"%>" 383 context="<%=cc%>" 380 384 > 381 <tbl:columndef 382 id="name" 383 title="Name" 384 /> 385 <tbl:columndef 386 id="quantity" 387 title="Used quantity (µg)" 388 /> 389 <tbl:columndef 390 id="description" 391 title="Description" 392 /> 393 <tbl:data> 394 <tbl:columns> 395 </tbl:columns> 396 <tbl:rows> 397 <% 398 for (BioMaterialEventSource item : sources) 399 { 400 BioMaterial bm = null; 401 try 385 <tbl:table 386 id="parents" 387 clazz="itemlist" 388 columns="all" 389 > 390 <tbl:columndef 391 id="name" 392 title="Name" 393 /> 394 <tbl:columndef 395 id="type" 396 title="Type" 397 /> 398 <tbl:columndef 399 id="quantity" 400 title="Used quantity (µg)" 401 /> 402 <tbl:columndef 403 id="description" 404 title="Description" 405 /> 406 <tbl:data> 407 <tbl:columns> 408 </tbl:columns> 409 <tbl:rows> 410 <% 411 for (BioMaterialEventSource item : sources) 402 412 { 403 bm = item.getBioMaterial(); 413 BioMaterial bm = null; 414 try 415 { 416 bm = item.getBioMaterial(); 417 } 418 catch (PermissionDeniedException ex) 419 {} 420 %> 421 <tbl:row> 422 <tbl:cell column="name"><base:icon 423 image="deleted.gif" 424 tooltip="This item has been scheduled for deletion" 425 visible="<%=bm != null && bm.isRemoved()%>" 426 /><%=Base.getLinkedName(ID, bm, bm == null, true)%></tbl:cell> 427 <tbl:cell column="type"><%=bm != null ? bm.getType() : "" %></tbl:cell> 428 <tbl:cell column="quantity"><%=Values.formatNumber(item.getUsedQuantity(), 2)%></tbl:cell> 429 <tbl:cell column="description"><%=HTML.encodeTags(bm == null ? "" : bm.getDescription())%></tbl:cell> 430 </tbl:row> 431 <% 404 432 } 405 catch (PermissionDeniedException ex)406 {}407 433 %> 408 <tbl:row> 409 <tbl:cell column="name"><base:icon 410 image="deleted.gif" 411 tooltip="This item has been scheduled for deletion" 412 visible="<%=bm != null && bm.isRemoved()%>" 413 /><%=Base.getLinkedName(ID, bm, bm == null, true)%></tbl:cell> 414 <tbl:cell column="quantity"><%=Values.formatNumber(item.getUsedQuantity(), 2)%></tbl:cell> 415 <tbl:cell column="description"><%=HTML.encodeTags(bm == null ? "" : bm.getDescription())%></tbl:cell> 416 </tbl:row> 417 <% 418 } 419 %> 420 </tbl:rows> 421 </tbl:data> 422 </tbl:table> 434 </tbl:rows> 435 </tbl:data> 436 </tbl:table> 437 </base:section> 423 438 <% 424 439 } 425 440 426 441 // Samples this item is pooled in. 427 ItemQuery<BioMaterialEvent> poolingQuery = sample.getPoolingEvents(); 428 ItemResultList<BioMaterialEvent> poolingEvents = poolingQuery.list(dc); 429 if (poolingEvents.size() == 0) 430 { 431 %> 432 <h4>Pooled in samples</h4> 433 No samples have been pooled from this sample 442 SpecialQuery<BioMaterialEventSource> childQuery = sample.getChildCreationEvents(); 443 childQuery.join(Hql.innerJoin("es", "event", "evt", true)); 444 childQuery.join(Hql.innerJoin("evt", "bioMaterial", "bm", true)); 445 childQuery.order(Orders.asc(Hql.property("bm", "name"))); 446 ResultList<BioMaterialEventSource> children = childQuery.list(dc); 447 if (children.size() == 0) 448 { 449 %> 450 <h4>Child items</h4> 451 No child items have been created from this sample 434 452 (or, you don't have permission to view them). 435 453 <% … … 439 457 %> 440 458 <base:section 441 id=" pooledSection"442 title="<%=" Pooled in samples (" + poolingEvents.size() + ")"%>"459 id="childSection" 460 title="<%="Child items (" + children.size() + ")"%>" 443 461 context="<%=cc%>" 444 462 > 445 463 <tbl:table 446 id=" poolChilds"464 id="children" 447 465 clazz="itemlist" 448 466 columns="all" … … 453 471 /> 454 472 <tbl:columndef 455 id=" quantity"456 title=" Original quantity (µg)"473 id="type" 474 title="Type" 457 475 /> 458 476 <tbl:columndef 459 id=" parents"460 title="Used samples[quantity]"477 id="quantity" 478 title="Used quantity (µg)" 461 479 /> 462 480 <tbl:columndef … … 468 486 <tbl:rows> 469 487 <% 470 for (BioMaterialEvent poolingEvt : poolingEvents)488 for (BioMaterialEventSource item : children) 471 489 { 472 Sample child = (Sample)poolingEvt.getBioMaterial(); 473 ItemQuery<Sample> samplesQuery = (ItemQuery<Sample>)poolingEvt.getSources(); 474 samplesQuery.include(Include.ALL); 475 samplesQuery.order(Orders.asc(Hql.property("name"))); 476 ItemResultList<Sample> parentSamples = samplesQuery.list(dc); 490 BioMaterial bm = null; 491 try 492 { 493 bm = item.getEvent().getBioMaterial(); 494 } 495 catch (PermissionDeniedException ex) 496 {} 477 497 %> 478 498 <tbl:row> 479 <tbl:cell column="name"> 480 <base:icon 499 <tbl:cell column="name"><base:icon 481 500 image="deleted.gif" 482 501 tooltip="This item has been scheduled for deletion" 483 visible="<%=child.isRemoved()%>" 484 /> 485 <%=Base.getLinkedName(ID, child, false, true)%> 486 </tbl:cell> 487 <tbl:cell column="quantity"><%=Values.formatNumber(child.getOriginalQuantity(), 2)%></tbl:cell> 488 <tbl:cell column="parents"> 489 <% 490 String separator = ""; 491 for (Sample parent : parentSamples) 492 { 493 out.write(separator); 494 if (parent.equals(sample)) 495 out.write(HTML.encodeTags(parent.getName())); 496 else 497 out.write(Base.getLinkedName(ID, parent, false, true)); 498 out.write("[" + Values.formatNumber(poolingEvt.getUsedQuantity(parent), 2) + "µg]"); 499 separator = ", "; 500 } 501 %> 502 </tbl:cell> 503 <tbl:cell column="description"><%=HTML.encodeTags(child.getDescription())%></tbl:cell> 502 visible="<%=bm != null && bm.isRemoved()%>" 503 /><%=Base.getLinkedName(ID, bm, bm == null, true)%></tbl:cell> 504 <tbl:cell column="type"><%=bm != null ? bm.getType() : "" %></tbl:cell> 505 <tbl:cell column="quantity"><%=Values.formatNumber(item.getUsedQuantity(), 2)%></tbl:cell> 506 <tbl:cell column="description"><%=HTML.encodeTags(bm == null ? "" : bm.getDescription())%></tbl:cell> 504 507 </tbl:row> 505 508 <% … … 512 515 <% 513 516 } 514 515 // Extracts created from this sample516 ItemQuery<Extract> extractQuery = sample.getExtracts();517 extractQuery.include(Include.ALL);518 extractQuery.order(Orders.asc(Hql.property("name")));519 ItemResultList<Extract> extracts = extractQuery.list(dc);520 if (extracts.size() == 0)521 {522 %>523 <h4>Extracts</h4>524 No extracts have been created from this sample525 (or, you don't have permission to view them).526 <%527 }528 else529 {530 %>531 <base:section532 id="extractSection"533 title="<%="Extracts (" + extracts.size() + ")"%>"534 context="<%=cc%>"535 >536 <tbl:table537 id="extracts"538 clazz="itemlist"539 columns="all"540 >541 <tbl:columndef542 id="name"543 title="Name"544 />545 <tbl:columndef546 id="quantity"547 title="Used quantity (µg)"548 />549 <tbl:columndef550 id="description"551 title="Description"552 />553 <tbl:data>554 <tbl:columns></tbl:columns>555 <tbl:rows>556 <%557 for (Extract e : extracts)558 {559 %>560 <tbl:row>561 <tbl:cell column="name"><base:icon562 image="deleted.gif"563 tooltip="This item has been scheduled for deletion"564 visible="<%=e.isRemoved()%>"565 /><%=Base.getLinkedName(ID, e, false, true)%></tbl:cell>566 <tbl:cell column="quantity"><%=Values.formatNumber(e.getCreationEvent().getUsedQuantity(sample), 2)%></tbl:cell>567 <tbl:cell column="description"><%=HTML.encodeTags(e.getDescription())%></tbl:cell>568 </tbl:row>569 <%570 }571 %>572 </tbl:rows>573 </tbl:data>574 </tbl:table>575 </base:section>576 <%577 }578 517 %> 579 518 <jsp:include page="../../common/anytoany/list_anytoany.jsp"> -
trunk/www/include/styles/main.css
r5643 r5663 345 345 } 346 346 347 .buttonclass _hover {347 .buttonclass:hover { 348 348 background: #F0F0F0; 349 349 border-top: 1px solid #333333;
Note: See TracChangeset
for help on using the changeset viewer.