Project

General

Profile

Download (4.24 KB) Statistics
| Branch: | Tag: | Revision:
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.validation.constraints.NotNull;
15
import javax.xml.bind.annotation.XmlAccessType;
16
import javax.xml.bind.annotation.XmlAccessorType;
17
import javax.xml.bind.annotation.XmlElement;
18
import javax.xml.bind.annotation.XmlIDREF;
19
import javax.xml.bind.annotation.XmlSchemaType;
20
import javax.xml.bind.annotation.XmlType;
21

    
22
import org.apache.logging.log4j.LogManager;
23
import org.apache.logging.log4j.Logger;
24
import org.hibernate.envers.Audited;
25

    
26
import eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.model.term.DefinedTerm;
29

    
30
/**
31
 * The class representing the assignment of a occurrence status to a
32
 * {@link DerivedUnit derived unit}. This includes an {@link OccurrenceStatusType occurrence status type}
33
 * (for instance "destroyed", "lost" or "not seen by ...").
34
 *
35
 * @author m.doering
36
 * @since 08-Nov-2007 13:06:39
37
 */
38
@XmlAccessorType(XmlAccessType.FIELD)
39
@XmlType(name = "OccurrenceStatus", propOrder = {
40
    "unit",
41
    "type"
42
})
43
@Entity
44
@Audited
45
public class OccurrenceStatus
46
        extends SingleSourcedEntityBase {
47

    
48
    private static final long serialVersionUID = 623891726208046243L;
49
    private static final Logger logger = LogManager.getLogger();
50

    
51
	@XmlElement(name = "OccurrenceStatusType")
52
    @XmlIDREF
53
    @XmlSchemaType(name = "IDREF")
54
    @ManyToOne(fetch = FetchType.LAZY)
55
	@NotNull(message="Occurrence status must have a type defined")
56
	private DefinedTerm type;
57

    
58
    @XmlElement(name = "Name")
59
    @XmlIDREF
60
    @XmlSchemaType(name = "IDREF")
61
    @ManyToOne(fetch = FetchType.LAZY)
62
    private DerivedUnit unit;
63

    
64
// ************************** FACTORY *********************************/
65

    
66
    /**
67
	 * Creates a new occurrence status instance with a given
68
	 * occurrence status type.
69
	 *
70
	 * @see #OccurrenceStatus()
71
	 */
72
	public static OccurrenceStatus NewInstance(DefinedTerm occurrenceStatusType){
73
		return NewInstance(occurrenceStatusType, null, null);
74
	}
75

    
76

    
77
	/**
78
	 * Creates a new occurrence status instance with a given
79
	 * occurrence status type.
80
	 *
81
	 * @see #OccurrenceStatus()
82
	 */
83
	public static OccurrenceStatus NewInstance(DefinedTerm occurrenceStatusType, Reference citation, String microCitation){
84
		OccurrenceStatus status = new OccurrenceStatus();
85
		status.setType(occurrenceStatusType);
86
		status.setCitation(citation);
87
		status.setCitationMicroReference(microCitation);
88
		return status;
89
	}
90

    
91
// ************************ CONSTRUCTOR *************************/
92

    
93
    //*packet* private required by bytebuddy
94
	OccurrenceStatus() {
95
        super();
96
    }
97

    
98
// ************************ GETTER / SETTER ************************/
99

    
100
    public DerivedUnit getUnit() {
101
        return unit;
102
    }
103
    protected void setUnit(DerivedUnit unit) {
104
        if (this.unit != null && !this.unit.equals(unit)){
105
            this.unit.removeStatus(this);
106
        }
107
        this.unit = unit;
108
        if (unit != null){
109
            unit.addStatus(this);
110
        }
111
    }
112

    
113
	/**
114
	 * Returns the occurrence status type of <i>this</i>
115
	 * occurrence status.
116
	 */
117
	public DefinedTerm getType(){
118
		return this.type;
119
	}
120
	/**
121
	 * @see  #getType()
122
	 */
123
	public void setType(DefinedTerm type){
124
		this.type = type;
125
	}
126

    
127
//*********************** CLONE ********************************************************/
128

    
129
	/**
130
	 * Clones <i>this</i> occurrence status. This is a shortcut that enables to create
131
	 * a new instance that differs only slightly from <i>this</i> occurrence status by
132
	 * modifying only some of the attributes.
133
	 *
134
	 * @see eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase#clone()
135
	 * @see java.lang.Object#clone()
136
	 */
137
	@Override
138
	public OccurrenceStatus clone() {
139
		try {
140
			OccurrenceStatus result = (OccurrenceStatus)super.clone();
141
	        //no changes to: type
142
			return result;
143
		} catch (CloneNotSupportedException e) {
144
			logger.warn("Object does not implement cloneable");
145
			e.printStackTrace();
146
			return null;
147
		}
148
	}
149
}
(10-10/15)