Revision cf76baeb
Added by Andreas Müller over 7 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TaxonNodeDto.java | ||
---|---|---|
24 | 24 |
*/ |
25 | 25 |
public class TaxonNodeDto { |
26 | 26 |
|
27 |
public enum TaxonStatus{ |
|
28 |
Accepted, |
|
29 |
SynonymObjective, |
|
30 |
Synonym; //All others including undefined and explicitly subjective /heterotypic synonyms |
|
31 |
|
|
32 |
public boolean isSynonym(){ |
|
33 |
return this == SynonymObjective || this == Synonym; |
|
34 |
} |
|
35 |
} |
|
36 |
|
|
37 | 27 |
/** |
38 | 28 |
* The TaxonNode uuid |
39 | 29 |
*/ |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TaxonStatus.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2016 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.cdm.persistence.dto; |
|
11 |
|
|
12 |
public enum TaxonStatus{ |
|
13 |
Accepted, |
|
14 |
SynonymObjective, |
|
15 |
Synonym; //All others including undefined and explicitly subjective /heterotypic synonyms |
|
16 |
|
|
17 |
public boolean isSynonym(){ |
|
18 |
return this == SynonymObjective || this == Synonym; |
|
19 |
} |
|
20 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImpl.java | ||
---|---|---|
18 | 18 |
import java.util.HashMap; |
19 | 19 |
import java.util.List; |
20 | 20 |
import java.util.Map; |
21 |
import java.util.Set; |
|
21 | 22 |
import java.util.TreeMap; |
22 | 23 |
import java.util.UUID; |
23 | 24 |
|
25 |
import javax.persistence.EntityNotFoundException; |
|
26 |
|
|
24 | 27 |
import org.apache.commons.collections.CollectionUtils; |
28 |
import org.apache.commons.lang.StringUtils; |
|
25 | 29 |
import org.apache.log4j.Logger; |
26 | 30 |
import org.springframework.beans.factory.annotation.Autowired; |
27 | 31 |
import org.springframework.stereotype.Service; |
... | ... | |
65 | 69 |
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao; |
66 | 70 |
import eu.etaxonomy.cdm.persistence.dto.ClassificationLookupDTO; |
67 | 71 |
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto; |
68 |
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto.TaxonStatus;
|
|
72 |
import eu.etaxonomy.cdm.persistence.dto.TaxonStatus; |
|
69 | 73 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
70 | 74 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
71 | 75 |
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy; |
... | ... | |
715 | 719 |
* {@inheritDoc} |
716 | 720 |
*/ |
717 | 721 |
@Override |
718 |
public TaxonInContextDTO getTaxonInContext(UUID classificationUuid, UUID taxonUuid, |
|
722 |
public TaxonInContextDTO getTaxonInContext(UUID classificationUuid, UUID taxonBaseUuid,
|
|
719 | 723 |
Boolean doChildren, Boolean doSynonyms, List<UUID> ancestorMarkers, |
720 | 724 |
NodeSortMode sortMode) { |
721 | 725 |
TaxonInContextDTO result = new TaxonInContextDTO(); |
722 |
TaxonBase<?> taxonBase = taxonDao.load(taxonUuid); |
|
726 |
|
|
727 |
TaxonBase<?> taxonBase = taxonDao.load(taxonBaseUuid); |
|
723 | 728 |
if (taxonBase == null){ |
724 |
return result; //TODO |
|
729 |
throw new EntityNotFoundException("Taxon with uuid " + taxonBaseUuid + " not found in datasource"); |
|
730 |
} |
|
731 |
boolean isSynonym = false; |
|
732 |
Taxon acceptedTaxon; |
|
733 |
if (taxonBase.isInstanceOf(Synonym.class)){ |
|
734 |
isSynonym = true; |
|
735 |
Synonym synonym = CdmBase.deproxy(taxonBase, Synonym.class); |
|
736 |
Set<Taxon> acceptedTaxa = synonym.getAcceptedTaxa(); |
|
737 |
//we expect every synonym to have only 1 accepted taxon as this is how |
|
738 |
//CDM will be modelled soon |
|
739 |
acceptedTaxon = acceptedTaxa.isEmpty()? null : acceptedTaxa.iterator().next(); |
|
740 |
if (acceptedTaxon == null) { |
|
741 |
throw new EntityNotFoundException("Accepted taxon not found for synonym" ); |
|
742 |
} |
|
743 |
TaxonStatus taxonStatus = TaxonStatus.Synonym; |
|
744 |
if (synonym.getName()!= null && acceptedTaxon.getName() != null |
|
745 |
&& synonym.getName().getHomotypicalGroup().equals(acceptedTaxon.getName().getHomotypicalGroup())){ |
|
746 |
taxonStatus = TaxonStatus.SynonymObjective; |
|
747 |
} |
|
748 |
result.setTaxonStatus(taxonStatus); |
|
749 |
|
|
750 |
}else{ |
|
751 |
acceptedTaxon = CdmBase.deproxy(taxonBase, Taxon.class); |
|
752 |
result.setTaxonStatus(TaxonStatus.Accepted); |
|
753 |
} |
|
754 |
UUID acceptedTaxonUuid = acceptedTaxon.getUuid(); |
|
755 |
|
|
756 |
UUID taxonNodeUuid = getTaxonNodeUuidByTaxonUuid(classificationUuid, acceptedTaxonUuid); |
|
757 |
if (taxonNodeUuid == null) { |
|
758 |
throw new EntityNotFoundException("Taxon not found in classficiation with uuid " + classificationUuid + ". Either classification does not exist or does not contain taxon/synonym with uuid " + taxonBaseUuid ); |
|
759 |
} |
|
760 |
result.setTaxonNodeUuid(taxonNodeUuid); |
|
761 |
result.setTaxonUuid(taxonBaseUuid); |
|
762 |
result.setClassificationUuid(classificationUuid); |
|
763 |
if (taxonBase.getSec() != null){ |
|
764 |
result.setSecundumUuid(taxonBase.getSec().getUuid()); |
|
765 |
result.setSecundumLabel(taxonBase.getSec().getTitleCache()); |
|
725 | 766 |
} |
767 |
result.setTaxonLabel(taxonBase.getTitleCache()); |
|
726 | 768 |
|
727 | 769 |
TaxonNameBase<?,?> name = taxonBase.getName(); |
728 | 770 |
result.setNameUuid(name.getUuid()); |
... | ... | |
741 | 783 |
Rank rank = name.getRank(); |
742 | 784 |
if (rank != null){ |
743 | 785 |
result.setRankUuid(rank.getUuid()); |
744 |
result.setRankLabel(rank.getTitleCache()); |
|
786 |
String rankLabel = rank.getAbbreviation(); |
|
787 |
if (StringUtils.isBlank(rankLabel)){ |
|
788 |
rankLabel = rank.getLabel(); |
|
789 |
} |
|
790 |
result.setRankLabel(rankLabel); |
|
745 | 791 |
} |
746 | 792 |
} |
747 | 793 |
|
748 |
UUID taxonNodeUuid = getTaxonNodeUuidByTaxonUuid(classificationUuid, taxonUuid); |
|
749 |
result.setTaxonNodeUuid(taxonNodeUuid); |
|
750 |
|
|
751 | 794 |
boolean recursive = false; |
752 | 795 |
Integer pageSize = null; |
753 | 796 |
Integer pageIndex = null; |
754 | 797 |
Pager<TaxonNodeDto> children = taxonNodeService.pageChildNodesDTOs(taxonNodeUuid, recursive, doSynonyms, sortMode, pageSize, pageIndex); |
755 | 798 |
|
756 | 799 |
//children |
757 |
for (TaxonNodeDto childDto : children.getRecords()){ |
|
758 |
if (doChildren && childDto.getStatus().equals(TaxonStatus.Accepted)){ |
|
759 |
EntityDTO<Taxon> child = new EntityDTO<Taxon>(childDto.getTaxonUuid(), childDto.getTitleCache()); |
|
760 |
result.addChild(child); |
|
761 |
}else if (doSynonyms && childDto.getStatus().isSynonym()){ |
|
762 |
EntityDTO<Synonym> child = new EntityDTO<Synonym>(childDto.getTaxonUuid(), childDto.getTitleCache()); |
|
763 |
result.addSynonym(child); |
|
800 |
if(! isSynonym) { |
|
801 |
for (TaxonNodeDto childDto : children.getRecords()){ |
|
802 |
if (doChildren && childDto.getStatus().equals(TaxonStatus.Accepted)){ |
|
803 |
EntityDTO<Taxon> child = new EntityDTO<Taxon>(childDto.getTaxonUuid(), childDto.getTitleCache()); |
|
804 |
result.addChild(child); |
|
805 |
}else if (doSynonyms && childDto.getStatus().isSynonym()){ |
|
806 |
EntityDTO<Synonym> child = new EntityDTO<Synonym>(childDto.getTaxonUuid(), childDto.getTitleCache()); |
|
807 |
result.addSynonym(child); |
|
808 |
} |
|
764 | 809 |
} |
810 |
}else{ |
|
811 |
result.setAcceptedTaxonUuid(acceptedTaxonUuid); |
|
812 |
String nameTitel = acceptedTaxon.getName() == null ? null : acceptedTaxon.getName().getTitleCache(); |
|
813 |
result.setAcceptedTaxonLabel(acceptedTaxon.getTitleCache()); |
|
814 |
result.setAcceptedNameLabel(nameTitel); |
|
765 | 815 |
} |
766 | 816 |
|
767 | 817 |
//marked ancestors |
... | ... | |
791 | 841 |
for (MarkerType type : markerTypes){ |
792 | 842 |
Taxon taxon = node.getTaxon(); |
793 | 843 |
if (taxon != null && taxon.hasMarker(type, true)){ |
794 |
MarkedEntityDTO<Taxon> dto = new MarkedEntityDTO<>(type, true, taxon.getUuid(), taxon.getTitleCache()); |
|
844 |
String label = taxon.getName() == null? taxon.getTitleCache() : taxon.getName().getTitleCache(); |
|
845 |
MarkedEntityDTO<Taxon> dto = new MarkedEntityDTO<>(type, true, taxon.getUuid(), label); |
|
795 | 846 |
result.addMarkedAncestor(dto); |
796 | 847 |
} |
797 | 848 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/TaxonInContextDTO.java | ||
---|---|---|
15 | 15 |
|
16 | 16 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
17 | 17 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
18 |
import eu.etaxonomy.cdm.persistence.dto.TaxonStatus; |
|
18 | 19 |
|
19 | 20 |
/** |
20 | 21 |
* @author a.mueller |
... | ... | |
26 | 27 |
private UUID taxonNodeUuid; |
27 | 28 |
private UUID taxonUuid; |
28 | 29 |
private String taxonLabel; |
30 |
private TaxonStatus taxonStatus; |
|
29 | 31 |
|
30 | 32 |
//name |
31 | 33 |
private UUID nameUuid; |
32 | 34 |
private String nameLabel; |
35 |
|
|
33 | 36 |
private String nameWithoutAuthor; |
34 | 37 |
private UUID rankUuid; |
35 | 38 |
private String rankLabel; |
... | ... | |
43 | 46 |
private UUID secundumUuid; |
44 | 47 |
private String secundumLabel; |
45 | 48 |
|
49 |
//accepted taxon |
|
50 |
private UUID acceptedTaxonUuid; |
|
51 |
private String acceptedNameLabel; |
|
52 |
|
|
53 |
|
|
54 |
private String acceptedTaxonLabel; |
|
55 |
|
|
56 |
|
|
57 |
/** |
|
58 |
* @return the acceptedTaxonLabel |
|
59 |
*/ |
|
60 |
public String getAcceptedTaxonLabel() { |
|
61 |
return acceptedTaxonLabel; |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* @param acceptedTaxonLabel the acceptedTaxonLabel to set |
|
66 |
*/ |
|
67 |
public void setAcceptedTaxonLabel(String acceptedTaxonLabel) { |
|
68 |
this.acceptedTaxonLabel = acceptedTaxonLabel; |
|
69 |
} |
|
70 |
|
|
46 | 71 |
private List<EntityDTO<Taxon>> children = new ArrayList<>(); |
47 | 72 |
|
48 | 73 |
private List<EntityDTO<Synonym>> synonyms = new ArrayList<>(); |
... | ... | |
321 | 346 |
return markedAncestors; |
322 | 347 |
} |
323 | 348 |
|
349 |
|
|
350 |
/** |
|
351 |
* @return the acceptedTaxonUuid |
|
352 |
*/ |
|
353 |
public UUID getAcceptedTaxonUuid() { |
|
354 |
return acceptedTaxonUuid; |
|
355 |
} |
|
356 |
|
|
357 |
/** |
|
358 |
* @param acceptedTaxonUuid the acceptedTaxonUuid to set |
|
359 |
*/ |
|
360 |
public void setAcceptedTaxonUuid(UUID acceptedTaxonUuid) { |
|
361 |
this.acceptedTaxonUuid = acceptedTaxonUuid; |
|
362 |
} |
|
363 |
|
|
364 |
/** |
|
365 |
* @return the acceptedNameLabel |
|
366 |
*/ |
|
367 |
public String getAcceptedNameLabel() { |
|
368 |
return acceptedNameLabel; |
|
369 |
} |
|
370 |
|
|
371 |
/** |
|
372 |
* @param acceptedNameLabel the acceptedNameLabel to set |
|
373 |
*/ |
|
374 |
public void setAcceptedNameLabel(String acceptedNameLabel) { |
|
375 |
this.acceptedNameLabel = acceptedNameLabel; |
|
376 |
} |
|
377 |
|
|
378 |
/** |
|
379 |
* @return the taxonStatus |
|
380 |
*/ |
|
381 |
public TaxonStatus getTaxonStatus() { |
|
382 |
return taxonStatus; |
|
383 |
} |
|
384 |
|
|
385 |
/** |
|
386 |
* @param taxonStatus the taxonStatus to set |
|
387 |
*/ |
|
388 |
public void setTaxonStatus(TaxonStatus taxonStatus) { |
|
389 |
this.taxonStatus = taxonStatus; |
|
390 |
} |
|
391 |
|
|
324 | 392 |
// *************************** ADDER *******************************/ |
325 | 393 |
|
326 | 394 |
public void addChild(EntityDTO<Taxon> childDto){ |
Also available in: Unified diff
ref #6065 Handle synonyms in taxonInContext