Changeset 5662


Ignore:
Timestamp:
Jun 20, 2011, 1:55:13 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #1153: Handling short read transcript sequence data

Removed the old "hack" with UsedQuantity and the dummy column used to store the array index. This has now been replaced with BioMaterialEventSource which is almost a full-fledged item and it should be easier to handle and create queries using the information.

Location:
trunk
Files:
5 added
2 deleted
30 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/BioMaterialEvent.java

    r5650 r5662  
    2626import net.sf.basedb.core.query.Hql;
    2727
     28import net.sf.basedb.core.data.BioMaterialData;
    2829import net.sf.basedb.core.data.BioMaterialEventData;
     30import net.sf.basedb.core.data.BioMaterialEventSourceData;
    2931import net.sf.basedb.core.data.HardwareData;
    3032import net.sf.basedb.core.data.MeasuredBioMaterialData;
    3133import net.sf.basedb.core.data.ProtocolData;
    3234import net.sf.basedb.core.data.UserData;
    33 import net.sf.basedb.core.data.UsedQuantity;
    3435import net.sf.basedb.core.data.SharedData;
    3536
     
    3738import java.util.HashMap;
    3839import java.util.Date;
    39 import java.util.Iterator;
    4040
    4141/**
     
    599599    else
    600600    {
    601       UsedQuantity used = getData().getSources().get((MeasuredBioMaterialData)bioMaterial.getData());
    602       return used == null ? null : used.getUsedQuantity();
    603     }
    604   }
    605  
    606   /**
    607     Get the source group of the biomaterial
    608     @param bioMaterial The source biomaterial
    609     @return The source group index or 0 if the biomaterial is not a source of this event
    610     @since 2.6
    611     @see #setSourceGroup(MeasuredBioMaterial, int)
    612   */
    613   public int getSourceGroup(MeasuredBioMaterial bioMaterial)
    614   {
    615     UsedQuantity used = getData().getSources().get(bioMaterial.getData());
    616     return used != null ? used.getSourceGroup() : 0;
    617   }
    618  
    619   /**
    620     Add a source biomaterial to this event or update
    621     the used quantity of an existing source. Sources can only be specified if
    622     the produced biomaterial is a pooled biomaterial and this is a creation event.
    623    
    624     @param bioMaterial The biomaterial used as a source
    625     @param usedQuantity The quantity that was used from the source biomaterial
    626     @throws PermissionDeniedException If the logged in user doesn't have
    627       write permission for this event of use permission for the source
    628     @throws InvalidDataException If this is not a creation event or
    629       if the produced biomaterial is not pooled or if the source
    630       biomaterial is of another type
    631     @throws BaseException If there is another error
    632   */
    633   public void addSource(MeasuredBioMaterial bioMaterial, Float usedQuantity)
    634     throws PermissionDeniedException, InvalidDataException, BaseException
     601      BioMaterialEventSourceData src = getData().getSources().get(bioMaterial.getData());
     602      return src == null ? null : src.getUsedQuantity();
     603    }
     604  }
     605 
     606  /**
     607    Get information about a biomaterial used as a source to this event.
     608    @param bioMaterial The biomaterial
     609    @return A BioMaterialEventSource object or null if the given biomaterial
     610      is not a source to the event
     611    @see #addSource(BioMaterial)
     612  */
     613  public BioMaterialEventSource getEventSource(BioMaterial bioMaterial)
     614  {
     615    BioMaterialEventSourceData src = getData().getSources().get(bioMaterial.getData());
     616    return src == null ? null : new BioMaterialEventSource(getDbControl(), src); //(this);
     617  }
     618 
     619  /**
     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
     624    @return A BioMaterialEventSource object
     625  */
     626  public BioMaterialEventSource addSource(BioMaterial bioMaterial)
    635627  {
    636628    checkPermission(Permission.RESTRICTED_WRITE);
     
    638630    bioMaterial.checkPermission(Permission.USE);
    639631    checkAllowedSource(bioMaterial);
    640     MeasuredBioMaterialData data = (MeasuredBioMaterialData)bioMaterial.getData();
    641     UsedQuantity used = getData().getSources().get(data);
    642     if (used != null)
    643     {
    644       // There is already an entry for this biomaterial
    645       if (used.getUsedQuantity() != null)
    646       {
    647         // Return the old value to the biomaterial
    648         MeasuredBioMaterial.updateRemainingQuantity(getDbControl(), data, -used.getUsedQuantity());
    649       }
    650       // Set the new value
    651       used.setUsedQuantity(usedQuantity);
    652     }
    653     else
    654     {
    655       // This is a new entry
    656       used = new UsedQuantity(usedQuantity, 1);
    657       getData().getSources().put(data, used);
    658     }
    659     if (usedQuantity != null)
    660     {
    661       // Take away the new used quantity from the biomaterial
    662       MeasuredBioMaterial.updateRemainingQuantity(getDbControl(), data, usedQuantity);
    663     }
    664   }
    665  
    666   /**
    667     Set the source group for a biomaterial that was used as a source in this event.
    668     The source group value is used to group sources that are related. The only
    669     example and use case is when using multi-array hybridizations
    670     where it is essential to know which array a labeled extract goes on. The source
    671     group is then simply the number of the array on the hybridization and should be
    672     a value between 1 and {@link PhysicalBioAssay#getSize()}.
    673     <p>
    674     A single labeled extract can only be used in a single group. Experiments using a n-channel
    675     platform and a common reference must first split the reference labeled extract
    676     into individual labeled extracts. This can be done with the 'pooling' functionality.
    677     <p>
    678     If the source biomaterial has not been added with {@link #addSource(MeasuredBioMaterial, Float)}
    679     this method will automatically add it with usedQuantity = null.
    680  
    681     @param bioMaterial The source biomaterial
    682     @param sourceGroup The source group
    683     @throws PermissionDeniedException If the logged in user doesn't have
    684       write permission for this event of use permission for the source
    685     @throws InvalidDataException If this is not a creation event or
    686       if the produced biomaterial is not pooled or if the source
    687       biomaterial is of another type
    688     @since 2.6
    689   */
    690   public void setSourceGroup(MeasuredBioMaterial bioMaterial, int sourceGroup)
    691     throws PermissionDeniedException, InvalidDataException, BaseException
    692   {
    693     checkPermission(Permission.RESTRICTED_WRITE);
    694     if (bioMaterial == null) throw new InvalidUseOfNullException("bioMaterial");
    695     MeasuredBioMaterialData data = (MeasuredBioMaterialData)bioMaterial.getData();
    696 
    697     UsedQuantity used = getData().getSources().get(data);
    698     if (used == null)
    699     {
    700       addSource(bioMaterial, null);
    701       used = getData().getSources().get(data);
    702     }
    703     if (used != null)
    704     {
    705       used.setSourceGroup(sourceGroup);
    706     }
    707   }
    708  
     632    return addCheckedSource(bioMaterial);
     633  }
     634 
     635  private BioMaterialEventSource addCheckedSource(BioMaterial bioMaterial)
     636  {
     637    BioMaterialData bmData = (BioMaterialData)bioMaterial.getData();
     638    BioMaterialEventSourceData src = getData().getSources().get(bmData);
     639    if (src == null)
     640    {
     641      src = new BioMaterialEventSourceData();
     642      src.setBioMaterial(bmData);
     643      src.setEvent(this.getData());
     644      getData().getSources().put(bmData, src);
     645    }
     646    return new BioMaterialEventSource(getDbControl(), src);
     647  }
     648
    709649  /**
    710650    Remove a biomaterial used as a source. Sources can only be specified if
     
    718658    @throws BaseException If there is another error
    719659  */
    720   public void removeSource(MeasuredBioMaterial bioMaterial)
     660  public void removeSource(BioMaterial bioMaterial)
    721661    throws PermissionDeniedException, InvalidDataException, BaseException
    722662  {
     
    724664    if (bioMaterial == null) throw new InvalidUseOfNullException("bioMaterial");
    725665    checkAllowedSource(bioMaterial);
    726     MeasuredBioMaterialData data = (MeasuredBioMaterialData)bioMaterial.getData();
    727     UsedQuantity used = getData().getSources().remove(data);
    728     Float usedQuantity = used == null ? null : used.getUsedQuantity();
    729     if (usedQuantity != null) MeasuredBioMaterial.updateRemainingQuantity(getDbControl(), data, -usedQuantity);
     666    BioMaterialData data = (BioMaterialData)bioMaterial.getData();
     667    BioMaterialEventSourceData src = getData().getSources().remove(data);
     668    if (src == null) return;
     669   
     670    if (src.getId() != 0) getDbControl().getHibernateSession().delete(src);
     671    if (data instanceof MeasuredBioMaterialData)
     672    {
     673      Float used = src.getUsedQuantity();
     674      if (used != null)
     675      {
     676        MeasuredBioMaterial.updateRemainingQuantity(getDbControl(), (MeasuredBioMaterialData)data, -used);
     677      }
     678    }
    730679  }
    731680
     
    739688    </ul>
    740689  */
    741   private void checkAllowedSource(MeasuredBioMaterial bioMaterial)
     690  private void checkAllowedSource(BioMaterial bioMaterial)
    742691    throws PermissionDeniedException, InvalidDataException, BaseException
    743692  {
     
    784733    Set a single source. This method is used for non-pooled biomaterial
    785734    to specify the parent.
    786     @see Extract#setSample(Sample, Float)
    787   */
    788   void setSource(MeasuredBioMaterial bioMaterial, Float usedQuantity)
     735    @see Extract#setSample(Sample)
     736  */
     737  BioMaterialEventSource setSource(MeasuredBioMaterial bioMaterial)
    789738    throws PermissionDeniedException, InvalidDataException
    790739  {
    791740    clearSources();
    792     if (bioMaterial != null)
    793     {
    794       MeasuredBioMaterialData data = (MeasuredBioMaterialData)bioMaterial.getData();
    795       getData().getSources().put(data, new UsedQuantity(usedQuantity, 1));
    796       if (usedQuantity != null) MeasuredBioMaterial.updateRemainingQuantity(getDbControl(), data, usedQuantity);
    797     }
     741    return bioMaterial == null ? null : addCheckedSource(bioMaterial);
    798742  }
    799743 
     
    804748  void clearSources()
    805749  {
    806     Iterator<Map.Entry<MeasuredBioMaterialData, UsedQuantity>> i = getData().getSources().entrySet().iterator();
    807     while (i.hasNext())
    808     {
    809       Map.Entry<MeasuredBioMaterialData, UsedQuantity> entry = i.next();
    810       MeasuredBioMaterialData source = entry.getKey();
    811       UsedQuantity used = entry.getValue();
    812       Float usedQuantity = used == null ? null : used.getUsedQuantity();
    813       if (usedQuantity != null) MeasuredBioMaterial.updateRemainingQuantity(getDbControl(), source, -usedQuantity);
    814       i.remove();
    815     }
     750    DbControl dc = getDbControl();
     751    for (BioMaterialEventSourceData src : getData().getSources().values())
     752    {
     753      BioMaterialData bioMaterial = src.getBioMaterial();
     754      Float used = src.getUsedQuantity();
     755      if (used != null && bioMaterial instanceof MeasuredBioMaterialData)
     756      {
     757        MeasuredBioMaterial.updateRemainingQuantity(dc, (MeasuredBioMaterialData)bioMaterial, -used);
     758      }
     759      dc.getHibernateSession().delete(src);
     760    }
     761    getData().getSources().clear();
    816762  }
    817763
    818764  /**
    819765    Get a query that return all biomaterials used as sources
    820     for this event. To filter or sort on the used quantity or source group columns
    821     use 'srcevt' as alias. For example to only return sources in source group 2
     766    for this event. To filter or sort on the used quantity or position columns
     767    use 'srcevt' as alias. For example to only return sources in position 2
    822768    and to order the result by used quantity:
    823769    <pre class="code">
    824770query = event.getSources();
    825771query.restrict(Expressions.gteq(
    826   Hql.property("srcevt", "sourceGroup"), Expressions.integer(2))
     772  Hql.property("srcevt", "position"), Expressions.integer(2))
    827773);
    828774query.order(Orders.asc(Hql.property("srcevt", "usedQuantity")));
     
    870816    }
    871817   
    872     query.joinPermanent(Hql.innerJoin("sourceEvents", "srcevt"));
     818    query.joinPermanent(Hql.innerJoin("childCreationEvents", "srcevt"));
    873819    query.joinPermanent(Hql.innerJoin("srcevt", "event", TYPE.getAlias()));
    874820    query.restrictPermanent(
     
    882828 
    883829  /**
     830    Create a special query that return BioMaterialEventSource objects.
     831    The objects are not {@link BasicItem}:s but can be used to get information
     832    about and modify the source biomaterials used in the event. Note
     833    that the query may return objects that link to biomaterial that the
     834    logged in used doesn't have read access to.
     835    @return A special query
     836    @since 3.0
     837  */
     838  public SpecialQuery<BioMaterialEventSource> getEventSources()
     839  {
     840    SpecialQuery<BioMaterialEventSource> query =
     841      new SpecialQuery<BioMaterialEventSource>(null, "BioMaterialEventSourceData", "es",
     842          new BioMaterialEventSource.BioMaterialEventSourceTransformer());
     843    query.restrictPermanent(Restrictions.eq(Hql.property("es", "event"), Hql.entity(this)));
     844    return query;
     845  }
     846 
     847  /**
    884848    The maximum length of the comment about this event. Check the length
    885849    against this value before calling the {@link #setComment(String)}
  • trunk/src/core/net/sf/basedb/core/Extract.java

    r5648 r5662  
    258258    of this extract.
    259259    @param sample The new <code>Sample</code> item
    260     @param usedQuantity The quantity that was used from the sample when
    261       the extract was created
    262260    @throws PermissionDeniedException If the logged in user doesn't have
    263261      write permission for this extract or use permission for the sample
    264262    @throws InvalidDataException If this is a pooled extract
    265263    @throws BaseException If there is another error
    266   */
    267   public void setSample(Sample sample, Float usedQuantity)
     264    @since 3.0
     265  */
     266  public BioMaterialEventSource setSample(Sample sample)
    268267    throws PermissionDeniedException, InvalidDataException, BaseException
    269268  {
     
    275274    }
    276275    getData().setParent(sample == null ? null : sample.getData());
    277     getCreationEvent().setSource(sample, usedQuantity);
    278   }
    279  
    280 
    281   public void setExtract(Extract extract, Float usedQuantity)
     276    return getCreationEvent().setSource(sample);
     277  }
     278 
     279
     280  public BioMaterialEventSource setExtract(Extract extract)
    282281    throws PermissionDeniedException, InvalidDataException, BaseException
    283282  {
     
    286285   
    287286    getData().setPooled(true);
    288 
    289287    getData().setParent(extract == null ? null : extract.getData());
    290     getCreationEvent().setSource(extract, usedQuantity);
     288    return getCreationEvent().setSource(extract);
    291289  }
    292290
  • trunk/src/core/net/sf/basedb/core/Sample.java

    r5643 r5662  
    281281  {
    282282    Extract e = Extract.getNew(getDbControl(), master);
    283     e.setSample(this, usedQuantity);
     283    e.setSample(this).setUsedQuantity(usedQuantity);
    284284    return e;
    285285  }
  • trunk/src/core/net/sf/basedb/core/data/BioMaterialData.java

    r5643 r5662  
    120120  }
    121121 
     122  private Set<BioMaterialEventSourceData> childCreationEvents;
     123  /**
     124    This is the inverse end.
     125    @see BioMaterialEventSourceData#getBioMaterial()
     126    @hibernate.set lazy="true" inverse="true"
     127    @hibernate.collection-key column="`biomaterial_id`"
     128    @hibernate.collection-one-to-many class="net.sf.basedb.core.data.BioMaterialEventSourceData"
     129  */
     130  Set<BioMaterialEventSourceData> getChildCreationEvents()
     131  {
     132    return childCreationEvents;
     133  }
     134  void setChildCreationEvents(Set<BioMaterialEventSourceData> childCreationEvents)
     135  {
     136    this.childCreationEvents = childCreationEvents;
     137  }
     138
    122139}
  • trunk/src/core/net/sf/basedb/core/data/BioMaterialEventData.java

    r5642 r5662  
    2626import java.util.Map;
    2727import java.util.HashMap;
    28 import java.util.Set;
    2928
    3029/**
     
    123122  private PhysicalBioAssayData bioassay;
    124123  /**
    125     Get the hybridization that was created by this event.
     124    Get the physical bioassay that was created by this event.
    126125    @hibernate.many-to-one column="`physicalbioassay_id`" not-null="false" outer-join="false" update="false"
    127126  */
     
    210209  }
    211210 
    212   private Map<MeasuredBioMaterialData, UsedQuantity> sources;
    213   /**
    214     Get a map containing the source biomaterials and the used quantity for
    215     this event.
    216     @hibernate.map table="`BioMaterialEventSources`" lazy="true" cascade="delete"
     211  private Map<BioMaterialData, BioMaterialEventSourceData> sources;
     212  /**
     213    Get a map containing information about the source biomaterials used
     214    in the event. This is only used for events that create child biomaterial or
     215    physical bioassay. This is the inverse end. See
     216    {@link BioMaterialEventSourceData#getEvent()}
     217    @hibernate.map inverse="true" lazy="true" cascade="all"
    217218    @hibernate.collection-key column="`event_id`"
    218     @hibernate.index-many-to-many column="`biomaterial_id`" class="net.sf.basedb.core.data.MeasuredBioMaterialData"
    219     @hibernate.collection-composite-element class="net.sf.basedb.core.data.UsedQuantity"
    220   */
    221   public Map<MeasuredBioMaterialData, UsedQuantity> getSources()
    222   {
    223     if (sources == null) sources = new HashMap<MeasuredBioMaterialData, UsedQuantity>();
     219    @hibernate.index-many-to-many column="`biomaterial_id`" class="net.sf.basedb.core.data.BioMaterialData"
     220    @hibernate.collection-one-to-many class="net.sf.basedb.core.data.BioMaterialEventSourceData"
     221    @since 3.0
     222  */
     223  public Map<BioMaterialData, BioMaterialEventSourceData> getSources()
     224  {
     225    if (sources == null)
     226    {
     227      sources = new HashMap<BioMaterialData, BioMaterialEventSourceData>();
     228    }
    224229    return sources;
    225230  }
    226   void setSources(Map<MeasuredBioMaterialData, UsedQuantity> sources)
     231  void setSources(Map<BioMaterialData, BioMaterialEventSourceData> sources)
    227232  {
    228233    this.sources = sources;
    229234  }
    230235 
    231   private Set<MeasuredBioMaterialData> sourceBioMaterials;
    232   /**
    233     This is the inverse end. The children is the non-pooled biomaterials
    234     that has this item as a parent.
    235     @see MeasuredBioMaterialData#getParent()
    236     @since 2.9
    237     @hibernate.set table="`BioMaterialEventSources`" inverse="true" lazy="true"
    238     @hibernate.collection-key column="`event_id`"
    239     @hibernate.collection-many-to-many column="`biomaterial_id`" class="net.sf.basedb.core.data.MeasuredBioMaterialData"
    240   */
    241   Set<MeasuredBioMaterialData> getSourceBioMaterials()
    242   {
    243     return sourceBioMaterials;
    244   }
    245   void setSourceBioMaterials(Set<MeasuredBioMaterialData> sourceBioMaterials)
    246   {
    247     this.sourceBioMaterials = sourceBioMaterials;
    248   }
    249 
    250236}
  • trunk/src/core/net/sf/basedb/core/data/MeasuredBioMaterialData.java

    r5643 r5662  
    133133  }
    134134 
    135   private Set<BioMaterialSourceEventData> sourceEvents;
    136   /**
    137     This is the inverse end.
    138     @see BioMaterialEventData#getSources()
    139     @hibernate.set table="`BioMaterialEventSources`" lazy="true" inverse="true"
    140     @hibernate.collection-key column="`biomaterial_id`"
    141     @hibernate.collection-composite-element class="net.sf.basedb.core.data.BioMaterialSourceEventData"
    142     hibernate.collection-many-to-many column="`event_id`" class="net.sf.basedb.core.data.BioMaterialEventData"
    143   */
    144   Set<BioMaterialSourceEventData> getSourceEvents()
    145   {
    146     return sourceEvents;
    147   }
    148   void setSourceEvents(Set<BioMaterialSourceEventData> sourceEvents)
    149   {
    150     this.sourceEvents = sourceEvents;
    151   }
    152  
    153135  private BioWellData bioWell;
    154136  /**
  • trunk/src/core/net/sf/basedb/util/biomaterial/PooledChildrenTransformer.java

    r4723 r5662  
    6161    query.include(Include.ALL);
    6262    query.join(Hql.innerJoin("creationEvent", "ce"));
    63     query.join(Hql.innerJoin("ce", "sourceBioMaterials", "sbm"));
     63    query.join(Hql.innerJoin("ce", "sources", "sbm"));
     64    query.join(Hql.innerJoin("sbm", "bioMaterial", "bm"));
    6465    query.restrict(
    6566      Restrictions.in(
    66         Hql.alias("sbm"),
     67        Hql.alias("bm"),
    6768        Expressions.parameter("sources")
    6869      )
  • trunk/src/core/net/sf/basedb/util/biomaterial/PooledParentsTransformer.java

    r4723 r5662  
    6060    this.query = query;
    6161    query.include(Include.ALL);
    62     query.join(Hql.innerJoin("sourceEvents", "se"));
    63     query.join(Hql.innerJoin("se", "event", "evt"));
     62    query.join(Hql.innerJoin("childCreationEvents", "ce"));
     63    query.join(Hql.innerJoin("ce", "event", "evt"));
    6464    query.restrict(
    6565      Restrictions.in(
  • trunk/src/core/net/sf/basedb/util/overview/loader/PhysicalBioAssayLoader.java

    r5657 r5662  
    200200    {
    201201      PhysicalBioAssay bioAssay = it.next();
    202       int arrayNum = bioAssay.getCreationEvent().getSourceGroup(extract);
    203       Object cacheKey = arrayNum == 0 ? bioAssay : new IndexedCacheKey(bioAssay, arrayNum);
     202      int position = bioAssay.getCreationEvent().getEventSource(extract).getPosition();
     203      Object cacheKey = position == 0 ? bioAssay : new IndexedCacheKey(bioAssay, position);
    204204      if (folderNode == null)
    205205      {
  • trunk/src/core/net/sf/basedb/util/overview/loader/RawBioAssayLoader.java

    r5652 r5662  
    2323
    2424
     25import net.sf.basedb.core.BioMaterialEventSource;
    2526import net.sf.basedb.core.DbControl;
    2627import net.sf.basedb.core.DerivedBioAssay;
     
    8283    // to be able to load the correct raw bioassays -- The same physical bioassay
    8384    // may have other raw bioassays that are NOT related to the same extract
    84     int arrayNum = 0;
     85    int position = 0;
    8586    PhysicalBioAssay pba = null;
    8687    Node physicalBioAssayNode = bioAssayNode.getFirstParent(new ItemTypeFilter(Item.PHYSICALBIOASSAY));
     
    9293        pba = (PhysicalBioAssay)physicalBioAssayNode.getItem(dc);
    9394        Extract extract = (Extract)extractNode.getItem();
    94         arrayNum = pba.getCreationEvent().getSourceGroup(extract);
     95        BioMaterialEventSource eventSource = pba.getCreationEvent().getEventSource(extract);
     96        position = eventSource == null ? 0 : eventSource.getPosition();
    9597      }
    9698    }
    97     if (arrayNum > 0)
     99    if (position > 0)
    98100    {
    99       query.restrict(Restrictions.eq(Hql.property("arrayNum"), Expressions.integer(arrayNum)));
     101      query.restrict(Restrictions.eq(Hql.property("arrayNum"), Expressions.integer(position)));
    100102    }
    101103   
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ExtractImporter.java

    r5648 r5662  
    2727
    2828import net.sf.basedb.core.BioMaterialEvent;
     29import net.sf.basedb.core.BioMaterialEventSource;
    2930import net.sf.basedb.core.BioPlate;
    3031import net.sf.basedb.core.BioWell;
     
    241242        Float usedQuantity = usedQuantityMapper == null ?
    242243          null : usedQuantityMapper.getFloat(data);
    243         if (nameOrId == null || sample != null) extract.setSample(sample, usedQuantity);
     244        if (nameOrId == null || sample != null)
     245        {
     246          BioMaterialEventSource evtSrc = extract.setSample(sample);
     247          if (evtSrc != null) evtSrc.setUsedQuantity(usedQuantity);
     248        }
    244249      }
    245250    }
     
    266271        Float usedQuantity = usedQuantityMapper == null ?
    267272            null : usedQuantityMapper.getFloat(data);
    268         extract.getCreationEvent().addSource(parent, usedQuantity);
     273        extract.getCreationEvent().addSource(parent).setUsedQuantity(usedQuantity);
    269274        // Use same tag as parent if not yet set and not mapped in the file
    270275        if (tagMapper == null && parent.getTag() != null && extract.getTag() == null)
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/HybridizationImporter.java

    r5649 r5662  
    2929import net.sf.basedb.core.ArraySlide;
    3030import net.sf.basedb.core.BioMaterialEvent;
     31import net.sf.basedb.core.BioMaterialEventSource;
    3132import net.sf.basedb.core.DbControl;
    3233import net.sf.basedb.core.Extract;
     
    305306      {
    306307        BioMaterialEvent creationEvent = hyb.getCreationEvent();
    307         int currentIndex = creationEvent.getSourceGroup(parent);
     308        BioMaterialEventSource eventSource = creationEvent.addSource(parent);
     309        int currentIndex = eventSource.getPosition();
    308310        Float usedQuantity = usedQuantityMapper == null ?
    309311            null : usedQuantityMapper.getFloat(data);
    310         creationEvent.addSource(parent, usedQuantity);
     312        eventSource.setUsedQuantity(usedQuantity);
    311313        if (arrayIndexMapper != null)
    312314        {
     
    321323                  "also associate it with array index " + arrayIndex);
    322324            }
    323             creationEvent.setSourceGroup(parent, arrayIndex);
     325            eventSource.setPosition(arrayIndex);
    324326          }
    325327        }
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/LabeledExtractImporter.java

    r5648 r5662  
    2727
    2828import net.sf.basedb.core.BioMaterialEvent;
     29import net.sf.basedb.core.BioMaterialEventSource;
    2930import net.sf.basedb.core.BioPlate;
    3031import net.sf.basedb.core.BioWell;
     
    244245        Float usedQuantity = usedQuantityMapper == null ?
    245246          null : usedQuantityMapper.getFloat(data);
    246         if (nameOrId == null || parent != null) extract.setExtract(parent, usedQuantity);
     247        if (nameOrId == null || parent != null)
     248        {
     249          BioMaterialEventSource evtSrc = extract.setExtract(parent);
     250          if (evtSrc != null) evtSrc.setUsedQuantity(usedQuantity);
     251        }
    247252      }
    248253    }
     
    268273        Float usedQuantity = usedQuantityMapper == null ?
    269274            null : usedQuantityMapper.getFloat(data);
    270         extract.getCreationEvent().addSource(parent, usedQuantity);
     275        extract.getCreationEvent().addSource(parent).setUsedQuantity(usedQuantity);
    271276        // Use same tag as parent if not yet set and not mapped in the file
    272277        if (labelMapper == null && parent.getTag() != null && extract.getTag() == null)
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/PhysicalBioAssayImporter.java

    r5649 r5662  
    2929import net.sf.basedb.core.ArraySlide;
    3030import net.sf.basedb.core.BioMaterialEvent;
     31import net.sf.basedb.core.BioMaterialEventSource;
    3132import net.sf.basedb.core.DbControl;
    3233import net.sf.basedb.core.Extract;
     
    301302      {
    302303        BioMaterialEvent creationEvent = pba.getCreationEvent();
    303         int currentPosition = creationEvent.getSourceGroup(parent);
    304         Float usedQuantity = usedQuantityMapper == null ?
    305             null : usedQuantityMapper.getFloat(data);
    306         creationEvent.addSource(parent, usedQuantity);
     304        BioMaterialEventSource eventSource = creationEvent.addSource(parent);
     305        int currentPosition = eventSource.getPosition();
     306        if (usedQuantityMapper != null)
     307        {
     308          eventSource.setUsedQuantity(usedQuantityMapper.getFloat(data));
     309        }
    307310        if (extractPositionMapper != null)
    308311        {
     
    317320                  "also associate it with position " + position);
    318321            }
    319             creationEvent.setSourceGroup(parent, position);
     322            eventSource.setPosition(position);
    320323          }
    321324        }
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/SampleImporter.java

    r5648 r5662  
    351351        Float usedQuantity = usedQuantityMapper == null ?
    352352            null : usedQuantityMapper.getFloat(data);
    353         sample.getCreationEvent().addSource(parent, usedQuantity);
     353        sample.getCreationEvent().addSource(parent).setUsedQuantity(usedQuantity);
    354354      }
    355355    }
  • trunk/src/test/TestExtract.java

    r5653 r5662  
    9797        {
    9898          Sample s = (Sample)parent;
    99           e.setSample(s, 200.0f);
     99          e.setSample(s).setUsedQuantity(200.0f);
    100100        }
    101101        else
    102102        {
    103103          e.setPooled(true);
    104           e.getCreationEvent().addSource((MeasuredBioMaterial)parent,  200.0f);
     104          e.getCreationEvent().addSource(parent).setUsedQuantity(200.0f);
    105105        }
    106106      }
     
    153153        Extract s = Extract.getById(dc, sourceId);
    154154        Float original = s.getOriginalQuantity();
    155         evt.addSource(s, original == null ? null : original/2);
     155        BioMaterialEventSource eventSource = evt.addSource(s);
     156        if (original != null)
     157        {
     158          eventSource.setUsedQuantity(original/2);
     159        }
    156160      }
    157161      dc.saveItem(e);
  • trunk/src/test/TestPhysicalBioAssay.java

    r5653 r5662  
    106106      {
    107107        Extract le = Extract.getById(dc, extractId);
    108         evt.addSource(le, 100.0f);
     108        BioMaterialEventSource eventSource = evt.addSource(le);
     109        eventSource.setUsedQuantity(100.0f);
    109110      }
    110111      dc.saveItem(h);
     
    265266  }
    266267 
    267   static void test_add_extract(int hybId, int extractId, int arrayNum, Float usedQuantity)
     268  static void test_add_extract(int hybId, int extractId, int position, Float usedQuantity)
    268269  {
    269270    if (hybId == 0 || extractId == 0) return;
     
    275276      Extract le = Extract.getById(dc, extractId);
    276277      BioMaterialEvent event = h.getCreationEvent();
    277       event.addSource(le, usedQuantity);
    278       event.setSourceGroup(le, arrayNum);
     278      BioMaterialEventSource eventSource = event.addSource(le);
     279      eventSource.setUsedQuantity(usedQuantity);
     280      eventSource.setPosition(position);
    279281      dc.commit();
    280282      write("--Add extract to bioassay OK");
  • trunk/src/test/TestSample.java

    r5340 r5662  
    142142        Sample src = Sample.getById(dc, sourceId);
    143143        Float original = src.getOriginalQuantity();
    144         evt.addSource(src, original == null ? null : original/2);
     144        BioMaterialEventSource eventSource = evt.addSource(src);
     145        if (original != null)
     146        {
     147          eventSource.setUsedQuantity(original/2);
     148        }
    145149      }
    146150      dc.saveItem(s);
  • trunk/src/test/TestTag.java

    r5632 r5662  
    7676      dc.commit();
    7777      id = t.getId();
     78      dc = TestUtil.getDbControl();
     79      dc.reattachItem(t, false);
    7880      write_item(0, t);
    7981      write("--Create tag OK");
  • trunk/src/test/net/sf/basedb/test/roles/UserTest.java

    r5652 r5662  
    398398    extract.setName(name);
    399399    extract.setOriginalQuantity(100.0f);
    400     extract.setSample(sample, 50.0f);
     400    extract.setSample(sample).setUsedQuantity(50.0f);
    401401    extract.getCreationEvent().setProtocol(Util.findProtocol(dc, "Extraction A"));
    402402    dc.saveItem(extract);
     
    418418    labeledExtract.setPooled(true);
    419419    labeledExtract.getCreationEvent().setProtocol(Util.findProtocol(dc, "Labeling A"));
    420     labeledExtract.getCreationEvent().addSource(extract, 50.0f);
     420    labeledExtract.getCreationEvent().addSource(extract).setUsedQuantity(50.0f);
    421421    dc.saveItem(labeledExtract);
    422422    return labeledExtract;
     
    450450    for (Extract le : extracts)
    451451    {
    452       creationEvent.addSource(le, 50.0f);
     452      creationEvent.addSource(le).setUsedQuantity(50.0f);
    453453    }
    454454    dc.saveItem(hyb);
  • trunk/www/biomaterials/extracts/index.jsp

    r5648 r5662  
    2424  @version 2.0
    2525--%>
     26<%@page import="net.sf.basedb.core.BioMaterialEventSource"%>
    2627<%@ page pageEncoding="UTF-8" session="false"
    2728  import="net.sf.basedb.core.SessionControl"
     
    283284        {
    284285          Sample s = sampleId == 0 ? null : Sample.getById(dc, sampleId);
    285           extract.setSample(s, s == null ? null : Values.getFloat(request.getParameter("used_from_sample"), null));
     286          BioMaterialEventSource evtSrc = extract.setSample(s);
     287          if (evtSrc != null)
     288          {
     289            evtSrc.setUsedQuantity(Values.getFloat(request.getParameter("used_from_sample"), null));
     290          }
    286291          if (s != null) cc.setRecent(s, maxRecent);
    287292        }
     
    296301          {
    297302            Extract e = Extract.getById(dc, eId);
    298             creationEvent.addSource(e, Values.getFloat(request.getParameter("E"+eId), null));
     303            creationEvent.addSource(e).setUsedQuantity(Values.getFloat(request.getParameter("E"+eId), null));
    299304          }
    300305        }
  • trunk/www/biomaterials/extracts/list_extracts.jsp

    r5648 r5662  
    118118 
    119119  final ItemQuery<Extract> parentExtractsQuery = Extract.getQuery();
    120   parentExtractsQuery.join(Hql.innerJoin("sourceEvents", "srcevt"));
    121   parentExtractsQuery.join(Hql.innerJoin("srcevt", "event", "evt"));
     120  parentExtractsQuery.join(Hql.innerJoin("childCreationEvents", "cce"));
     121  parentExtractsQuery.join(Hql.innerJoin("cce", "event", "evt"));
    122122  parentExtractsQuery.restrict(Restrictions.eq(Hql.alias("evt"), Hql.entityParameter("creationEvent", Item.BIOMATERIALEVENT)));
    123123  parentExtractsQuery.order(Orders.asc(Hql.property("name")));
     
    398398        id="parents"
    399399        title="Parent extracts"
    400         property="&creationEvent.sourceBioMaterials(name)"
     400        property="&creationEvent.sources(bioMaterial.name)"
    401401        datatype="string"
    402402        filterable="true"
     
    406406        id="children"
    407407        title="Child extracts"
    408         property="&sourceEvents(event.bioMaterial.name)"
     408        property="&childCreationEvents(event.bioMaterial.name)"
    409409        datatype="string"
    410410        filterable="true"
     
    414414        id="physicalBioAssays"
    415415        title="Physical bioassays"
    416         property="&sourceEvents(event.physicalBioAssay.name)"
     416        property="&childCreationEvents(event.physicalBioAssay.name)"
    417417        datatype="string"
    418418        filterable="true"
  • trunk/www/biomaterials/samples/index.jsp

    r5645 r5662  
    284284          {
    285285            Sample s = Sample.getById(dc, sId);
    286             creationEvent.addSource(s, Values.getFloat(request.getParameter("S"+sId), null));
     286            creationEvent.addSource(s).setUsedQuantity(Values.getFloat(request.getParameter("S"+sId), null));
    287287          }
    288288        }
  • trunk/www/biomaterials/samples/list_samples.jsp

    r5645 r5662  
    115115 
    116116  final ItemQuery<Sample> parentSamplesQuery = Sample.getQuery();
    117   parentSamplesQuery.join(Hql.innerJoin("sourceEvents", "srcevt"));
    118   parentSamplesQuery.join(Hql.innerJoin("srcevt", "event", "evt"));
     117  parentSamplesQuery.join(Hql.innerJoin("childCreationEvents", "cce"));
     118  parentSamplesQuery.join(Hql.innerJoin("cce", "event", "evt"));
    119119  parentSamplesQuery.restrict(Restrictions.eq(Hql.alias("evt"), Hql.entityParameter("creationEvent", Item.BIOMATERIALEVENT)));
    120120  parentSamplesQuery.order(Orders.asc(Hql.property("name")));
     
    395395        id="parents"
    396396        title="Parent samples"
    397         property="&creationEvent.sourceBioMaterials(name)"
     397        property="&creationEvent.sources(bioMaterial.name)"
    398398        datatype="string"
    399399        filterable="true"
     
    403403        id="children"
    404404        title="Child samples"
    405         property="&sourceEvents(event.bioMaterial.name)"
     405        property="&childCreationEvents(event.bioMaterial.name)"
    406406        datatype="string"
    407407        filterable="true"
  • trunk/www/biomaterials/samples/view_sample.jsp

    r5645 r5662  
    3434  import="net.sf.basedb.core.Sample"
    3535  import="net.sf.basedb.core.BioSource"
     36  import="net.sf.basedb.core.BioMaterial"
    3637  import="net.sf.basedb.core.BioMaterialEvent"
     38  import="net.sf.basedb.core.BioMaterialEventSource"
    3739  import="net.sf.basedb.core.BioWell"
    3840  import="net.sf.basedb.core.Protocol"
     
    4244  import="net.sf.basedb.core.ItemQuery"
    4345  import="net.sf.basedb.core.ItemResultList"
     46  import="net.sf.basedb.core.query.ResultList"
     47  import="net.sf.basedb.core.SpecialQuery"
    4448  import="net.sf.basedb.core.Include"
    4549  import="net.sf.basedb.core.MultiPermissions"
     
    365369      if (sample.isPooled())
    366370      {
    367         ItemQuery<Sample> samplesQuery = (ItemQuery<Sample>)creationEvent.getSources();
    368         samplesQuery.include(Include.ALL);
    369         samplesQuery.order(Orders.asc(Hql.property("name")));
    370         ItemResultList<Sample> samples = samplesQuery.list(dc);
     371        SpecialQuery<BioMaterialEventSource> sourceQuery = creationEvent.getEventSources();
     372        sourceQuery.order(Orders.asc(Hql.property("bioMaterial.name")));
     373        ResultList<BioMaterialEventSource> sources = sourceQuery.list(dc);
    371374        %>
    372375        <h4 class="docked">Pooled from samples</h4>
     
    393396          <tbl:rows>
    394397          <%
    395           for (Sample item : samples)
     398          for (BioMaterialEventSource item : sources)
    396399          {
     400            BioMaterial bm = null;
     401            try
     402            {
     403              bm = item.getBioMaterial();
     404            }
     405            catch (PermissionDeniedException ex)
     406            {}
    397407            %>
    398408            <tbl:row>
     
    400410                  image="deleted.gif"
    401411                  tooltip="This item has been scheduled for deletion"
    402                   visible="<%=item.isRemoved()%>"
    403                 /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
    404               <tbl:cell column="quantity"><%=Values.formatNumber(creationEvent.getUsedQuantity(item), 2)%></tbl:cell>
    405               <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
     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>
    406416            </tbl:row>
    407417            <%
  • trunk/www/biomaterials/wizards/index.jsp

    r5642 r5662  
    2222  @author Nicklas
    2323--%>
     24<%@page import="net.sf.basedb.core.BioMaterialEventSource"%>
    2425<%@ page pageEncoding="UTF-8" session="false"
    2526  import="net.sf.basedb.core.SessionControl"
     
    293294            if (isBioAssayEvent)
    294295            {
    295               pbaCreationEvent.addSource(parent, usedQuantity);
    296               pbaCreationEvent.setSourceGroup(parent, column+1);
     296              BioMaterialEventSource evtSrc = pbaCreationEvent.addSource(parent);
     297              evtSrc.setUsedQuantity(usedQuantity);
     298              evtSrc.setPosition(column+1);
    297299            }
    298300            else
     
    308310              {
    309311                child = Extract.getNew(dc, destParticipant);
    310                 if (!pooled) ((Extract)child).setSample((Sample)parent, usedQuantity);
     312                if (!pooled) ((Extract)child).setSample((Sample)parent).setUsedQuantity(usedQuantity);
    311313              }
    312314              /*
     
    329331              if (pooled)
    330332              {
    331                 child.getCreationEvent().addSource(parent, usedQuantity);
     333                child.getCreationEvent().addSource(parent).setUsedQuantity(usedQuantity);
    332334              }
    333335              dc.saveItem(child);
  • trunk/www/views/physicalbioassays/edit_bioassay.jsp

    r5657 r5662  
    3535  import="net.sf.basedb.core.PhysicalBioAssay"
    3636  import="net.sf.basedb.core.BioMaterialEvent"
     37  import="net.sf.basedb.core.BioMaterialEventSource"
    3738  import="net.sf.basedb.core.ItemSubtype"
    3839  import="net.sf.basedb.core.ArraySlide"
     
    553554          else
    554555          {
    555             Float used = creationEvent.getUsedQuantity(extract);
     556            BioMaterialEventSource evtSrc = creationEvent.getEventSource(extract);
     557            Float used = evtSrc.getUsedQuantity();
    556558            String usedQuantity = Values.formatNumber(used, -1);
    557559            String usedWithUnit = used == null ? "-" : usedQuantity + " µg";
    558             int arrayIndex = creationEvent.getSourceGroup(extract);
     560            int position = evtSrc.getPosition();
    559561            %>
    560             Link.addNewItem(extracts, new Item('E', <%=extract.getId()%>, '<%=arrayIndex + ": " + HTML.javaScriptEncode(extract.getName())%> [<%=usedWithUnit%>]', '<%=usedQuantity%>:<%=arrayIndex%>'));
     562            Link.addNewItem(extracts, new Item('E', <%=extract.getId()%>, '<%=position + ": " + HTML.javaScriptEncode(extract.getName())%> [<%=usedWithUnit%>]', '<%=usedQuantity%>:<%=position%>'));
    561563            <%
    562564          }
  • trunk/www/views/physicalbioassays/index.jsp

    r5657 r5662  
    3232  import="net.sf.basedb.core.ArraySlide"
    3333  import="net.sf.basedb.core.BioMaterialEvent"
     34  import="net.sf.basedb.core.BioMaterialEventSource"
    3435  import="net.sf.basedb.core.Extract"
    3536  import="net.sf.basedb.core.Protocol"
     
    242243          Float usedQuantity = Values.getFloat(extra[0], null);
    243244          int position = extra.length > 1 ? Values.getInt(extra[1], 1) : 1;
    244           creationEvent.addSource(e, usedQuantity);
    245           creationEvent.setSourceGroup(e, position);
     245          BioMaterialEventSource evtSrc = creationEvent.addSource(e);
     246          evtSrc.setUsedQuantity(usedQuantity);
     247          evtSrc.setPosition(position);
    246248        }
    247249      }
  • trunk/www/views/physicalbioassays/list_bioassays.jsp

    r5657 r5662  
    3333  import="net.sf.basedb.core.DerivedBioAssaySet"
    3434  import="net.sf.basedb.core.BioMaterialEvent"
     35  import="net.sf.basedb.core.BioMaterialEventSource"
    3536  import="net.sf.basedb.core.AnnotationType"
    3637  import="net.sf.basedb.core.AnnotationSet"
     
    100101  final ItemQuery<Extract> extractQuery = Extract.getQuery();
    101102  extractQuery.include(cc.getInclude());
    102   extractQuery.join(Hql.innerJoin("sourceEvents", "srcevt"));
    103   extractQuery.join(Hql.innerJoin("srcevt", "event", "evt"));
     103  extractQuery.join(Hql.innerJoin("childCreationEvents", "cce"));
     104  extractQuery.join(Hql.innerJoin("cce", "event", "evt"));
    104105  extractQuery.restrict(Restrictions.eq(Hql.property("evt", "physicalBioAssay"), Expressions.parameter("bioAssay")));
    105   extractQuery.order(Orders.asc(Hql.property("srcevt", "sourceGroup")));
     106  extractQuery.order(Orders.asc(Hql.property("cce", "position")));
    106107  extractQuery.order(Orders.asc(Hql.property("name")));
    107108
     
    292293        id="extracts"
    293294        title="Extracts"
    294         property="&creationEvent.sourceBioMaterials(name)"
     295        property="&creationEvent.sources(bioMaterial.name)"
    295296        datatype="string"
    296297        filterable="true"
     
    609610                      if (needIndex)
    610611                      {
    611                         out.write(creationEvent.getSourceGroup(extract) + ": ");
     612                        out.write(creationEvent.getEventSource(extract).getPosition() + ": ");
    612613                      }
    613614                      if (mode.hasPropertyLink())
  • trunk/www/views/physicalbioassays/view_bioassay.jsp

    r5657 r5662  
    3636  import="net.sf.basedb.core.ArraySlide"
    3737  import="net.sf.basedb.core.BioMaterialEvent"
     38  import="net.sf.basedb.core.BioMaterialEventSource"
    3839  import="net.sf.basedb.core.Protocol"
    3940  import="net.sf.basedb.core.DerivedBioAssaySet"
     
    327328      ItemQuery<Extract> extractsQuery = (ItemQuery<Extract>)creationEvent.getSources();
    328329      extractsQuery.include(Include.ALL);
    329       extractsQuery.order(Orders.asc(Hql.property("srcevt", "sourceGroup")));
     330      extractsQuery.order(Orders.asc(Hql.property("srcevt", "position")));
    330331      extractsQuery.order(Orders.asc(Hql.property("name")));
    331332      ItemResultList<Extract> extracts = extractsQuery.list(dc);
     
    379380            for (Extract item : extracts)
    380381            {
     382              BioMaterialEventSource evtSrc = creationEvent.getEventSource(item);
    381383              %>
    382384              <tbl:row>
    383                 <tbl:cell column="position"><%=creationEvent.getSourceGroup(item)%></tbl:cell>
     385                <tbl:cell column="position"><%=evtSrc.getPosition()%></tbl:cell>
    384386                <tbl:cell column="name"><base:icon
    385387                    image="deleted.gif"
     
    388390                  /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
    389391                <tbl:cell column="tag"><base:propertyvalue item="<%=item%>" property="tag" /></tbl:cell>
    390                 <tbl:cell column="quantity"><%=Values.formatNumber(creationEvent.getUsedQuantity(item), 2)%></tbl:cell>
     392                <tbl:cell column="quantity"><%=Values.formatNumber(evtSrc.getUsedQuantity(), 2)%></tbl:cell>
    391393                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
    392394              </tbl:row>
Note: See TracChangeset for help on using the changeset viewer.