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
|
package eu.etaxonomy.cdm.model.occurrence;
|
10
|
|
11
|
import javax.persistence.Entity;
|
12
|
import javax.persistence.FetchType;
|
13
|
import javax.persistence.ManyToOne;
|
14
|
import javax.xml.bind.annotation.XmlAccessType;
|
15
|
import javax.xml.bind.annotation.XmlAccessorType;
|
16
|
import javax.xml.bind.annotation.XmlElement;
|
17
|
import javax.xml.bind.annotation.XmlIDREF;
|
18
|
import javax.xml.bind.annotation.XmlSchemaType;
|
19
|
import javax.xml.bind.annotation.XmlType;
|
20
|
|
21
|
import org.apache.logging.log4j.LogManager;
|
22
|
import org.apache.logging.log4j.Logger;
|
23
|
import org.hibernate.envers.Audited;
|
24
|
|
25
|
import eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase;
|
26
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
27
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
28
|
|
29
|
/**
|
30
|
* The class representing the assignment of a occurrence status to a
|
31
|
* {@link DerivedUnit derived unit}. This includes an {@link OccurrenceStatusType occurrence status type}
|
32
|
* (for instance "destroyed", "lost" or "not seen by ...").
|
33
|
*
|
34
|
* @author m.doering
|
35
|
* @since 08-Nov-2007 13:06:39
|
36
|
*/
|
37
|
@XmlAccessorType(XmlAccessType.FIELD)
|
38
|
@XmlType(name = "OccurrenceStatus", propOrder = {
|
39
|
"unit",
|
40
|
"type"
|
41
|
})
|
42
|
@Entity
|
43
|
@Audited
|
44
|
public class OccurrenceStatus
|
45
|
extends SingleSourcedEntityBase {
|
46
|
|
47
|
private static final long serialVersionUID = 623891726208046243L;
|
48
|
private static Logger logger = LogManager.getLogger(OccurrenceStatus.class);
|
49
|
|
50
|
@XmlElement(name = "OccurrenceStatusType")
|
51
|
@XmlIDREF
|
52
|
@XmlSchemaType(name = "IDREF")
|
53
|
@ManyToOne(fetch = FetchType.LAZY)
|
54
|
private DefinedTerm type;
|
55
|
|
56
|
@XmlElement(name = "Name")
|
57
|
@XmlIDREF
|
58
|
@XmlSchemaType(name = "IDREF")
|
59
|
@ManyToOne(fetch = FetchType.LAZY)
|
60
|
private DerivedUnit unit;
|
61
|
|
62
|
// ************************** FACTORY *********************************/
|
63
|
|
64
|
/**
|
65
|
* Creates a new occurrence status instance with a given
|
66
|
* occurrence status type.
|
67
|
*
|
68
|
* @see #OccurrenceStatus()
|
69
|
*/
|
70
|
public static OccurrenceStatus NewInstance(DefinedTerm occurrenceStatusType){
|
71
|
return NewInstance(occurrenceStatusType, null, null);
|
72
|
}
|
73
|
|
74
|
|
75
|
/**
|
76
|
* Creates a new occurrence status instance with a given
|
77
|
* occurrence status type.
|
78
|
*
|
79
|
* @see #OccurrenceStatus()
|
80
|
*/
|
81
|
public static OccurrenceStatus NewInstance(DefinedTerm occurrenceStatusType, Reference citation, String microCitation){
|
82
|
OccurrenceStatus status = new OccurrenceStatus();
|
83
|
status.setType(occurrenceStatusType);
|
84
|
status.setCitation(citation);
|
85
|
status.setCitationMicroReference(microCitation);
|
86
|
return status;
|
87
|
}
|
88
|
|
89
|
// ************************ CONSTRUCTOR *************************/
|
90
|
|
91
|
//*packet* private required by bytebuddy
|
92
|
OccurrenceStatus() {
|
93
|
super();
|
94
|
}
|
95
|
|
96
|
// ************************ GETTER / SETTER ************************/
|
97
|
|
98
|
public DerivedUnit getUnit() {
|
99
|
return unit;
|
100
|
}
|
101
|
protected void setUnit(DerivedUnit unit) {
|
102
|
if (this.unit != null && !this.unit.equals(unit)){
|
103
|
this.unit.removeStatus(this);
|
104
|
}
|
105
|
this.unit = unit;
|
106
|
if (unit != null){
|
107
|
unit.addStatus(this);
|
108
|
}
|
109
|
}
|
110
|
|
111
|
/**
|
112
|
* Returns the occurrence status type of <i>this</i>
|
113
|
* occurrence status.
|
114
|
*/
|
115
|
public DefinedTerm getType(){
|
116
|
return this.type;
|
117
|
}
|
118
|
/**
|
119
|
* @see #getType()
|
120
|
*/
|
121
|
public void setType(DefinedTerm type){
|
122
|
this.type = type;
|
123
|
}
|
124
|
|
125
|
//*********************** CLONE ********************************************************/
|
126
|
|
127
|
/**
|
128
|
* Clones <i>this</i> occurrence status. This is a shortcut that enables to create
|
129
|
* a new instance that differs only slightly from <i>this</i> occurrence status by
|
130
|
* modifying only some of the attributes.
|
131
|
*
|
132
|
* @see eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase#clone()
|
133
|
* @see java.lang.Object#clone()
|
134
|
*/
|
135
|
@Override
|
136
|
public OccurrenceStatus clone() {
|
137
|
try {
|
138
|
OccurrenceStatus result = (OccurrenceStatus)super.clone();
|
139
|
//no changes to: type
|
140
|
return result;
|
141
|
} catch (CloneNotSupportedException e) {
|
142
|
logger.warn("Object does not implement cloneable");
|
143
|
e.printStackTrace();
|
144
|
return null;
|
145
|
}
|
146
|
}
|
147
|
}
|