use of eu.etaxonomy.cdm.model.description.StatisticalMeasure in project cdmlib by cybertaxonomy.
the class TermNodeServiceImpl method saveCharacterNodeDtoList.
@Override
public UpdateResult saveCharacterNodeDtoList(List<CharacterNodeDto> dtos) {
MergeResult<TermNode> mergeResult;
UpdateResult result = new UpdateResult();
List<UUID> nodeUuids = new ArrayList<>();
dtos.stream().forEach(dto -> nodeUuids.add(dto.getUuid()));
List<TermNode> nodes = dao.list(nodeUuids, null, 0, null, null);
// check all attributes for changes and adapt
for (TermNode<Character> node : nodes) {
for (CharacterNodeDto dto : dtos) {
// TermNodeDto dto = dtoIterator.next();
if (dto.getUuid().equals(node.getUuid())) {
updateFeatureStates(node, dto, true);
updateFeatureStates(node, dto, false);
// if (!dto.getInapplicableIf().equals(node.getInapplicableIf())){
// node.getInapplicableIf().clear();
// node.getInapplicableIf().addAll(dto.getInapplicableIf());
// }
// if (!dto.getOnlyApplicableIf().equals(node.getOnlyApplicableIf())){
// node.getOnlyApplicableIf().clear();
// node.getOnlyApplicableIf().addAll(dto.getOnlyApplicableIf());
// }
Character character = null;
CharacterDto characterDto = (CharacterDto) dto.getTerm();
character = HibernateProxyHelper.deproxy(node.getTerm(), Character.class);
if (characterDto.getRatioTo() != null) {
TermNode ratioToStructure = this.load(characterDto.getRatioTo().getUuid());
character.setRatioToStructure(ratioToStructure);
} else {
character.setRatioToStructure(null);
}
// supportsXXX
// TODO add all other supportsXXX (6 are missing)
character.setSupportsCategoricalData(characterDto.isSupportsCategoricalData());
character.setSupportsQuantitativeData(characterDto.isSupportsQuantitativeData());
// availableForXXX
character.setAvailableForTaxon(characterDto.isAvailableForTaxon());
character.setAvailableForOccurrence(characterDto.isAvailableForOccurrence());
character.setAvailableForTaxonName(characterDto.isAvailableForTaxonName());
// representations
for (Representation rep : dto.getTerm().getRepresentations()) {
Representation oldRep = character.getRepresentation(rep.getLanguage());
if (oldRep == null) {
oldRep = new Representation();
oldRep.setLanguage(rep.getLanguage());
character.addRepresentation(oldRep);
}
oldRep.setLabel(rep.getLabel());
oldRep.setAbbreviatedLabel(rep.getAbbreviatedLabel());
oldRep.setText(rep.getText());
oldRep.setPlural(rep.getPlural());
}
Set<Representation> deleteRepresentations = new HashSet<>();
if (character.getRepresentations().size() > dto.getTerm().getRepresentations().size()) {
for (Representation rep : character.getRepresentations()) {
if (dto.getTerm().getRepresentation(rep.getLanguage()) == null) {
deleteRepresentations.add(rep);
}
}
}
if (!deleteRepresentations.isEmpty()) {
for (Representation rep : deleteRepresentations) {
character.removeRepresentation(rep);
}
}
// structural modifier
if (characterDto.getStructureModifier() != null) {
DefinedTerm structureModifier = (DefinedTerm) termService.load(characterDto.getStructureModifier().getUuid());
character.setStructureModifier(structureModifier);
} else {
character.setStructureModifier(null);
}
// recommended measurement units
character.getRecommendedMeasurementUnits().clear();
List<UUID> uuids = new ArrayList<>();
for (TermDto termDto : characterDto.getRecommendedMeasurementUnits()) {
uuids.add(termDto.getUuid());
}
List<DefinedTermBase> terms;
if (!uuids.isEmpty()) {
terms = termService.load(uuids, null);
Set<MeasurementUnit> measurementUnits = new HashSet<>();
for (DefinedTermBase term : terms) {
if (term instanceof MeasurementUnit) {
measurementUnits.add((MeasurementUnit) term);
}
}
character.getRecommendedMeasurementUnits().addAll(measurementUnits);
}
// statistical measures
character.getRecommendedStatisticalMeasures().clear();
uuids = new ArrayList<>();
for (TermDto termDto : characterDto.getRecommendedStatisticalMeasures()) {
uuids.add(termDto.getUuid());
}
if (!uuids.isEmpty()) {
terms = termService.load(uuids, null);
Set<StatisticalMeasure> statisticalMeasures = new HashSet<>();
for (DefinedTermBase<?> term : terms) {
if (term instanceof StatisticalMeasure) {
statisticalMeasures.add((StatisticalMeasure) term);
}
}
character.getRecommendedStatisticalMeasures().addAll(statisticalMeasures);
}
// recommended mod. vocabularies
character.getRecommendedModifierEnumeration().clear();
uuids = new ArrayList<>();
for (TermVocabularyDto termDto : characterDto.getRecommendedModifierEnumeration()) {
uuids.add(termDto.getUuid());
}
List<TermVocabulary> termVocs;
if (!uuids.isEmpty()) {
termVocs = vocabularyService.load(uuids, null);
for (TermVocabulary voc : termVocs) {
character.addRecommendedModifierEnumeration(voc);
}
}
// supported state vocabularies
character.getSupportedCategoricalEnumerations().clear();
uuids = new ArrayList<>();
for (TermVocabularyDto termDto : characterDto.getSupportedCategoricalEnumerations()) {
uuids.add(termDto.getUuid());
}
if (!uuids.isEmpty()) {
termVocs = vocabularyService.load(uuids, null);
for (TermVocabulary voc : termVocs) {
character.addSupportedCategoricalEnumeration(voc);
}
}
node.setTerm(character);
mergeResult = dao.merge(node, true);
result.addUpdatedObject(mergeResult.getMergedEntity());
}
}
}
return result;
}
Aggregations