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
|
package eu.etaxonomy.cdm.io.caryo;
|
10
|
|
11
|
import java.sql.ResultSet;
|
12
|
import java.sql.SQLException;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.Map;
|
16
|
import java.util.Set;
|
17
|
|
18
|
import org.apache.commons.lang.StringUtils;
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.springframework.stereotype.Component;
|
21
|
|
22
|
import eu.etaxonomy.cdm.io.common.DbImportBase;
|
23
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
24
|
import eu.etaxonomy.cdm.io.common.Source;
|
25
|
import eu.etaxonomy.cdm.model.agent.Person;
|
26
|
import eu.etaxonomy.cdm.model.agent.Team;
|
27
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
28
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
29
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
30
|
import eu.etaxonomy.cdm.model.common.Language;
|
31
|
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
|
32
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
33
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
34
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
35
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
36
|
import eu.etaxonomy.cdm.model.name.Rank;
|
37
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
38
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
39
|
import eu.etaxonomy.cdm.model.reference.IArticle;
|
40
|
import eu.etaxonomy.cdm.model.reference.IBook;
|
41
|
import eu.etaxonomy.cdm.model.reference.IBookSection;
|
42
|
import eu.etaxonomy.cdm.model.reference.IJournal;
|
43
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
44
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
|
45
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
46
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
47
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
48
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
49
|
import eu.etaxonomy.cdm.model.taxon.SynonymType;
|
50
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
51
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
52
|
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
|
53
|
|
54
|
/**
|
55
|
* @author a.mueller
|
56
|
* @since 20.02.2010
|
57
|
*/
|
58
|
@Component
|
59
|
public class CaryoTaxonImport extends DbImportBase<CaryoImportState, CaryoImportConfigurator> {
|
60
|
|
61
|
private static final long serialVersionUID = 5369739490456155285L;
|
62
|
private static final Logger logger = Logger.getLogger(CaryoTaxonImport.class);
|
63
|
|
64
|
private final int modCount = 10000;
|
65
|
private static final String pluralString = "taxa";
|
66
|
private static final String dbTableName = "CARYOPHYLLALES";
|
67
|
|
68
|
private final Map<String, Taxon> familyMap = new HashMap<>();
|
69
|
private final Map<String, Person> personMap = new HashMap<>();
|
70
|
private final Map<String, Team> teamMap = new HashMap<>();
|
71
|
private final Map<String, TeamOrPersonBase> inAuthorMap = new HashMap<>();
|
72
|
private final Map<String, IJournal> journalMap = new HashMap<>();
|
73
|
private final Map<String, IBook> bookMap = new HashMap<>();
|
74
|
|
75
|
private Classification classification;
|
76
|
|
77
|
public CaryoTaxonImport(){
|
78
|
super(dbTableName, pluralString);
|
79
|
}
|
80
|
|
81
|
@Override
|
82
|
protected String getIdQuery(CaryoImportState state) {
|
83
|
String strRecordQuery =
|
84
|
" SELECT ID " +
|
85
|
" FROM " + dbTableName +
|
86
|
" ORDER BY id ";
|
87
|
return strRecordQuery;
|
88
|
}
|
89
|
|
90
|
@Override
|
91
|
protected String getRecordQuery(CaryoImportConfigurator config) {
|
92
|
String strRecordQuery =
|
93
|
" SELECT t.* " +
|
94
|
" FROM " + getTableName() + " t " +
|
95
|
" WHERE ( t.ID IN (" + ID_LIST_TOKEN + ") )";
|
96
|
return strRecordQuery;
|
97
|
}
|
98
|
|
99
|
@Override
|
100
|
public boolean doPartition(ResultSetPartitioner partitioner, CaryoImportState state) {
|
101
|
boolean success = true;
|
102
|
|
103
|
Set<TaxonBase> objectsToSave = new HashSet<>();
|
104
|
|
105
|
classification = getClassification(state);
|
106
|
|
107
|
try {
|
108
|
doFamilies(state);
|
109
|
doAuthors(state);
|
110
|
doInAuthors(state);
|
111
|
doJournals(state);
|
112
|
doBooks(state);
|
113
|
|
114
|
ResultSet rs = partitioner.getResultSet();
|
115
|
|
116
|
int i = 0;
|
117
|
Reference sec = state.getTransactionalSourceReference();
|
118
|
|
119
|
//for each reference
|
120
|
while (rs.next()){
|
121
|
|
122
|
if ((i++ % modCount) == 0 && i!= 1 ){ logger.info(pluralString + " handled: " + (i-1));}
|
123
|
|
124
|
Integer id = rs.getInt("Id");
|
125
|
Integer taxonId = rs.getInt("NCUGenID");
|
126
|
String genus = rs.getString("Genus");
|
127
|
String family = rs.getString("Family");
|
128
|
String pages = rs.getString("Pages");
|
129
|
String autoren = rs.getString("Autoren");
|
130
|
String typeStr = rs.getString("Type");
|
131
|
String nomStatusStr = rs.getString("NomenclaturalStatus");
|
132
|
String basioStr = rs.getString("Basionym");
|
133
|
|
134
|
// ,[EtInCitation]
|
135
|
// ,[Gender]
|
136
|
|
137
|
// ,[Basionym]
|
138
|
// ,[OriginalCitation]
|
139
|
|
140
|
IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
141
|
name.setGenusOrUninomial(genus);
|
142
|
makeAuthors(name, autoren, id);
|
143
|
INomenclaturalReference nomRef = makeNomRef(state, rs, id);
|
144
|
name.setNomenclaturalReference(nomRef);
|
145
|
name.setNomenclaturalMicroReference(pages);
|
146
|
makeStatus(name, nomStatusStr, id);
|
147
|
|
148
|
Taxon taxon = Taxon.NewInstance(name, state.getTransactionalSourceReference());
|
149
|
handleTypes(state, rs, taxon, typeStr, id);
|
150
|
handleBasionym(state, rs, taxon, basioStr, id);
|
151
|
|
152
|
Taxon parent = familyMap.get(family);
|
153
|
|
154
|
classification.addParentChild(parent, taxon, sec, null);
|
155
|
|
156
|
taxon.addSource(OriginalSourceType.Import, String.valueOf(taxonId), "NCUGenID", sec, null);
|
157
|
|
158
|
objectsToSave.add(taxon);
|
159
|
|
160
|
}
|
161
|
|
162
|
logger.warn(pluralString + " to save: " + objectsToSave.size());
|
163
|
getTaxonService().save(objectsToSave);
|
164
|
|
165
|
return success;
|
166
|
} catch (SQLException e) {
|
167
|
logger.error("SQLException:" + e);
|
168
|
return false;
|
169
|
}
|
170
|
}
|
171
|
|
172
|
private void handleBasionym(CaryoImportState state, ResultSet rs, Taxon taxon, String basioStr, Integer id) {
|
173
|
if (StringUtils.isNotBlank(basioStr)){
|
174
|
IBotanicalName name = taxon.getName();
|
175
|
TaxonName basionym = (TaxonName)TaxonNameFactory.PARSED_BOTANICAL_REFERENCE(basioStr);
|
176
|
if (basionym.hasProblem()){
|
177
|
logger.warn("Problem when parsing basionym ("+id+"): " + basioStr);
|
178
|
}
|
179
|
name.addBasionym(basionym);
|
180
|
Synonym syn = Synonym.NewInstance(basionym, state.getTransactionalSourceReference());
|
181
|
taxon.addSynonym(syn, SynonymType.HOMOTYPIC_SYNONYM_OF());
|
182
|
getTaxonService().save(syn);
|
183
|
}
|
184
|
}
|
185
|
|
186
|
private void handleTypes(CaryoImportState state, ResultSet rs, Taxon taxon, String origType, Integer id) {
|
187
|
NameTypeDesignation desig = NameTypeDesignation.NewInstance();
|
188
|
String type = origType;
|
189
|
if (StringUtils.isBlank(type) || "to be designated".equalsIgnoreCase(type)){
|
190
|
return;
|
191
|
}else{
|
192
|
IBotanicalName name = taxon.getName();
|
193
|
TaxonName typeName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
194
|
if ("not designated".equalsIgnoreCase(type)){
|
195
|
desig.setNotDesignated(true);
|
196
|
}else{
|
197
|
String genus = name.getGenusOrUninomial();
|
198
|
typeName.setGenusOrUninomial(genus);
|
199
|
if (! type.startsWith(genus.substring(0,1) + ". " )){
|
200
|
int i = type.indexOf(" ");
|
201
|
String genusOrig = type.substring(0, i);
|
202
|
logger.info("First genus letter not recognized: " + genusOrig + "-" + genus + ":"+ id);
|
203
|
typeName.setGenusOrUninomial(genusOrig);
|
204
|
type = type.substring(i + 1).trim();
|
205
|
}else{
|
206
|
type = type.substring(3);
|
207
|
}
|
208
|
int i = type.indexOf(" ");
|
209
|
if (i <= 0){
|
210
|
logger.warn("No space: " + type +"; " + id);
|
211
|
}else{
|
212
|
String species = type.substring(0, i);
|
213
|
typeName.setSpecificEpithet(species);
|
214
|
type = type.substring(i + 1).trim();
|
215
|
|
216
|
int posBracket = type.indexOf("(", 2);
|
217
|
if (posBracket > 0){
|
218
|
String bracket = type.substring(posBracket);
|
219
|
// logger.warn("Type has bracket("+id+"): " + bracket);
|
220
|
taxon.addAnnotation(Annotation.NewInstance("Type-bracket: " + bracket, Language.DEFAULT()));
|
221
|
type = type.substring(0, posBracket).trim();
|
222
|
}else{
|
223
|
Taxon speciesTaxon = Taxon.NewInstance(typeName, state.getTransactionalSourceReference());
|
224
|
classification.addParentChild(taxon, speciesTaxon, null, null);
|
225
|
}
|
226
|
type = makeTypeNomStatus(typeName, type);
|
227
|
|
228
|
|
229
|
makeAuthors(typeName, type, id);
|
230
|
}
|
231
|
|
232
|
desig.setTypeName(typeName);
|
233
|
}
|
234
|
name.addTypeDesignation(desig, true);
|
235
|
}
|
236
|
}
|
237
|
|
238
|
private String makeTypeNomStatus(IBotanicalName typeName, String type) {
|
239
|
if (type.endsWith(", nom. illeg.")){
|
240
|
type = type.replaceAll(", nom. illeg.", "");
|
241
|
typeName.addStatus(NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ILLEGITIMATE()));
|
242
|
}
|
243
|
return type;
|
244
|
}
|
245
|
|
246
|
private void makeStatus(IBotanicalName name, String nomStatusStr, Integer id) throws SQLException {
|
247
|
|
248
|
if (StringUtils.isNotBlank(nomStatusStr)){
|
249
|
NomenclaturalStatusType nomStatusType;
|
250
|
try {
|
251
|
nomStatusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(nomStatusStr, name);
|
252
|
} catch (UnknownCdmTypeException e) {
|
253
|
if (nomStatusStr.startsWith("nom. rej. prop.")){
|
254
|
nomStatusType = NomenclaturalStatusType.REJECTED_PROP();
|
255
|
logger.info("in favour not supported ("+id+"): " + nomStatusStr);
|
256
|
}else if (nomStatusStr.startsWith("nom. rej. in favour")){
|
257
|
nomStatusType = NomenclaturalStatusType.REJECTED();
|
258
|
logger.info("in favour not supported ("+id+"): " + nomStatusStr);
|
259
|
}else if (nomStatusStr.startsWith("nom. cons. against")){
|
260
|
nomStatusType = NomenclaturalStatusType.CONSERVED();
|
261
|
logger.info("against not supported ("+id+"): " + nomStatusStr);
|
262
|
}else if (nomStatusStr.startsWith("nom. cons. prop. against")){
|
263
|
nomStatusType = NomenclaturalStatusType.CONSERVED_PROP();
|
264
|
logger.info("against not supported ("+id+"): " + nomStatusStr);
|
265
|
}else{
|
266
|
logger.warn("Unknown status type ("+id+"): " + nomStatusStr);
|
267
|
nomStatusType = NomenclaturalStatusType.DOUBTFUL();
|
268
|
}
|
269
|
}
|
270
|
|
271
|
NomenclaturalStatus status = NomenclaturalStatus.NewInstance(nomStatusType);
|
272
|
name.addStatus(status);
|
273
|
}
|
274
|
}
|
275
|
|
276
|
private INomenclaturalReference makeNomRef(CaryoImportState state, ResultSet rs, Integer id) throws SQLException {
|
277
|
INomenclaturalReference result;
|
278
|
String periodicalTitle = rs.getString("PeriodicalTitle");
|
279
|
String volume = rs.getString("PeriodicalVolume");
|
280
|
String bookTitle = rs.getString("BookTitle");
|
281
|
String inAutorStr = rs.getString("InAutor");
|
282
|
String autorenStr = rs.getString("Autoren");
|
283
|
|
284
|
TeamOrPersonBase<?> author = getNomRefAuthor(autorenStr, id);
|
285
|
if (StringUtils.isNotBlank(periodicalTitle)){
|
286
|
IJournal journal = journalMap.get(periodicalTitle);
|
287
|
if (journal == null){
|
288
|
logger.warn("Journal not found: " + periodicalTitle + ";" + id);
|
289
|
}
|
290
|
IArticle article = ReferenceFactory.newArticle();
|
291
|
article.setInJournal(journal);
|
292
|
article.setVolume(volume);
|
293
|
result = article;
|
294
|
}else if (StringUtils.isNotBlank(bookTitle)){
|
295
|
IBook book = bookMap.get(bookTitle);
|
296
|
if (inAutorStr != null){
|
297
|
IBookSection section = ReferenceFactory.newBookSection();
|
298
|
section.setInBook(book);
|
299
|
TeamOrPersonBase<?> inAuthor = getInAuthor(inAutorStr);
|
300
|
book.setAuthorship(inAuthor);
|
301
|
result = section;
|
302
|
}else{
|
303
|
result = book;
|
304
|
}
|
305
|
}else{
|
306
|
logger.warn("No nomRef found: " + id);
|
307
|
result = null;
|
308
|
}
|
309
|
if (result != null){
|
310
|
result.setAuthorship(author);
|
311
|
makeDate(state, rs, result, id);
|
312
|
}
|
313
|
return result;
|
314
|
}
|
315
|
|
316
|
private void makeDate(CaryoImportState state, ResultSet rs, INomenclaturalReference ref, Integer id) throws SQLException {
|
317
|
VerbatimTimePeriod tp = VerbatimTimePeriod.NewVerbatimInstance();
|
318
|
String pre1 = rs.getString("DatePre1");
|
319
|
String pre2 = rs.getString("DatePre2");
|
320
|
Float year1 = nullSafeFloat(rs, "DateYear1");
|
321
|
Float year2 = nullSafeFloat(rs, "DateYear2");
|
322
|
if (year2 == 0.0 ){
|
323
|
year2 = null;
|
324
|
}
|
325
|
String modi1 = rs.getString("DateModi1");
|
326
|
String modi2 = rs.getString("DateModi2");
|
327
|
String date = rs.getString("Date");
|
328
|
|
329
|
tp.setStartYear(year1.intValue());
|
330
|
Integer[] preDate1 = getDay(pre1,id);
|
331
|
// tp.setStartMonth(preDate1[1]);
|
332
|
// tp.setStartDay(preDate1[0]);
|
333
|
if (year2 != null){
|
334
|
tp.setEndYear(year2.intValue());
|
335
|
}
|
336
|
Integer[] preDate2 = getDay(pre2, id);
|
337
|
// tp.setEndMonth(preDate2[1]);
|
338
|
// tp.setEndDay(preDate2[0]);
|
339
|
|
340
|
// if (StringUtils.isNotBlank(modi1) || StringUtils.isNotBlank(modi2)){
|
341
|
// tp.setFreeText(date);
|
342
|
// }
|
343
|
ref.setDatePublished(tp);
|
344
|
}
|
345
|
|
346
|
private Integer[] getDay(String pre, Integer id) {
|
347
|
Integer[] result = new Integer[2];
|
348
|
if (! StringUtils.isBlank(pre)){
|
349
|
try {
|
350
|
String[] split = pre.split("\\s");
|
351
|
String monthStr;
|
352
|
if (split.length > 2){
|
353
|
logger.warn("L > 2: " + pre);
|
354
|
monthStr = "";
|
355
|
}else if(split.length == 2){
|
356
|
result[0] = Integer.valueOf(split[0]);
|
357
|
monthStr = split[1];
|
358
|
}else{
|
359
|
monthStr = split[0];
|
360
|
}
|
361
|
Integer month;
|
362
|
if ("Jan".equalsIgnoreCase(monthStr)){
|
363
|
month = 1;
|
364
|
}else if ("Feb".equalsIgnoreCase(monthStr)){
|
365
|
month = 2;
|
366
|
}else if ("Mar".equalsIgnoreCase(monthStr)){
|
367
|
month = 3;
|
368
|
}else if ("Apr".equalsIgnoreCase(monthStr)){
|
369
|
month = 4;
|
370
|
}else if ("Mai".equalsIgnoreCase(monthStr)){
|
371
|
month = 5;
|
372
|
}else if ("Jun".equalsIgnoreCase(monthStr)){
|
373
|
month = 6;
|
374
|
}else if ("Jul".equalsIgnoreCase(monthStr)){
|
375
|
month = 7;
|
376
|
}else if ("Aug".equalsIgnoreCase(monthStr)){
|
377
|
month = 8;
|
378
|
}else if ("Sep".equalsIgnoreCase(monthStr)){
|
379
|
month = 9;
|
380
|
}else if ("Oct".equalsIgnoreCase(monthStr)){
|
381
|
month = 10;
|
382
|
}else if ("Nov".equalsIgnoreCase(monthStr)){
|
383
|
month = 11;
|
384
|
}else if ("Dec".equalsIgnoreCase(monthStr)){
|
385
|
month = 12;
|
386
|
}else{
|
387
|
logger.warn("Unknown month ("+id+"): " + monthStr );
|
388
|
month = null;
|
389
|
}
|
390
|
result[1]= month;
|
391
|
} catch (Exception e) {
|
392
|
e.printStackTrace();
|
393
|
}
|
394
|
}
|
395
|
return result;
|
396
|
}
|
397
|
|
398
|
private TeamOrPersonBase<?> getInAuthor(String inAutorStr) {
|
399
|
if (StringUtils.isBlank(inAutorStr)){
|
400
|
return null;
|
401
|
}
|
402
|
TeamOrPersonBase<?> inAuthor = inAuthorMap.get(inAutorStr);
|
403
|
if (inAuthor == null){
|
404
|
logger.warn("Inauthor not found: " + inAutorStr);
|
405
|
}
|
406
|
return inAuthor;
|
407
|
}
|
408
|
|
409
|
private void makeAuthors(IBotanicalName name, String autoren, Integer id) {
|
410
|
String[] parsedAuthorTeams = getParsedAuthors(autoren);
|
411
|
name.setBasionymAuthorship(getTeam(parsedAuthorTeams[0], id));
|
412
|
name.setExBasionymAuthorship(getTeam(parsedAuthorTeams[1], id));
|
413
|
name.setCombinationAuthorship(getTeam(parsedAuthorTeams[2], id));
|
414
|
name.setExCombinationAuthorship(getTeam(parsedAuthorTeams[3], id));
|
415
|
}
|
416
|
|
417
|
private TeamOrPersonBase<?> getNomRefAuthor(String authorStr, Integer id) {
|
418
|
String[] parsedAuthorTeams = getParsedAuthors(authorStr);
|
419
|
TeamOrPersonBase<?> team = getTeam(parsedAuthorTeams[2], id);
|
420
|
return team;
|
421
|
}
|
422
|
|
423
|
private TeamOrPersonBase<?> getTeam(String author, Integer id) {
|
424
|
if (StringUtils.isBlank(author)){
|
425
|
return null;
|
426
|
}
|
427
|
TeamOrPersonBase<?> result;
|
428
|
if (personMap.get(author) != null){
|
429
|
result = personMap.get(author);
|
430
|
}else{
|
431
|
result = teamMap.get(author);
|
432
|
}
|
433
|
if (result == null){
|
434
|
logger.warn("Team not found ("+id+"): " + author);
|
435
|
}
|
436
|
return result;
|
437
|
}
|
438
|
|
439
|
private void doInAuthors(CaryoImportState state) throws SQLException {
|
440
|
Source source = state.getConfig().getSource();
|
441
|
String sql = "SELECT DISTINCT inAutor FROM " + getTableName() + " WHERE inAutor IS NOT NULL AND inAutor <> '' ";
|
442
|
ResultSet rs = source.getResultSet(sql);
|
443
|
while (rs.next()){
|
444
|
String inAutorStr = rs.getString("inAutor");
|
445
|
if (inAuthorMap.get(inAutorStr) == null){
|
446
|
Team team = Team.NewTitledInstance(inAutorStr, inAutorStr);
|
447
|
|
448
|
inAuthorMap.put(inAutorStr, team);
|
449
|
getAgentService().save(team);
|
450
|
}
|
451
|
}
|
452
|
}
|
453
|
|
454
|
private void doAuthors(CaryoImportState state) throws SQLException {
|
455
|
Source source = state.getConfig().getSource();
|
456
|
String sql = "SELECT DISTINCT Autoren FROM " + getTableName() + " WHERE Autoren IS NOT NULL AND Autoren <> '' ";
|
457
|
ResultSet rs = source.getResultSet(sql);
|
458
|
doTypeAuthors(state);
|
459
|
while (rs.next()){
|
460
|
String autorenStr = rs.getString("Autoren");
|
461
|
String[] parsedAuthorTeams = getParsedAuthors(autorenStr);
|
462
|
for (String teamStr : parsedAuthorTeams){
|
463
|
doTeam(teamStr);
|
464
|
}
|
465
|
}
|
466
|
}
|
467
|
|
468
|
private void doTypeAuthors(CaryoImportState state) {
|
469
|
doTeam("Dinter & Derenb.");
|
470
|
doTeam("Marloth");
|
471
|
doTeam("Engl.");
|
472
|
doTeam("Kensit");
|
473
|
doTeam("Sond.");
|
474
|
doTeam("L. f.");
|
475
|
doTeam("Dinter & A. Berger");
|
476
|
doTeam("Schltr.");
|
477
|
doTeam("Dinter & Berger");
|
478
|
doTeam("Poir.");
|
479
|
doTeam("J. C. Wendl.");
|
480
|
doTeam("Baker & Clarke");
|
481
|
doTeam("Vahl");
|
482
|
doTeam("Nicolai");
|
483
|
doTeam("Gürke");
|
484
|
doTeam("Cels");
|
485
|
doTeam("Dams");
|
486
|
doTeam("Coult.");
|
487
|
doTeam("A. Weber");
|
488
|
doTeam("Vaupel");
|
489
|
doTeam("Gay");
|
490
|
doTeam("Pall.");
|
491
|
doTeam("Moq. & Coss.");
|
492
|
doTeam("Durieu & Moq.");
|
493
|
doTeam("Lag. & Rodrigues");
|
494
|
doTeam("M. Martens & Galeotti");
|
495
|
doTeam("Steud.");
|
496
|
doTeam("Aitch. & Hemsl.");
|
497
|
doTeam("Ikonn.-Gal.");
|
498
|
doTeam("Freitag");
|
499
|
doTeam("Regel");
|
500
|
doTeam("Ledeb.");
|
501
|
doTeam("Schur");
|
502
|
doTeam("Asch.");
|
503
|
doTeam("G. Forst.");
|
504
|
doTeam("Gray");
|
505
|
doTeam("Curran");
|
506
|
doTeam("Donn. Sm.");
|
507
|
doTeam("Diels");
|
508
|
doTeam("Colla");
|
509
|
doTeam("Miers");
|
510
|
doTeam("Gillis");
|
511
|
doTeam("Royle");
|
512
|
doTeam("Monv.");
|
513
|
doTeam("Werderm. & Backeb.");
|
514
|
doTeam("Wright");
|
515
|
doTeam("Meyen");
|
516
|
doTeam("Runge");
|
517
|
doTeam("Böd.");
|
518
|
doTeam("Rol.-Goss.");
|
519
|
doTeam("Poselg.");
|
520
|
doTeam("Andreae & Backeberg");
|
521
|
doTeam("Miq.");
|
522
|
doTeam("Rol.");
|
523
|
doTeam("Backeb. & Voll");
|
524
|
doTeam("Engelm. & Bigelow");
|
525
|
doTeam("Pfeiffer & Otto");
|
526
|
doTeam("Humb. & Bonpl.");
|
527
|
doTeam("Schmalh.");
|
528
|
doTeam("Preobr.");
|
529
|
doTeam("Labill.");
|
530
|
doTeam("Barkoudah");
|
531
|
doTeam("Regel & Schmalh.");
|
532
|
doTeam("Cambess.");
|
533
|
doTeam("Pax & K. Hoff.");
|
534
|
doTeam("Bergeret");
|
535
|
doTeam("Walp.");
|
536
|
doTeam("Huds.");
|
537
|
doTeam("Kit.");
|
538
|
doTeam("Schott, Nymann & Kotschy");
|
539
|
doTeam("Boiss. & Buhse");
|
540
|
doTeam("Medik.");
|
541
|
doTeam("Coss. & Germ.");
|
542
|
doTeam("Moss");
|
543
|
doTeam("Pax & Hoffm.");
|
544
|
doTeam("Schischk.");
|
545
|
doTeam("Lipsch.");
|
546
|
doTeam("Maerkl.");
|
547
|
doTeam("Vierh.");
|
548
|
doTeam("Exell");
|
549
|
}
|
550
|
|
551
|
protected void doTeam(String teamStr) {
|
552
|
if (StringUtils.isBlank(teamStr)){
|
553
|
return;
|
554
|
}
|
555
|
String[] parsedTeam = parseTeam(teamStr);
|
556
|
if (parsedTeam.length == 1){
|
557
|
savePerson(parsedTeam[0]);
|
558
|
}else{
|
559
|
Team team = teamMap.get(teamStr);
|
560
|
if (team == null){
|
561
|
team = Team.NewInstance();
|
562
|
for (String member : parsedTeam){
|
563
|
Person person = savePerson(member);
|
564
|
team.addTeamMember(person);
|
565
|
}
|
566
|
teamMap.put(teamStr, team);
|
567
|
getAgentService().saveOrUpdate(team);
|
568
|
}
|
569
|
}
|
570
|
return;
|
571
|
}
|
572
|
|
573
|
private String[] parseTeam(String teamStr) {
|
574
|
String[] split = teamStr.split("[&,]");
|
575
|
for (int i = 0; i < split.length; i++){
|
576
|
split[i] = split[i].trim();
|
577
|
}
|
578
|
return split;
|
579
|
}
|
580
|
|
581
|
private Person savePerson(String personStr) {
|
582
|
Person result = personMap.get(personStr);
|
583
|
if (result == null ){
|
584
|
Person person = Person.NewTitledInstance(personStr);
|
585
|
personMap.put(personStr, person);
|
586
|
getAgentService().save(person);
|
587
|
result = person;
|
588
|
}
|
589
|
return result;
|
590
|
}
|
591
|
|
592
|
private String[] getParsedAuthors(String autorenStr) {
|
593
|
String[] result = new String[4];
|
594
|
String basioFull = null;
|
595
|
String origFull;
|
596
|
|
597
|
String[] split = autorenStr.split("\\)");
|
598
|
if (split.length > 1){
|
599
|
basioFull = split[0].replace("(", "").trim();
|
600
|
origFull = split[1].trim();
|
601
|
}else{
|
602
|
origFull = split[0].trim();
|
603
|
}
|
604
|
String[] splitBasio = splitExAuthors(basioFull);
|
605
|
String[] splitOrig = splitExAuthors(origFull);
|
606
|
result[0] = splitBasio[0];
|
607
|
result[1] = splitBasio[1];
|
608
|
result[2] = splitOrig[0];
|
609
|
result[3] = splitOrig[1];
|
610
|
|
611
|
return result;
|
612
|
}
|
613
|
|
614
|
private String[] splitExAuthors(String author) {
|
615
|
String[] result = new String[2];
|
616
|
if (author != null){
|
617
|
String[] split = author.split("\\sex\\s");
|
618
|
if (split.length > 1){
|
619
|
result[0] = split[1].trim();
|
620
|
result[1] = split[0].trim();
|
621
|
}else{
|
622
|
result[0] = split[0].trim();
|
623
|
}
|
624
|
}
|
625
|
return result;
|
626
|
}
|
627
|
|
628
|
private void doBooks(CaryoImportState state) throws SQLException {
|
629
|
Source source = state.getConfig().getSource();
|
630
|
String sql = "SELECT DISTINCT BookTitle FROM " + getTableName() + " WHERE BookTitle IS NOT NULL AND BookTitle <> '' ";
|
631
|
ResultSet rs = source.getResultSet(sql);
|
632
|
while (rs.next()){
|
633
|
String bookStr = rs.getString("BookTitle");
|
634
|
if (bookMap.get(bookStr) == null ){
|
635
|
|
636
|
IBook book = ReferenceFactory.newBook();
|
637
|
|
638
|
book.setTitle(bookStr);
|
639
|
|
640
|
bookMap.put(bookStr, book);
|
641
|
getReferenceService().save((Reference)book);
|
642
|
}
|
643
|
}
|
644
|
}
|
645
|
|
646
|
private void doJournals(CaryoImportState state) throws SQLException {
|
647
|
Source source = state.getConfig().getSource();
|
648
|
String sqlPeriodical = "SELECT DISTINCT PeriodicalTitle FROM " + getTableName() + " WHERE PeriodicalTitle IS NOT NULL AND PeriodicalTitle <> '' ";
|
649
|
ResultSet rs = source.getResultSet(sqlPeriodical);
|
650
|
while (rs.next()){
|
651
|
String periodical = rs.getString("PeriodicalTitle");
|
652
|
if (journalMap.get(periodical) == null ){
|
653
|
|
654
|
Reference journal = ReferenceFactory.newJournal();
|
655
|
|
656
|
journal.setTitle(periodical);
|
657
|
|
658
|
journalMap.put(periodical, journal);
|
659
|
getReferenceService().save(journal);
|
660
|
}
|
661
|
}
|
662
|
}
|
663
|
|
664
|
private void doFamilies(CaryoImportState state) throws SQLException {
|
665
|
Source source = state.getConfig().getSource();
|
666
|
String sqlFamily = "SELECT DISTINCT Family FROM " + getTableName() + " WHERE Family IS NOT NULL";
|
667
|
ResultSet rs = source.getResultSet(sqlFamily);
|
668
|
while (rs.next()){
|
669
|
String family = rs.getString("family");
|
670
|
if (familyMap.get(family) == null ){
|
671
|
|
672
|
IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.FAMILY());
|
673
|
name.setGenusOrUninomial(family);
|
674
|
Taxon taxon = Taxon.NewInstance(name, state.getTransactionalSourceReference());
|
675
|
classification.addChildTaxon(taxon, null, null);
|
676
|
// taxon.addSource(id, idNamespace, citation, null);
|
677
|
|
678
|
familyMap.put(family, taxon);
|
679
|
getTaxonService().save(taxon);
|
680
|
}
|
681
|
}
|
682
|
}
|
683
|
|
684
|
private Classification getClassification(CaryoImportState state) {
|
685
|
if (this.classification == null){
|
686
|
String name = state.getConfig().getClassificationName();
|
687
|
Reference reference = state.getTransactionalSourceReference();
|
688
|
this.classification = Classification.NewInstance(name, reference, Language.DEFAULT());
|
689
|
if (state.getConfig().getClassificationUuid() != null){
|
690
|
classification.setUuid(state.getConfig().getClassificationUuid());
|
691
|
}
|
692
|
getClassificationService().save(classification);
|
693
|
}
|
694
|
return this.classification;
|
695
|
}
|
696
|
|
697
|
@Override
|
698
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, CaryoImportState state) {
|
699
|
// String nameSpace;
|
700
|
// Class cdmClass;
|
701
|
// Set<String> idSet;
|
702
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
|
703
|
// try{
|
704
|
// Set<String> taxonIdSet = new HashSet<>();
|
705
|
//
|
706
|
// while (rs.next()){
|
707
|
//// handleForeignKey(rs, taxonIdSet, "taxonId");
|
708
|
// }
|
709
|
//
|
710
|
// //taxon map
|
711
|
// nameSpace = TAXON_NAMESPACE;
|
712
|
// cdmClass = Taxon.class;
|
713
|
// idSet = taxonIdSet;
|
714
|
// Map<String, Taxon> objectMap = (Map<String, Taxon>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
715
|
// result.put(nameSpace, objectMap);
|
716
|
//
|
717
|
//
|
718
|
// } catch (SQLException e) {
|
719
|
// throw new RuntimeException(e);
|
720
|
// }
|
721
|
return result;
|
722
|
}
|
723
|
|
724
|
@Override
|
725
|
protected boolean doCheck(CaryoImportState state){
|
726
|
return true;
|
727
|
}
|
728
|
|
729
|
@Override
|
730
|
protected boolean isIgnore(CaryoImportState state){
|
731
|
return ! state.getConfig().isDoTaxa();
|
732
|
}
|
733
|
}
|