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