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.pesi.out;
|
10
|
|
11
|
import static java.util.EnumSet.of;
|
12
|
|
13
|
import java.sql.Connection;
|
14
|
import java.sql.PreparedStatement;
|
15
|
import java.sql.SQLException;
|
16
|
import java.sql.Types;
|
17
|
import java.util.Arrays;
|
18
|
import java.util.HashSet;
|
19
|
import java.util.List;
|
20
|
import java.util.Map;
|
21
|
import java.util.Set;
|
22
|
|
23
|
import org.apache.log4j.Logger;
|
24
|
import org.springframework.stereotype.Component;
|
25
|
import org.springframework.transaction.TransactionStatus;
|
26
|
|
27
|
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
|
28
|
import eu.etaxonomy.cdm.io.common.DbExportStateBase;
|
29
|
import eu.etaxonomy.cdm.io.common.Source;
|
30
|
import eu.etaxonomy.cdm.io.common.TdwgAreaProvider;
|
31
|
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
|
32
|
import eu.etaxonomy.cdm.io.common.mapping.out.CollectionExportMapping;
|
33
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbAnnotationMapper;
|
34
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbAreaMapper;
|
35
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbConstantMapper;
|
36
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbDescriptionElementTaxonMapper;
|
37
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbDistributionStatusMapper;
|
38
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbExportIgnoreMapper;
|
39
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbLanguageMapper;
|
40
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbObjectMapper;
|
41
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbOriginalNameMapper;
|
42
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbSimpleFilterMapper;
|
43
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbSingleSourceMapper;
|
44
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbStringMapper;
|
45
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbTextDataMapper;
|
46
|
import eu.etaxonomy.cdm.io.common.mapping.out.IdMapper;
|
47
|
import eu.etaxonomy.cdm.io.common.mapping.out.MethodMapper;
|
48
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
49
|
import eu.etaxonomy.cdm.model.common.Extension;
|
50
|
import eu.etaxonomy.cdm.model.common.ExtensionType;
|
51
|
import eu.etaxonomy.cdm.model.common.Language;
|
52
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
53
|
import eu.etaxonomy.cdm.model.common.Marker;
|
54
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
55
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
56
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
57
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
58
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
59
|
import eu.etaxonomy.cdm.model.description.Feature;
|
60
|
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
|
61
|
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
|
62
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
63
|
import eu.etaxonomy.cdm.model.description.TextData;
|
64
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
65
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
66
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
67
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
68
|
import eu.etaxonomy.cdm.profiler.ProfilerController;
|
69
|
/**
|
70
|
* The export class for {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase DescriptionElements}.<p>
|
71
|
* Inserts into DataWarehouse database table <code>Note</code>.<p>
|
72
|
* It is divided into two phases:<ul>
|
73
|
* <li>Phase 1: Export of DescriptionElements as Notes.
|
74
|
* <li>Phase 2: Export of TaxonName extensions <code>taxComment</code>, <code>fauComment</code> and <code>fauExtraCodes</code> as Notes.</ul>
|
75
|
* @author e.-m.lee
|
76
|
* @since 23.02.2010
|
77
|
*/
|
78
|
@Component
|
79
|
public class PesiDescriptionExport extends PesiExportBase {
|
80
|
|
81
|
private static final long serialVersionUID = -1486235807814098217L;
|
82
|
private static final Logger logger = Logger.getLogger(PesiDescriptionExport.class);
|
83
|
|
84
|
private static final Class<? extends CdmBase> standardMethodParameter = DescriptionElementBase.class;
|
85
|
|
86
|
private static int modCount = 1000;
|
87
|
private static final String dbNoteTableName = "Note";
|
88
|
private static final String dbOccurrenceTableName = "Occurrence";
|
89
|
private static final String dbVernacularTableName = "CommonName";
|
90
|
private static final String dbImageTableName = "Image";
|
91
|
private static final String dbAdditionalSourceTableName = "AdditionalTaxonSource";
|
92
|
private static final String pluralString = "attached infos";
|
93
|
private static final String parentPluralString = "Taxa";
|
94
|
|
95
|
//decide where to handle them best (configurator, transformer, single method, ...)
|
96
|
private static Set<Integer> excludedNoteCategories = new HashSet<Integer>(Arrays.asList(new Integer[]{250,251,252,253,10,11,13}));
|
97
|
|
98
|
|
99
|
//debugging
|
100
|
private static int countDescriptions;
|
101
|
private static int countTaxa;
|
102
|
private static int countDistribution;
|
103
|
private static int countAdditionalSources;
|
104
|
private static int countImages;
|
105
|
private static int countNotes;
|
106
|
|
107
|
private static int countCommonName;
|
108
|
private static int countOccurrence;
|
109
|
private static int countOthers;
|
110
|
|
111
|
public PesiDescriptionExport() {
|
112
|
super();
|
113
|
}
|
114
|
|
115
|
@Override
|
116
|
public Class<? extends CdmBase> getStandardMethodParameter() {
|
117
|
return standardMethodParameter;
|
118
|
}
|
119
|
|
120
|
@Override
|
121
|
protected boolean doCheck(PesiExportState state) {
|
122
|
boolean result = true;
|
123
|
return result;
|
124
|
}
|
125
|
|
126
|
@Override
|
127
|
protected void doInvoke(PesiExportState state) {
|
128
|
try {
|
129
|
logger.info("*** Started Making " + pluralString + " ...");
|
130
|
|
131
|
// Stores whether this invoke was successful or not.
|
132
|
boolean success = true;
|
133
|
|
134
|
// Get specific mappings: (CDM) DescriptionElement -> (PESI) Note
|
135
|
PesiExportMapping notesMapping = getNotesMapping();
|
136
|
notesMapping.initialize(state);
|
137
|
|
138
|
// Get specific mappings: (CDM) DescriptionElement -> (PESI) Occurrence
|
139
|
PesiExportMapping occurrenceMapping = getOccurrenceMapping();
|
140
|
occurrenceMapping.initialize(state);
|
141
|
|
142
|
// Get specific mappings: (CDM) DescriptionElement -> (PESI) Additional taxon source
|
143
|
PesiExportMapping addSourceSourceMapping = getAddTaxonSourceSourceMapping();
|
144
|
addSourceSourceMapping.initialize(state);
|
145
|
PesiExportMapping additionalSourceMapping = getAdditionalTaxonSourceMapping();
|
146
|
additionalSourceMapping.initialize(state);
|
147
|
|
148
|
// Get specific mappings: (CDM) DescriptionElement -> (PESI) Additional taxon source
|
149
|
|
150
|
PesiExportMapping vernacularMapping = getVernacularNamesMapping();
|
151
|
vernacularMapping.initialize(state);
|
152
|
|
153
|
// Get specific mappings: (CDM) DescriptionElement -> (PESI) Additional taxon source
|
154
|
PesiExportMapping imageMapping = getImageMapping();
|
155
|
imageMapping.initialize(state);
|
156
|
|
157
|
// Start transaction
|
158
|
success &= doPhase01(state, notesMapping, occurrenceMapping, addSourceSourceMapping, additionalSourceMapping, vernacularMapping, imageMapping);
|
159
|
|
160
|
// Start transaction
|
161
|
success &= doPhase01b(state, notesMapping, occurrenceMapping, addSourceSourceMapping, additionalSourceMapping, vernacularMapping, imageMapping);
|
162
|
|
163
|
|
164
|
logger.info("PHASE 2...");
|
165
|
success &= doPhase02(state);
|
166
|
|
167
|
|
168
|
logger.info("*** Finished Making " + pluralString + " ..." + getSuccessString(success));
|
169
|
|
170
|
if (!success){
|
171
|
state.getResult().addError("An unknown problem occurred");
|
172
|
}
|
173
|
return;
|
174
|
} catch (SQLException e) {
|
175
|
e.printStackTrace();
|
176
|
logger.error(e.getMessage());
|
177
|
state.getResult().addException(e, e.getMessage());
|
178
|
}
|
179
|
}
|
180
|
|
181
|
//PHASE 01: Description Elements
|
182
|
private boolean doPhase01(PesiExportState state, PesiExportMapping notesMapping, PesiExportMapping occurrenceMapping, PesiExportMapping addSourceSourceMapping,
|
183
|
PesiExportMapping additionalSourceMapping, PesiExportMapping vernacularMapping, PesiExportMapping imageMapping) throws SQLException {
|
184
|
|
185
|
System.out.println("PHASE 1 of description import");
|
186
|
logger.info("PHASE 1...");
|
187
|
int count = 0;
|
188
|
int pastCount = 0;
|
189
|
boolean success = true;
|
190
|
//int limit = state.getConfig().getLimitSave();
|
191
|
int limit = 100;
|
192
|
|
193
|
List<Taxon> taxonList = null;
|
194
|
|
195
|
TransactionStatus txStatus = startTransaction(true);
|
196
|
logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ...");
|
197
|
List<String> propPath = Arrays.asList(new String[]{"descriptions.elements.*"});
|
198
|
|
199
|
if (logger.isDebugEnabled()){
|
200
|
logger.debug("Start snapshot, before starting loop");
|
201
|
ProfilerController.memorySnapshot();
|
202
|
}
|
203
|
//taxon descriptions
|
204
|
int partitionCount = 0;
|
205
|
while ((taxonList = getNextTaxonPartition(Taxon.class, limit, partitionCount++, propPath )) != null ) {
|
206
|
|
207
|
logger.info("Fetched " + taxonList.size() + " " + pluralString + ". Exporting...");
|
208
|
System.out.println("Fetched " + taxonList.size() + " " + pluralString + ". Exporting...");
|
209
|
|
210
|
for (Taxon taxon : taxonList) {
|
211
|
countTaxa++;
|
212
|
doCount(count++, modCount, pluralString);
|
213
|
state.setCurrentTaxon(taxon);
|
214
|
if (!taxon.getDescriptions().isEmpty()){
|
215
|
success &= handleSingleTaxon(taxon, state, notesMapping, occurrenceMapping, addSourceSourceMapping,
|
216
|
additionalSourceMapping, vernacularMapping, imageMapping);
|
217
|
}
|
218
|
}
|
219
|
taxonList = null;
|
220
|
state.setCurrentTaxon(null);
|
221
|
|
222
|
// Commit transaction
|
223
|
commitTransaction(txStatus);
|
224
|
logger.info("Exported " + (count - pastCount) + " " + pluralString + ". Total: " + count);
|
225
|
System.out.println("Exported " + (count - pastCount) + " " + pluralString + ". Total: " + count);
|
226
|
pastCount = count;
|
227
|
ProfilerController.memorySnapshot();
|
228
|
// Start transaction
|
229
|
txStatus = startTransaction(true);
|
230
|
logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") for description import ...");
|
231
|
}
|
232
|
|
233
|
logger.info("No " + pluralString + " left to fetch.");
|
234
|
logger.info("Partition: " + partitionCount);
|
235
|
logger.info("Taxa: " + countTaxa);
|
236
|
logger.info("Desc: " + countDescriptions);
|
237
|
logger.info("Distr: " + countDistribution);
|
238
|
logger.info("Occur: " + countOccurrence);
|
239
|
logger.info("Commons: " + countCommonName);
|
240
|
logger.info("AddSrc: " + countAdditionalSources);
|
241
|
logger.info("Images: " + countImages);
|
242
|
logger.info("Notes: " + countNotes);
|
243
|
logger.info("Others: " + countOthers);
|
244
|
|
245
|
// Commit transaction
|
246
|
commitTransaction(txStatus);
|
247
|
logger.debug("Committed transaction.");
|
248
|
return success;
|
249
|
}
|
250
|
|
251
|
//PHASE 01b: Name Descriptions
|
252
|
private boolean doPhase01b(PesiExportState state, PesiExportMapping notesMapping, PesiExportMapping occurrenceMapping, PesiExportMapping addSourceSourceMapping,
|
253
|
PesiExportMapping additionalSourceMapping, PesiExportMapping vernacularMapping, PesiExportMapping imageMapping) throws SQLException {
|
254
|
logger.info("PHASE 1b...");
|
255
|
int count = 0;
|
256
|
int pastCount = 0;
|
257
|
boolean success = true;
|
258
|
//int limit = state.getConfig().getLimitSave();
|
259
|
int limit = 100;
|
260
|
List<TaxonNameDescription> nameDescList = null;
|
261
|
|
262
|
TransactionStatus txStatus = startTransaction(true);
|
263
|
logger.info("Started new transaction. Fetching some name descriptions (max: " + limit + ") ...");
|
264
|
List<String> propPath = Arrays.asList(new String[]{"descriptions.elements.*"});
|
265
|
|
266
|
//name descriptions
|
267
|
int partitionCount = 0;
|
268
|
while ((nameDescList = getNextNameDescriptionPartition( limit, partitionCount++, propPath )) != null ) {
|
269
|
|
270
|
logger.info("Fetched " + nameDescList.size() + " name descriptions. Exporting...");
|
271
|
|
272
|
for (TaxonNameDescription desc : nameDescList) {
|
273
|
countTaxa++;
|
274
|
doCount(count++, modCount, "name descriptions");
|
275
|
boolean isImageGallery = desc.isImageGallery();
|
276
|
|
277
|
TaxonName name = desc.getTaxonName();
|
278
|
|
279
|
for (DescriptionElementBase element : desc.getElements()){
|
280
|
if (isPurePesiName(name)){
|
281
|
success &= handleDescriptionElement(state, notesMapping, occurrenceMapping, vernacularMapping, imageMapping,
|
282
|
addSourceSourceMapping, additionalSourceMapping, isImageGallery, element);
|
283
|
}else{
|
284
|
for (TaxonBase<?> taxonBase : name.getTaxonBases()){
|
285
|
if (isPesiTaxon(taxonBase)){
|
286
|
state.setCurrentTaxon(taxonBase);
|
287
|
success &= handleDescriptionElement(state, notesMapping, occurrenceMapping, vernacularMapping, imageMapping,
|
288
|
addSourceSourceMapping, additionalSourceMapping, isImageGallery, element);
|
289
|
state.setSourceForAdditionalSourceCreated(true);
|
290
|
}
|
291
|
}
|
292
|
state.setSourceForAdditionalSourceCreated(false);
|
293
|
}
|
294
|
}
|
295
|
}
|
296
|
nameDescList = null;
|
297
|
state.setCurrentTaxon(null);
|
298
|
|
299
|
// Commit transaction
|
300
|
commitTransaction(txStatus);
|
301
|
logger.info("Exported " + (count - pastCount) + " name descriptions. Total: " + count);
|
302
|
pastCount = count;
|
303
|
|
304
|
// Start transaction
|
305
|
txStatus = startTransaction(true);
|
306
|
logger.info("Started new transaction. Fetching some name descriptions (max: " + limit + ") for description import ...");
|
307
|
}
|
308
|
|
309
|
logger.info("No " + pluralString + " left to fetch.");
|
310
|
logger.info("Partition: " + partitionCount);
|
311
|
logger.info("Taxa: " + countTaxa);
|
312
|
logger.info("Desc: " + countDescriptions);
|
313
|
logger.info("Distr: " + countDistribution);
|
314
|
logger.info("Occur: " + countOccurrence);
|
315
|
logger.info("Commons: " + countCommonName);
|
316
|
logger.info("AddSrc: " + countAdditionalSources);
|
317
|
logger.info("Images: " + countImages);
|
318
|
logger.info("Notes: " + countNotes);
|
319
|
logger.info("Others: " + countOthers);
|
320
|
|
321
|
// Commit transaction
|
322
|
commitTransaction(txStatus);
|
323
|
logger.debug("Committed transaction.");
|
324
|
return success;
|
325
|
}
|
326
|
|
327
|
private boolean handleSingleTaxon(Taxon taxon, PesiExportState state, PesiExportMapping notesMapping, PesiExportMapping occurrenceMapping,
|
328
|
PesiExportMapping addSourceSourceMapping, PesiExportMapping additionalSourceMapping,
|
329
|
PesiExportMapping vernacularMapping, PesiExportMapping imageMapping) throws SQLException {
|
330
|
boolean success = true;
|
331
|
|
332
|
|
333
|
Set<DescriptionBase<?>> descriptions = new HashSet<>();
|
334
|
descriptions.addAll(taxon.getDescriptions());
|
335
|
|
336
|
for (DescriptionBase<?> desc : descriptions){
|
337
|
|
338
|
|
339
|
boolean isImageGallery = desc.isImageGallery();
|
340
|
for (DescriptionElementBase element : desc.getElements()){
|
341
|
success &= handleDescriptionElement(state, notesMapping, occurrenceMapping, vernacularMapping, imageMapping,
|
342
|
addSourceSourceMapping, additionalSourceMapping, isImageGallery, element);
|
343
|
countDescriptions++;
|
344
|
}
|
345
|
}
|
346
|
logger.info("number of handled decriptionelements " + countDescriptions);
|
347
|
descriptions = null;
|
348
|
return success;
|
349
|
}
|
350
|
|
351
|
private boolean handleDescriptionElement(PesiExportState state, PesiExportMapping notesMapping,
|
352
|
PesiExportMapping occurrenceMapping, PesiExportMapping vernacularMapping, PesiExportMapping imageMapping,
|
353
|
PesiExportMapping addSourceSourceMapping, PesiExportMapping additionalSourceMapping, boolean isImageGallery, DescriptionElementBase element) throws SQLException {
|
354
|
try {
|
355
|
boolean success = true;
|
356
|
if (isImageGallery){
|
357
|
//TODO handle Images
|
358
|
countImages++;
|
359
|
success &= imageMapping.invoke(element);
|
360
|
}else if (isCommonName(element)){
|
361
|
countCommonName++;
|
362
|
if (element.isInstanceOf(TextData.class)){
|
363
|
//we do not import text data common names
|
364
|
}else{
|
365
|
success &= vernacularMapping.invoke(element);
|
366
|
}
|
367
|
}else if (isOccurrence(element)){
|
368
|
countOccurrence++;
|
369
|
Distribution distribution = CdmBase.deproxy(element, Distribution.class);
|
370
|
MarkerType markerType = getUuidMarkerType(PesiTransformer.uuidMarkerTypeHasNoLastAction, state);
|
371
|
|
372
|
distribution.addMarker(Marker.NewInstance(markerType, true));
|
373
|
if (isPesiDistribution(state, distribution)){
|
374
|
countDistribution++;
|
375
|
try{
|
376
|
success &=occurrenceMapping.invoke(distribution);
|
377
|
}catch(Exception e){
|
378
|
System.err.println(distribution.getInDescription().getTitleCache());
|
379
|
e.printStackTrace();
|
380
|
}
|
381
|
}
|
382
|
}else if (isAdditionalTaxonSource(element)){
|
383
|
countAdditionalSources++;
|
384
|
if (! state.isSourceForAdditionalSourceCreated()){
|
385
|
success &= addSourceSourceMapping.invoke(element);
|
386
|
}
|
387
|
success &= additionalSourceMapping.invoke(element);
|
388
|
}else if (isExcludedNote(element)){
|
389
|
//do nothing
|
390
|
}else if (isPesiNote(element)){
|
391
|
countNotes++;
|
392
|
success &= notesMapping.invoke(element);
|
393
|
|
394
|
}else{
|
395
|
countOthers++;
|
396
|
String featureTitle = element.getFeature() == null ? "no feature" :element.getFeature().getTitleCache();
|
397
|
logger.warn("Description element type not yet handled by PESI export: " + element.getUuid() + ", " + element.getClass() + ", " + featureTitle);
|
398
|
}
|
399
|
return success;
|
400
|
} catch (Exception e) {
|
401
|
logger.warn("Exception appeared in description element handling: " + e);
|
402
|
e.printStackTrace();
|
403
|
return false;
|
404
|
}
|
405
|
}
|
406
|
|
407
|
private boolean isExcludedNote(DescriptionElementBase element) {
|
408
|
Integer categoryFk = PesiTransformer.feature2NoteCategoryFk(element.getFeature());
|
409
|
//TODO decide where to handle them best (configurator, transformer, single method, ...)
|
410
|
return (excludedNoteCategories.contains(categoryFk));
|
411
|
}
|
412
|
|
413
|
private boolean isPesiDistribution(PesiExportState state, Distribution distribution) {
|
414
|
//currently we use the E+M summary status to decide if a distribution should be exported
|
415
|
if (distribution.getStatus() == null){
|
416
|
return false;
|
417
|
}
|
418
|
|
419
|
//...this may change in future so we keep the following code
|
420
|
Integer key;
|
421
|
//area filter
|
422
|
NamedArea area = distribution.getArea();
|
423
|
if (area == null){
|
424
|
logger.warn("Area is null for distribution " + distribution.getUuid());
|
425
|
return false;
|
426
|
}else if (area.getUuid().equals(BerlinModelTransformer.euroMedUuid)){
|
427
|
//E+M area only holds endemic status information and therefore is not exported to PESI
|
428
|
return false;
|
429
|
}else if (area.equals(TdwgAreaProvider.getAreaByTdwgAbbreviation("1"))){
|
430
|
//Europe area never holds status information (may probably be deleted in E+M)
|
431
|
return false;
|
432
|
// }else if (area.equals(TdwgArea.getAreaByTdwgAbbreviation("21"))){
|
433
|
// //Macaronesia records should not be exported to PESI
|
434
|
// return false;
|
435
|
// //TODO exclude Russion areas Rs*, and maybe ohters
|
436
|
|
437
|
} else {
|
438
|
try {
|
439
|
if (state.getTransformer().getKeyByNamedArea(area) == null){
|
440
|
String warning = "Area (%s,%s) not available in PESI transformer for taxon %S: ";
|
441
|
TaxonBase<?> taxon = state.getCurrentTaxon();
|
442
|
warning = String.format(warning, area.getTitleCache(), area.getRepresentation(Language.ENGLISH()).getAbbreviatedLabel(),taxon ==null? "-" : taxon.getTitleCache());
|
443
|
logger.warn(warning);
|
444
|
return false;
|
445
|
}
|
446
|
} catch (UndefinedTransformerMethodException e1) {
|
447
|
logger.warn("Area not available in PESI transformer " + area.getTitleCache());
|
448
|
return false;
|
449
|
}
|
450
|
}
|
451
|
return true;
|
452
|
|
453
|
//
|
454
|
// //status
|
455
|
// PresenceAbsenceTermBase<?> status = distribution.getStatus();
|
456
|
// if (status == null){
|
457
|
// logger.warn("No status for distribution: " + distribution.getUuid());
|
458
|
// return false;
|
459
|
// }
|
460
|
// try {
|
461
|
// key = (Integer)state.getTransformer().getKeyByPresenceAbsenceTerm(status);
|
462
|
// if (key != null){
|
463
|
// return true;
|
464
|
// }else{
|
465
|
// logger.warn("PresenceAbsenceTerm " + status.getTitleCache() + "not handled in transformer");
|
466
|
// return false;
|
467
|
// }
|
468
|
// } catch (UndefinedTransformerMethodException e) {
|
469
|
// logger.warn("PresenceAbsenceTerm " + status.getTitleCache() + "not handled in transformer");
|
470
|
// return false;
|
471
|
// }
|
472
|
}
|
473
|
|
474
|
private boolean isPesiNote(DescriptionElementBase element) {
|
475
|
return (getNoteCategoryFk(element) != null);
|
476
|
}
|
477
|
|
478
|
private boolean isAdditionalTaxonSource(DescriptionElementBase element) {
|
479
|
Feature feature = element.getFeature();
|
480
|
if (feature == null){
|
481
|
return false;
|
482
|
}
|
483
|
return (feature.equals(Feature.CITATION()) || feature.equals(Feature.ADDITIONAL_PUBLICATION()));
|
484
|
}
|
485
|
|
486
|
private boolean isOccurrence(DescriptionElementBase element) {
|
487
|
Feature feature = element.getFeature();
|
488
|
if (feature != null && feature.equals(Feature.DISTRIBUTION())){
|
489
|
return true;
|
490
|
}else if (element.isInstanceOf(Distribution.class)){
|
491
|
logger.warn("Description element has class 'Distribution' but has no feature 'Distribution'");
|
492
|
return true;
|
493
|
}else{
|
494
|
return false;
|
495
|
}
|
496
|
}
|
497
|
|
498
|
private boolean isCommonName(DescriptionElementBase element) {
|
499
|
Feature feature = element.getFeature();
|
500
|
if (feature == null){
|
501
|
return false;
|
502
|
}
|
503
|
return (feature.equals(Feature.COMMON_NAME()));
|
504
|
}
|
505
|
|
506
|
//PHASE 02: Name extensions
|
507
|
private boolean doPhase02(PesiExportState state) {
|
508
|
TransactionStatus txStatus;
|
509
|
boolean success = true;
|
510
|
|
511
|
// Get the limit for objects to save within a single transaction.
|
512
|
//int limit = state.getConfig().getLimitSave();
|
513
|
int limit = 100;
|
514
|
txStatus = startTransaction(true);
|
515
|
ExtensionType taxCommentExtensionType = (ExtensionType)getTermService().find(PesiTransformer.taxCommentUuid);
|
516
|
ExtensionType fauCommentExtensionType = (ExtensionType)getTermService().find(PesiTransformer.fauCommentUuid);
|
517
|
ExtensionType fauExtraCodesExtensionType = (ExtensionType)getTermService().find(PesiTransformer.fauExtraCodesUuid);
|
518
|
List<TaxonName> taxonNameList = null;
|
519
|
|
520
|
int count = 0;
|
521
|
int pastCount = 0;
|
522
|
Connection connection = state.getConfig().getDestination().getConnection();
|
523
|
logger.info("Started new transaction. Fetching some " + parentPluralString + " first (max: " + limit + ") ...");
|
524
|
logger.warn("TODO handle extensions on taxon level, not name level (");
|
525
|
while ((taxonNameList = getNameService().list(null, limit, count, null, null)).size() > 0) {
|
526
|
|
527
|
logger.info("Fetched " + taxonNameList.size() + " names. Exporting...");
|
528
|
for (TaxonName taxonName : taxonNameList) {
|
529
|
Set<Extension> extensions = taxonName.getExtensions();
|
530
|
for (Extension extension : extensions) {
|
531
|
if (extension.getType().equals(taxCommentExtensionType)) {
|
532
|
String taxComment = extension.getValue();
|
533
|
invokeNotes(taxComment,
|
534
|
PesiTransformer.getNoteCategoryFk(PesiTransformer.taxCommentUuid),
|
535
|
PesiTransformer.getNoteCategoryCache(PesiTransformer.taxCommentUuid),
|
536
|
null, null, getTaxonKey(taxonName, state),connection);
|
537
|
} else if (extension.getType().equals(fauCommentExtensionType)) {
|
538
|
String fauComment = extension.getValue();
|
539
|
invokeNotes(fauComment,
|
540
|
PesiTransformer.getNoteCategoryFk(PesiTransformer.fauCommentUuid),
|
541
|
PesiTransformer.getNoteCategoryCache(PesiTransformer.fauCommentUuid),
|
542
|
null, null, getTaxonKey(taxonName, state),connection);
|
543
|
} else if (extension.getType().equals(fauExtraCodesExtensionType)) {
|
544
|
String fauExtraCodes = extension.getValue();
|
545
|
invokeNotes(fauExtraCodes,
|
546
|
PesiTransformer.getNoteCategoryFk(PesiTransformer.fauExtraCodesUuid),
|
547
|
PesiTransformer.getNoteCategoryCache(PesiTransformer.fauExtraCodesUuid),
|
548
|
null, null, getTaxonKey(taxonName, state),connection);
|
549
|
}
|
550
|
}
|
551
|
|
552
|
doCount(count++, modCount, pluralString);
|
553
|
}
|
554
|
|
555
|
// Commit transaction
|
556
|
commitTransaction(txStatus);
|
557
|
logger.debug("Committed transaction.");
|
558
|
logger.info("Exported " + (count - pastCount) + " names. Total: " + count);
|
559
|
pastCount = count;
|
560
|
|
561
|
// Start transaction
|
562
|
txStatus = startTransaction(true);
|
563
|
logger.info("Started new transaction. Fetching some names first (max: " + limit + ") ...");
|
564
|
}
|
565
|
if (taxonNameList.size() == 0) {
|
566
|
logger.info("No names left to fetch.");
|
567
|
}
|
568
|
taxonNameList = null;
|
569
|
// Commit transaction
|
570
|
commitTransaction(txStatus);
|
571
|
logger.debug("Committed transaction.");
|
572
|
return success;
|
573
|
}
|
574
|
|
575
|
/**
|
576
|
* @param taxComment
|
577
|
* @param noteCategoryFk
|
578
|
* @param noteCategoryCache
|
579
|
* @param object
|
580
|
* @param object2
|
581
|
*/
|
582
|
private void invokeNotes(String note, Integer noteCategoryFk,
|
583
|
String noteCategoryCache, Integer languageFk, String languageCache,
|
584
|
Integer taxonFk, Connection connection) {
|
585
|
String notesSql = "UPDATE Note SET Note_1 = ?, NoteCategoryFk = ?, NoteCategoryCache = ?, LanguageFk = ?, LanguageCache = ? WHERE TaxonFk = ?";
|
586
|
try {
|
587
|
PreparedStatement notesStmt = connection.prepareStatement(notesSql);
|
588
|
|
589
|
if (note != null) {
|
590
|
notesStmt.setString(1, note);
|
591
|
} else {
|
592
|
notesStmt.setObject(1, null);
|
593
|
}
|
594
|
|
595
|
if (noteCategoryFk != null) {
|
596
|
notesStmt.setInt(2, noteCategoryFk);
|
597
|
} else {
|
598
|
notesStmt.setObject(2, null);
|
599
|
}
|
600
|
|
601
|
if (noteCategoryCache != null) {
|
602
|
notesStmt.setString(3, noteCategoryCache);
|
603
|
} else {
|
604
|
notesStmt.setObject(3, null);
|
605
|
}
|
606
|
|
607
|
if (languageFk != null) {
|
608
|
notesStmt.setInt(4, languageFk);
|
609
|
} else {
|
610
|
notesStmt.setObject(4, null);
|
611
|
}
|
612
|
|
613
|
if (languageCache != null) {
|
614
|
notesStmt.setString(5, languageCache);
|
615
|
} else {
|
616
|
notesStmt.setObject(5, null);
|
617
|
}
|
618
|
|
619
|
if (taxonFk != null) {
|
620
|
notesStmt.setInt(6, taxonFk);
|
621
|
} else {
|
622
|
notesStmt.setObject(6, null);
|
623
|
}
|
624
|
|
625
|
notesStmt.executeUpdate();
|
626
|
} catch (SQLException e) {
|
627
|
logger.error("Note could not be created: " + note);
|
628
|
e.printStackTrace();
|
629
|
}
|
630
|
|
631
|
|
632
|
}
|
633
|
|
634
|
/**
|
635
|
* Deletes all entries of database tables related to <code>Note</code>.
|
636
|
* @param state The PesiExportState
|
637
|
* @return Whether the delete operation was successful or not.
|
638
|
*/
|
639
|
protected boolean doDelete(PesiExportState state) {
|
640
|
PesiExportConfigurator pesiConfig = state.getConfig();
|
641
|
|
642
|
String sql;
|
643
|
Source destination = pesiConfig.getDestination();
|
644
|
|
645
|
// Clear NoteSource
|
646
|
sql = "DELETE FROM NoteSource";
|
647
|
destination.setQuery(sql);
|
648
|
destination.update(sql);
|
649
|
|
650
|
// Clear Note
|
651
|
sql = "DELETE FROM " + dbNoteTableName;
|
652
|
destination.setQuery(sql);
|
653
|
destination.update(sql);
|
654
|
return true;
|
655
|
}
|
656
|
|
657
|
/* (non-Javadoc)
|
658
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IoStateBase)
|
659
|
*/
|
660
|
@Override
|
661
|
protected boolean isIgnore(PesiExportState state) {
|
662
|
return ! state.getConfig().isDoDescription();
|
663
|
}
|
664
|
|
665
|
|
666
|
/**
|
667
|
* Returns the <code>Note_2</code> attribute.
|
668
|
* @param descriptionElement The {@link DescriptionElementBase DescriptionElement}.
|
669
|
* @return The <code>Note_2</code> attribute.
|
670
|
* @see MethodMapper
|
671
|
*/
|
672
|
@SuppressWarnings("unused") //used for mapper
|
673
|
private static String getNote_2(DescriptionElementBase element) {
|
674
|
//E+M map links -> medium
|
675
|
if (element.getFeature() != null && element.getFeature().getUuid().equals(BerlinModelTransformer.uuidFeatureMaps)){
|
676
|
String text = CdmBase.deproxy(element, TextData.class).getText(Language.ENGLISH());
|
677
|
if (text.contains("medium")){
|
678
|
return "medium";
|
679
|
}
|
680
|
}
|
681
|
return null;
|
682
|
}
|
683
|
|
684
|
/**
|
685
|
* Returns the <code>NoteCategoryFk</code> attribute.
|
686
|
* @param descriptionElement The {@link DescriptionElementBase DescriptionElement}.
|
687
|
* @return The <code>NoteCategoryFk</code> attribute.
|
688
|
* @see MethodMapper
|
689
|
*/
|
690
|
private static Integer getNoteCategoryFk(DescriptionElementBase descriptionElement) {
|
691
|
Integer result = null;
|
692
|
result = PesiTransformer.feature2NoteCategoryFk(descriptionElement.getFeature());
|
693
|
//TODO decide where to handle them best (configurator, transformer, single method, ...)
|
694
|
if (excludedNoteCategories.contains(result)){
|
695
|
result = null;
|
696
|
}
|
697
|
return result;
|
698
|
}
|
699
|
|
700
|
/**
|
701
|
* Returns the <code>NoteCategoryCache</code> attribute.
|
702
|
* @param descriptionElement The {@link DescriptionElementBase DescriptionElement}.
|
703
|
* @return The <code>NoteCategoryCache</code> attribute.
|
704
|
* @see MethodMapper
|
705
|
*/
|
706
|
@SuppressWarnings("unused")
|
707
|
private static String getNoteCategoryCache(DescriptionElementBase descriptionElement, PesiExportState state) {
|
708
|
return state.getTransformer().getCacheByFeature(descriptionElement.getFeature());
|
709
|
}
|
710
|
|
711
|
|
712
|
|
713
|
|
714
|
/**
|
715
|
* Returns the <code>LanguageFk</code> attribute.
|
716
|
* @param descriptionElement The {@link DescriptionElementBase DescriptionElement}.
|
717
|
* @return The <code>LanguageFk</code> attribute.
|
718
|
* @see MethodMapper
|
719
|
*/
|
720
|
@SuppressWarnings("unused")
|
721
|
private static Integer getLanguageFk(DescriptionElementBase descriptionElement) {
|
722
|
Language language = getLanguage(descriptionElement);
|
723
|
|
724
|
return PesiTransformer.language2LanguageId(language);
|
725
|
}
|
726
|
|
727
|
/**
|
728
|
* Returns the <code>LanguageCache</code> attribute.
|
729
|
* @param descriptionElement The {@link DescriptionElementBase DescriptionElement}.
|
730
|
* @return The <code>LanguageCache</code> attribute.
|
731
|
* @throws UndefinedTransformerMethodException
|
732
|
* @see MethodMapper
|
733
|
*/
|
734
|
@SuppressWarnings("unused")
|
735
|
private static String getLanguageCache(DescriptionElementBase descriptionElement, PesiExportState state) throws UndefinedTransformerMethodException {
|
736
|
Language language = getLanguage(descriptionElement);
|
737
|
return state.getTransformer().getCacheByLanguage(language);
|
738
|
}
|
739
|
|
740
|
private static Language getLanguage(DescriptionElementBase descriptionElement) {
|
741
|
Language language = null;
|
742
|
|
743
|
Map<Language, LanguageString> multilanguageText = null;
|
744
|
if (descriptionElement.isInstanceOf(CommonTaxonName.class)) {
|
745
|
CommonTaxonName commonTaxonName = CdmBase.deproxy(descriptionElement, CommonTaxonName.class);
|
746
|
language = commonTaxonName.getLanguage();
|
747
|
} else if (descriptionElement.isInstanceOf(TextData.class)) {
|
748
|
TextData textData = CdmBase.deproxy(descriptionElement, TextData.class);
|
749
|
multilanguageText = textData.getMultilanguageText();
|
750
|
} else if (descriptionElement.isInstanceOf(IndividualsAssociation.class)) {
|
751
|
IndividualsAssociation individualsAssociation = CdmBase.deproxy(descriptionElement, IndividualsAssociation.class);
|
752
|
multilanguageText = individualsAssociation.getDescription();
|
753
|
} else if (descriptionElement.isInstanceOf(TaxonInteraction.class)) {
|
754
|
TaxonInteraction taxonInteraction = CdmBase.deproxy(descriptionElement, TaxonInteraction.class);
|
755
|
multilanguageText = taxonInteraction.getDescription();
|
756
|
} else {
|
757
|
logger.debug("Given descriptionElement does not support languages. Hence LanguageCache could not be determined: " + descriptionElement.getUuid());
|
758
|
}
|
759
|
|
760
|
if (multilanguageText != null) {
|
761
|
Set<Language> languages = multilanguageText.keySet();
|
762
|
|
763
|
// TODO: Think of something more sophisticated than this
|
764
|
if (languages.size() > 0) {
|
765
|
language = languages.iterator().next();
|
766
|
}
|
767
|
if (languages.size() > 1){
|
768
|
logger.warn("There is more than 1 language for a given description (" + descriptionElement.getClass().getSimpleName() + "):" + descriptionElement.getUuid());
|
769
|
}
|
770
|
}
|
771
|
return language;
|
772
|
}
|
773
|
|
774
|
// /**
|
775
|
// * Returns the <code>Region</code> attribute.
|
776
|
// * @param descriptionElement The {@link DescriptionElementBase DescriptionElement}.
|
777
|
// * @return The <code>Region</code> attribute.
|
778
|
// * @see MethodMapper
|
779
|
// */
|
780
|
// @SuppressWarnings("unused")
|
781
|
// private static String getRegion(DescriptionElementBase descriptionElement) {
|
782
|
// String result = null;
|
783
|
// DescriptionBase<?> inDescription = descriptionElement.getInDescription();
|
784
|
//
|
785
|
// // Area information are associated to TaxonDescriptions and Distributions.
|
786
|
// if (descriptionElement.isInstanceOf(Distribution.class)) {
|
787
|
// Distribution distribution = CdmBase.deproxy(descriptionElement, Distribution.class);
|
788
|
// result = PesiTransformer.area2AreaCache(distribution.getArea());
|
789
|
// } else if (inDescription != null && inDescription.isInstanceOf(TaxonDescription.class)) {
|
790
|
// TaxonDescription taxonDescription = CdmBase.deproxy(inDescription, TaxonDescription.class);
|
791
|
// Set<NamedArea> namedAreas = taxonDescription.getGeoScopes();
|
792
|
// if (namedAreas.size() == 1) {
|
793
|
// result = PesiTransformer.area2AreaCache(namedAreas.iterator().next());
|
794
|
// } else if (namedAreas.size() > 1) {
|
795
|
// logger.warn("This TaxonDescription contains more than one NamedArea: " + taxonDescription.getTitleCache());
|
796
|
// }
|
797
|
// }
|
798
|
// return result;
|
799
|
// }
|
800
|
|
801
|
|
802
|
/**
|
803
|
* Returns the TaxonFk for a given TaxonName or Taxon.
|
804
|
* @param state The {@link DbExportStateBase DbExportState}.
|
805
|
* @return
|
806
|
*/
|
807
|
@SuppressWarnings("unused") //used by mapper
|
808
|
private static Integer getTaxonFk(DescriptionElementBase deb, PesiExportState state) {
|
809
|
TaxonBase<?> entity = state.getCurrentTaxon();
|
810
|
return state.getDbId(entity);
|
811
|
}
|
812
|
|
813
|
/**
|
814
|
* Returns the TaxonFk for a given TaxonName.
|
815
|
* @param taxonName The {@link TaxonNameBase TaxonName}.
|
816
|
* @param state The {@link DbExportStateBase DbExportState}.
|
817
|
* @return
|
818
|
*/
|
819
|
private static Integer getTaxonKey(TaxonName taxonName, DbExportStateBase<?, PesiTransformer> state) {
|
820
|
return state.getDbId(taxonName);
|
821
|
}
|
822
|
|
823
|
/**
|
824
|
* Returns the <code>FullName</code> attribute.
|
825
|
* @param taxonName The {@link NonViralName NonViralName}.
|
826
|
* @return The <code>FullName</code> attribute.
|
827
|
* @see MethodMapper
|
828
|
*/
|
829
|
@SuppressWarnings("unused")
|
830
|
private static String getTaxonFullNameCache(DescriptionElementBase deb, PesiExportState state) {
|
831
|
|
832
|
TaxonBase<?> taxon = state.getCurrentTaxon();
|
833
|
TaxonName taxonName = taxon.getName();
|
834
|
TaxonName nvn = CdmBase.deproxy(taxonName);
|
835
|
String result = getCacheStrategy(nvn).getTitleCache(nvn);
|
836
|
return result;
|
837
|
}
|
838
|
|
839
|
|
840
|
/**
|
841
|
* Returns the CDM to PESI specific export mappings for PESI notes.
|
842
|
* @return The {@link PesiExportMapping PesiExportMapping}.
|
843
|
*/
|
844
|
private PesiExportMapping getNotesMapping() {
|
845
|
PesiExportMapping mapping = new PesiExportMapping(dbNoteTableName);
|
846
|
|
847
|
mapping.addMapper(IdMapper.NewInstance("NoteId"));
|
848
|
mapping.addMapper(DbTextDataMapper.NewInstance(Language.ENGLISH(), "Note_1"));
|
849
|
//TODO
|
850
|
mapping.addMapper(MethodMapper.NewInstance("Note_2", this, DescriptionElementBase.class));
|
851
|
mapping.addMapper(MethodMapper.NewInstance("NoteCategoryFk", this, DescriptionElementBase.class ));
|
852
|
|
853
|
mapping.addMapper(MethodMapper.NewInstance("NoteCategoryCache", this, DescriptionElementBase.class, PesiExportState.class ));
|
854
|
mapping.addMapper(MethodMapper.NewInstance("LanguageFk", this));
|
855
|
mapping.addMapper(MethodMapper.NewInstance("LanguageCache", this, DescriptionElementBase.class, PesiExportState.class));
|
856
|
|
857
|
// mapping.addMapper(MethodMapper.NewInstance("Region", this));
|
858
|
mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("taxonFk"));
|
859
|
// mapping.addMapper(ExpertsAndLastActionMapper.NewInstance());
|
860
|
mapping.addCollectionMapping(getNoteSourceMapping());
|
861
|
return mapping;
|
862
|
}
|
863
|
|
864
|
private CollectionExportMapping<PesiExportState, PesiExportConfigurator,PesiTransformer> getNoteSourceMapping() {
|
865
|
String tableName = "NoteSource";
|
866
|
String collectionAttribute = "sources";
|
867
|
IdMapper parentMapper = IdMapper.NewInstance("NoteFk");
|
868
|
CollectionExportMapping<PesiExportState, PesiExportConfigurator, PesiTransformer> mapping = CollectionExportMapping.NewInstance(tableName, collectionAttribute, parentMapper);
|
869
|
mapping.addMapper(DbSimpleFilterMapper.NewSingleNullAttributeInstance("idInSource", "Sources with idInSource currently handle data lineage"));
|
870
|
mapping.addMapper(DbObjectMapper.NewInstance("Citation", "SourceFk"));
|
871
|
mapping.addMapper(DbObjectMapper.NewInstance("Citation", "SourceNameCache", IS_CACHE));
|
872
|
mapping.addMapper(DbStringMapper.NewInstance("CitationMicroReference", "SourceDetail"));
|
873
|
return mapping;
|
874
|
}
|
875
|
|
876
|
|
877
|
/**
|
878
|
* Returns the CDM to PESI specific export mappings for occurrences.
|
879
|
* @return The {@link PesiExportMapping PesiExportMapping}.
|
880
|
*/
|
881
|
private PesiExportMapping getOccurrenceMapping() {
|
882
|
PesiExportMapping mapping = new PesiExportMapping(dbOccurrenceTableName);
|
883
|
|
884
|
mapping.addMapper(IdMapper.NewInstance("OccurrenceId"));
|
885
|
mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("taxonFk"));
|
886
|
mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("TaxonFullNameCache", true, true, null));
|
887
|
|
888
|
mapping.addMapper(DbAreaMapper.NewInstance(Distribution.class, "Area", "AreaFk", ! IS_CACHE));
|
889
|
mapping.addMapper(DbAreaMapper.NewInstance(Distribution.class, "Area", "AreaNameCache", IS_CACHE));
|
890
|
mapping.addMapper(DbDistributionStatusMapper.NewInstance("OccurrenceStatusFk", ! IS_CACHE));
|
891
|
mapping.addMapper(DbDistributionStatusMapper.NewInstance("OccurrenceStatusCache", IS_CACHE));
|
892
|
|
893
|
// Use Occurrence source instead
|
894
|
mapping.addMapper(DbExportIgnoreMapper.NewInstance("SourceFk", "Use OccurrenceSource table for sources instead"));
|
895
|
mapping.addMapper(DbExportIgnoreMapper.NewInstance("SourceNameCache", "Use OccurrenceSource table for sources instead"));
|
896
|
|
897
|
mapping.addMapper(DbAnnotationMapper.NewInstance(null, "Notes"));
|
898
|
mapping.addMapper(ExpertsAndLastActionMapper.NewInstance());
|
899
|
mapping.addCollectionMapping(getOccurrenceSourceMapping());
|
900
|
|
901
|
return mapping;
|
902
|
}
|
903
|
|
904
|
private CollectionExportMapping<PesiExportState, PesiExportConfigurator, PesiTransformer> getOccurrenceSourceMapping() {
|
905
|
String tableName = "OccurrenceSource";
|
906
|
String collectionAttribute = "sources";
|
907
|
IdMapper parentMapper = IdMapper.NewInstance("OccurrenceFk");
|
908
|
CollectionExportMapping<PesiExportState, PesiExportConfigurator, PesiTransformer> mapping = CollectionExportMapping.NewInstance(tableName, collectionAttribute, parentMapper);
|
909
|
mapping.addMapper(DbSimpleFilterMapper.NewSingleNullAttributeInstance("idInSource", "Sources with idInSource currently handle data lineage"));
|
910
|
mapping.addMapper(DbObjectMapper.NewInstance("Citation", "SourceFk"));
|
911
|
mapping.addMapper(DbObjectMapper.NewInstance("Citation", "SourceNameCache", IS_CACHE));
|
912
|
mapping.addMapper(DbOriginalNameMapper.NewInstance("OldTaxonName", IS_CACHE, null));
|
913
|
|
914
|
return mapping;
|
915
|
}
|
916
|
|
917
|
|
918
|
/**
|
919
|
* Returns the CDM to PESI specific export mappings for additional taxon sources to create a new
|
920
|
* source for the additional source
|
921
|
* @see #{@link PesiDescriptionExport#getAdditionalTaxonSourceMapping()}
|
922
|
* @return The {@link PesiExportMapping PesiExportMapping}.
|
923
|
*/
|
924
|
private PesiExportMapping getAddTaxonSourceSourceMapping() {
|
925
|
PesiExportMapping sourceMapping = new PesiExportMapping(PesiSourceExport.dbTableName);
|
926
|
|
927
|
sourceMapping.addMapper(IdMapper.NewInstance("SourceId"));
|
928
|
sourceMapping.addMapper(DbConstantMapper.NewInstance("SourceCategoryFk", Types.INTEGER, PesiTransformer.REF_UNRESOLVED));
|
929
|
sourceMapping.addMapper(DbConstantMapper.NewInstance("SourceCategoryCache", Types.VARCHAR, PesiTransformer.REF_STR_UNRESOLVED));
|
930
|
|
931
|
// sourceMapping.addMapper(MethodMapper.NewInstance("NomRefCache", PesiSourceExport.class, "getNomRefCache", Reference.class));
|
932
|
|
933
|
sourceMapping.addMapper(DbTextDataMapper.NewInstance(Language.ENGLISH(), "NomRefCache"));
|
934
|
|
935
|
return sourceMapping;
|
936
|
}
|
937
|
|
938
|
|
939
|
/**
|
940
|
* Returns the CDM to PESI specific export mappings for additional taxon sources.
|
941
|
* @see #{@link PesiDescriptionExport#getAddTaxonSourceSourceMapping()}
|
942
|
* @return The {@link PesiExportMapping PesiExportMapping}.
|
943
|
*/
|
944
|
private PesiExportMapping getAdditionalTaxonSourceMapping() {
|
945
|
|
946
|
PesiExportMapping mapping = new PesiExportMapping(dbAdditionalSourceTableName);
|
947
|
|
948
|
mapping.addMapper(MethodMapper.NewInstance("TaxonFk", this, DescriptionElementBase.class, PesiExportState.class));
|
949
|
|
950
|
mapping.addMapper(IdMapper.NewInstance("SourceFk"));
|
951
|
mapping.addMapper(DbTextDataMapper.NewInstance(Language.ENGLISH(), "SourceNameCache"));
|
952
|
|
953
|
mapping.addMapper(DbConstantMapper.NewInstance("SourceUseFk", Types.INTEGER, PesiTransformer.NOMENCLATURAL_REFERENCE));
|
954
|
mapping.addMapper(DbConstantMapper.NewInstance("SourceUseCache", Types.VARCHAR, PesiTransformer.STR_NOMENCLATURAL_REFERENCE));
|
955
|
|
956
|
mapping.addMapper(DbExportIgnoreMapper.NewInstance("SourceDetail", "SourceDetails not available for additional sources"));
|
957
|
|
958
|
return mapping;
|
959
|
}
|
960
|
|
961
|
/**
|
962
|
* Returns the CDM to PESI specific export mappings for common names.
|
963
|
* @return The {@link PesiExportMapping PesiExportMapping}.
|
964
|
*/
|
965
|
private PesiExportMapping getVernacularNamesMapping() {
|
966
|
PesiExportMapping mapping = new PesiExportMapping(dbVernacularTableName);
|
967
|
|
968
|
mapping.addMapper(IdMapper.NewInstance("CommonNameId"));
|
969
|
mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("taxonFk"));
|
970
|
|
971
|
mapping.addMapper(DbStringMapper.NewInstance("Name", "CommonName"));
|
972
|
mapping.addMapper(DbAreaMapper.NewInstance(CommonTaxonName.class, "Area", "Region", IS_CACHE));
|
973
|
|
974
|
mapping.addMapper(DbLanguageMapper.NewInstance(CommonTaxonName.class, "Language", "LanguageFk", ! IS_CACHE));
|
975
|
mapping.addMapper(DbLanguageMapper.NewInstance(CommonTaxonName.class, "Language", "LanguageCache", IS_CACHE));
|
976
|
|
977
|
mapping.addMapper(DbSingleSourceMapper.NewInstance("SourceFk", of ( DbSingleSourceMapper.EXCLUDE.WITH_ID) , ! IS_CACHE));
|
978
|
mapping.addMapper(DbSingleSourceMapper.NewInstance("SourceNameCache", of ( DbSingleSourceMapper.EXCLUDE.WITH_ID) , IS_CACHE));
|
979
|
//mapping.addMapper(ExpertsAndLastActionMapper.NewInstance());
|
980
|
return mapping;
|
981
|
|
982
|
}
|
983
|
|
984
|
private PesiExportMapping getImageMapping() {
|
985
|
PesiExportMapping mapping = new PesiExportMapping(dbImageTableName);
|
986
|
mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("taxonFk"));
|
987
|
|
988
|
//TODO xxx
|
989
|
|
990
|
return mapping;
|
991
|
}
|
992
|
|
993
|
}
|