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
|
|
10
|
package eu.etaxonomy.cdm.io.csv.redlist.out;
|
11
|
|
12
|
import java.io.IOException;
|
13
|
|
14
|
import org.apache.commons.lang.StringUtils;
|
15
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.io.common.mapping.InputTransformerBase;
|
18
|
import eu.etaxonomy.cdm.io.dwca.out.TermMapping;
|
19
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
20
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
|
21
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
22
|
import eu.etaxonomy.cdm.model.name.Rank;
|
23
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
24
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
25
|
|
26
|
/**
|
27
|
* @author a.mueller
|
28
|
* @since 02.05.2011
|
29
|
*
|
30
|
*/
|
31
|
public class CsvTaxExportTransformerRedlist extends InputTransformerBase {
|
32
|
private static final Logger logger = LogManager.getLogger(CsvTaxExportTransformerRedlist.class);
|
33
|
|
34
|
// private static Map<UUID, String> nomStatusMap = new HashMap<UUID, String>();
|
35
|
private static TermMapping nomStatusMapping;
|
36
|
private static TermMapping rankMapping;
|
37
|
private static TermMapping specimenTypeMapping;
|
38
|
private static TermMapping nameTypeMapping;
|
39
|
private static TermMapping sexMapping;
|
40
|
private static TermMapping lifeStageMapping;
|
41
|
private static TermMapping occStatusMapping;
|
42
|
private static TermMapping establishmentMeansMapping;
|
43
|
|
44
|
|
45
|
// public static String transformToGbifTaxonomicStatus(){
|
46
|
// //TODO
|
47
|
// return null;
|
48
|
// }
|
49
|
|
50
|
public static String transformToGbifNomStatus(NomenclaturalStatusType nomStatus){
|
51
|
if ( nomStatus == null){
|
52
|
return null;
|
53
|
}else{
|
54
|
if (nomStatusMapping == null){
|
55
|
try {
|
56
|
nomStatusMapping = new TermMapping("nomStatusToGbif.tsv");
|
57
|
} catch (IOException e) {
|
58
|
throw new RuntimeException(e);
|
59
|
}
|
60
|
}
|
61
|
String result = nomStatusMapping.getTerm(nomStatus.getUuid());
|
62
|
if (StringUtils.isBlank(result)){
|
63
|
logger.info("Nom. Status (" + nomStatus.getLabel() + ") could not be mapped. Use CDM status label.");
|
64
|
}
|
65
|
return result;
|
66
|
}
|
67
|
}
|
68
|
|
69
|
// private static void initNomStatusMap() {
|
70
|
// nomStatusMap.put(NomenclaturalStatusType.uuidAlternative, "alternativum");
|
71
|
// nomStatusMap.put(NomenclaturalStatusType.uuidAmbiguous, "ambigua");
|
72
|
//// nomStatusMap.put(NomenclaturalStatusType.uuidCombinationIllegitimate, "");
|
73
|
//// nomStatusMap.put(NomenclaturalStatusType.uuidCombinationInvalid, "");
|
74
|
// nomStatusMap.put(NomenclaturalStatusType.uuidConfusum, "confusum");
|
75
|
// nomStatusMap.put(NomenclaturalStatusType.uuidConserved, "conservandum");
|
76
|
// nomStatusMap.put(NomenclaturalStatusType.uuidConservedProp, "conservandumProp");
|
77
|
// //TODO Wrong at GBIF !!!: dubimum
|
78
|
// nomStatusMap.put(NomenclaturalStatusType.uuidDoubtful, "dubium");
|
79
|
// nomStatusMap.put(NomenclaturalStatusType.uuidIllegitimate, "illegitimum");
|
80
|
// nomStatusMap.put(NomenclaturalStatusType.uuidInvalid, "invalidum");
|
81
|
// nomStatusMap.put(NomenclaturalStatusType.uuidLegitimate, "legitimate"); //why english not latin ??
|
82
|
// nomStatusMap.put(NomenclaturalStatusType.uuidNovum, "novum");
|
83
|
// nomStatusMap.put(NomenclaturalStatusType.uuidNudum, "nudum");
|
84
|
// //TODO
|
85
|
// nomStatusMap.put(NomenclaturalStatusType.uuidOpusUtiqueOppr, "opressa");
|
86
|
// //TODO
|
87
|
// nomStatusMap.put(NomenclaturalStatusType.uuidOrthographyConserved, "orthographia");
|
88
|
// //TODO
|
89
|
// nomStatusMap.put(NomenclaturalStatusType.uuidOrthographyConservedProp, "orthographia");
|
90
|
// nomStatusMap.put(NomenclaturalStatusType.uuidProvisional, "provisorium");
|
91
|
// nomStatusMap.put(NomenclaturalStatusType.uuidRejected, "rejiciendum");
|
92
|
// nomStatusMap.put(NomenclaturalStatusType.uuidRejectedProp, "rejiciendumProp");
|
93
|
//// nomStatusMap.put(NomenclaturalStatusType.uuidSanctioned, "");
|
94
|
//
|
95
|
// nomStatusMap.put(NomenclaturalStatusType.uuidSubnudum, "rejiciendum");
|
96
|
// nomStatusMap.put(NomenclaturalStatusType.uuidSuperfluous, "superfluum");
|
97
|
// nomStatusMap.put(NomenclaturalStatusType.uuidValid, "valid");
|
98
|
//
|
99
|
// //CDM is missing abortivum, available, combinatio, negatum, oblitum,
|
100
|
// // protectum, rejiciendumUtique, rejiciendumUtiqueProp
|
101
|
// }
|
102
|
|
103
|
public static String transformToGbifRank(Rank term){
|
104
|
if ( term == null){
|
105
|
return null;
|
106
|
}else{
|
107
|
if (rankMapping == null){
|
108
|
try {
|
109
|
rankMapping = new TermMapping("rankToGbif.tsv");
|
110
|
} catch (IOException e) {
|
111
|
throw new RuntimeException(e);
|
112
|
}
|
113
|
}
|
114
|
String result = rankMapping.getTerm(term.getUuid());
|
115
|
if (StringUtils.isBlank(result)){
|
116
|
logger.info("Rank (" + term.getLabel() + ") could not be mapped. Use CDM abbreviated label instead.");
|
117
|
}
|
118
|
return result;
|
119
|
}
|
120
|
}
|
121
|
|
122
|
public static String transformSpecimenTypeStatusToGbif(SpecimenTypeDesignationStatus status){
|
123
|
if ( status == null){
|
124
|
return null;
|
125
|
}else{
|
126
|
if (specimenTypeMapping == null){
|
127
|
try {
|
128
|
specimenTypeMapping = new TermMapping("specimenTypeStatusToGbif.tsv");
|
129
|
} catch (IOException e) {
|
130
|
throw new RuntimeException(e);
|
131
|
}
|
132
|
}
|
133
|
String result = specimenTypeMapping.getTerm(status.getUuid());
|
134
|
if (StringUtils.isBlank(result)){
|
135
|
logger.info("Specimen type status (" + status.getLabel() + ") could not be mapped. Use CDM status label.");
|
136
|
}
|
137
|
return result;
|
138
|
}
|
139
|
}
|
140
|
|
141
|
|
142
|
public static String transformNameTypeStatusToGbif(NameTypeDesignationStatus status){
|
143
|
if ( status == null){
|
144
|
return null;
|
145
|
}else{
|
146
|
if (nameTypeMapping == null){
|
147
|
try {
|
148
|
nameTypeMapping = new TermMapping("nameTypeStatusToGbif.tsv");
|
149
|
} catch (IOException e) {
|
150
|
throw new RuntimeException(e);
|
151
|
}
|
152
|
}
|
153
|
String result = nameTypeMapping.getTerm(status.getUuid());
|
154
|
if (StringUtils.isBlank(result)){
|
155
|
logger.info("Name type status (" + status.getLabel() + ") could not be mapped. Use CDM status label.");
|
156
|
}
|
157
|
return result;
|
158
|
}
|
159
|
}
|
160
|
|
161
|
public static String transformToGbifSex(DefinedTerm sex) {
|
162
|
if ( sex == null){
|
163
|
return null;
|
164
|
}else{
|
165
|
if (sexMapping == null){
|
166
|
try {
|
167
|
sexMapping = new TermMapping("sexToGbif.tsv");
|
168
|
} catch (IOException e) {
|
169
|
throw new RuntimeException(e);
|
170
|
}
|
171
|
}
|
172
|
String result = sexMapping.getTerm(sex.getUuid());
|
173
|
if (StringUtils.isBlank(result)){
|
174
|
logger.info("Sex (" + sex.getLabel() + ") could not be mapped. Use CDM status label.");
|
175
|
}
|
176
|
return result;
|
177
|
}
|
178
|
}
|
179
|
|
180
|
public static String transformToGbifLifeStage(DefinedTerm stage) {
|
181
|
if ( stage == null){
|
182
|
return null;
|
183
|
}else{
|
184
|
if (lifeStageMapping == null){
|
185
|
try {
|
186
|
lifeStageMapping = new TermMapping("lifeStageToGbif.tsv");
|
187
|
} catch (IOException e) {
|
188
|
throw new RuntimeException(e);
|
189
|
}
|
190
|
}
|
191
|
String result = lifeStageMapping.getTerm(stage.getUuid());
|
192
|
if (StringUtils.isBlank(result)){
|
193
|
logger.info("Life stage (" + stage.getLabel() + ") could not be mapped. Use CDM status label.");
|
194
|
}
|
195
|
return result;
|
196
|
}
|
197
|
}
|
198
|
|
199
|
public static String transformToGbifOccStatus(PresenceAbsenceTerm status) {
|
200
|
if ( status == null){
|
201
|
return null;
|
202
|
}else{
|
203
|
if (occStatusMapping == null){
|
204
|
try {
|
205
|
occStatusMapping = new TermMapping("presenceTermToGbifOccurrenceStatus.tsv");
|
206
|
} catch (IOException e) {
|
207
|
throw new RuntimeException(e);
|
208
|
}
|
209
|
}
|
210
|
String result = occStatusMapping.getTerm(status.getUuid());
|
211
|
if (StringUtils.isBlank(result)){
|
212
|
logger.info("PresenceAbsence term (" + status.getLabel() + ") could not be mapped to GBIF occurrence status. Use CDM status label.");
|
213
|
}
|
214
|
return result;
|
215
|
}
|
216
|
}
|
217
|
|
218
|
public static String transformToGbifEstablishmentMeans(PresenceAbsenceTerm status) {
|
219
|
if ( status == null){
|
220
|
return null;
|
221
|
}else{
|
222
|
if (establishmentMeansMapping == null){
|
223
|
try {
|
224
|
establishmentMeansMapping = new TermMapping("presenceTermToGbifEstablishmentMeans.tsv");
|
225
|
} catch (IOException e) {
|
226
|
throw new RuntimeException(e);
|
227
|
}
|
228
|
}
|
229
|
String result = establishmentMeansMapping.getTerm(status.getUuid());
|
230
|
if (StringUtils.isBlank(result)){
|
231
|
logger.info("PresenceAbsence term (" + status.getLabel() + ") could not be mapped to GBIF establishment means. Use CDM status label.");
|
232
|
}
|
233
|
return result;
|
234
|
}
|
235
|
}
|
236
|
|
237
|
}
|