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