2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.model
.occurrence
;
14 import javax
.persistence
.Entity
;
15 import javax
.persistence
.ManyToOne
;
16 import javax
.persistence
.Transient
;
18 import org
.hibernate
.annotations
.Cascade
;
19 import org
.hibernate
.annotations
.CascadeType
;
21 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
24 * http://www.bgbm.org/biodivinf/docs/CollectionModel/ReprintTNR.pdf
25 * http://www.bgbm.org/biodivinf/docs/CollectionModel/
30 public abstract class DerivedUnitBase
extends SpecimenOrObservationBase
{
32 private Collection collection
;
33 private String catalogNumber
;
34 private TaxonNameBase storedUnder
;
35 private DerivationEvent derivedFrom
;
40 protected DerivedUnitBase() {
44 * create new unit derived from an existing field observation
45 * @param fieldObservation existing field observation from where this unit is derived
47 protected DerivedUnitBase(FieldObservation fieldObservation
) {
49 DerivationEvent derivedFrom
= new DerivationEvent();
50 // TODO: should be done in a more controlled way. Probably by making derivation event implement a general relationship interface (for bidirectional add/remove etc)
51 fieldObservation
.addDerivationEvent(derivedFrom
);
52 derivedFrom
.getOriginals().add(fieldObservation
);
53 derivedFrom
.getDerivatives().add(this);
54 this.setDerivedFrom(derivedFrom
);
57 * create new unit derived from an existing gathering event,
58 * thereby creating a new empty field observation
59 * @param gatheringEvent the gathering event this unit was collected at
61 protected DerivedUnitBase(GatheringEvent gatheringEvent
) {
62 this(new FieldObservation());
63 FieldObservation field
= (FieldObservation
) this.getOriginalUnit();
64 field
.setGatheringEvent(gatheringEvent
);
70 @Deprecated //only for bidirectional and persistence use
71 private DerivationEvent
getDerivationEvent() {
72 return getDerivedFrom();
74 @Deprecated //only for bidirectional and persistence use
75 private void setDerivationEvent(DerivationEvent derivationEvent
) {
76 this.derivedFrom
= derivationEvent
;
79 public DerivationEvent
getDerivedFrom() {
82 public void setDerivedFrom(DerivationEvent derivedFrom
){
83 if (getDerivedFrom() != null){
84 getDerivedFrom().getDerivatives().remove(derivedFrom
);
86 this.derivedFrom
= derivedFrom
;
87 if (derivedFrom
!= null){
88 derivedFrom
.getDerivatives().add(this);
93 public Set
<SpecimenOrObservationBase
> getOriginals(){
94 return this.getDerivedFrom().getOriginals();
100 public GatheringEvent
getGatheringEvent() {
101 // FIXME: implement efficient way of getting original gathering event
102 // keep link to original gathering event for performance mainly.
108 @Cascade({CascadeType
.SAVE_UPDATE
})
109 public Collection
getCollection(){
110 return this.collection
;
112 public void setCollection(Collection collection
){
113 this.collection
= collection
;
117 public String
getCatalogNumber() {
118 return catalogNumber
;
121 public void setCatalogNumber(String catalogNumber
) {
122 this.catalogNumber
= catalogNumber
;
126 @Cascade({CascadeType
.SAVE_UPDATE
})
127 public TaxonNameBase
getStoredUnder() {
130 public void setStoredUnder(TaxonNameBase storedUnder
) {
131 this.storedUnder
= storedUnder
;