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.cuba;
|
11
|
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.springframework.stereotype.Component;
|
16
|
import org.springframework.transaction.TransactionStatus;
|
17
|
|
18
|
import eu.etaxonomy.cdm.io.common.CdmImportBase;
|
19
|
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
|
20
|
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
|
21
|
import eu.etaxonomy.cdm.model.common.TermType;
|
22
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
23
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
24
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
25
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
26
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
27
|
|
28
|
/**
|
29
|
* @author a.mueller
|
30
|
* @created 05.01.2016
|
31
|
*/
|
32
|
|
33
|
@Component
|
34
|
public class CubaVocabularyImport extends CdmImportBase<CubaImportConfigurator, CubaImportState> {
|
35
|
private static final long serialVersionUID = -747486709409732371L;
|
36
|
|
37
|
private static final Logger logger = Logger.getLogger(CubaVocabularyImport.class);
|
38
|
|
39
|
/**
|
40
|
* {@inheritDoc}
|
41
|
*/
|
42
|
@Override
|
43
|
protected void doInvoke(CubaImportState state) {
|
44
|
try {
|
45
|
makeAreas(state);
|
46
|
makePresenceAbsenceTerms(state);
|
47
|
} catch (UndefinedTransformerMethodException e) {
|
48
|
e.printStackTrace();
|
49
|
}
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* @param state
|
54
|
* @throws UndefinedTransformerMethodException
|
55
|
*/
|
56
|
private void makePresenceAbsenceTerms(CubaImportState state) throws UndefinedTransformerMethodException {
|
57
|
TransactionStatus tx = startTransaction();
|
58
|
|
59
|
IInputTransformer transformer = state.getTransformer();
|
60
|
|
61
|
//vocabulary
|
62
|
UUID cubaStatusVocabularyUuid = UUID.fromString("e74bba61-551b-4f59-af83-a1a770e4b0ae");
|
63
|
String label = "Flora of Cuba Distribution Status";
|
64
|
String abbrev = null;
|
65
|
boolean isOrdered = true;
|
66
|
PresenceAbsenceTerm anyTerm = PresenceAbsenceTerm.PRESENT(); //just any
|
67
|
TermVocabulary<PresenceAbsenceTerm> cubaStatusVocabualary = getVocabulary(TermType.PresenceAbsenceTerm, cubaStatusVocabularyUuid, label, label, abbrev, null, isOrdered, anyTerm);
|
68
|
|
69
|
final boolean PRESENT = false;
|
70
|
|
71
|
|
72
|
//indigenous
|
73
|
UUID indigenousUuid = transformer.getPresenceTermUuid("+");
|
74
|
PresenceAbsenceTerm indigenous = this.getPresenceTerm(state, indigenousUuid, "indigenous", "Indigenous", "+", false);
|
75
|
UUID indigenousDoubtfulUuid = transformer.getPresenceTermUuid("?");
|
76
|
PresenceAbsenceTerm indigenousDoubtful = this.getPresenceTerm(state, indigenousDoubtfulUuid, "indigenous, doubtfully present", "indigenous, doubtfully present", "?", false);
|
77
|
UUID nonNativeDoubtfulNaturalizedUuid = transformer.getPresenceTermUuid("P");
|
78
|
PresenceAbsenceTerm nonNative = this.getPresenceTerm(state, nonNativeDoubtfulNaturalizedUuid, "non-native and doubtfully naturalised", "non-native and doubtfully naturalised", "P", false);
|
79
|
UUID casualUuid = transformer.getPresenceTermUuid("A");
|
80
|
PresenceAbsenceTerm casual = this.getPresenceTerm(state, casualUuid, "adventive (casual) alien", "adventive (casual) alien", "A", false);
|
81
|
|
82
|
//occasionally cultivated
|
83
|
label = "occasionally cultivated";
|
84
|
abbrev = "(C)";
|
85
|
UUID occasionallyCultivatedUuid = transformer.getPresenceTermUuid(abbrev);
|
86
|
PresenceAbsenceTerm occasionallyCultivated = getPresenceTerm(state, occasionallyCultivatedUuid, label, label, abbrev, PRESENT, cubaStatusVocabualary);
|
87
|
|
88
|
//doubtfully present
|
89
|
UUID doubtfullyIndigenousUuid = transformer.getPresenceTermUuid("D");
|
90
|
PresenceAbsenceTerm doubtfullyIndigenous = this.getPresenceTerm(state, doubtfullyIndigenousUuid, "indigenous?", "Indigenous?", "D", false);
|
91
|
UUID doubtfullyIndigenousDoubtfulUuid = transformer.getPresenceTermUuid("??");
|
92
|
PresenceAbsenceTerm doubtfulIndigenousDoutful = this.getPresenceTerm(state, doubtfullyIndigenousDoubtfulUuid, "?indigenous?", "doubfully indigenous, (und) doubtfully present", "??", false);
|
93
|
|
94
|
UUID doubtfullyNaturalisedUuid = transformer.getPresenceTermUuid("?N");
|
95
|
PresenceAbsenceTerm doubtfullyNaturalised = this.getPresenceTerm(state, doubtfullyNaturalisedUuid, "?non-native and doubtfully naturalised", "non-native and doubtfully naturalised, doubtfully present", "?N", false);
|
96
|
UUID doubtfullyNonNativeUuid = transformer.getPresenceTermUuid("?P");
|
97
|
PresenceAbsenceTerm doubtfullyNonNative = this.getPresenceTerm(state, doubtfullyNonNativeUuid, "?adventive (casual) alien ", "adventive (casual) alien, doubtfully present", "?P", false);
|
98
|
|
99
|
//reported in error
|
100
|
boolean isAbsent = true;
|
101
|
UUID endemicErrorUuid = transformer.getPresenceTermUuid("-E");
|
102
|
PresenceAbsenceTerm endemicError = this.getPresenceTerm(state, endemicErrorUuid, "endemic, reported in error", "endemic, reported in error", "-E", isAbsent);
|
103
|
UUID naturalizedErrorUuid = transformer.getPresenceTermUuid("-N");
|
104
|
PresenceAbsenceTerm naturalizedError = this.getPresenceTerm(state, naturalizedErrorUuid, "naturalised, reported in error", "naturalised, reported in error", "-N", isAbsent);
|
105
|
UUID nonNativeErrorUuid = transformer.getPresenceTermUuid("-P");
|
106
|
PresenceAbsenceTerm nonNativeError = this.getPresenceTerm(state, nonNativeErrorUuid, "non-native and doubtfully naturalised, reported in error", "non-native and doubtfully naturalised, reported in error", "-P", isAbsent);
|
107
|
UUID casualErrorUuid = transformer.getPresenceTermUuid("-A");
|
108
|
PresenceAbsenceTerm casualError = this.getPresenceTerm(state, casualErrorUuid, "adventive alien , reported in error", "adventive alien , reported in error", "-A", isAbsent);
|
109
|
|
110
|
|
111
|
|
112
|
commitTransaction(tx);
|
113
|
}
|
114
|
|
115
|
private boolean makeAreas(CubaImportState state) throws UndefinedTransformerMethodException{
|
116
|
TransactionStatus tx = startTransaction();
|
117
|
|
118
|
IInputTransformer transformer = state.getTransformer();
|
119
|
|
120
|
//vocabulary
|
121
|
UUID cubaAreasVocabularyUuid = UUID.fromString("c81e3c7b-3c01-47d1-87cf-388de4b1908c");
|
122
|
String label = "Cuba Areas";
|
123
|
String abbrev = null;
|
124
|
boolean isOrdered = true;
|
125
|
NamedArea anyArea = NamedArea.ARCTICOCEAN(); //just any
|
126
|
TermVocabulary<NamedArea> cubaAreasVocabualary = getVocabulary(TermType.NamedArea, cubaAreasVocabularyUuid, label, label, abbrev, null, isOrdered, anyArea);
|
127
|
|
128
|
TermMatchMode matchMode = null;
|
129
|
|
130
|
NamedAreaType areaType = null; //TODO
|
131
|
NamedAreaLevel level = null; //TODO
|
132
|
|
133
|
//Cuba
|
134
|
level = NamedAreaLevel.COUNTRY();
|
135
|
label = "Cuba";
|
136
|
abbrev = "C";
|
137
|
UUID cubaUuid = transformer.getNamedAreaUuid(abbrev);
|
138
|
NamedArea cuba = getNamedArea(state, cubaUuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
139
|
|
140
|
//Regions
|
141
|
level = null;
|
142
|
|
143
|
//Western Cuba
|
144
|
label = "Western Cuba";
|
145
|
abbrev = "CuW";
|
146
|
UUID cubaWestUuid = transformer.getNamedAreaUuid(abbrev);
|
147
|
NamedArea westernCuba = getNamedArea(state, cubaWestUuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
148
|
cuba.addIncludes(westernCuba);
|
149
|
|
150
|
//Central Cuba
|
151
|
label = "Central Cuba";
|
152
|
abbrev = "CuC";
|
153
|
UUID cubaCentralUuid = transformer.getNamedAreaUuid(abbrev);
|
154
|
NamedArea centralCuba = getNamedArea(state, cubaCentralUuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
155
|
cuba.addIncludes(centralCuba);
|
156
|
|
157
|
//East Cuba
|
158
|
label = "East Cuba";
|
159
|
abbrev = "CuE";
|
160
|
UUID cubaEastUuid = transformer.getNamedAreaUuid(abbrev);
|
161
|
NamedArea eastCuba = getNamedArea(state, cubaEastUuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
162
|
cuba.addIncludes(eastCuba);
|
163
|
|
164
|
//Provinces - West
|
165
|
level = NamedAreaLevel.PROVINCE();
|
166
|
|
167
|
//Pinar del Río PR
|
168
|
label = "Pinar del Río";
|
169
|
abbrev = "PR*";
|
170
|
UUID uuid = transformer.getNamedAreaUuid(abbrev);
|
171
|
NamedArea area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
172
|
westernCuba.addIncludes(area);
|
173
|
|
174
|
// //Habana Hab
|
175
|
// label = "Habana"; //including Ciudad de la Habana, Mayabeque, Artemisa
|
176
|
// abbrev = "HAB";
|
177
|
// uuid = transformer.getNamedAreaUuid(abbrev);
|
178
|
// NamedArea habana = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
179
|
// westernCuba.addIncludes(habana);
|
180
|
|
181
|
//Ciudad de la Habana
|
182
|
label = "Ciudad de la Habana";
|
183
|
abbrev = "Hab*";
|
184
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
185
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
186
|
westernCuba.addIncludes(area);
|
187
|
//Ciudad de la Habana
|
188
|
label = "Mayabeque";
|
189
|
abbrev = "May";
|
190
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
191
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
192
|
westernCuba.addIncludes(area);
|
193
|
//Ciudad de la Habana
|
194
|
label = "Artemisa";
|
195
|
abbrev = "Art";
|
196
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
197
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
198
|
westernCuba.addIncludes(area);
|
199
|
|
200
|
|
201
|
//Matanzas Mat
|
202
|
label = "Matanzas";
|
203
|
abbrev = "Mat";
|
204
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
205
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
206
|
westernCuba.addIncludes(area);
|
207
|
|
208
|
//Isla de la Juventud IJ
|
209
|
label = "Isla de la Juventud";
|
210
|
abbrev = "IJ";
|
211
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
212
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
213
|
westernCuba.addIncludes(area);
|
214
|
|
215
|
//Provinces - Central
|
216
|
//Villa Clara VC
|
217
|
label = "Villa Clara";
|
218
|
abbrev = "VC";
|
219
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
220
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
221
|
centralCuba.addIncludes(area);
|
222
|
|
223
|
//Cienfuegos Ci VC
|
224
|
label = "Cienfuegos";
|
225
|
abbrev = "Ci";
|
226
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
227
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
228
|
centralCuba.addIncludes(area);
|
229
|
|
230
|
//Sancti Spiritus SS
|
231
|
label = "Sancti Spiritus";
|
232
|
abbrev = "SS";
|
233
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
234
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
235
|
centralCuba.addIncludes(area);
|
236
|
|
237
|
//Ciego de Ávila CA
|
238
|
label = "Ciego de Ávila";
|
239
|
abbrev = "CA";
|
240
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
241
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
242
|
centralCuba.addIncludes(area);
|
243
|
|
244
|
//Camagüey Cam
|
245
|
label = "Camagüey";
|
246
|
abbrev = "Cam";
|
247
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
248
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
249
|
centralCuba.addIncludes(area);
|
250
|
|
251
|
//Las Tunas LT
|
252
|
label = "Las Tunas";
|
253
|
abbrev = "LT";
|
254
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
255
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
256
|
centralCuba.addIncludes(area);
|
257
|
|
258
|
//Provinces - East
|
259
|
//Granma Gr
|
260
|
label = "Granma";
|
261
|
abbrev = "Gr";
|
262
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
263
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
264
|
eastCuba.addIncludes(area);
|
265
|
|
266
|
//Holguín Ho
|
267
|
label = "Holguín";
|
268
|
abbrev = "Ho";
|
269
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
270
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
271
|
eastCuba.addIncludes(area);
|
272
|
|
273
|
//Santiago de Cuba SC
|
274
|
label = "Santiago de Cuba";
|
275
|
abbrev = "SC";
|
276
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
277
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
278
|
eastCuba.addIncludes(area);
|
279
|
|
280
|
//Guantánamo Gu
|
281
|
label = "Guantánamo";
|
282
|
abbrev = "Gu";
|
283
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
284
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
285
|
eastCuba.addIncludes(area);
|
286
|
|
287
|
//other Greater Antilles (Cuba, Española, Jamaica, Puerto Rico)
|
288
|
level = null;
|
289
|
//Española Esp (=Haiti + Dominican Republic)
|
290
|
label = "Española";
|
291
|
abbrev = "Esp";
|
292
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
293
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
294
|
|
295
|
//Jamaica Ja
|
296
|
level = NamedAreaLevel.COUNTRY();
|
297
|
label = "Jamaica";
|
298
|
abbrev = "Ja";
|
299
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
300
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
301
|
|
302
|
//Puerto Rico PR
|
303
|
level = NamedAreaLevel.COUNTRY();
|
304
|
label = "Puerto Rico";
|
305
|
abbrev = "PR";
|
306
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
307
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
308
|
|
309
|
//Lesser Antilles Men
|
310
|
level = null;
|
311
|
label = "Lesser Antilles";
|
312
|
abbrev = "Men";
|
313
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
314
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
315
|
|
316
|
//Bahamas
|
317
|
label = "Bahamas";
|
318
|
abbrev = "Bah";
|
319
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
320
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
321
|
|
322
|
//Cayman Islands
|
323
|
label = "Cayman Islands"; //[Trinidad, Tobago, Curaçao, Margarita, ABC Isl. => S. America];
|
324
|
abbrev = "Cay";
|
325
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
326
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
327
|
|
328
|
//World
|
329
|
//N America
|
330
|
label = "N America"; //(incl. Mexico)
|
331
|
abbrev = "AmN";
|
332
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
333
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
334
|
|
335
|
//Central America
|
336
|
label = "Central America";
|
337
|
abbrev = "AmC";
|
338
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
339
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
340
|
|
341
|
//S America
|
342
|
label = "S America";
|
343
|
abbrev = "AmS";
|
344
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
345
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
346
|
|
347
|
//Old World
|
348
|
label = "Old World ";
|
349
|
abbrev = "VM";
|
350
|
uuid = transformer.getNamedAreaUuid(abbrev);
|
351
|
area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
|
352
|
|
353
|
commitTransaction(tx);
|
354
|
return true;
|
355
|
}
|
356
|
|
357
|
|
358
|
@Override
|
359
|
protected boolean isIgnore(CubaImportState state) {
|
360
|
return ! state.getConfig().isDoVocabularies();
|
361
|
}
|
362
|
|
363
|
|
364
|
@Override
|
365
|
protected boolean doCheck(CubaImportState state) {
|
366
|
logger.warn("DoCheck not yet implemented for CubaVocabularyImport");
|
367
|
return true;
|
368
|
}
|
369
|
|
370
|
|
371
|
|
372
|
}
|