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
|
package eu.etaxonomy.cdm.io.pesi.out;
|
11
|
|
12
|
import java.sql.Connection;
|
13
|
import java.sql.PreparedStatement;
|
14
|
import java.sql.SQLException;
|
15
|
import java.util.Arrays;
|
16
|
import java.util.List;
|
17
|
import java.util.Map;
|
18
|
import java.util.Set;
|
19
|
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.springframework.stereotype.Component;
|
22
|
import org.springframework.transaction.TransactionStatus;
|
23
|
|
24
|
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
|
25
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.RefDetailMapper;
|
26
|
import eu.etaxonomy.cdm.io.common.DbExportStateBase;
|
27
|
import eu.etaxonomy.cdm.io.common.Source;
|
28
|
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
|
29
|
import eu.etaxonomy.cdm.io.common.mapping.out.CollectionExportMapping;
|
30
|
import eu.etaxonomy.cdm.io.common.mapping.out.CreatedAndNotesMapper;
|
31
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbAreaMapper;
|
32
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbDescriptionElementTaxonMapper;
|
33
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbDistributionStatusMapper;
|
34
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbExportIgnoreMapper;
|
35
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbExportNotYetImplementedMapper;
|
36
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbLanguageMapper;
|
37
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbMarkerMapper;
|
38
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbObjectMapper;
|
39
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbOriginalNameMapper;
|
40
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbSimpleFilterMapper;
|
41
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbSingleSourceMapper;
|
42
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbStringMapper;
|
43
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbTextDataMapper;
|
44
|
import eu.etaxonomy.cdm.io.common.mapping.out.IdMapper;
|
45
|
import eu.etaxonomy.cdm.io.common.mapping.out.MethodMapper;
|
46
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
47
|
import eu.etaxonomy.cdm.model.common.Extension;
|
48
|
import eu.etaxonomy.cdm.model.common.ExtensionType;
|
49
|
import eu.etaxonomy.cdm.model.common.Language;
|
50
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
51
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
52
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
53
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
54
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
55
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
56
|
import eu.etaxonomy.cdm.model.description.Feature;
|
57
|
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
|
58
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
|
59
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
60
|
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
|
61
|
import eu.etaxonomy.cdm.model.description.TextData;
|
62
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
63
|
import eu.etaxonomy.cdm.model.location.TdwgArea;
|
64
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
65
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
66
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
67
|
import static java.util.EnumSet.of;
|
68
|
/**
|
69
|
* The export class for {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase DescriptionElements}.<p>
|
70
|
* Inserts into DataWarehouse database table <code>Note</code>.<p>
|
71
|
* It is divided into two phases:<ul>
|
72
|
* <li>Phase 1: Export of DescriptionElements as Notes.
|
73
|
* <li>Phase 2: Export of TaxonName extensions <code>taxComment</code>, <code>fauComment</code> and <code>fauExtraCodes</code> as Notes.</ul>
|
74
|
* @author e.-m.lee
|
75
|
* @date 23.02.2010
|
76
|
*
|
77
|
*/
|
78
|
@Component
|
79
|
public class PesiDescriptionExport extends PesiExportBase {
|
80
|
private static final Logger logger = Logger.getLogger(PesiDescriptionExport.class);
|
81
|
|
82
|
private static final boolean IS_CACHE = true;
|
83
|
private static final Class<? extends CdmBase> standardMethodParameter = DescriptionElementBase.class;
|
84
|
|
85
|
private static int modCount = 1000;
|
86
|
private static final String dbNoteTableName = "Note";
|
87
|
private static final String dbOccurrenceTableName = "Occurrence";
|
88
|
private static final String dbVernacularTableName = "CommonName";
|
89
|
private static final String dbImageTableName = "Image";
|
90
|
private static final String dbAdditionalSourceTableName = "AdditionalTaxonSource";
|
91
|
private static final String pluralString = "attached infos";
|
92
|
private static final String parentPluralString = "Taxa";
|
93
|
|
94
|
public PesiDescriptionExport() {
|
95
|
super();
|
96
|
}
|
97
|
|
98
|
/* (non-Javadoc)
|
99
|
* @see eu.etaxonomy.cdm.io.common.DbExportBase#getStandardMethodParameter()
|
100
|
*/
|
101
|
@Override
|
102
|
public Class<? extends CdmBase> getStandardMethodParameter() {
|
103
|
return standardMethodParameter;
|
104
|
}
|
105
|
|
106
|
/* (non-Javadoc)
|
107
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
|
108
|
*/
|
109
|
@Override
|
110
|
protected boolean doCheck(PesiExportState state) {
|
111
|
boolean result = true;
|
112
|
return result;
|
113
|
}
|
114
|
|
115
|
/* (non-Javadoc)
|
116
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doInvoke(eu.etaxonomy.cdm.io.common.IoStateBase)
|
117
|
*/
|
118
|
@Override
|
119
|
protected void doInvoke(PesiExportState state) {
|
120
|
try {
|
121
|
logger.info("*** Started Making " + pluralString + " ...");
|
122
|
|
123
|
// Stores whether this invoke was successful or not.
|
124
|
boolean success = true;
|
125
|
|
126
|
// PESI: Clear the database table Note.
|
127
|
// doDelete(state);
|
128
|
|
129
|
// Start transaction
|
130
|
success &= doPhase01(state);
|
131
|
|
132
|
|
133
|
logger.info("PHASE 2...");
|
134
|
success &= doPhase02(state);
|
135
|
|
136
|
|
137
|
logger.info("*** Finished Making " + pluralString + " ..." + getSuccessString(success));
|
138
|
|
139
|
if (!success){
|
140
|
state.setUnsuccessfull();
|
141
|
}
|
142
|
return;
|
143
|
} catch (SQLException e) {
|
144
|
e.printStackTrace();
|
145
|
logger.error(e.getMessage());
|
146
|
state.setUnsuccessfull();
|
147
|
}
|
148
|
}
|
149
|
|
150
|
//PHASE 01: Description Elements
|
151
|
private boolean doPhase01(PesiExportState state) throws SQLException {
|
152
|
logger.info("PHASE 1...");
|
153
|
int count = 0;
|
154
|
int pastCount = 0;
|
155
|
boolean success = true;
|
156
|
int limit = state.getConfig().getLimitSave();
|
157
|
|
158
|
// Get specific mappings: (CDM) DescriptionElement -> (PESI) Note
|
159
|
PesiExportMapping notesMapping = getNotesMapping();
|
160
|
notesMapping.initialize(state);
|
161
|
|
162
|
// Get specific mappings: (CDM) DescriptionElement -> (PESI) Occurrence
|
163
|
PesiExportMapping occurrenceMapping = getOccurrenceMapping();
|
164
|
occurrenceMapping.initialize(state);
|
165
|
|
166
|
// Get specific mappings: (CDM) DescriptionElement -> (PESI) Additional taxon source
|
167
|
PesiExportMapping addittionalSourceMapping = getAdditionalTaxonSourceMapping();
|
168
|
addittionalSourceMapping.initialize(state);
|
169
|
|
170
|
// Get specific mappings: (CDM) DescriptionElement -> (PESI) Additional taxon source
|
171
|
PesiExportMapping vernacularMapping = getVernacularNamesMapping();
|
172
|
vernacularMapping.initialize(state);
|
173
|
|
174
|
// Get specific mappings: (CDM) DescriptionElement -> (PESI) Additional taxon source
|
175
|
PesiExportMapping imageMapping = getImageMapping();
|
176
|
imageMapping.initialize(state);
|
177
|
|
178
|
|
179
|
List<Taxon> list = null;
|
180
|
|
181
|
TransactionStatus txStatus = startTransaction(true);
|
182
|
logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ...");
|
183
|
List<String> propPath = Arrays.asList(new String[]{"descriptions.elements.*"});
|
184
|
|
185
|
int partitionCount = 0;
|
186
|
while ((list = getNextTaxonPartition(Taxon.class, limit, partitionCount++, propPath )).size() > 0 ) {
|
187
|
|
188
|
logger.info("Fetched " + list.size() + " " + pluralString + ". Exporting...");
|
189
|
|
190
|
for (Taxon taxon : list) {
|
191
|
doCount(count++, modCount, pluralString);
|
192
|
success &= handleSingleTaxon(taxon, state, notesMapping, occurrenceMapping, addittionalSourceMapping, vernacularMapping, imageMapping);
|
193
|
}
|
194
|
|
195
|
// Commit transaction
|
196
|
commitTransaction(txStatus);
|
197
|
logger.debug("Committed transaction.");
|
198
|
logger.info("Exported " + (count - pastCount) + " " + pluralString + ". Total: " + count);
|
199
|
pastCount = count;
|
200
|
|
201
|
// Start transaction
|
202
|
txStatus = startTransaction(true);
|
203
|
logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ...");
|
204
|
}
|
205
|
if (list.size() == 0) {
|
206
|
logger.info("No " + pluralString + " left to fetch.");
|
207
|
}
|
208
|
// Commit transaction
|
209
|
commitTransaction(txStatus);
|
210
|
logger.debug("Committed transaction.");
|
211
|
return success;
|
212
|
}
|
213
|
|
214
|
private boolean handleSingleTaxon(Taxon taxon, PesiExportState state, PesiExportMapping notesMapping, PesiExportMapping occurrenceMapping,
|
215
|
PesiExportMapping addittionalSourceMapping, PesiExportMapping vernacularMapping, PesiExportMapping imageMapping) throws SQLException {
|
216
|
boolean success = true;
|
217
|
for (TaxonDescription desc : taxon.getDescriptions()){
|
218
|
boolean isImageGallery = desc.isImageGallery();
|
219
|
for (DescriptionElementBase element : desc.getElements()){
|
220
|
if (isImageGallery){
|
221
|
//TODO handle Images
|
222
|
success &= imageMapping.invoke(element);
|
223
|
}else if (isCommonName(element)){
|
224
|
success &= vernacularMapping.invoke(element);
|
225
|
}else if (isOccurrence(element)){
|
226
|
Distribution distribution = CdmBase.deproxy(element, Distribution.class);
|
227
|
if (isPesiDistribution(state, distribution)){
|
228
|
success &=occurrenceMapping.invoke(element);
|
229
|
}
|
230
|
}else if (isAdditionalTaxonSource(element)){
|
231
|
success &= addittionalSourceMapping.invoke(element);
|
232
|
}else if (isPesiNote(element)){
|
233
|
success &= notesMapping.invoke(element);
|
234
|
}else{
|
235
|
logger.warn("Description element type not yet handled by PESI export: " + element.getUuid() + ", " + element.getClass() + ", " + element.getFeature().getTitleCache());
|
236
|
}
|
237
|
}
|
238
|
}
|
239
|
return success;
|
240
|
}
|
241
|
|
242
|
private boolean isPesiDistribution(PesiExportState state, Distribution distribution) {
|
243
|
//currently we use the E+M summary status to decide if a distribution should be exported
|
244
|
if (distribution.getStatus() == null){
|
245
|
return false;
|
246
|
}
|
247
|
|
248
|
//...this may change in future so we keep the following code
|
249
|
Integer key;
|
250
|
//area filter
|
251
|
NamedArea area = distribution.getArea();
|
252
|
if (area == null){
|
253
|
logger.warn("Area is null for distribution " + distribution.getUuid());
|
254
|
return false;
|
255
|
}else if (area.getUuid().equals(BerlinModelTransformer.euroMedUuid)){
|
256
|
//E+M area only holds endemic status information and therefore is not exported to PESI
|
257
|
return false;
|
258
|
}else if (area.equals(TdwgArea.getAreaByTdwgAbbreviation("1"))){
|
259
|
//Europe area never holds status information (may probably be deleted in E+M)
|
260
|
return false;
|
261
|
// }else if (area.equals(TdwgArea.getAreaByTdwgAbbreviation("21"))){
|
262
|
// //Macaronesia records should not be exported to PESI
|
263
|
// return false;
|
264
|
// //TODO exclude Russion areas Rs*, and maybe ohters
|
265
|
|
266
|
} else
|
267
|
try {
|
268
|
if (state.getTransformer().getKeyByNamedArea(area) == null){
|
269
|
logger.warn("Area not available in PESI transformer " + area.getTitleCache() + ", " + area.getRepresentation(Language.ENGLISH()).getAbbreviatedLabel());
|
270
|
return false;
|
271
|
}
|
272
|
} catch (UndefinedTransformerMethodException e1) {
|
273
|
logger.warn("Area not available in PESI transformer " + area.getTitleCache());
|
274
|
return false;
|
275
|
}
|
276
|
return true;
|
277
|
|
278
|
//
|
279
|
// //status
|
280
|
// PresenceAbsenceTermBase<?> status = distribution.getStatus();
|
281
|
// if (status == null){
|
282
|
// logger.warn("No status for distribution: " + distribution.getUuid());
|
283
|
// return false;
|
284
|
// }
|
285
|
// try {
|
286
|
// key = (Integer)state.getTransformer().getKeyByPresenceAbsenceTerm(status);
|
287
|
// if (key != null){
|
288
|
// return true;
|
289
|
// }else{
|
290
|
// logger.warn("PresenceAbsenceTerm " + status.getTitleCache() + "not handled in transformer");
|
291
|
// return false;
|
292
|
// }
|
293
|
// } catch (UndefinedTransformerMethodException e) {
|
294
|
// logger.warn("PresenceAbsenceTerm " + status.getTitleCache() + "not handled in transformer");
|
295
|
// return false;
|
296
|
// }
|
297
|
}
|
298
|
|
299
|
private boolean isPesiNote(DescriptionElementBase element) {
|
300
|
return (getNoteCategoryFk(element) != null);
|
301
|
}
|
302
|
|
303
|
private boolean isAdditionalTaxonSource(DescriptionElementBase element) {
|
304
|
Feature feature = element.getFeature();
|
305
|
return (feature.equals(Feature.CITATION()));
|
306
|
}
|
307
|
|
308
|
private boolean isOccurrence(DescriptionElementBase element) {
|
309
|
Feature feature = element.getFeature();
|
310
|
return (feature.equals(Feature.DISTRIBUTION()));
|
311
|
}
|
312
|
|
313
|
private boolean isCommonName(DescriptionElementBase element) {
|
314
|
Feature feature = element.getFeature();
|
315
|
return (feature.equals(Feature.COMMON_NAME()));
|
316
|
}
|
317
|
|
318
|
//PHASE 02: Name extensions
|
319
|
private boolean doPhase02(PesiExportState state) {
|
320
|
TransactionStatus txStatus;
|
321
|
boolean success = true;
|
322
|
|
323
|
// Get the limit for objects to save within a single transaction.
|
324
|
int limit = state.getConfig().getLimitSave();
|
325
|
|
326
|
txStatus = startTransaction(true);
|
327
|
ExtensionType taxCommentExtensionType = (ExtensionType)getTermService().find(PesiTransformer.taxCommentUuid);
|
328
|
ExtensionType fauCommentExtensionType = (ExtensionType)getTermService().find(PesiTransformer.fauCommentUuid);
|
329
|
ExtensionType fauExtraCodesExtensionType = (ExtensionType)getTermService().find(PesiTransformer.fauExtraCodesUuid);
|
330
|
List<TaxonNameBase> taxonNameList = null;
|
331
|
|
332
|
int count = 0;
|
333
|
int pastCount = 0;
|
334
|
Connection connection = state.getConfig().getDestination().getConnection();
|
335
|
logger.info("Started new transaction. Fetching some " + parentPluralString + " first (max: " + limit + ") ...");
|
336
|
logger.warn("TODO handle extensions on taxon level, not name level (");
|
337
|
while ((taxonNameList = getNameService().list(null, limit, count, null, null)).size() > 0) {
|
338
|
|
339
|
logger.info("Fetched " + taxonNameList.size() + " names. Exporting...");
|
340
|
for (TaxonNameBase<?,?> taxonName : taxonNameList) {
|
341
|
Set<Extension> extensions = taxonName.getExtensions();
|
342
|
for (Extension extension : extensions) {
|
343
|
if (extension.getType().equals(taxCommentExtensionType)) {
|
344
|
String taxComment = extension.getValue();
|
345
|
invokeNotes(taxComment,
|
346
|
PesiTransformer.getNoteCategoryFk(PesiTransformer.taxCommentUuid),
|
347
|
PesiTransformer.getNoteCategoryCache(PesiTransformer.taxCommentUuid),
|
348
|
null, null, getTaxonFk(taxonName, state),connection);
|
349
|
} else if (extension.getType().equals(fauCommentExtensionType)) {
|
350
|
String fauComment = extension.getValue();
|
351
|
invokeNotes(fauComment,
|
352
|
PesiTransformer.getNoteCategoryFk(PesiTransformer.fauCommentUuid),
|
353
|
PesiTransformer.getNoteCategoryCache(PesiTransformer.fauCommentUuid),
|
354
|
null, null, getTaxonFk(taxonName, state),connection);
|
355
|
} else if (extension.getType().equals(fauExtraCodesExtensionType)) {
|
356
|
String fauExtraCodes = extension.getValue();
|
357
|
invokeNotes(fauExtraCodes,
|
358
|
PesiTransformer.getNoteCategoryFk(PesiTransformer.fauExtraCodesUuid),
|
359
|
PesiTransformer.getNoteCategoryCache(PesiTransformer.fauExtraCodesUuid),
|
360
|
null, null, getTaxonFk(taxonName, state),connection);
|
361
|
}
|
362
|
}
|
363
|
|
364
|
doCount(count++, modCount, pluralString);
|
365
|
}
|
366
|
|
367
|
// Commit transaction
|
368
|
commitTransaction(txStatus);
|
369
|
logger.debug("Committed transaction.");
|
370
|
logger.info("Exported " + (count - pastCount) + " names. Total: " + count);
|
371
|
pastCount = count;
|
372
|
|
373
|
// Start transaction
|
374
|
txStatus = startTransaction(true);
|
375
|
logger.info("Started new transaction. Fetching some names first (max: " + limit + ") ...");
|
376
|
}
|
377
|
if (taxonNameList.size() == 0) {
|
378
|
logger.info("No names left to fetch.");
|
379
|
}
|
380
|
// Commit transaction
|
381
|
commitTransaction(txStatus);
|
382
|
logger.debug("Committed transaction.");
|
383
|
return success;
|
384
|
}
|
385
|
|
386
|
/**
|
387
|
* @param taxComment
|
388
|
* @param noteCategoryFk
|
389
|
* @param noteCategoryCache
|
390
|
* @param object
|
391
|
* @param object2
|
392
|
*/
|
393
|
private void invokeNotes(String note, Integer noteCategoryFk,
|
394
|
String noteCategoryCache, Integer languageFk, String languageCache,
|
395
|
Integer taxonFk, Connection connection) {
|
396
|
String notesSql = "UPDATE Note SET Note_1 = ?, NoteCategoryFk = ?, NoteCategoryCache = ?, LanguageFk = ?, LanguageCache = ? WHERE TaxonFk = ?";
|
397
|
try {
|
398
|
PreparedStatement notesStmt = connection.prepareStatement(notesSql);
|
399
|
|
400
|
if (note != null) {
|
401
|
notesStmt.setString(1, note);
|
402
|
} else {
|
403
|
notesStmt.setObject(1, null);
|
404
|
}
|
405
|
|
406
|
if (noteCategoryFk != null) {
|
407
|
notesStmt.setInt(2, noteCategoryFk);
|
408
|
} else {
|
409
|
notesStmt.setObject(2, null);
|
410
|
}
|
411
|
|
412
|
if (noteCategoryCache != null) {
|
413
|
notesStmt.setString(3, noteCategoryCache);
|
414
|
} else {
|
415
|
notesStmt.setObject(3, null);
|
416
|
}
|
417
|
|
418
|
if (languageFk != null) {
|
419
|
notesStmt.setInt(4, languageFk);
|
420
|
} else {
|
421
|
notesStmt.setObject(4, null);
|
422
|
}
|
423
|
|
424
|
if (languageCache != null) {
|
425
|
notesStmt.setString(5, languageCache);
|
426
|
} else {
|
427
|
notesStmt.setObject(5, null);
|
428
|
}
|
429
|
|
430
|
if (taxonFk != null) {
|
431
|
notesStmt.setInt(6, taxonFk);
|
432
|
} else {
|
433
|
notesStmt.setObject(6, null);
|
434
|
}
|
435
|
|
436
|
notesStmt.executeUpdate();
|
437
|
} catch (SQLException e) {
|
438
|
logger.error("Note could not be created: " + note);
|
439
|
e.printStackTrace();
|
440
|
}
|
441
|
|
442
|
|
443
|
}
|
444
|
|
445
|
/**
|
446
|
* Deletes all entries of database tables related to <code>Note</code>.
|
447
|
* @param state The PesiExportState
|
448
|
* @return Whether the delete operation was successful or not.
|
449
|
*/
|
450
|
protected boolean doDelete(PesiExportState state) {
|
451
|
PesiExportConfigurator pesiConfig = (PesiExportConfigurator) state.getConfig();
|
452
|
|
453
|
String sql;
|
454
|
Source destination = pesiConfig.getDestination();
|
455
|
|
456
|
// Clear NoteSource
|
457
|
sql = "DELETE FROM NoteSource";
|
458
|
destination.setQuery(sql);
|
459
|
destination.update(sql);
|
460
|
|
461
|
// Clear Note
|
462
|
sql = "DELETE FROM " + dbNoteTableName;
|
463
|
destination.setQuery(sql);
|
464
|
destination.update(sql);
|
465
|
return true;
|
466
|
}
|
467
|
|
468
|
/* (non-Javadoc)
|
469
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IoStateBase)
|
470
|
*/
|
471
|
@Override
|
472
|
protected boolean isIgnore(PesiExportState state) {
|
473
|
return ! state.getConfig().isDoDescription();
|
474
|
}
|
475
|
|
476
|
|
477
|
/**
|
478
|
* Returns the <code>Note_2</code> attribute.
|
479
|
* @param descriptionElement The {@link DescriptionElementBase DescriptionElement}.
|
480
|
* @return The <code>Note_2</code> attribute.
|
481
|
* @see MethodMapper
|
482
|
*/
|
483
|
@SuppressWarnings("unused")
|
484
|
private static String getNote_2(DescriptionElementBase descriptionElement) {
|
485
|
logger.warn("Not yet implemented");
|
486
|
return null;
|
487
|
}
|
488
|
|
489
|
/**
|
490
|
* Returns the <code>NoteCategoryFk</code> attribute.
|
491
|
* @param descriptionElement The {@link DescriptionElementBase DescriptionElement}.
|
492
|
* @return The <code>NoteCategoryFk</code> attribute.
|
493
|
* @see MethodMapper
|
494
|
*/
|
495
|
private static Integer getNoteCategoryFk(DescriptionElementBase descriptionElement) {
|
496
|
Integer result = null;
|
497
|
result = PesiTransformer.feature2NodeCategoryFk(descriptionElement.getFeature());
|
498
|
return result;
|
499
|
}
|
500
|
|
501
|
/**
|
502
|
* Returns the <code>NoteCategoryCache</code> attribute.
|
503
|
* @param descriptionElement The {@link DescriptionElementBase DescriptionElement}.
|
504
|
* @return The <code>NoteCategoryCache</code> attribute.
|
505
|
* @see MethodMapper
|
506
|
*/
|
507
|
@SuppressWarnings("unused")
|
508
|
private static String getNoteCategoryCache(DescriptionElementBase descriptionElement) {
|
509
|
String result = null;
|
510
|
|
511
|
if (descriptionElement.isInstanceOf(TextData.class)) {
|
512
|
result = PesiTransformer.textData2NodeCategoryCache(descriptionElement.getFeature());
|
513
|
}
|
514
|
|
515
|
return result;
|
516
|
}
|
517
|
|
518
|
/**
|
519
|
* Returns the <code>LanguageFk</code> attribute.
|
520
|
* @param descriptionElement The {@link DescriptionElementBase DescriptionElement}.
|
521
|
* @return The <code>LanguageFk</code> attribute.
|
522
|
* @see MethodMapper
|
523
|
*/
|
524
|
@SuppressWarnings("unused")
|
525
|
private static Integer getLanguageFk(DescriptionElementBase descriptionElement) {
|
526
|
Language language = getLanguage(descriptionElement);
|
527
|
|
528
|
return PesiTransformer.language2LanguageId(language);
|
529
|
}
|
530
|
|
531
|
/**
|
532
|
* Returns the <code>LanguageCache</code> attribute.
|
533
|
* @param descriptionElement The {@link DescriptionElementBase DescriptionElement}.
|
534
|
* @return The <code>LanguageCache</code> attribute.
|
535
|
* @see MethodMapper
|
536
|
*/
|
537
|
@SuppressWarnings("unused")
|
538
|
private static String getLanguageCache(DescriptionElementBase descriptionElement) {
|
539
|
Language language = getLanguage(descriptionElement);
|
540
|
|
541
|
return PesiTransformer.language2LanguageCache(language);
|
542
|
}
|
543
|
|
544
|
private static Language getLanguage(DescriptionElementBase descriptionElement) {
|
545
|
Language language = null;
|
546
|
|
547
|
Map<Language, LanguageString> multilanguageText = null;
|
548
|
if (descriptionElement.isInstanceOf(CommonTaxonName.class)) {
|
549
|
CommonTaxonName commonTaxonName = CdmBase.deproxy(descriptionElement, CommonTaxonName.class);
|
550
|
language = commonTaxonName.getLanguage();
|
551
|
} else if (descriptionElement.isInstanceOf(TextData.class)) {
|
552
|
TextData textData = CdmBase.deproxy(descriptionElement, TextData.class);
|
553
|
multilanguageText = textData.getMultilanguageText();
|
554
|
} else if (descriptionElement.isInstanceOf(IndividualsAssociation.class)) {
|
555
|
IndividualsAssociation individualsAssociation = CdmBase.deproxy(descriptionElement, IndividualsAssociation.class);
|
556
|
multilanguageText = individualsAssociation.getDescription();
|
557
|
} else if (descriptionElement.isInstanceOf(TaxonInteraction.class)) {
|
558
|
TaxonInteraction taxonInteraction = CdmBase.deproxy(descriptionElement, TaxonInteraction.class);
|
559
|
multilanguageText = taxonInteraction.getDescriptions();
|
560
|
} else {
|
561
|
logger.debug("Given descriptionElement does not support languages. Hence LanguageCache could not be determined: " + descriptionElement.getUuid());
|
562
|
}
|
563
|
|
564
|
if (multilanguageText != null) {
|
565
|
Set<Language> languages = multilanguageText.keySet();
|
566
|
|
567
|
// TODO: Think of something more sophisticated than this
|
568
|
if (languages.size() > 0) {
|
569
|
language = languages.iterator().next();
|
570
|
}
|
571
|
if (languages.size() > 1){
|
572
|
logger.warn("There is more than 1 language for a given description (" + descriptionElement.getClass().getSimpleName() + "):" + descriptionElement.getUuid());
|
573
|
}
|
574
|
}
|
575
|
return language;
|
576
|
}
|
577
|
|
578
|
// /**
|
579
|
// * Returns the <code>Region</code> attribute.
|
580
|
// * @param descriptionElement The {@link DescriptionElementBase DescriptionElement}.
|
581
|
// * @return The <code>Region</code> attribute.
|
582
|
// * @see MethodMapper
|
583
|
// */
|
584
|
// @SuppressWarnings("unused")
|
585
|
// private static String getRegion(DescriptionElementBase descriptionElement) {
|
586
|
// String result = null;
|
587
|
// DescriptionBase<?> inDescription = descriptionElement.getInDescription();
|
588
|
//
|
589
|
// // Area information are associated to TaxonDescriptions and Distributions.
|
590
|
// if (descriptionElement.isInstanceOf(Distribution.class)) {
|
591
|
// Distribution distribution = CdmBase.deproxy(descriptionElement, Distribution.class);
|
592
|
// result = PesiTransformer.area2AreaCache(distribution.getArea());
|
593
|
// } else if (inDescription != null && inDescription.isInstanceOf(TaxonDescription.class)) {
|
594
|
// TaxonDescription taxonDescription = CdmBase.deproxy(inDescription, TaxonDescription.class);
|
595
|
// Set<NamedArea> namedAreas = taxonDescription.getGeoScopes();
|
596
|
// if (namedAreas.size() == 1) {
|
597
|
// result = PesiTransformer.area2AreaCache(namedAreas.iterator().next());
|
598
|
// } else if (namedAreas.size() > 1) {
|
599
|
// logger.warn("This TaxonDescription contains more than one NamedArea: " + taxonDescription.getTitleCache());
|
600
|
// }
|
601
|
// }
|
602
|
// return result;
|
603
|
// }
|
604
|
|
605
|
|
606
|
/**
|
607
|
* Returns the TaxonFk for a given TaxonName.
|
608
|
* @param taxonName The {@link TaxonNameBase TaxonName}.
|
609
|
* @param state The {@link DbExportStateBase DbExportState}.
|
610
|
* @return
|
611
|
*/
|
612
|
private static Integer getTaxonFk(TaxonNameBase<?,?> taxonName, DbExportStateBase<?> state) {
|
613
|
return state.getDbId(taxonName);
|
614
|
}
|
615
|
|
616
|
|
617
|
/**
|
618
|
* Returns the CDM to PESI specific export mappings for PESI notes.
|
619
|
* @return The {@link PesiExportMapping PesiExportMapping}.
|
620
|
*/
|
621
|
private PesiExportMapping getNotesMapping() {
|
622
|
PesiExportMapping mapping = new PesiExportMapping(dbNoteTableName);
|
623
|
|
624
|
mapping.addMapper(IdMapper.NewInstance("NoteId"));
|
625
|
mapping.addMapper(DbTextDataMapper.NewInstance(Language.ENGLISH(), "Note_1"));
|
626
|
//TODO
|
627
|
mapping.addMapper(DbExportNotYetImplementedMapper.NewInstance("Note_2", "Need to research what Note_2 is for"));
|
628
|
mapping.addMapper(MethodMapper.NewInstance("NoteCategoryFk", this));
|
629
|
mapping.addMapper(MethodMapper.NewInstance("NoteCategoryCache", this));
|
630
|
mapping.addMapper(MethodMapper.NewInstance("LanguageFk", this));
|
631
|
mapping.addMapper(MethodMapper.NewInstance("LanguageCache", this));
|
632
|
// mapping.addMapper(MethodMapper.NewInstance("Region", this));
|
633
|
mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("taxonFk"));
|
634
|
mapping.addMapper(ExpertsAndLastActionMapper.NewInstance());
|
635
|
return mapping;
|
636
|
}
|
637
|
|
638
|
|
639
|
/**
|
640
|
* Returns the CDM to PESI specific export mappings for occurrences.
|
641
|
* @return The {@link PesiExportMapping PesiExportMapping}.
|
642
|
*/
|
643
|
private PesiExportMapping getOccurrenceMapping() {
|
644
|
PesiExportMapping mapping = new PesiExportMapping(dbOccurrenceTableName);
|
645
|
|
646
|
mapping.addMapper(IdMapper.NewInstance("OccurrenceId"));
|
647
|
mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("taxonFk"));
|
648
|
mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("TaxonFullNameCache", true, true, null));
|
649
|
mapping.addMapper(DbAreaMapper.NewInstance(Distribution.class, "Area", "AreaFk", ! IS_CACHE));
|
650
|
mapping.addMapper(DbAreaMapper.NewInstance(Distribution.class, "Area", "AreaNameCache", IS_CACHE));
|
651
|
mapping.addMapper(DbDistributionStatusMapper.NewInstance("OccurrenceStatusFk", ! IS_CACHE));
|
652
|
mapping.addMapper(DbDistributionStatusMapper.NewInstance("OccurrenceStatusCache", IS_CACHE));
|
653
|
|
654
|
// Use Occurrence source instead
|
655
|
mapping.addMapper(DbExportIgnoreMapper.NewInstance("SourceFk", "Use OccurrenceSource table for sources instead"));
|
656
|
mapping.addMapper(DbExportIgnoreMapper.NewInstance("SourceNameCache", "Use OccurrenceSource table for sources instead"));
|
657
|
|
658
|
|
659
|
mapping.addMapper(DbExportNotYetImplementedMapper.NewInstance("Notes", "Needs reimplementation in description export"));
|
660
|
mapping.addMapper(ExpertsAndLastActionMapper.NewInstance());
|
661
|
mapping.addCollectionMapping(getOccurrenceSourceMapping());
|
662
|
|
663
|
return mapping;
|
664
|
}
|
665
|
|
666
|
private CollectionExportMapping<PesiExportState, PesiExportConfigurator> getOccurrenceSourceMapping() {
|
667
|
String tableName = "OccurrenceSource";
|
668
|
String collectionAttribute = "sources";
|
669
|
IdMapper parentMapper = IdMapper.NewInstance("OccurrenceFk");
|
670
|
CollectionExportMapping<PesiExportState, PesiExportConfigurator> mapping = CollectionExportMapping.NewInstance(tableName, collectionAttribute, parentMapper);
|
671
|
mapping.addMapper(DbSimpleFilterMapper.NewSingleNullAttributeInstance("idInSource", "Sources with idInSource currently handle data lineage"));
|
672
|
mapping.addMapper(DbObjectMapper.NewInstance("Citation", "SourceFk"));
|
673
|
mapping.addMapper(DbObjectMapper.NewInstance("Citation", "SourceNameCache", IS_CACHE));
|
674
|
mapping.addMapper(DbOriginalNameMapper.NewInstance("OldTaxonName", IS_CACHE, null));
|
675
|
|
676
|
return mapping;
|
677
|
}
|
678
|
|
679
|
/**
|
680
|
* Returns the CDM to PESI specific export mappings for additional taxon sources.
|
681
|
* @return The {@link PesiExportMapping PesiExportMapping}.
|
682
|
*/
|
683
|
private PesiExportMapping getAdditionalTaxonSourceMapping() {
|
684
|
PesiExportMapping mapping = new PesiExportMapping(dbAdditionalSourceTableName);
|
685
|
|
686
|
mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("taxonFk"));
|
687
|
mapping.addMapper(DbSingleSourceMapper.NewInstance("SourceFk", of (DbSingleSourceMapper.EXCLUDE.WITH_ID) , ! IS_CACHE));
|
688
|
mapping.addMapper(DbSingleSourceMapper.NewInstance("SourceNameCache", of(DbSingleSourceMapper.EXCLUDE.WITH_ID) , ! IS_CACHE));
|
689
|
|
690
|
// mapping.addMapper(MethodMapper.NewInstance("SourceUseFk", this));
|
691
|
// mapping.addMapper(MethodMapper.NewInstance("SourceUseCache", this));
|
692
|
// mapping.addMapper(MethodMapper.NewInstance("SourceFk", this.getClass(), "getSourceFk", standardMethodParameter, PesiExportState.class));
|
693
|
// mapping.addMapper(MethodMapper.NewInstance("SourceNameCache", this));
|
694
|
// mapping.addMapper(MethodMapper.NewInstance("SourceDetail", this));
|
695
|
|
696
|
return mapping;
|
697
|
}
|
698
|
|
699
|
/**
|
700
|
* Returns the CDM to PESI specific export mappings for common names.
|
701
|
* @return The {@link PesiExportMapping PesiExportMapping}.
|
702
|
*/
|
703
|
private PesiExportMapping getVernacularNamesMapping() {
|
704
|
PesiExportMapping mapping = new PesiExportMapping(dbVernacularTableName);
|
705
|
|
706
|
mapping.addMapper(IdMapper.NewInstance("CommonNameId"));
|
707
|
mapping.addMapper(DbStringMapper.NewInstance("Name", "CommonName"));
|
708
|
mapping.addMapper(DbAreaMapper.NewInstance(CommonTaxonName.class, "Area", "Region", IS_CACHE));
|
709
|
mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("taxonFk"));
|
710
|
|
711
|
mapping.addMapper(DbLanguageMapper.NewInstance(CommonTaxonName.class, "Language", "LanguageFk", ! IS_CACHE));
|
712
|
mapping.addMapper(DbLanguageMapper.NewInstance(CommonTaxonName.class, "Language", "LanguageCache", IS_CACHE));
|
713
|
|
714
|
mapping.addMapper(DbSingleSourceMapper.NewInstance("SourceFk", of ( DbSingleSourceMapper.EXCLUDE.WITH_ID) , ! IS_CACHE));
|
715
|
mapping.addMapper(DbSingleSourceMapper.NewInstance("SourceNameCache", of ( DbSingleSourceMapper.EXCLUDE.WITH_ID) , IS_CACHE));
|
716
|
mapping.addMapper(ExpertsAndLastActionMapper.NewInstance());
|
717
|
return mapping;
|
718
|
|
719
|
}
|
720
|
|
721
|
private PesiExportMapping getImageMapping() {
|
722
|
PesiExportMapping mapping = new PesiExportMapping(dbImageTableName);
|
723
|
mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("taxonFk"));
|
724
|
|
725
|
//TODO xxx
|
726
|
|
727
|
return mapping;
|
728
|
}
|
729
|
|
730
|
}
|