Project

General

Profile

« Previous | Next » 

Revision e5237e50

Added by Andreas Kohlbecker over 5 years ago

fix #7899 orthographic variant and corrections implemented in taxon name popup editor

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/model/name/TaxonNameDTO.java
46 46

  
47 47
    private TaxonName persistedValidatedName;
48 48

  
49
    private TaxonName persistedOrthographicVariant;
50

  
49 51
    /**
50 52
     * @param entity
51 53
     */
......
106 108

  
107 109
    public NameRelationshipDTO getValidationFor() {
108 110
        NameRelationshipDTO nameRelDto  = null;
109
        NameRelationship validatingRelationship = validatingRelationship();
111
        NameRelationship validatingRelationship = uniqueNameRelationship(NameRelationshipType.VALIDATED_BY_NAME(), Direction.relatedTo);
110 112
        if(validatingRelationship != null){
111 113
            nameRelDto = new NameRelationshipDTO(Direction.relatedTo, validatingRelationship);
112 114
            if(persistedValidatedName == null){
......
116 118
        return nameRelDto;
117 119
    }
118 120

  
119
    /**
120
     * @return
121
     */
122
    protected NameRelationship validatingRelationship() {
123
        Set<NameRelationship> toRelations = name.getRelationsToThisName();
124
        Set<NameRelationship> validatedNameRelations = toRelations.stream().filter(
125
                    nr -> nr.getType().equals(NameRelationshipType.VALIDATED_BY_NAME())
126
                ).collect(Collectors.toSet());
127
        if(validatedNameRelations.size() > 1){
128
            // TODO use non RuntimeException
129
            throw new RuntimeException("More than one validated name found.");
130
        } else if(validatedNameRelations.size() == 0) {
131
            return null;
121
    public void setValidationFor(NameRelationshipDTO nameRelDto) {
122
        setUniqeNameRelationDTO(nameRelDto, NameRelationshipType.VALIDATED_BY_NAME(), Direction.relatedTo, persistedValidatedName);
123
    }
124

  
125

  
126
    public NameRelationshipDTO getOrthographicVariant() {
127
        NameRelationshipDTO nameRelDto  = null;
128
        NameRelationship nameRelationship = uniqueNameRelationship(NameRelationshipType.ORTHOGRAPHIC_VARIANT(), Direction.relatedTo);
129
        if(nameRelationship != null){
130
            nameRelDto = new NameRelationshipDTO(Direction.relatedTo, nameRelationship);
131
            if(persistedOrthographicVariant == null){
132
               persistedOrthographicVariant = nameRelDto.getOtherName();
133
            }
132 134
        }
133
        return validatedNameRelations.iterator().next();
135
        return nameRelDto;
134 136
    }
135 137

  
136
    public void setValidationFor(NameRelationshipDTO nameRelDto) {
138
    public void setOrthographicVariant(NameRelationshipDTO nameRelDto) {
139
        setUniqeNameRelationDTO(nameRelDto, NameRelationshipType.ORTHOGRAPHIC_VARIANT(), Direction.relatedTo, persistedOrthographicVariant);
140
    }
137 141

  
142
    /**
143
     * @param nameRelDto
144
     * @param nameRelationshipType
145
     * @param direction
146
     * @param persistedRelatedName
147
     */
148
    public void setUniqeNameRelationDTO(NameRelationshipDTO nameRelDto, NameRelationshipType nameRelationshipType,
149
            Direction direction, TaxonName persistedRelatedName) {
138 150
        if(nameRelDto != null && nameRelDto.getOtherName() == null){
139
            // treat as if there is no validation
151
            // treat as if there is no related name
140 152
            nameRelDto = null;
141 153
        }
142 154

  
143
        NameRelationship validatingRelationship = validatingRelationship();
155
        NameRelationship relationship = uniqueNameRelationship(nameRelationshipType, direction);
144 156

  
145 157
        if(nameRelDto != null){
146 158
            // add or update ...
147
            if(validatingRelationship != null && persistedValidatedName != null && validatingRelationship.getFromName().equals(persistedValidatedName)){
148
                // validated name has not changed, so we can update the relation
149
                validatingRelationship.setCitation(nameRelDto.getCitation());
150
                validatingRelationship.setCitationMicroReference(nameRelDto.getCitationMicroReference());
151
                validatingRelationship.setRuleConsidered(nameRelDto.getRuleConsidered());
159
            boolean currentNameIsTarget = false;
160
            if(relationship != null && persistedRelatedName != null){
161
                if(direction == Direction.relatedTo){
162
                    relationship.getFromName().equals(persistedRelatedName);
163
                } else {
164
                    relationship.getToName().equals(persistedRelatedName);
165
                }
166
            }
167
            if(relationship != null && currentNameIsTarget){
168
                // related name has not changed, so we can update the relation
169
                relationship.setCitation(nameRelDto.getCitation());
170
                relationship.setCitationMicroReference(nameRelDto.getCitationMicroReference());
171
                relationship.setRuleConsidered(nameRelDto.getRuleConsidered());
152 172
            } else {
153 173
                // need to remove the old relationship and to create a new one.
154 174
                // the actual removal will take place ....
155
                name.addRelationshipFromName(nameRelDto.getOtherName(), NameRelationshipType.VALIDATED_BY_NAME(),
156
                        nameRelDto.getCitation(), nameRelDto.getCitationMicroReference(), nameRelDto.getRuleConsidered());
157
                if(persistedValidatedName != null){
158
                    name.removeRelationWithTaxonName(persistedValidatedName, Direction.relatedTo, NameRelationshipType.VALIDATED_BY_NAME());
175
                if(direction == Direction.relatedTo){
176
                    name.addRelationshipFromName(nameRelDto.getOtherName(), nameRelationshipType,
177
                            nameRelDto.getCitation(), nameRelDto.getCitationMicroReference(), nameRelDto.getRuleConsidered());
178
                } else {
179
                    name.addRelationshipToName(nameRelDto.getOtherName(), nameRelationshipType,
180
                            nameRelDto.getCitation(), nameRelDto.getCitationMicroReference(), nameRelDto.getRuleConsidered());
181
                }
182
                if(persistedRelatedName != null){
183
                    name.removeRelationWithTaxonName(persistedRelatedName, direction, nameRelationshipType);
159 184
                }
160 185
            }
161 186
        } else {
162 187
            // remove ...
163
            if(persistedValidatedName != null && validatingRelationship != null){
164
                name.removeRelationWithTaxonName(persistedValidatedName, Direction.relatedTo, NameRelationshipType.VALIDATED_BY_NAME());
188
            if(persistedRelatedName != null && relationship != null){
189
                name.removeRelationWithTaxonName(persistedRelatedName, direction, nameRelationshipType);
165 190
            }
166 191
        }
167 192
    }
......
174 199
        setRelatedNames(Direction.relatedTo, NameRelationshipType.REPLACED_SYNONYM(), replacedSynonyms);
175 200
    }
176 201

  
202
    /**
203
     * @return
204
     */
205
    protected NameRelationship uniqueNameRelationship(NameRelationshipType relationShipType, Direction direction) {
206

  
207
        Set<NameRelationship> relations;
208

  
209
        if(direction == Direction.relatedTo){
210
            relations = name.getRelationsToThisName();
211
        } else {
212
            relations = name.getRelationsFromThisName();
213
        }
214
        Set<NameRelationship> nameRelations = relations.stream().filter(
215
                    nr -> nr.getType().equals(relationShipType)
216
                ).collect(Collectors.toSet());
217
        if(nameRelations.size() > 1){
218
            // TODO use non RuntimeException
219
            throw new RuntimeException("More than one relationship of type " + relationShipType.getLabel() + " found.");
220
        } else if(nameRelations.size() == 0) {
221
            return null;
222
        }
223
        return nameRelations.iterator().next();
224
    }
225

  
177 226
    /**
178 227
     * @param basionyms
179 228
     * @param relType

Also available in: Unified diff