Revision 0da64da4
Added by Katja Luther over 2 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/CharacterDto.java | ||
---|---|---|
45 | 45 |
private TermNodeDto ratioTo; |
46 | 46 |
|
47 | 47 |
public CharacterDto(UUID uuid, Set<Representation> representations, UUID partOfUuid, UUID kindOfUuid, |
48 |
UUID vocabularyUuid, Integer orderIndex, String idInVocabulary, //Set<Representation> vocRepresentations,
|
|
48 |
UUID vocabularyUuid, Integer orderIndex, String idInVocabulary, |
|
49 | 49 |
boolean isAvailableForTaxon, boolean isAvailableForTaxonName, boolean isAvailableForOccurrence, |
50 | 50 |
String titleCache, TermNodeDto structure, TermDto structureModifier, TermNodeDto property, |
51 | 51 |
TermDto propertyModifier, TermNodeDto ratioTo, boolean isSupportCategoricalData, boolean isSupportsQuantitativeData, Set<TermVocabularyDto> supportedCategoricalEnumerations, Set<TermVocabularyDto> recommendedModifierEnumeration, Set<TermDto> recommendedMeasurementUnits, Set<TermDto> recommendedStatisticalMeasures) { |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/FeatureDto.java | ||
---|---|---|
50 | 50 |
Set<TermVocabularyDto> recommendedModifierEnumeration = new HashSet<>(); |
51 | 51 |
|
52 | 52 |
public FeatureDto(UUID uuid, Set<Representation> representations, UUID partOfUuid, UUID kindOfUuid, |
53 |
UUID vocabularyUuid, Integer orderIndex, String idInVocabulary, //Set<Representation> vocRepresentations,
|
|
53 |
UUID vocabularyUuid, Integer orderIndex, String idInVocabulary, |
|
54 | 54 |
boolean isAvailableForTaxon, boolean isAvailableForTaxonName, boolean isAvailableForOccurrence, String titleCache, boolean isSupportsCategoricalData, boolean isSupportsQuantitativeData, |
55 | 55 |
Set<TermVocabularyDto> supportedCategoricalEnumerations, Set<TermVocabularyDto> recommendedModifierEnumeration, Set<TermDto> recommendedMeasurementUnits, Set<TermDto> recommendedStatisticalMeasures){ |
56 | 56 |
super(uuid, representations, TermType.Feature, partOfUuid, kindOfUuid, |
... | ... | |
389 | 389 |
if (o instanceof StatisticalMeasure){ |
390 | 390 |
recommendedStatisticalMeasuresDtos.add(TermDto.fromTerm((StatisticalMeasure)o)); |
391 | 391 |
}else if (o instanceof Set){ |
392 |
Set<StatisticalMeasure> recommendedStatisticalMeasures = (Set<StatisticalMeasure>) o;
|
|
392 |
Set<StatisticalMeasure> recommendedStatisticalMeasures = new HashSet((Set<StatisticalMeasure>) o);
|
|
393 | 393 |
if (recommendedStatisticalMeasures != null) { |
394 | 394 |
for (StatisticalMeasure term: recommendedStatisticalMeasures){ |
395 | 395 |
recommendedStatisticalMeasuresDtos.add(TermDto.fromTerm(term)); |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/FeatureStateDto.java | ||
---|---|---|
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.persistence.dto; |
|
10 |
|
|
11 |
import java.util.UUID; |
|
12 |
|
|
13 |
import eu.etaxonomy.cdm.model.description.FeatureState; |
|
14 |
|
|
15 |
/** |
|
16 |
* @author k.luther |
|
17 |
* @since 29.11.2021 |
|
18 |
*/ |
|
19 |
public class FeatureStateDto extends UuidAndTitleCache<FeatureState>{ |
|
20 |
|
|
21 |
private static final long serialVersionUID = -240581482613107317L; |
|
22 |
|
|
23 |
private FeatureDto feature; |
|
24 |
private TermDto state; |
|
25 |
|
|
26 |
/** |
|
27 |
* @param uuid |
|
28 |
* @param titleCache |
|
29 |
*/ |
|
30 |
public FeatureStateDto(UUID uuid, FeatureDto feature, TermDto state) { |
|
31 |
super(uuid, ""); |
|
32 |
this.feature = feature; |
|
33 |
this.state = state; |
|
34 |
} |
|
35 |
/** |
|
36 |
* @return the feature |
|
37 |
*/ |
|
38 |
public FeatureDto getFeature() { |
|
39 |
return feature; |
|
40 |
} |
|
41 |
|
|
42 |
/** |
|
43 |
* @param feature the feature to set |
|
44 |
*/ |
|
45 |
public void setFeature(FeatureDto feature) { |
|
46 |
this.feature = feature; |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* @return the state |
|
51 |
*/ |
|
52 |
public TermDto getState() { |
|
53 |
return state; |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* @param state the state to set |
|
58 |
*/ |
|
59 |
public void setState(TermDto state) { |
|
60 |
this.state = state; |
|
61 |
} |
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/FeatureStateDtoComparator.java | ||
---|---|---|
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.persistence.dto; |
|
10 |
|
|
11 |
import java.io.Serializable; |
|
12 |
import java.util.Comparator; |
|
13 |
|
|
14 |
/** |
|
15 |
* @author k.luther |
|
16 |
* @since 30.11.2021 |
|
17 |
*/ |
|
18 |
public class FeatureStateDtoComparator implements Serializable, Comparator<FeatureStateDto> { |
|
19 |
|
|
20 |
private static final long serialVersionUID = -4808908193485190520L; |
|
21 |
|
|
22 |
@Override |
|
23 |
public int compare(FeatureStateDto o1, FeatureStateDto o2) { |
|
24 |
if(o1==null){ |
|
25 |
return -1; |
|
26 |
} |
|
27 |
if(o2==null){ |
|
28 |
return 1; |
|
29 |
} |
|
30 |
if (o1.getUuid() == null && o2.getUuid() != null){ |
|
31 |
return -1; |
|
32 |
} |
|
33 |
if (o2.getUuid() == null && o1.getUuid() != null){ |
|
34 |
return 1; |
|
35 |
} |
|
36 |
if (o1.getUuid() != null && o2.getUuid() != null){ |
|
37 |
return o1.getFeature().getTitleCache().compareTo(o2.getTitleCache()); |
|
38 |
} else { |
|
39 |
return o1.getFeature().getUuid().compareTo(o2.getFeature().getUuid()); |
|
40 |
} |
|
41 |
|
|
42 |
} |
|
43 |
|
|
44 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TermNodeDto.java | ||
---|---|---|
33 | 33 |
private UUID parentUuid; |
34 | 34 |
private String treeIndex; |
35 | 35 |
private List<TermNodeDto> children; |
36 |
private Set<FeatureState> onlyApplicableIf = new HashSet<>(); |
|
37 |
private Set<FeatureState> inapplicableIf = new HashSet<>(); |
|
36 |
private Set<FeatureStateDto> onlyApplicableIf = new HashSet<>();
|
|
37 |
private Set<FeatureStateDto> inapplicableIf = new HashSet<>();
|
|
38 | 38 |
private UUID uuid; |
39 | 39 |
private TermDto term; |
40 | 40 |
private TermType type; |
... | ... | |
47 | 47 |
if (treeDto != null){ |
48 | 48 |
treeDto.addTerm(term); |
49 | 49 |
} |
50 |
|
|
50 | 51 |
TermNodeDto dto = new TermNodeDto(term, node.getParent() != null? node.getParent().getIndex(node): 0, treeDto != null? treeDto: TermTreeDto.fromTree((TermTree)node.getGraph()), node.getUuid(), node.treeIndex(), node.getPath()); |
51 | 52 |
if (node.getParent() != null){ |
52 | 53 |
dto.setParentUuid(node.getParent().getUuid()); |
53 | 54 |
} |
54 |
|
|
55 |
|
|
55 | 56 |
List<TermNodeDto> children = new ArrayList<>(); |
56 | 57 |
for (Object o: node.getChildNodes()){ |
57 | 58 |
if (o instanceof TermNode){ |
... | ... | |
152 | 153 |
this.children = children; |
153 | 154 |
} |
154 | 155 |
|
155 |
public Set<FeatureState> getOnlyApplicableIf() { |
|
156 |
public Set<FeatureStateDto> getOnlyApplicableIf() {
|
|
156 | 157 |
return onlyApplicableIf; |
157 | 158 |
} |
158 | 159 |
|
159 |
public void setOnlyApplicableIf(Set<FeatureState> onlyApplicableIf) {
|
|
160 |
public void setOnlyApplicableIfDto(Set<FeatureStateDto> onlyApplicableIf) {
|
|
160 | 161 |
this.onlyApplicableIf = onlyApplicableIf; |
161 | 162 |
} |
163 |
public void setOnlyApplicableIf(Set<FeatureState> onlyApplicableIf) { |
|
164 |
if (this.onlyApplicableIf == null){ |
|
165 |
this.onlyApplicableIf = new HashSet<>(); |
|
166 |
} |
|
167 |
for (FeatureState state: onlyApplicableIf){ |
|
168 |
this.onlyApplicableIf.add(new FeatureStateDto(state.getUuid(), FeatureDto.fromFeature(state.getFeature()), TermDto.fromTerm(state.getState()))); |
|
169 |
} |
|
162 | 170 |
|
163 |
public Set<FeatureState> getInapplicableIf() { |
|
171 |
} |
|
172 |
|
|
173 |
public Set<FeatureStateDto> getInapplicableIf() { |
|
164 | 174 |
return inapplicableIf; |
165 | 175 |
} |
166 | 176 |
|
167 |
public void setInapplicableIf(Set<FeatureState> inapplicableIf) {
|
|
177 |
public void setInapplicableIfDto(Set<FeatureStateDto> inapplicableIf) {
|
|
168 | 178 |
this.inapplicableIf = inapplicableIf; |
169 | 179 |
} |
170 | 180 |
|
181 |
public void setInapplicableIf(Set<FeatureState> inApplicableIf) { |
|
182 |
if (this.inapplicableIf == null){ |
|
183 |
this.inapplicableIf = new HashSet<>(); |
|
184 |
} |
|
185 |
for (FeatureState state: inApplicableIf){ |
|
186 |
this.inapplicableIf.add( new FeatureStateDto(state.getUuid(),FeatureDto.fromFeature(state.getFeature()), TermDto.fromTerm(state.getState()))); |
|
187 |
} |
|
188 |
|
|
189 |
} |
|
190 |
|
|
171 | 191 |
public UUID getUuid() { |
172 | 192 |
return uuid; |
173 | 193 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TermNodeServiceImpl.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.cdm.api.service; |
11 | 11 |
|
12 | 12 |
import java.util.ArrayList; |
13 |
import java.util.HashMap; |
|
13 | 14 |
import java.util.HashSet; |
14 | 15 |
import java.util.List; |
15 | 16 |
import java.util.Map; |
... | ... | |
30 | 31 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
31 | 32 |
import eu.etaxonomy.cdm.model.description.Character; |
32 | 33 |
import eu.etaxonomy.cdm.model.description.Feature; |
34 |
import eu.etaxonomy.cdm.model.description.FeatureState; |
|
33 | 35 |
import eu.etaxonomy.cdm.model.description.MeasurementUnit; |
36 |
import eu.etaxonomy.cdm.model.description.State; |
|
34 | 37 |
import eu.etaxonomy.cdm.model.description.StatisticalMeasure; |
35 | 38 |
import eu.etaxonomy.cdm.model.term.DefinedTerm; |
36 | 39 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
... | ... | |
42 | 45 |
import eu.etaxonomy.cdm.persistence.dao.term.ITermNodeDao; |
43 | 46 |
import eu.etaxonomy.cdm.persistence.dto.CharacterDto; |
44 | 47 |
import eu.etaxonomy.cdm.persistence.dto.CharacterNodeDto; |
48 |
import eu.etaxonomy.cdm.persistence.dto.FeatureStateDto; |
|
45 | 49 |
import eu.etaxonomy.cdm.persistence.dto.MergeResult; |
46 | 50 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
47 | 51 |
import eu.etaxonomy.cdm.persistence.dto.TermNodeDto; |
... | ... | |
248 | 252 |
|
249 | 253 |
if (dto.getUuid().equals(node.getUuid())){ |
250 | 254 |
// only node changes, everything else will be handled by the operations/service methods |
251 |
if (!dto.getInapplicableIf().equals(node.getInapplicableIf())){ |
|
252 |
node.getInapplicableIf().clear(); |
|
253 |
node.getInapplicableIf().addAll(dto.getInapplicableIf()); |
|
254 |
} |
|
255 |
if (!dto.getOnlyApplicableIf().equals(node.getOnlyApplicableIf())){ |
|
256 |
node.getOnlyApplicableIf().clear(); |
|
257 |
node.getOnlyApplicableIf().addAll(dto.getOnlyApplicableIf()); |
|
258 |
} |
|
255 |
updateFeatureStates(node, dto, true); |
|
256 |
updateFeatureStates(node, dto, false); |
|
257 |
|
|
259 | 258 |
} |
260 | 259 |
MergeResult<TermNode> mergeResult = dao.merge(node, true); |
261 | 260 |
result.addUpdatedObject(mergeResult.getMergedEntity()); |
... | ... | |
264 | 263 |
return result; |
265 | 264 |
} |
266 | 265 |
|
266 |
/** |
|
267 |
* @param node |
|
268 |
* @param dto |
|
269 |
*/ |
|
270 |
private void updateFeatureStates(TermNode<?> node, TermNodeDto dto, boolean inApplicable) { |
|
271 |
Map<FeatureState, FeatureStateDto> changeState = new HashMap<>(); |
|
272 |
Set<FeatureStateDto> newStates = new HashSet<>(); |
|
273 |
Set<FeatureState> deleteState = new HashSet<>(); |
|
274 |
boolean stillExist = false; |
|
275 |
Set<FeatureState> setToUpdate = null; |
|
276 |
Set<FeatureStateDto> setForUpdate = null; |
|
277 |
if (inApplicable){ |
|
278 |
setToUpdate = node.getInapplicableIf(); |
|
279 |
setForUpdate = dto.getInapplicableIf(); |
|
280 |
}else{ |
|
281 |
setToUpdate = node.getOnlyApplicableIf(); |
|
282 |
setForUpdate = dto.getOnlyApplicableIf(); |
|
283 |
} |
|
284 |
for (FeatureState featureState: setToUpdate){ |
|
285 |
stillExist = false; |
|
286 |
for (FeatureStateDto featureStateDto: setForUpdate){ |
|
287 |
if (featureStateDto.getUuid() != null && featureStateDto.getUuid().equals(featureState.getUuid())){ |
|
288 |
stillExist = true; |
|
289 |
if (featureStateDto.getFeature().getUuid().equals(featureState.getFeature().getUuid()) && featureStateDto.getState().getUuid().equals(featureState.getState().getUuid())){ |
|
290 |
//do nothing |
|
291 |
}else{ |
|
292 |
changeState.put(featureState, featureStateDto); |
|
293 |
} |
|
294 |
break; |
|
295 |
} |
|
296 |
} |
|
297 |
if (!stillExist){ |
|
298 |
deleteState.add(featureState); |
|
299 |
} |
|
300 |
|
|
301 |
} |
|
302 |
|
|
303 |
for (FeatureStateDto featureStateDto: setForUpdate){ |
|
304 |
stillExist = false; |
|
305 |
if (featureStateDto.getUuid() == null){ |
|
306 |
newStates.add(featureStateDto); |
|
307 |
}else{ |
|
308 |
for (FeatureState featureState: setToUpdate){ |
|
309 |
if (featureStateDto.getUuid() != null && featureStateDto.getUuid().equals(featureState.getUuid())){ |
|
310 |
stillExist = true; |
|
311 |
break; |
|
312 |
} |
|
313 |
} |
|
314 |
if (!stillExist){ |
|
315 |
newStates.add(featureStateDto); |
|
316 |
} |
|
317 |
} |
|
318 |
|
|
319 |
} |
|
320 |
if (inApplicable){ |
|
321 |
node.getInapplicableIf().removeAll(deleteState); |
|
322 |
}else{ |
|
323 |
node.getOnlyApplicableIf().removeAll(deleteState); |
|
324 |
} |
|
325 |
for (Entry<FeatureState, FeatureStateDto> change: changeState.entrySet()){ |
|
326 |
if (!change.getKey().getFeature().getUuid().equals(change.getValue().getFeature().getUuid())){ |
|
327 |
DefinedTermBase term = termService.load(change.getValue().getFeature().getUuid()); |
|
328 |
if (term instanceof Feature){ |
|
329 |
Feature feature = HibernateProxyHelper.deproxy(term, Feature.class); |
|
330 |
change.getKey().setFeature(feature); |
|
331 |
} |
|
332 |
|
|
333 |
} |
|
334 |
if (!change.getKey().getState().getUuid().equals(change.getValue().getState().getUuid())){ |
|
335 |
DefinedTermBase term = termService.load(change.getValue().getState().getUuid()); |
|
336 |
if (term instanceof State){ |
|
337 |
State state = HibernateProxyHelper.deproxy(term, State.class); |
|
338 |
change.getKey().setState(state); |
|
339 |
} |
|
340 |
|
|
341 |
} |
|
342 |
if (inApplicable){ |
|
343 |
node.getInapplicableIf().add(change.getKey()); |
|
344 |
}else{ |
|
345 |
node.getOnlyApplicableIf().add(change.getKey()); |
|
346 |
} |
|
347 |
} |
|
348 |
for (FeatureStateDto stateDto: newStates){ |
|
349 |
Feature feature = null; |
|
350 |
State state = null; |
|
351 |
DefinedTermBase term = termService.load(stateDto.getFeature().getUuid()); |
|
352 |
if (term instanceof Feature){ |
|
353 |
feature = HibernateProxyHelper.deproxy(term, Feature.class); |
|
354 |
} |
|
355 |
term = termService.load(stateDto.getState().getUuid()); |
|
356 |
if (term instanceof State){ |
|
357 |
state = HibernateProxyHelper.deproxy(term, State.class); |
|
358 |
} |
|
359 |
FeatureState newState = FeatureState.NewInstance(feature, state); |
|
360 |
if (inApplicable){ |
|
361 |
node.getInapplicableIf().add(newState); |
|
362 |
}else{ |
|
363 |
node.getOnlyApplicableIf().add(newState); |
|
364 |
} |
|
365 |
} |
|
366 |
} |
|
367 |
|
|
267 | 368 |
@Override |
268 | 369 |
public UpdateResult saveCharacterNodeDtoList(List<CharacterNodeDto> dtos){ |
269 | 370 |
MergeResult<TermNode> mergeResult; |
... | ... | |
277 | 378 |
for (CharacterNodeDto dto: dtos){ |
278 | 379 |
// TermNodeDto dto = dtoIterator.next(); |
279 | 380 |
if (dto.getUuid().equals(node.getUuid())){ |
280 |
|
|
281 |
if (!dto.getInapplicableIf().equals(node.getInapplicableIf())){ |
|
282 |
node.getInapplicableIf().clear(); |
|
283 |
node.getInapplicableIf().addAll(dto.getInapplicableIf()); |
|
284 |
} |
|
285 |
if (!dto.getOnlyApplicableIf().equals(node.getOnlyApplicableIf())){ |
|
286 |
node.getOnlyApplicableIf().clear(); |
|
287 |
node.getOnlyApplicableIf().addAll(dto.getOnlyApplicableIf()); |
|
288 |
} |
|
381 |
updateFeatureStates(node, dto, true); |
|
382 |
updateFeatureStates(node, dto, false); |
|
383 |
// if (!dto.getInapplicableIf().equals(node.getInapplicableIf())){ |
|
384 |
// node.getInapplicableIf().clear(); |
|
385 |
// node.getInapplicableIf().addAll(dto.getInapplicableIf()); |
|
386 |
// } |
|
387 |
// if (!dto.getOnlyApplicableIf().equals(node.getOnlyApplicableIf())){ |
|
388 |
// node.getOnlyApplicableIf().clear(); |
|
389 |
// node.getOnlyApplicableIf().addAll(dto.getOnlyApplicableIf()); |
|
390 |
// } |
|
289 | 391 |
|
290 | 392 |
Character character = null; |
291 | 393 |
CharacterDto characterDto = (CharacterDto) dto.getTerm(); |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TermServiceImpl.java | ||
---|---|---|
635 | 635 |
|
636 | 636 |
@Override |
637 | 637 |
public Map<UUID, TermDto> findFeatureByUUIDsAsDtos(List<UUID> uuidList){ |
638 |
if (uuidList == null || uuidList.isEmpty()){ |
|
639 |
return null; |
|
640 |
} |
|
638 | 641 |
Collection<TermDto> col = dao.findFeatureByUUIDsAsDto(uuidList); |
639 | 642 |
Map<UUID, TermDto> result = new HashMap<>(); |
640 |
for (TermDto dto: col){ |
|
641 |
result.put(dto.getUuid(), dto); |
|
643 |
if (col != null){ |
|
644 |
for (TermDto dto: col){ |
|
645 |
result.put(dto.getUuid(), dto); |
|
646 |
} |
|
642 | 647 |
} |
643 | 648 |
return result; |
644 | 649 |
} |
Also available in: Unified diff
ref #9861: termnode contains featurestate as dto