(no commit message)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / occurrence / DerivedUnitBase.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.cdm.model.occurrence;
11
12 import java.util.Set;
13
14 import javax.persistence.Entity;
15 import javax.persistence.ManyToOne;
16 import javax.persistence.Transient;
17
18 import org.hibernate.annotations.Cascade;
19 import org.hibernate.annotations.CascadeType;
20
21 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
22
23 /**
24 * http://www.bgbm.org/biodivinf/docs/CollectionModel/ReprintTNR.pdf
25 * http://www.bgbm.org/biodivinf/docs/CollectionModel/
26 * @author markus
27 *
28 */
29 @Entity
30 public abstract class DerivedUnitBase extends SpecimenOrObservationBase {
31
32 private Collection collection;
33 private String catalogNumber;
34 private TaxonNameBase storedUnder;
35 private DerivationEvent derivedFrom;
36
37 /**
38 * Constructor
39 */
40 protected DerivedUnitBase() {
41 super();
42 }
43 /**
44 * create new unit derived from an existing field observation
45 * @param fieldObservation existing field observation from where this unit is derived
46 */
47 protected DerivedUnitBase(FieldObservation fieldObservation) {
48 super();
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);
55 }
56 /**
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
60 */
61 protected DerivedUnitBase(GatheringEvent gatheringEvent) {
62 this(new FieldObservation());
63 FieldObservation field = (FieldObservation) this.getOriginalUnit();
64 field.setGatheringEvent(gatheringEvent);
65 }
66
67
68
69 @ManyToOne
70 @Deprecated //only for bidirectional and persistence use
71 private DerivationEvent getDerivationEvent() {
72 return getDerivedFrom();
73 }
74 @Deprecated //only for bidirectional and persistence use
75 private void setDerivationEvent(DerivationEvent derivationEvent) {
76 this.derivedFrom = derivationEvent;
77 }
78 @Transient
79 public DerivationEvent getDerivedFrom() {
80 return derivedFrom;
81 }
82 public void setDerivedFrom(DerivationEvent derivedFrom){
83 if (getDerivedFrom() != null){
84 getDerivedFrom().getDerivatives().remove(derivedFrom);
85 }
86 this.derivedFrom = derivedFrom;
87 if (derivedFrom != null){
88 derivedFrom.getDerivatives().add(this);
89 }
90 }
91
92 @Transient
93 public Set<SpecimenOrObservationBase> getOriginals(){
94 return this.getDerivedFrom().getOriginals();
95 }
96
97
98 @Override
99 @Transient
100 public GatheringEvent getGatheringEvent() {
101 // FIXME: implement efficient way of getting original gathering event
102 // keep link to original gathering event for performance mainly.
103 return null;
104 }
105
106
107 @ManyToOne
108 @Cascade({CascadeType.SAVE_UPDATE})
109 public Collection getCollection(){
110 return this.collection;
111 }
112 public void setCollection(Collection collection){
113 this.collection = collection;
114 }
115
116
117 public String getCatalogNumber() {
118 return catalogNumber;
119 }
120
121 public void setCatalogNumber(String catalogNumber) {
122 this.catalogNumber = catalogNumber;
123 }
124
125 @ManyToOne
126 @Cascade({CascadeType.SAVE_UPDATE})
127 public TaxonNameBase getStoredUnder() {
128 return storedUnder;
129 }
130 public void setStoredUnder(TaxonNameBase storedUnder) {
131 this.storedUnder = storedUnder;
132 }
133
134 }