Revision 904cd1c0
Added by Andreas Kohlbecker almost 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/model/name/TaxonNameDTO.java | ||
---|---|---|
11 | 11 |
import java.util.HashSet; |
12 | 12 |
import java.util.List; |
13 | 13 |
import java.util.Set; |
14 |
import java.util.stream.Collectors; |
|
14 | 15 |
|
15 | 16 |
import org.joda.time.DateTime; |
16 | 17 |
|
... | ... | |
22 | 23 |
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction; |
23 | 24 |
import eu.etaxonomy.cdm.model.common.User; |
24 | 25 |
import eu.etaxonomy.cdm.model.name.HomotypicalGroup; |
26 |
import eu.etaxonomy.cdm.model.name.NameRelationship; |
|
25 | 27 |
import eu.etaxonomy.cdm.model.name.NameRelationshipType; |
26 | 28 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
27 | 29 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus; |
... | ... | |
37 | 39 |
*/ |
38 | 40 |
public class TaxonNameDTO extends CdmEntityDecoraterDTO<TaxonName> { |
39 | 41 |
|
40 |
class TN extends TaxonName { |
|
41 |
|
|
42 |
} |
|
43 |
|
|
44 | 42 |
private static final long serialVersionUID = -8018109905949198530L; |
45 | 43 |
|
46 | 44 |
private TaxonName name; |
... | ... | |
49 | 47 |
|
50 | 48 |
private Set<TaxonName> persistedReplacedSynonyms; |
51 | 49 |
|
50 |
private TaxonName persistedValidatedName; |
|
51 |
|
|
52 | 52 |
/** |
53 | 53 |
* @param entity |
54 | 54 |
*/ |
... | ... | |
96 | 96 |
return replacedSynonyms; |
97 | 97 |
} |
98 | 98 |
|
99 |
public NameRelationshipDTO getValidationFor() { |
|
100 |
NameRelationshipDTO nameRelDto = null; |
|
101 |
NameRelationship validatingRelationship = validatingRelationship(); |
|
102 |
if(validatingRelationship != null){ |
|
103 |
nameRelDto = new NameRelationshipDTO(Direction.relatedTo, validatingRelationship); |
|
104 |
if(persistedValidatedName == null){ |
|
105 |
persistedValidatedName = nameRelDto.getOtherName(); |
|
106 |
} |
|
107 |
} |
|
108 |
return nameRelDto; |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* @return |
|
113 |
*/ |
|
114 |
protected NameRelationship validatingRelationship() { |
|
115 |
Set<NameRelationship> toRelations = name.getRelationsToThisName(); |
|
116 |
Set<NameRelationship> validatedNameRelations = toRelations.stream().filter( |
|
117 |
nr -> nr.getType().equals(NameRelationshipType.VALIDATED_BY_NAME()) |
|
118 |
).collect(Collectors.toSet()); |
|
119 |
if(validatedNameRelations.size() > 1){ |
|
120 |
// TODO use non RuntimeException |
|
121 |
throw new RuntimeException("More than one validated name found."); |
|
122 |
} else if(validatedNameRelations.size() == 0) { |
|
123 |
return null; |
|
124 |
} |
|
125 |
return validatedNameRelations.iterator().next(); |
|
126 |
} |
|
127 |
|
|
128 |
public void setValidationFor(NameRelationshipDTO nameRelDto) { |
|
129 |
|
|
130 |
if(nameRelDto != null && nameRelDto.getOtherName() == null){ |
|
131 |
// treat as if there is no validation |
|
132 |
nameRelDto = null; |
|
133 |
} |
|
134 |
|
|
135 |
NameRelationship validatingRelationship = validatingRelationship(); |
|
136 |
|
|
137 |
if(nameRelDto != null){ |
|
138 |
// add or update ... |
|
139 |
if(validatingRelationship != null && persistedValidatedName != null && validatingRelationship.getFromName().equals(persistedValidatedName)){ |
|
140 |
// validated name has not changed, so we can update the relation |
|
141 |
validatingRelationship.setCitation(nameRelDto.getCitation()); |
|
142 |
validatingRelationship.setCitationMicroReference(nameRelDto.getCitationMicroReference()); |
|
143 |
validatingRelationship.setRuleConsidered(nameRelDto.getRuleConsidered()); |
|
144 |
} else { |
|
145 |
// need to remove the old relationship and to create a new one. |
|
146 |
// the actual removal will take place .... |
|
147 |
name.addRelationshipFromName(nameRelDto.getOtherName(), NameRelationshipType.VALIDATED_BY_NAME(), |
|
148 |
nameRelDto.getCitation(), nameRelDto.getCitationMicroReference(), nameRelDto.getRuleConsidered()); |
|
149 |
if(persistedValidatedName != null){ |
|
150 |
name.removeRelationWithTaxonName(persistedValidatedName, Direction.relatedTo, NameRelationshipType.VALIDATED_BY_NAME()); |
|
151 |
} |
|
152 |
} |
|
153 |
} else { |
|
154 |
// remove ... |
|
155 |
if(persistedValidatedName != null && validatingRelationship != null){ |
|
156 |
name.removeRelationWithTaxonName(persistedValidatedName, Direction.relatedTo, NameRelationshipType.VALIDATED_BY_NAME()); |
|
157 |
} |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
99 | 161 |
public void setBasionyms(Set<TaxonName> basionyms) { |
100 | 162 |
setRelatedNames(Direction.relatedTo, NameRelationshipType.BASIONYM(), basionyms); |
101 | 163 |
} |
Also available in: Unified diff
ref #7364 validation section implemented in TaxonNameEditor