2 * Copyright (C) 2023 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.io
.coldp
;
11 import org
.apache
.logging
.log4j
.LogManager
;
12 import org
.apache
.logging
.log4j
.Logger
;
14 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.UndefinedTransformerMethodException
;
15 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.out
.ExportTransformerBase
;
16 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
17 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
18 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
19 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
20 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
21 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
22 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
23 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
24 import eu
.etaxonomy
.cdm
.model
.term
.Representation
;
30 public class ColDpExportTransformer
extends ExportTransformerBase
{
32 private static final long serialVersionUID
= -527652844010832994L;
34 @SuppressWarnings("unused")
35 private static final Logger logger
= LogManager
.getLogger();
37 //maps to http://api.checklistbank.org/vocab/distributionstatus
39 public String
getCacheByPresenceAbsenceTerm(PresenceAbsenceTerm status
) throws UndefinedTransformerMethodException
{
43 if (status
.isAnyNative()) {
46 if (status
.isAnyIntroduced()) {
52 @SuppressWarnings("incomplete-switch") //we ignore this warning as the enumeration should always be completely covered, otherwise an error will be shown if we do not add a default state. This is wanted behavior here.
54 public String
getCacheByReferenceType(Reference ref
) throws UndefinedTransformerMethodException
{
55 if (ref
== null || ref
.getType() == null) {
58 ReferenceType refType
= ref
.getType();
61 case Journal
: //should not happen
64 case PrintSeries
: //should not happen
69 return "dataset"; //TODO
71 return "dataset"; //TODO
73 return "paper conference";
78 case PersonalCommunication
:
79 return "personal communication";
81 return "paper conference";
90 if (ref
.getInReference() != null) {
91 return getCacheByReferenceType(ref
.getInReference());
100 public String
getCacheByNomStatus(NomenclaturalStatusType nomStatusType
) {
101 if (nomStatusType
== null) {
104 }else if (nomStatusType
.equals(NomenclaturalStatusType
.CONSERVED())) {
106 }else if (nomStatusType
.equals(NomenclaturalStatusType
.REJECTED())) {
108 }else if (nomStatusType
.equals(NomenclaturalStatusType
.DOUBTFUL())) {
110 }else if (nomStatusType
.equals(NomenclaturalStatusType
.INED())) {
113 }else if (nomStatusType
.isLegitimate()) {
115 }else if (nomStatusType
.isIllegitimate()) {
116 return "nomen illegitimum";
117 }else if (nomStatusType
.isInvalid()) {
118 return "not established";
124 @SuppressWarnings("incomplete-switch") //we ignore this warning as the enumeration should always be completely covered, otherwise an error will be shown if we do not add a default state. This is wanted behavior here.
126 public String
getCacheByNomenclaturalCode(NomenclaturalCode nomenclaturalCode
) throws UndefinedTransformerMethodException
{
127 if (nomenclaturalCode
== null) {
130 switch (nomenclaturalCode
) {
135 return "ICN"; //"botanical";
137 return "ICNCP"; //"cultivars";
139 return "ICNP"; //"bacterial";
141 return "ICVCN"; //"virus";
143 return "ICZN"; //"zoological";
149 public String
getCacheByRank(Rank rank
) throws UndefinedTransformerMethodException
{
153 Representation preferredRep
= rank
.getPreferredRepresentation(Language
.ENGLISH());
154 if (preferredRep
!= null) {
155 return preferredRep
.getLabel() == null ?
null :preferredRep
.getLabel().toLowerCase();
157 return rank
.getTitleCache().toLowerCase();
159 //TODO maybe we still need to adapt some ranks
162 public static enum ColDpNameRelType
{
163 BASIONYM("basionym", 0),
164 SPELLING_CORRECTION("spelling correction", 0),
165 EMENDATION("spelling correction", 1),
166 BASED_ON("based on", 0),
167 REPLACEMENT_NAME("replacement name", 0),
168 CONSERVED("conserved", 0),
169 LATER_HOMONYM("later homonym", 0),
170 SUPERFLUOUS("superfluous", 1),
174 private String label
;
175 private int direction
;
176 ColDpNameRelType(String label
, int direction
){
178 this.direction
= direction
;
180 public String
getLabel() {
183 public int getDirection() {
188 public ColDpNameRelType
getColDpNameRelTypeByNameRelationType(NameRelationshipType nameRelType
) {
189 if (nameRelType
== null) {
192 if (nameRelType
.getUuid().equals(NameRelationshipType
.uuidBasionym
)){
193 return ColDpNameRelType
.BASIONYM
;
194 } else if (nameRelType
.getUuid().equals(NameRelationshipType
.uuidOrthographicVariant
)) {
195 return ColDpNameRelType
.SPELLING_CORRECTION
;
196 } else if (nameRelType
.getUuid().equals(NameRelationshipType
.uuidEmendation
)) {
197 return ColDpNameRelType
.EMENDATION
;
198 } else if (nameRelType
.getUuid().equals(NameRelationshipType
.uuidValidatedByName
)
199 || nameRelType
.getUuid().equals(NameRelationshipType
.uuidLaterValidatedByName
)) {
200 return ColDpNameRelType
.BASED_ON
;
201 } else if (nameRelType
.getUuid().equals(NameRelationshipType
.uuidReplacedSynonym
)) {
202 return ColDpNameRelType
.REPLACEMENT_NAME
;
203 } else if (nameRelType
.getUuid().equals(NameRelationshipType
.uuidConservedAgainst
)) {
204 return ColDpNameRelType
.CONSERVED
;
205 } else if (nameRelType
.getUuid().equals(NameRelationshipType
.uuidLaterHomonym
)
206 || nameRelType
.getUuid().equals(NameRelationshipType
.uuidTreatedAsLaterHomonym
)) {
207 return ColDpNameRelType
.LATER_HOMONYM
;
208 } else if (nameRelType
.getUuid().equals(NameRelationshipType
.uuidLaterIsonym
)
209 //only for future merged, currently it will never match as the type is different
210 || nameRelType
.getUuid().equals(NomenclaturalStatusType
.uuidSuperfluous
)) {
211 return ColDpNameRelType
.SUPERFLUOUS
;
213 //TODO misspelling, alternative name, blocking name for, avoids homonym of, unspecific "non"
214 String warning
= "Name relationship type not yet handled by COL-DP: " + nameRelType
.getTitleCache();
215 //TODO handle warning, is currently handled in calling method
216 Representation preferredRep
= nameRelType
.getPreferredRepresentation(Language
.ENGLISH());
217 // if (preferredRep != null) {
218 // return preferredRep.getLabel() == null ? null :preferredRep.getLabel().toLowerCase();
220 // return nameRelType.getTitleCache().toLowerCase();