1
|
/**
|
2
|
* Copyright (C) 2007 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.pesi.faunaEuropaea;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.sql.SQLException;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
20
|
import eu.etaxonomy.cdm.io.pesi.out.PesiTransformer;
|
21
|
import eu.etaxonomy.cdm.model.common.Language;
|
22
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
23
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
24
|
import eu.etaxonomy.cdm.model.name.Rank;
|
25
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
26
|
import eu.etaxonomy.cdm.model.term.Representation;
|
27
|
import eu.etaxonomy.cdm.model.term.TermType;
|
28
|
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
|
29
|
|
30
|
/**
|
31
|
* @author a.babadshanjan
|
32
|
* @since 12.05.2009
|
33
|
*/
|
34
|
public final class FaunaEuropaeaTransformer {
|
35
|
private static final Logger logger = Logger.getLogger(FaunaEuropaeaTransformer.class);
|
36
|
|
37
|
public static final UUID uuidFauEuArea = UUID.fromString("16325043-e7da-4742-b012-9ce03362a124");
|
38
|
|
39
|
// Query
|
40
|
public static final int Q_NO_RESTRICTION = -1;
|
41
|
|
42
|
// TaxonStatus
|
43
|
public static final int T_STATUS_ACCEPTED = 1;
|
44
|
public static final int T_STATUS_NOT_ACCEPTED = 0;
|
45
|
|
46
|
// Author
|
47
|
public static final int A_AUCT = 1;
|
48
|
public static final String A_AUCTNAME = "auct.";
|
49
|
|
50
|
// Parenthesis
|
51
|
public static final int P_PARENTHESIS = 1;
|
52
|
|
53
|
// User
|
54
|
|
55
|
public static final int U_ACTIVE = 1;
|
56
|
|
57
|
//new AbsencePresenceTermUUIDs
|
58
|
|
59
|
// Rank
|
60
|
public static final int R_KINGDOM = 1;
|
61
|
public static final int R_SUBKINGDOM = 2;
|
62
|
public static final int R_SUPERPHYLUM = 3;
|
63
|
public static final int R_PHYLUM = 4;
|
64
|
public static final int R_SUBPHYLUM = 5;
|
65
|
public static final int R_INFRAPHYLUM = 6;
|
66
|
public static final int R_CLASS = 7;
|
67
|
public static final int R_SUBCLASS = 8;
|
68
|
public static final int R_INFRACLASS = 9;
|
69
|
public static final int R_SUPERORDER = 10;
|
70
|
public static final int R_ORDER = 11;
|
71
|
public static final int R_SUBORDER = 12;
|
72
|
public static final int R_INFRAORDER = 13;
|
73
|
public static final int R_SUPERFAMILY = 14;
|
74
|
public static final int R_FAMILY = 15;
|
75
|
public static final int R_SUBFAMILY = 16;
|
76
|
public static final int R_TRIBE = 17;
|
77
|
public static final int R_SUBTRIBE = 18;
|
78
|
public static final int R_GENUS = 19;
|
79
|
public static final int R_SUBGENUS = 20;
|
80
|
public static final int R_SPECIES = 21;
|
81
|
public static final int R_SUBSPECIES = 22;
|
82
|
|
83
|
public static PresenceAbsenceTerm occStatus2PresenceAbsence(int occStatusId){
|
84
|
|
85
|
if (Integer.valueOf(occStatusId) == null) {
|
86
|
return PresenceAbsenceTerm.PRESENT();
|
87
|
}
|
88
|
switch (occStatusId){
|
89
|
case 0: return PresenceAbsenceTerm.PRESENT();
|
90
|
case 2: return PresenceAbsenceTerm.ABSENT();
|
91
|
case 1: return PresenceAbsenceTerm.PRESENT_DOUBTFULLY();
|
92
|
default: {
|
93
|
return null;
|
94
|
}
|
95
|
}
|
96
|
}
|
97
|
|
98
|
|
99
|
public static PresenceAbsenceTerm occStatus2PresenceAbsence_ (int occStatusId) throws UnknownCdmTypeException{
|
100
|
switch (occStatusId){
|
101
|
case 0: return null;
|
102
|
//case 110: return AbsenceTerm.CULTIVATED_REPORTED_IN_ERROR();
|
103
|
case 120: return PresenceAbsenceTerm.CULTIVATED();
|
104
|
// case 210: return AbsenceTerm.INTRODUCED_REPORTED_IN_ERROR();
|
105
|
case 220: return PresenceAbsenceTerm.INTRODUCED_PRESENCE_QUESTIONABLE();
|
106
|
case 230: return PresenceAbsenceTerm.INTRODUCED_FORMERLY_INTRODUCED();
|
107
|
case 240: return PresenceAbsenceTerm.INTRODUCED_DOUBTFULLY_INTRODUCED();
|
108
|
case 250: return PresenceAbsenceTerm.INTRODUCED();
|
109
|
case 260: return PresenceAbsenceTerm.INTRODUCED_UNCERTAIN_DEGREE_OF_NATURALISATION();
|
110
|
case 270: return PresenceAbsenceTerm.CASUAL();
|
111
|
case 280: return PresenceAbsenceTerm.NATURALISED();
|
112
|
//case 310: return AbsenceTerm.NATIVE_REPORTED_IN_ERROR();
|
113
|
case 320: return PresenceAbsenceTerm.NATIVE_PRESENCE_QUESTIONABLE();
|
114
|
case 330: return PresenceAbsenceTerm.NATIVE_FORMERLY_NATIVE();
|
115
|
case 340: return PresenceAbsenceTerm.NATIVE_DOUBTFULLY_NATIVE();
|
116
|
case 350: return PresenceAbsenceTerm.NATIVE();
|
117
|
case 999: {
|
118
|
logger.warn("endemic for EM can not be transformed in legal status");
|
119
|
//TODO preliminary
|
120
|
return PresenceAbsenceTerm.PRESENT();
|
121
|
}
|
122
|
default: {
|
123
|
throw new UnknownCdmTypeException("Unknown occurrence status (id=" + Integer.valueOf(occStatusId).toString() + ")");
|
124
|
}
|
125
|
}
|
126
|
}
|
127
|
|
128
|
|
129
|
public static Rank rankId2Rank (ResultSet rs, boolean useUnknown) throws UnknownCdmTypeException {
|
130
|
Rank result;
|
131
|
try {
|
132
|
int rankId = rs.getInt("rnk_id");
|
133
|
int parentRankId = rs.getInt("rnk_rnk_id");
|
134
|
String rankName = rs.getString("rnk_name");
|
135
|
String rankLatinName = rs.getString("rnk_latinname");
|
136
|
int rankCategory = rs.getInt("rnk_category");
|
137
|
|
138
|
if (logger.isDebugEnabled()) {
|
139
|
logger.debug(rankId + ", " + parentRankId + ", " + rankName + ", " + rankCategory);
|
140
|
}
|
141
|
|
142
|
try {
|
143
|
result = Rank.getRankByNameOrIdInVoc(rankName);
|
144
|
} catch (UnknownCdmTypeException e1) {
|
145
|
|
146
|
switch (rankId) {
|
147
|
case 0: return null;
|
148
|
case R_KINGDOM: return Rank.KINGDOM();
|
149
|
case R_SUBKINGDOM: return Rank.SUBKINGDOM();
|
150
|
case R_SUPERPHYLUM: return Rank.SUPERPHYLUM();
|
151
|
case R_PHYLUM: return Rank.PHYLUM();
|
152
|
case R_SUBPHYLUM: return Rank.SUBPHYLUM();
|
153
|
case R_INFRAPHYLUM: return Rank.INFRAPHYLUM();
|
154
|
case R_CLASS: return Rank.CLASS();
|
155
|
case R_SUBCLASS: return Rank.SUBCLASS();
|
156
|
case R_INFRACLASS: return Rank.INFRACLASS();
|
157
|
case R_SUPERORDER: return Rank.SUPERORDER();
|
158
|
case R_ORDER: return Rank.ORDER();
|
159
|
case R_SUBORDER: return Rank.SUBORDER();
|
160
|
case R_INFRAORDER: return Rank.INFRAORDER();
|
161
|
case R_SUPERFAMILY: return Rank.SUPERFAMILY();
|
162
|
case R_FAMILY: return Rank.FAMILY();
|
163
|
case R_SUBFAMILY: return Rank.SUBFAMILY();
|
164
|
case R_TRIBE: return Rank.TRIBE();
|
165
|
case R_SUBTRIBE: return Rank.SUBTRIBE();
|
166
|
case R_GENUS: return Rank.GENUS();
|
167
|
case R_SUBGENUS: return Rank.SUBGENUS();
|
168
|
case R_SPECIES: return Rank.SPECIES();
|
169
|
case R_SUBSPECIES: return Rank.SUBSPECIES();
|
170
|
|
171
|
default: {
|
172
|
if (useUnknown){
|
173
|
logger.error("Rank unknown. Created UNKNOWN_RANK");
|
174
|
return Rank.UNKNOWN_RANK();
|
175
|
}
|
176
|
throw new UnknownCdmTypeException("Unknown Rank id" + Integer.valueOf(rankId).toString());
|
177
|
}
|
178
|
}
|
179
|
}
|
180
|
return result;
|
181
|
} catch (SQLException e) {
|
182
|
e.printStackTrace();
|
183
|
logger.warn("Exception occurred. Created UNKNOWN_RANK instead");
|
184
|
return Rank.UNKNOWN_RANK();
|
185
|
}
|
186
|
}
|
187
|
|
188
|
|
189
|
public final static HashMap<Integer, Language> languageFK2Language = new HashMap<>();
|
190
|
|
191
|
static
|
192
|
{
|
193
|
languageFK2Language.put(1, Language.ALBANIAN());
|
194
|
languageFK2Language.put(4, Language.AZERBAIJANI());
|
195
|
languageFK2Language.put(6, Language.BULGARIAN());
|
196
|
languageFK2Language.put(10, Language.DANISH());
|
197
|
languageFK2Language.put(11, Language.DUTCH_MIDDLE());
|
198
|
languageFK2Language.put(12, Language.ENGLISH());
|
199
|
languageFK2Language.put(16, Language.FRENCH());
|
200
|
|
201
|
languageFK2Language.put(18, Language.GERMAN());
|
202
|
languageFK2Language.put(19, Language.GREEK_MODERN());
|
203
|
languageFK2Language.put(23, Language.HEBREW());
|
204
|
languageFK2Language.put(24, Language.ITALIAN());
|
205
|
languageFK2Language.put(26, Language.LITHUANIAN());
|
206
|
languageFK2Language.put(30, Language.NORWEGIAN());
|
207
|
languageFK2Language.put(31, Language.POLISH());
|
208
|
languageFK2Language.put(34, Language.RUSSIAN());
|
209
|
languageFK2Language.put(54, Language.SLOVAK());
|
210
|
languageFK2Language.put(55, Language.SLOVENIAN());
|
211
|
languageFK2Language.put(57, Language.SWEDISH());
|
212
|
languageFK2Language.put(58, Language.TURKISH());
|
213
|
|
214
|
languageFK2Language.put(59, Language.UKRAINIAN());
|
215
|
languageFK2Language.put(60, Language.WELSH());
|
216
|
languageFK2Language.put(62, Language.GALICIAN());
|
217
|
//languageFK2Language.put(83, getEnglishUS());
|
218
|
languageFK2Language.put(97, Language.IRISH());
|
219
|
|
220
|
|
221
|
languageFK2Language.put(100, Language.NORWEGIAN_BOKMOL());
|
222
|
languageFK2Language.put(101, Language.NORWEGIAN_NYNORSK());
|
223
|
|
224
|
languageFK2Language.put(102, Language.ARABIC());
|
225
|
languageFK2Language.put(103, Language.ARMENIAN());
|
226
|
|
227
|
languageFK2Language.put(104, Language.CATALAN_VALENCIAN());
|
228
|
languageFK2Language.put(105, Language.CHINESE());
|
229
|
languageFK2Language.put(106, Language.ESTONIAN());
|
230
|
languageFK2Language.put(107, Language.FINNISH());
|
231
|
|
232
|
languageFK2Language.put(108, Language.GAELIC_SCOTTISH_GAELIC());
|
233
|
languageFK2Language.put(109, Language.JAPANESE());
|
234
|
languageFK2Language.put(110, Language.KOREAN());
|
235
|
languageFK2Language.put(111, Language.LATIN());
|
236
|
languageFK2Language.put(112, Language.LATVIAN());
|
237
|
languageFK2Language.put(113, Language.PERSIAN());
|
238
|
languageFK2Language.put(114, Language.PORTUGUESE());
|
239
|
languageFK2Language.put(115, Language.ROMANIAN());
|
240
|
languageFK2Language.put(116, Language.GAELIC_SCOTTISH_GAELIC());
|
241
|
languageFK2Language.put(117, Language.SWAHILI());
|
242
|
languageFK2Language.put(118, Language.SPANISH_CASTILIAN());
|
243
|
}
|
244
|
|
245
|
static NomenclaturalStatusType nomStatusTempNamed;
|
246
|
|
247
|
private static DefinedTerm taxonomicSpecialistType;
|
248
|
|
249
|
private static UUID uuidTaxonomicSpecialistType = UUID.fromString("006879e4-cf99-405a-a720-2e81d9cbc34c");
|
250
|
|
251
|
private static DefinedTerm groupCoordinatorType;
|
252
|
|
253
|
private static UUID uuidGroupCoordinatorType = UUID.fromString("3a827ebe-4410-40e5-a241-941b17028e11");
|
254
|
|
255
|
private static DefinedTerm associateSpecialistType;
|
256
|
|
257
|
private static UUID uuidAssociateSpecialistType = UUID.fromString("8258f73c-e0ad-4f87-a88c-53c58c08bba9");
|
258
|
|
259
|
private static Language langEnglishUS;
|
260
|
|
261
|
private static UUID uuidEnglishUS;
|
262
|
|
263
|
public static NomenclaturalStatusType getNomStatusTempNamed(ITermService termService){
|
264
|
if (nomStatusTempNamed == null){
|
265
|
nomStatusTempNamed = (NomenclaturalStatusType)termService.find(PesiTransformer.uuidNomStatusTemporaryName);
|
266
|
if (nomStatusTempNamed == null){
|
267
|
nomStatusTempNamed = NomenclaturalStatusType.NewInstance("temporary named", "temporary named", "temp. named", Language.ENGLISH());
|
268
|
Representation repLatin = Representation.NewInstance("", "", "", Language.LATIN());
|
269
|
nomStatusTempNamed.addRepresentation(repLatin);
|
270
|
nomStatusTempNamed.setUuid(PesiTransformer.uuidNomStatusTemporaryName);
|
271
|
NomenclaturalStatusType.ALTERNATIVE().getVocabulary().addTerm(nomStatusTempNamed);
|
272
|
termService.save(nomStatusTempNamed);
|
273
|
}
|
274
|
}
|
275
|
return nomStatusTempNamed;
|
276
|
}
|
277
|
|
278
|
public static Language getEnglishUS(ITermService termService){
|
279
|
if (langEnglishUS == null){
|
280
|
langEnglishUS = (Language)termService.find(uuidEnglishUS);
|
281
|
if (langEnglishUS == null){
|
282
|
logger.info("create language english-us");
|
283
|
langEnglishUS = Language.NewInstance("english-United States", "english-US", "eng-US");
|
284
|
langEnglishUS.setUuid(uuidEnglishUS);
|
285
|
|
286
|
langEnglishUS = (Language)termService.save(langEnglishUS);
|
287
|
languageFK2Language.put(83, langEnglishUS);
|
288
|
}
|
289
|
}
|
290
|
return langEnglishUS;
|
291
|
}
|
292
|
|
293
|
public static DefinedTerm getTaxonomicSpecialistType(ITermService termService) {
|
294
|
if (taxonomicSpecialistType == null){
|
295
|
taxonomicSpecialistType = (DefinedTerm)termService.find(uuidTaxonomicSpecialistType);
|
296
|
if (taxonomicSpecialistType == null){
|
297
|
logger.info("create taxonomic specialist type");
|
298
|
taxonomicSpecialistType = DefinedTerm.NewInstance(TermType.TaxonNodeAgentRelationType, "taxonomic specialist", "taxonomic specialist", "TS");
|
299
|
|
300
|
taxonomicSpecialistType.setUuid(uuidTaxonomicSpecialistType);
|
301
|
|
302
|
termService.save(taxonomicSpecialistType);
|
303
|
}
|
304
|
}
|
305
|
return taxonomicSpecialistType;
|
306
|
}
|
307
|
|
308
|
public static DefinedTerm getGroupCoordinatorType(ITermService termService) {
|
309
|
if (groupCoordinatorType == null){
|
310
|
groupCoordinatorType = (DefinedTerm)termService.find(uuidGroupCoordinatorType);
|
311
|
if (groupCoordinatorType == null){
|
312
|
groupCoordinatorType = DefinedTerm.NewInstance(TermType.TaxonNodeAgentRelationType, "group coordinator", "group coordinator", "GC");
|
313
|
|
314
|
groupCoordinatorType.setUuid(uuidGroupCoordinatorType);
|
315
|
|
316
|
termService.save(groupCoordinatorType);
|
317
|
}
|
318
|
}
|
319
|
return groupCoordinatorType;
|
320
|
}
|
321
|
|
322
|
public static DefinedTerm getAssociateSpecialistType(ITermService termService) {
|
323
|
if (associateSpecialistType == null){
|
324
|
associateSpecialistType = (DefinedTerm)termService.find(uuidAssociateSpecialistType);
|
325
|
if (associateSpecialistType == null){
|
326
|
associateSpecialistType = DefinedTerm.NewInstance(TermType.TaxonNodeAgentRelationType, "associate specialist", "associate specialist", "AS");
|
327
|
|
328
|
associateSpecialistType.setUuid(uuidAssociateSpecialistType);
|
329
|
|
330
|
termService.save(associateSpecialistType);
|
331
|
}
|
332
|
}
|
333
|
return associateSpecialistType;
|
334
|
}
|
335
|
|
336
|
public static Language langFK2Language(Integer languageFk) {
|
337
|
Language result = languageFK2Language.get(languageFk);
|
338
|
return result;
|
339
|
}
|
340
|
}
|