2 * Copyright (C) 2009 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
.dwca
.out
;
11 import java
.io
.IOException
;
13 import org
.apache
.commons
.lang
.StringUtils
;
14 import org
.apache
.log4j
.Logger
;
16 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.InputTransformerBase
;
17 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
18 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
19 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignationStatus
;
20 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
21 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
22 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
29 public class DwcaTaxExportTransformer
extends InputTransformerBase
{
30 private static final Logger logger
= Logger
.getLogger(DwcaTaxExportTransformer
.class);
32 // private static Map<UUID, String> nomStatusMap = new HashMap<UUID, String>();
33 private static TermMapping nomStatusMapping
;
34 private static TermMapping rankMapping
;
35 private static TermMapping specimenTypeMapping
;
36 private static TermMapping nameTypeMapping
;
37 private static TermMapping sexMapping
;
38 private static TermMapping lifeStageMapping
;
39 private static TermMapping occStatusMapping
;
40 private static TermMapping establishmentMeansMapping
;
43 // public static String transformToGbifTaxonomicStatus(){
48 public static String
transformToGbifNomStatus(NomenclaturalStatusType nomStatus
){
49 if ( nomStatus
== null){
52 if (nomStatusMapping
== null){
54 nomStatusMapping
= new TermMapping("nomStatusToGbif.tsv");
55 } catch (IOException e
) {
56 throw new RuntimeException(e
);
59 String result
= nomStatusMapping
.getTerm(nomStatus
.getUuid());
60 if (StringUtils
.isBlank(result
)){
61 logger
.info("Nom. Status (" + nomStatus
.getLabel() + ") could not be mapped. Use CDM status label.");
67 // private static void initNomStatusMap() {
68 // nomStatusMap.put(NomenclaturalStatusType.uuidAlternative, "alternativum");
69 // nomStatusMap.put(NomenclaturalStatusType.uuidAmbiguous, "ambigua");
70 //// nomStatusMap.put(NomenclaturalStatusType.uuidCombinationIllegitimate, "");
71 //// nomStatusMap.put(NomenclaturalStatusType.uuidCombinationInvalid, "");
72 // nomStatusMap.put(NomenclaturalStatusType.uuidConfusum, "confusum");
73 // nomStatusMap.put(NomenclaturalStatusType.uuidConserved, "conservandum");
74 // nomStatusMap.put(NomenclaturalStatusType.uuidConservedProp, "conservandumProp");
75 // //TODO Wrong at GBIF !!!: dubimum
76 // nomStatusMap.put(NomenclaturalStatusType.uuidDoubtful, "dubium");
77 // nomStatusMap.put(NomenclaturalStatusType.uuidIllegitimate, "illegitimum");
78 // nomStatusMap.put(NomenclaturalStatusType.uuidInvalid, "invalidum");
79 // nomStatusMap.put(NomenclaturalStatusType.uuidLegitimate, "legitimate"); //why english not latin ??
80 // nomStatusMap.put(NomenclaturalStatusType.uuidNovum, "novum");
81 // nomStatusMap.put(NomenclaturalStatusType.uuidNudum, "nudum");
83 // nomStatusMap.put(NomenclaturalStatusType.uuidOpusUtiqueOppr, "opressa");
85 // nomStatusMap.put(NomenclaturalStatusType.uuidOrthographyConserved, "orthographia");
87 // nomStatusMap.put(NomenclaturalStatusType.uuidOrthographyConservedProp, "orthographia");
88 // nomStatusMap.put(NomenclaturalStatusType.uuidProvisional, "provisorium");
89 // nomStatusMap.put(NomenclaturalStatusType.uuidRejected, "rejiciendum");
90 // nomStatusMap.put(NomenclaturalStatusType.uuidRejectedProp, "rejiciendumProp");
91 //// nomStatusMap.put(NomenclaturalStatusType.uuidSanctioned, "");
93 // nomStatusMap.put(NomenclaturalStatusType.uuidSubnudum, "rejiciendum");
94 // nomStatusMap.put(NomenclaturalStatusType.uuidSuperfluous, "superfluum");
95 // nomStatusMap.put(NomenclaturalStatusType.uuidValid, "valid");
97 // //CDM is missing abortivum, available, combinatio, negatum, oblitum,
98 // // protectum, rejiciendumUtique, rejiciendumUtiqueProp
101 public static String
transformToGbifRank(Rank term
){
105 if (rankMapping
== null){
107 rankMapping
= new TermMapping("rankToGbif.tsv");
108 } catch (IOException e
) {
109 throw new RuntimeException(e
);
112 String result
= rankMapping
.getTerm(term
.getUuid());
113 if (StringUtils
.isBlank(result
)){
114 logger
.info("Rank (" + term
.getLabel() + ") could not be mapped. Use CDM abbreviated label instead.");
120 public static String
transformSpecimenTypeStatusToGbif(SpecimenTypeDesignationStatus status
){
121 if ( status
== null){
124 if (specimenTypeMapping
== null){
126 specimenTypeMapping
= new TermMapping("specimenTypeStatusToGbif.tsv");
127 } catch (IOException e
) {
128 throw new RuntimeException(e
);
131 String result
= specimenTypeMapping
.getTerm(status
.getUuid());
132 if (StringUtils
.isBlank(result
)){
133 logger
.info("Specimen type status (" + status
.getLabel() + ") could not be mapped. Use CDM status label.");
140 public static String
transformNameTypeStatusToGbif(NameTypeDesignationStatus status
){
141 if ( status
== null){
144 if (nameTypeMapping
== null){
146 nameTypeMapping
= new TermMapping("nameTypeStatusToGbif.tsv");
147 } catch (IOException e
) {
148 throw new RuntimeException(e
);
151 String result
= nameTypeMapping
.getTerm(status
.getUuid());
152 if (StringUtils
.isBlank(result
)){
153 logger
.info("Name type status (" + status
.getLabel() + ") could not be mapped. Use CDM status label.");
159 public static String
transformToGbifSex(DefinedTerm sex
) {
163 if (sexMapping
== null){
165 sexMapping
= new TermMapping("sexToGbif.tsv");
166 } catch (IOException e
) {
167 throw new RuntimeException(e
);
170 String result
= sexMapping
.getTerm(sex
.getUuid());
171 if (StringUtils
.isBlank(result
)){
172 logger
.info("Sex (" + sex
.getLabel() + ") could not be mapped. Use CDM status label.");
178 public static String
transformToGbifLifeStage(DefinedTerm stage
) {
182 if (lifeStageMapping
== null){
184 lifeStageMapping
= new TermMapping("lifeStageToGbif.tsv");
185 } catch (IOException e
) {
186 throw new RuntimeException(e
);
189 String result
= lifeStageMapping
.getTerm(stage
.getUuid());
190 if (StringUtils
.isBlank(result
)){
191 logger
.info("Life stage (" + stage
.getLabel() + ") could not be mapped. Use CDM status label.");
197 public static String
transformToGbifOccStatus(PresenceAbsenceTerm status
) {
198 if ( status
== null){
201 if (occStatusMapping
== null){
203 occStatusMapping
= new TermMapping("presenceTermToGbifOccurrenceStatus.tsv");
204 } catch (IOException e
) {
205 throw new RuntimeException(e
);
208 String result
= occStatusMapping
.getTerm(status
.getUuid());
209 if (StringUtils
.isBlank(result
)){
210 logger
.info("PresenceAbsence term (" + status
.getLabel() + ") could not be mapped to GBIF occurrence status. Use CDM status label.");
216 public static String
transformToGbifEstablishmentMeans(PresenceAbsenceTerm status
) {
217 if ( status
== null){
220 if (establishmentMeansMapping
== null){
222 establishmentMeansMapping
= new TermMapping("presenceTermToGbifEstablishmentMeans.tsv");
223 } catch (IOException e
) {
224 throw new RuntimeException(e
);
227 String result
= establishmentMeansMapping
.getTerm(status
.getUuid());
228 if (StringUtils
.isBlank(result
)){
229 logger
.info("PresenceAbsence term (" + status
.getLabel() + ") could not be mapped to GBIF establishment means. Use CDM status label.");