ref #6369 adapt existing occurrences of interface to removed generics
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / dwca / out / DwcaTaxExportTransformer.java
1 /**
2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.cdm.io.dwca.out;
10
11 import java.io.IOException;
12
13 import org.apache.commons.lang.StringUtils;
14 import org.apache.log4j.Logger;
15
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;
23
24 /**
25 * @author a.mueller
26 * @date 02.05.2011
27 *
28 */
29 public class DwcaTaxExportTransformer extends InputTransformerBase {
30 private static final Logger logger = Logger.getLogger(DwcaTaxExportTransformer.class);
31
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;
41
42
43 // public static String transformToGbifTaxonomicStatus(){
44 // //TODO
45 // return null;
46 // }
47
48 public static String transformToGbifNomStatus(NomenclaturalStatusType nomStatus){
49 if ( nomStatus == null){
50 return null;
51 }else{
52 if (nomStatusMapping == null){
53 try {
54 nomStatusMapping = new TermMapping("nomStatusToGbif.tsv");
55 } catch (IOException e) {
56 throw new RuntimeException(e);
57 }
58 }
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.");
62 }
63 return result;
64 }
65 }
66
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");
82 // //TODO
83 // nomStatusMap.put(NomenclaturalStatusType.uuidOpusUtiqueOppr, "opressa");
84 // //TODO
85 // nomStatusMap.put(NomenclaturalStatusType.uuidOrthographyConserved, "orthographia");
86 // //TODO
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, "");
92 //
93 // nomStatusMap.put(NomenclaturalStatusType.uuidSubnudum, "rejiciendum");
94 // nomStatusMap.put(NomenclaturalStatusType.uuidSuperfluous, "superfluum");
95 // nomStatusMap.put(NomenclaturalStatusType.uuidValid, "valid");
96 //
97 // //CDM is missing abortivum, available, combinatio, negatum, oblitum,
98 // // protectum, rejiciendumUtique, rejiciendumUtiqueProp
99 // }
100
101 public static String transformToGbifRank(Rank term){
102 if ( term == null){
103 return null;
104 }else{
105 if (rankMapping == null){
106 try {
107 rankMapping = new TermMapping("rankToGbif.tsv");
108 } catch (IOException e) {
109 throw new RuntimeException(e);
110 }
111 }
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.");
115 }
116 return result;
117 }
118 }
119
120 public static String transformSpecimenTypeStatusToGbif(SpecimenTypeDesignationStatus status){
121 if ( status == null){
122 return null;
123 }else{
124 if (specimenTypeMapping == null){
125 try {
126 specimenTypeMapping = new TermMapping("specimenTypeStatusToGbif.tsv");
127 } catch (IOException e) {
128 throw new RuntimeException(e);
129 }
130 }
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.");
134 }
135 return result;
136 }
137 }
138
139
140 public static String transformNameTypeStatusToGbif(NameTypeDesignationStatus status){
141 if ( status == null){
142 return null;
143 }else{
144 if (nameTypeMapping == null){
145 try {
146 nameTypeMapping = new TermMapping("nameTypeStatusToGbif.tsv");
147 } catch (IOException e) {
148 throw new RuntimeException(e);
149 }
150 }
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.");
154 }
155 return result;
156 }
157 }
158
159 public static String transformToGbifSex(DefinedTerm sex) {
160 if ( sex == null){
161 return null;
162 }else{
163 if (sexMapping == null){
164 try {
165 sexMapping = new TermMapping("sexToGbif.tsv");
166 } catch (IOException e) {
167 throw new RuntimeException(e);
168 }
169 }
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.");
173 }
174 return result;
175 }
176 }
177
178 public static String transformToGbifLifeStage(DefinedTerm stage) {
179 if ( stage == null){
180 return null;
181 }else{
182 if (lifeStageMapping == null){
183 try {
184 lifeStageMapping = new TermMapping("lifeStageToGbif.tsv");
185 } catch (IOException e) {
186 throw new RuntimeException(e);
187 }
188 }
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.");
192 }
193 return result;
194 }
195 }
196
197 public static String transformToGbifOccStatus(PresenceAbsenceTerm status) {
198 if ( status == null){
199 return null;
200 }else{
201 if (occStatusMapping == null){
202 try {
203 occStatusMapping = new TermMapping("presenceTermToGbifOccurrenceStatus.tsv");
204 } catch (IOException e) {
205 throw new RuntimeException(e);
206 }
207 }
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.");
211 }
212 return result;
213 }
214 }
215
216 public static String transformToGbifEstablishmentMeans(PresenceAbsenceTerm status) {
217 if ( status == null){
218 return null;
219 }else{
220 if (establishmentMeansMapping == null){
221 try {
222 establishmentMeansMapping = new TermMapping("presenceTermToGbifEstablishmentMeans.tsv");
223 } catch (IOException e) {
224 throw new RuntimeException(e);
225 }
226 }
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.");
230 }
231 return result;
232 }
233 }
234
235 }