Revision 6667af2d
Added by Andreas Müller about 1 year ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/portal/PortalDtoLoader.java | ||
---|---|---|
91 | 91 |
import eu.etaxonomy.cdm.model.common.VersionableEntity; |
92 | 92 |
import eu.etaxonomy.cdm.model.description.CategoricalData; |
93 | 93 |
import eu.etaxonomy.cdm.model.description.CommonTaxonName; |
94 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
94 | 95 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
95 | 96 |
import eu.etaxonomy.cdm.model.description.DescriptionElementSource; |
96 | 97 |
import eu.etaxonomy.cdm.model.description.Distribution; |
97 | 98 |
import eu.etaxonomy.cdm.model.description.Feature; |
99 |
import eu.etaxonomy.cdm.model.description.IDescribable; |
|
98 | 100 |
import eu.etaxonomy.cdm.model.description.IndividualsAssociation; |
99 | 101 |
import eu.etaxonomy.cdm.model.description.PolytomousKey; |
100 | 102 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm; |
... | ... | |
183 | 185 |
// result.setTypedTaxonLabel(getTypedTaxonLabel(taxon, config)); |
184 | 186 |
result.setTaggedLabel(getTaggedTaxon(taxon, config)); |
185 | 187 |
if (name != null) { |
186 |
handleName(config, result, name); |
|
188 |
handleName(config, result, name, result);
|
|
187 | 189 |
} |
188 |
|
|
189 |
|
|
190 | 190 |
} catch (Exception e) { |
191 | 191 |
//e.printStackTrace(); |
192 | 192 |
result.addMessage(MessagesDto.NewErrorInstance("Error when loading accepted name data.", e)); |
193 | 193 |
} |
194 | 194 |
} |
195 | 195 |
|
196 |
private void handleName(TaxonPageDtoConfiguration config, TaxonBaseDto taxonDto, TaxonName name) { |
|
197 |
taxonDto.setNameLabel(name.getTitleCache()); |
|
198 |
handleRelatedNames(name, taxonDto, config); |
|
199 |
loadProtologues(name, taxonDto); |
|
200 |
taxonDto.setNameUuid(name.getUuid()); |
|
201 |
taxonDto.setNameType(name.getNameType().toString()); |
|
196 |
private void handleName(TaxonPageDtoConfiguration config, TaxonBaseDto nameDto, TaxonName name, TaxonPageDto pageDto) { |
|
197 |
nameDto.setNameLabel(name.getTitleCache()); |
|
198 |
handleRelatedNames(name, nameDto, config); |
|
199 |
loadProtologues(name, nameDto); |
|
200 |
nameDto.setNameUuid(name.getUuid()); |
|
201 |
nameDto.setNameType(name.getNameType().toString()); |
|
202 |
loadNameFacts(name, nameDto, config, pageDto); |
|
202 | 203 |
} |
203 | 204 |
|
204 | 205 |
private List<TaggedText> getTaggedTaxon(TaxonBase<?> taxon, TaxonPageDtoConfiguration config) { |
... | ... | |
428 | 429 |
loadBaseData(name.getHomotypicalGroup(), homotypicGroupDto); |
429 | 430 |
|
430 | 431 |
for (Synonym syn : homotypicSynonmys) { |
431 |
loadSynonymsInGroup(homotypicGroupDto, syn, config); |
|
432 |
loadSynonymsInGroup(homotypicGroupDto, syn, config, result);
|
|
432 | 433 |
} |
433 | 434 |
} |
434 | 435 |
if (name != null) { |
... | ... | |
451 | 452 |
|
452 | 453 |
List<Synonym> heteroSyns = taxon.getSynonymsInGroup(hg, comparator); |
453 | 454 |
for (Synonym syn : heteroSyns) { |
454 |
loadSynonymsInGroup(hgDto, syn, config); |
|
455 |
loadSynonymsInGroup(hgDto, syn, config, result);
|
|
455 | 456 |
} |
456 | 457 |
handleTypification(hg, hgDto, result, config); |
457 | 458 |
} |
... | ... | |
549 | 550 |
conceptRelContainer.addItem(dto); |
550 | 551 |
} |
551 | 552 |
|
552 |
private void loadSynonymsInGroup(TaxonPageDto.HomotypicGroupDTO hgDto, Synonym syn, TaxonPageDtoConfiguration config) { |
|
553 |
private void loadSynonymsInGroup(TaxonPageDto.HomotypicGroupDTO hgDto, Synonym syn, |
|
554 |
TaxonPageDtoConfiguration config, TaxonPageDto pageDto) { |
|
555 |
|
|
553 | 556 |
TaxonBaseDto synDto = new TaxonBaseDto(); |
554 | 557 |
loadBaseData(syn, synDto); |
555 | 558 |
synDto.setLabel(syn.getTitleCache()); |
556 | 559 |
synDto.setTaggedLabel(getTaggedTaxon(syn, config)); |
557 | 560 |
|
558 | 561 |
if (syn.getName() != null) { |
559 |
handleName(config, synDto, syn.getName()); |
|
562 |
handleName(config, synDto, syn.getName(), pageDto);
|
|
560 | 563 |
synDto.setNameLabel(syn.getName().getTitleCache()); |
561 | 564 |
handleRelatedNames(syn.getName(), synDto, config); |
562 | 565 |
loadProtologues(syn.getName(), synDto); |
... | ... | |
656 | 659 |
if (!filteredRootNode.getChildren().isEmpty()) { |
657 | 660 |
ContainerDto<FeatureDto> features = new ContainerDto<>(); |
658 | 661 |
for (TreeNode<Feature,UUID> node : filteredRootNode.getChildren()) { |
659 |
handleFeatureNode(taxon, config, featureMap, features, node);
|
|
662 |
handleFeatureNode(config, featureMap, features, node); |
|
660 | 663 |
} |
661 | 664 |
taxonPageDto.setFactualData(features); |
662 | 665 |
} |
... | ... | |
666 | 669 |
} |
667 | 670 |
} |
668 | 671 |
|
669 |
private void handleFeatureNode(Taxon taxon, TaxonPageDtoConfiguration config, |
|
672 |
//TODO merge with loadFacts, it is almost the same, see //DIFFERENT |
|
673 |
private void loadNameFacts(TaxonName name, TaxonBaseDto nameDto, TaxonPageDtoConfiguration config, TaxonPageDto pageDto) { |
|
674 |
|
|
675 |
try { |
|
676 |
//compute the features that do exist for this taxon |
|
677 |
Map<UUID, Feature> existingFeatureUuids = getExistingFeatureUuids(name); |
|
678 |
|
|
679 |
//filter, sort and structure according to feature tree |
|
680 |
TreeNode<Feature, UUID> filteredRootNode; |
|
681 |
if (config.getFeatureTree() != null) { |
|
682 |
|
|
683 |
//TODO class cast |
|
684 |
TermTree<Feature> featureTree = repository.getTermTreeService().find(config.getFeatureTree()); |
|
685 |
filteredRootNode = filterFeatureNode(featureTree.getRoot(), existingFeatureUuids.keySet()); |
|
686 |
} else { |
|
687 |
filteredRootNode = createDefaultFeatureNode(name); |
|
688 |
} |
|
689 |
|
|
690 |
//load facts per feature |
|
691 |
Map<UUID,Set<DescriptionElementBase>> featureMap = loadFeatureMap(name); |
|
692 |
|
|
693 |
//load final result |
|
694 |
if (!filteredRootNode.getChildren().isEmpty()) { |
|
695 |
ContainerDto<FeatureDto> features = new ContainerDto<>(); |
|
696 |
for (TreeNode<Feature,UUID> node : filteredRootNode.getChildren()) { |
|
697 |
handleFeatureNode(config, featureMap, features, node); |
|
698 |
} |
|
699 |
//DIFFERENT |
|
700 |
nameDto.setNameFacts(features); |
|
701 |
} |
|
702 |
} catch (Exception e) { |
|
703 |
//e.printStackTrace(); |
|
704 |
//DIFFERENT |
|
705 |
pageDto.addMessage(MessagesDto.NewErrorInstance("Error when loading factual data.", e)); |
|
706 |
} |
|
707 |
} |
|
708 |
|
|
709 |
private void handleFeatureNode(TaxonPageDtoConfiguration config, |
|
670 | 710 |
Map<UUID, Set<DescriptionElementBase>> featureMap, ContainerDto<FeatureDto> features, |
671 | 711 |
TreeNode<Feature, UUID> node) { |
672 | 712 |
|
... | ... | |
691 | 731 |
} |
692 | 732 |
} |
693 | 733 |
|
694 |
handleDistributions(config, featureDto, taxon, distributions);
|
|
734 |
handleDistributions(config, featureDto, distributions); |
|
695 | 735 |
//TODO really needed? |
696 | 736 |
orderFacts(featureDto); |
697 | 737 |
|
698 | 738 |
//children |
699 | 739 |
ContainerDto<FeatureDto> childFeatures = new ContainerDto<>(); |
700 | 740 |
for (TreeNode<Feature,UUID> child : node.getChildren()) { |
701 |
handleFeatureNode(taxon, config, featureMap, childFeatures, child);
|
|
741 |
handleFeatureNode(config, featureMap, childFeatures, child); |
|
702 | 742 |
} |
703 | 743 |
if (childFeatures.getCount() > 0) { |
704 | 744 |
featureDto.setSubFeatures(childFeatures); |
... | ... | |
733 | 773 |
|
734 | 774 |
} |
735 | 775 |
|
736 |
private Map<UUID, Set<DescriptionElementBase>> loadFeatureMap(Taxon taxon) {
|
|
776 |
private Map<UUID, Set<DescriptionElementBase>> loadFeatureMap(IDescribable<?> describable) {
|
|
737 | 777 |
Map<UUID, Set<DescriptionElementBase>> featureMap = new HashMap<>(); |
738 | 778 |
|
739 | 779 |
//... load facts |
740 |
for (TaxonDescription taxonDescription : taxon.getDescriptions()) {
|
|
741 |
if (taxonDescription.isImageGallery()) {
|
|
780 |
for (DescriptionBase<?> description : describable.getDescriptions()) {
|
|
781 |
if (description.isImageGallery()) {
|
|
742 | 782 |
continue; |
743 | 783 |
} |
744 |
for (DescriptionElementBase deb : taxonDescription.getElements()) {
|
|
784 |
for (DescriptionElementBase deb : description.getElements()) {
|
|
745 | 785 |
Feature feature = deb.getFeature(); |
746 | 786 |
if (featureMap.get(feature.getUuid()) == null) { |
747 | 787 |
featureMap.put(feature.getUuid(), new HashSet<>()); |
... | ... | |
752 | 792 |
return featureMap; |
753 | 793 |
} |
754 | 794 |
|
755 |
private TreeNode<Feature, UUID> createDefaultFeatureNode(Taxon taxon) {
|
|
795 |
private TreeNode<Feature, UUID> createDefaultFeatureNode(IDescribable<?> describable) {
|
|
756 | 796 |
TreeNode<Feature, UUID> root = new TreeNode<>(); |
757 | 797 |
Set<Feature> requiredFeatures = new HashSet<>(); |
758 | 798 |
|
759 |
for (TaxonDescription taxonDescription : taxon.getDescriptions()) {
|
|
760 |
if (taxonDescription.isImageGallery()) {
|
|
799 |
for (DescriptionBase<?> description : describable.getDescriptions()) {
|
|
800 |
if (description.isImageGallery()) {
|
|
761 | 801 |
continue; |
762 | 802 |
} |
763 |
for (DescriptionElementBase deb : taxonDescription.getElements()) {
|
|
803 |
for (DescriptionElementBase deb : description.getElements()) {
|
|
764 | 804 |
Feature feature = deb.getFeature(); |
765 | 805 |
if (feature != null) { //null should not happen |
766 | 806 |
requiredFeatures.add(feature); |
... | ... | |
813 | 853 |
* Computes the (unsorted) set of features for which facts exist |
814 | 854 |
* for the given taxon. |
815 | 855 |
*/ |
816 |
private Map<UUID, Feature> getExistingFeatureUuids(Taxon taxon) {
|
|
856 |
private Map<UUID, Feature> getExistingFeatureUuids(IDescribable<?> describable) {
|
|
817 | 857 |
Map<UUID, Feature> result = new HashMap<>(); |
818 |
for (TaxonDescription taxonDescription : taxon.getDescriptions()) {
|
|
819 |
if (taxonDescription.isImageGallery()) {
|
|
858 |
for (DescriptionBase<?> description : describable.getDescriptions()) {
|
|
859 |
if (description.isImageGallery()) {
|
|
820 | 860 |
continue; |
821 | 861 |
} |
822 |
for (DescriptionElementBase deb : taxonDescription.getElements()) {
|
|
862 |
for (DescriptionElementBase deb : description.getElements()) {
|
|
823 | 863 |
Feature feature = deb.getFeature(); |
824 | 864 |
if (feature != null) { //null should not happen |
825 | 865 |
result.put(feature.getUuid(), feature); |
... | ... | |
830 | 870 |
} |
831 | 871 |
|
832 | 872 |
private void handleDistributions(TaxonPageDtoConfiguration config, FeatureDto featureDto, |
833 |
Taxon taxon, List<Distribution> distributions) {
|
|
873 |
List<Distribution> distributions) { |
|
834 | 874 |
|
835 | 875 |
if (distributions.isEmpty()) { |
836 | 876 |
return; |
Also available in: Unified diff
ref #10222 add nameFacts to taxon dto