1
|
/**
|
2
|
* Copyright (C) 2020 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.taxon;
|
10
|
|
11
|
import java.beans.PropertyChangeListener;
|
12
|
|
13
|
import javax.persistence.Entity;
|
14
|
import javax.persistence.FetchType;
|
15
|
import javax.persistence.OneToOne;
|
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.hibernate.envers.Audited;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
24
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
|
25
|
import eu.etaxonomy.cdm.strategy.merge.Merge;
|
26
|
import eu.etaxonomy.cdm.strategy.merge.MergeMode;
|
27
|
|
28
|
/**
|
29
|
* This subclass of {@link DescriptionElementSource} exists to
|
30
|
* support bidirectionality for sources of type
|
31
|
* {@link OriginalSourceType#SecundumReference}.
|
32
|
* This is necessary e.g. to support recognition of state changes of the
|
33
|
* secundum reference which occur in the OriginalSource class
|
34
|
* but should be handled in the context of the {@link TaxonBase} instance
|
35
|
* this source instance belongs to.
|
36
|
*
|
37
|
* @author a.mueller
|
38
|
* @since 15.03.2021
|
39
|
*/
|
40
|
@XmlType(name = "SecundumSource", propOrder = {
|
41
|
})
|
42
|
@Entity
|
43
|
@Audited
|
44
|
public class SecundumSource extends DescriptionElementSource {
|
45
|
|
46
|
private static final long serialVersionUID = 7899107010799860914L;
|
47
|
|
48
|
public static SecundumSource NewSecundumInstance(TaxonBase<?> taxonBase) {
|
49
|
SecundumSource result = new SecundumSource();
|
50
|
result.sourcedTaxon = taxonBase;
|
51
|
return result;
|
52
|
}
|
53
|
|
54
|
// ************************* FIELDS ********************************/
|
55
|
|
56
|
@XmlElement(name = "sourcedTaxon")
|
57
|
@XmlIDREF
|
58
|
@XmlSchemaType(name = "IDREF")
|
59
|
@OneToOne(fetch = FetchType.LAZY /*, mappedBy="secSource"*/)
|
60
|
@Merge(value=MergeMode.MERGE) //TODO maybe there is a better solution
|
61
|
private TaxonBase<?> sourcedTaxon;
|
62
|
|
63
|
//*********************** CONSTRUCTOR ******************************/
|
64
|
|
65
|
@SuppressWarnings("deprecation")
|
66
|
public SecundumSource(){
|
67
|
setType(OriginalSourceType.SecundumReference);
|
68
|
initListener();
|
69
|
}
|
70
|
|
71
|
@Override
|
72
|
public void initListener(){
|
73
|
PropertyChangeListener sourceListener = event->{
|
74
|
String propName = event.getPropertyName();
|
75
|
if (propName.equals("citation")){
|
76
|
sourcedTaxon.checkNullSource();
|
77
|
}
|
78
|
if (propName.equals("citationMicroReference")){
|
79
|
if (event.getNewValue() == null) {
|
80
|
sourcedTaxon.checkNullSource();
|
81
|
}
|
82
|
}
|
83
|
sourcedTaxon.setTitleCache(null);
|
84
|
};
|
85
|
addPropertyChangeListener(sourceListener);
|
86
|
}
|
87
|
|
88
|
//***************** GETTER / SETTER ****************************/
|
89
|
|
90
|
public TaxonBase<?> getSourcedTaxon() {
|
91
|
return sourcedTaxon;
|
92
|
}
|
93
|
|
94
|
public void setSourcedTaxon(TaxonBase<?> sourcedTaxon) {
|
95
|
if (this.sourcedTaxon != sourcedTaxon){
|
96
|
this.sourcedTaxon = sourcedTaxon;
|
97
|
if (sourcedTaxon != null){
|
98
|
sourcedTaxon.setSecSource(this);
|
99
|
}
|
100
|
}
|
101
|
}
|
102
|
|
103
|
//************************* CLONE() ************************/
|
104
|
|
105
|
@Override
|
106
|
public SecundumSource clone() {
|
107
|
SecundumSource result;
|
108
|
try {
|
109
|
result = (SecundumSource)super.clone();
|
110
|
//a taxon may only have 1 single sec source at time
|
111
|
result.sourcedTaxon = null;
|
112
|
|
113
|
//no changes
|
114
|
return result;
|
115
|
} catch (CloneNotSupportedException e) {
|
116
|
throw new RuntimeException(e); //this should not happen
|
117
|
}
|
118
|
}
|
119
|
}
|