1
|
/**
|
2
|
* Copyright (C) 2021 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.reference;
|
10
|
|
11
|
import javax.persistence.FetchType;
|
12
|
import javax.persistence.ManyToOne;
|
13
|
import javax.persistence.MappedSuperclass;
|
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.XmlRootElement;
|
19
|
import javax.xml.bind.annotation.XmlSchemaType;
|
20
|
import javax.xml.bind.annotation.XmlType;
|
21
|
|
22
|
import org.apache.log4j.Logger;
|
23
|
import org.hibernate.annotations.Cascade;
|
24
|
import org.hibernate.annotations.CascadeType;
|
25
|
import org.hibernate.envers.Audited;
|
26
|
|
27
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
28
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
29
|
|
30
|
/**
|
31
|
* @author a.mueller
|
32
|
* @since 17.03.2021
|
33
|
*/
|
34
|
@XmlAccessorType(XmlAccessType.FIELD)
|
35
|
@XmlType(name = "NamedSourceBase", propOrder = {
|
36
|
"nameUsedInSource"
|
37
|
})
|
38
|
@XmlRootElement(name = "NamedSourceBase")
|
39
|
@MappedSuperclass
|
40
|
@Audited
|
41
|
public abstract class NamedSourceBase extends OriginalSourceBase {
|
42
|
|
43
|
private static final long serialVersionUID = 4262357256080305268L;
|
44
|
@SuppressWarnings("unused")
|
45
|
private static final Logger logger = Logger.getLogger(DescriptionElementSource.class);
|
46
|
|
47
|
// ************************* FIELDS ********************************/
|
48
|
|
49
|
@XmlElement(name = "nameUsedInSource")
|
50
|
@XmlIDREF
|
51
|
@XmlSchemaType(name = "IDREF")
|
52
|
@ManyToOne(fetch = FetchType.LAZY)
|
53
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
54
|
private TaxonName nameUsedInSource;
|
55
|
|
56
|
//*********************** CONSTRUCTOR ******************************/
|
57
|
|
58
|
//for hibernate use only
|
59
|
/**
|
60
|
* @deprecated for internal use only
|
61
|
*/
|
62
|
@Deprecated
|
63
|
protected NamedSourceBase(){}
|
64
|
|
65
|
protected NamedSourceBase(OriginalSourceType type){
|
66
|
super(type);
|
67
|
}
|
68
|
|
69
|
// ************************** GETTER / SETTER ***************************/
|
70
|
|
71
|
public TaxonName getNameUsedInSource() {
|
72
|
return nameUsedInSource;
|
73
|
}
|
74
|
|
75
|
public void setNameUsedInSource(TaxonName nameUsedInSource) {
|
76
|
this.nameUsedInSource = nameUsedInSource;
|
77
|
}
|
78
|
|
79
|
// **************** EMPTY ************************/
|
80
|
|
81
|
@Override
|
82
|
public boolean checkEmpty(){
|
83
|
return this.checkEmpty(false);
|
84
|
}
|
85
|
|
86
|
@Override
|
87
|
public boolean checkEmpty(boolean excludeType){
|
88
|
return super.checkEmpty(excludeType)
|
89
|
&& this.nameUsedInSource == null;
|
90
|
}
|
91
|
|
92
|
//*********************************** CLONE *********************************************************/
|
93
|
|
94
|
@Override
|
95
|
public NamedSourceBase clone() throws CloneNotSupportedException{
|
96
|
NamedSourceBase result = (NamedSourceBase)super.clone();
|
97
|
|
98
|
//no changes
|
99
|
return result;
|
100
|
}
|
101
|
|
102
|
//*********************************** EQUALS *********************************************************/
|
103
|
|
104
|
@Override
|
105
|
public boolean equalsByShallowCompare(OriginalSourceBase other) {
|
106
|
|
107
|
if(!super.equalsByShallowCompare(other)) {
|
108
|
return false;
|
109
|
}
|
110
|
|
111
|
int a = -1;
|
112
|
int b = -1;
|
113
|
if(this.getNameUsedInSource() != null) {
|
114
|
a = this.getNameUsedInSource().getId();
|
115
|
}
|
116
|
NamedSourceBase otherNamedSource = (NamedSourceBase)other;
|
117
|
if(otherNamedSource.getNameUsedInSource() != null) {
|
118
|
b = otherNamedSource.getNameUsedInSource().getId();
|
119
|
}
|
120
|
return a == b;
|
121
|
}
|
122
|
}
|