Revision 434cbfa8
Added by Andreas Kohlbecker almost 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/model/name/TaxonNameDTO.java | ||
---|---|---|
45 | 45 |
|
46 | 46 |
private TaxonName name; |
47 | 47 |
|
48 |
private Set<TaxonName> persistedBasionyms; |
|
49 |
|
|
48 | 50 |
/** |
49 | 51 |
* @param entity |
50 | 52 |
*/ |
... | ... | |
75 | 77 |
} |
76 | 78 |
|
77 | 79 |
public Set<TaxonName> getBasionyms() { |
78 |
return name.getRelatedNames(Direction.relatedTo, NameRelationshipType.BASIONYM()); |
|
80 |
Set<TaxonName> basionyms = name.getRelatedNames(Direction.relatedTo, NameRelationshipType.BASIONYM()); |
|
81 |
if(persistedBasionyms == null){ |
|
82 |
// remember the persisted state before starting to operate on the DTO |
|
83 |
persistedBasionyms = basionyms; |
|
84 |
} |
|
85 |
return basionyms; |
|
79 | 86 |
} |
80 | 87 |
|
81 | 88 |
public void setBasionyms(Set<TaxonName> basionyms) { |
82 |
setRelatedTaxa(Direction.relatedTo, NameRelationshipType.BASIONYM(), basionyms);
|
|
89 |
setRelatedNames(Direction.relatedTo, NameRelationshipType.BASIONYM(), basionyms);
|
|
83 | 90 |
} |
84 | 91 |
|
85 | 92 |
/** |
... | ... | |
87 | 94 |
* @param relType |
88 | 95 |
* @param direction |
89 | 96 |
*/ |
90 |
protected void setRelatedTaxa(Direction direction, NameRelationshipType relType, Set<TaxonName> basionyms) {
|
|
91 |
Set<TaxonName> currentBasionyms = new HashSet<>();
|
|
92 |
Set<TaxonName> basionymsSeen = new HashSet<>();
|
|
97 |
protected void setRelatedNames(Direction direction, NameRelationshipType relType, Set<TaxonName> relatedNames) {
|
|
98 |
Set<TaxonName> currentRelatedNames = new HashSet<>();
|
|
99 |
Set<TaxonName> namesSeen = new HashSet<>();
|
|
93 | 100 |
|
94 | 101 |
for(TaxonName tn : name.getRelatedNames(direction, relType)){ |
95 |
currentBasionyms.add(tn);
|
|
102 |
currentRelatedNames.add(tn);
|
|
96 | 103 |
} |
97 |
for(TaxonName tn : basionyms){ |
|
98 |
if(!currentBasionyms.contains(tn)){ |
|
99 |
name.addBasionym(tn); |
|
104 |
for(TaxonName tn : relatedNames){ |
|
105 |
if(!currentRelatedNames.contains(tn)){ |
|
106 |
if(direction.equals(Direction.relatedTo)){ |
|
107 |
tn.addRelationshipToName(name, relType, null); |
|
108 |
} else { |
|
109 |
tn.addRelationshipFromName(name, relType, null); |
|
110 |
} |
|
100 | 111 |
} |
101 |
basionymsSeen.add(tn);
|
|
112 |
namesSeen.add(tn);
|
|
102 | 113 |
} |
103 |
for(TaxonName tn : currentBasionyms){
|
|
104 |
if(!basionymsSeen.contains(tn)){
|
|
114 |
for(TaxonName tn : currentRelatedNames){
|
|
115 |
if(!namesSeen.contains(tn)){
|
|
105 | 116 |
name.removeRelationWithTaxonName(tn, direction, relType); |
106 | 117 |
} |
107 | 118 |
} |
108 | 119 |
} |
109 | 120 |
|
121 |
public Set<TaxonName> persistedBasionyms(){ |
|
122 |
return persistedBasionyms; |
|
123 |
} |
|
124 |
|
|
110 | 125 |
public TeamOrPersonBase<?> getCombinationAuthorship() { |
111 | 126 |
return name.getCombinationAuthorship(); |
112 | 127 |
} |
Also available in: Unified diff
ref #7386 adding missing setBasionyms() method to taxonNameDTO - 3