Project

General

Profile

Download (24.8 KB) Statistics
| Branch: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.cdm.io.caryo;
11

    
12
import java.sql.ResultSet;
13
import java.sql.SQLException;
14
import java.util.HashMap;
15
import java.util.HashSet;
16
import java.util.Map;
17
import java.util.Set;
18

    
19
import org.apache.commons.lang.StringUtils;
20
import org.apache.log4j.Logger;
21
import org.springframework.stereotype.Component;
22

    
23
import eu.etaxonomy.cdm.io.common.DbImportBase;
24
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
25
import eu.etaxonomy.cdm.io.common.Source;
26
import eu.etaxonomy.cdm.model.agent.Person;
27
import eu.etaxonomy.cdm.model.agent.Team;
28
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
29
import eu.etaxonomy.cdm.model.common.Annotation;
30
import eu.etaxonomy.cdm.model.common.CdmBase;
31
import eu.etaxonomy.cdm.model.common.Language;
32
import eu.etaxonomy.cdm.model.common.TimePeriod;
33
import eu.etaxonomy.cdm.model.name.BotanicalName;
34
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
35
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
36
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
37
import eu.etaxonomy.cdm.model.name.Rank;
38
import eu.etaxonomy.cdm.model.reference.IArticle;
39
import eu.etaxonomy.cdm.model.reference.IBook;
40
import eu.etaxonomy.cdm.model.reference.IBookSection;
41
import eu.etaxonomy.cdm.model.reference.IJournal;
42
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
43
import eu.etaxonomy.cdm.model.reference.Reference;
44
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
45
import eu.etaxonomy.cdm.model.taxon.Classification;
46
import eu.etaxonomy.cdm.model.taxon.Synonym;
47
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
48
import eu.etaxonomy.cdm.model.taxon.Taxon;
49
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
50
import eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy;
51
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
52
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
53
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
54

    
55

    
56
/**
57
 * @author a.mueller
58
 * @created 20.02.2010
59
 * @version 1.0
60
 */
61
@Component
62
public class CaryoTaxonImport  extends DbImportBase<CaryoImportState, CaryoImportConfigurator> {
63
	private static final Logger logger = Logger.getLogger(CaryoTaxonImport.class);
64
	
65
	private int modCount = 10000;
66
	private static final String pluralString = "taxa";
67
	private static final String dbTableName = "CARYOPHYLLALES";
68

    
69

    
70
	
71
	private Map<String, Taxon> familyMap = new HashMap<String, Taxon>();
72
	private Map<String, Person> personMap = new HashMap<String, Person>();
73
	private Map<String, Team> teamMap = new HashMap<String, Team>();
74
	private Map<String, TeamOrPersonBase> inAuthorMap = new HashMap<String, TeamOrPersonBase>();
75
	private Map<String, IJournal> journalMap = new HashMap<String, IJournal>();
76
	private Map<String, IBook> bookMap = new HashMap<String, IBook>();
77
	
78
	
79
	private Classification classification;
80

    
81
	
82
	
83
	public CaryoTaxonImport(){
84
		super(dbTableName, pluralString);
85
	}
86

    
87
	
88
	
89
	
90
	/* (non-Javadoc)
91
	 * @see eu.etaxonomy.cdm.io.common.DbImportBase#getIdQuery(eu.etaxonomy.cdm.io.common.DbImportStateBase)
92
	 */
93
	@Override
94
	protected String getIdQuery(CaryoImportState state) {
95
		String strRecordQuery = 
96
			" SELECT ID " + 
97
			" FROM " + dbTableName +
98
			" ORDER BY id "; 
99
		return strRecordQuery;	
100
	}
101

    
102

    
103
	/* (non-Javadoc)
104
	 * @see eu.etaxonomy.cdm.io.common.DbImportBase#getRecordQuery(eu.etaxonomy.cdm.io.common.DbImportConfiguratorBase)
105
	 */
106
	@Override
107
	protected String getRecordQuery(CaryoImportConfigurator config) {
108
		String strRecordQuery = 
109
			" SELECT t.* " + 
110
			" FROM " + getTableName() + " t " +
111
			" WHERE ( t.ID IN (" + ID_LIST_TOKEN + ") )";
112
		return strRecordQuery;
113
	}
114
	
115

    
116

    
117
	/* (non-Javadoc)
118
	 * @see eu.etaxonomy.cdm.io.globis.GlobisImportBase#doPartition(eu.etaxonomy.cdm.io.common.ResultSetPartitioner, eu.etaxonomy.cdm.io.globis.GlobisImportState)
119
	 */
120
	@Override
121
	public boolean doPartition(ResultSetPartitioner partitioner, CaryoImportState state) {
122
		boolean success = true;
123
		
124
		Set<TaxonBase> objectsToSave = new HashSet<TaxonBase>();
125
		
126
//		Map<String, Taxon> taxonMap = (Map<String, Taxon>) partitioner.getObjectMap(TAXON_NAMESPACE);
127

    
128
		
129
		classification = getClassification(state);
130
		
131
		try {
132
			doFamilies(state);
133
			doAuthors(state);
134
			doInAuthors(state);
135
			doJournals(state);
136
			doBooks(state);
137
			
138
			ResultSet rs = partitioner.getResultSet();
139
			
140
			int i = 0;
141
    		Reference<?> sec = state.getTransactionalSourceReference();
142

    
143
			//for each reference
144
            while (rs.next()){
145
                
146
        		if ((i++ % modCount) == 0 && i!= 1 ){ logger.info(pluralString + " handled: " + (i-1));}
147
				
148
        		Integer id = rs.getInt("Id");
149
        		Integer taxonId = rs.getInt("NCUGenID");
150
        		String genus = rs.getString("Genus");
151
        		String family = rs.getString("Family");
152
				String pages = rs.getString("Pages");
153
				String autoren = rs.getString("Autoren");
154
				String typeStr = rs.getString("Type");
155
				String nomStatusStr = rs.getString("NomenclaturalStatus");
156
				String basioStr = rs.getString("Basionym");
157
				
158
//        	      ,[EtInCitation]
159
//        	      ,[Gender]
160
				
161
//        	      ,[Basionym]
162
//        	      ,[OriginalCitation]
163
				
164
        		
165
				BotanicalName name = BotanicalName.NewInstance(Rank.GENUS());
166
				name.setGenusOrUninomial(genus);
167
				makeAuthors(name, autoren, id);
168
				INomenclaturalReference nomRef = makeNomRef(state, rs, id);
169
        		name.setNomenclaturalReference(nomRef);
170
				name.setNomenclaturalMicroReference(pages);
171
				makeStatus(name, nomStatusStr, id);
172
				
173
				
174
				Taxon taxon = Taxon.NewInstance(name, state.getTransactionalSourceReference());
175
				handleTypes(state, rs, taxon, typeStr, id);
176
				handleBasionym(state, rs, taxon, basioStr, id);
177
				
178
				Taxon parent = familyMap.get(family);
179
				
180
				classification.addParentChild(parent, taxon, sec, null);
181
				
182
				taxon.addSource(String.valueOf(taxonId), "NCUGenID", sec, null);
183
				
184
				
185
				
186
				objectsToSave.add(taxon);
187

    
188
            }
189
           
190
			logger.warn(pluralString + " to save: " + objectsToSave.size());
191
			getTaxonService().save(objectsToSave);	
192
			
193
			return success;
194
		} catch (SQLException e) {
195
			logger.error("SQLException:" +  e);
196
			return false;
197
		}
198
	}
199

    
200
	private void handleBasionym(CaryoImportState state, ResultSet rs, Taxon taxon, String basioStr, Integer id) {
201
		if (StringUtils.isNotBlank(basioStr)){
202
			BotanicalName name = (BotanicalName) taxon.getName();
203
			BotanicalName basionym = BotanicalName.PARSED_REFERENCE(basioStr);
204
			if (basionym.hasProblem()){
205
				logger.warn("Problem when parsing basionym ("+id+"): " +  basioStr);
206
			}
207
			name.addBasionym(basionym);
208
			Synonym syn = Synonym.NewInstance(basionym, state.getTransactionalSourceReference());
209
			taxon.addSynonym(syn, SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF());
210
			getTaxonService().save(syn);
211
		}
212
		
213
	}
214

    
215

    
216

    
217

    
218
	private void handleTypes(CaryoImportState state, ResultSet rs, Taxon taxon, String origType, Integer id) {
219
		NameTypeDesignation desig = NameTypeDesignation.NewInstance();
220
		String type = origType;
221
		if (StringUtils.isBlank(type) || "to be designated".equalsIgnoreCase(type)){
222
			return;
223
		}else{
224
			BotanicalName name = (BotanicalName)taxon.getName();
225
			BotanicalName typeName = BotanicalName.NewInstance(Rank.SPECIES());
226
			if ("not designated".equalsIgnoreCase(type)){
227
				desig.setNotDesignated(true);
228
			}else{
229
				String genus = name.getGenusOrUninomial();
230
				typeName.setGenusOrUninomial(genus);
231
				if (! type.startsWith(genus.substring(0,1) + ". " )){
232
					int i = type.indexOf(" ");
233
					String genusOrig = type.substring(0, i);
234
					logger.info("First genus letter not recognized: " + genusOrig + "-" + genus + ":"+  id);
235
					typeName.setGenusOrUninomial(genusOrig);
236
					type = type.substring(i + 1).trim();
237
				}else{
238
					type = type.substring(3);
239
				}
240
				int i = type.indexOf(" ");
241
				if (i <= 0){
242
					logger.warn("No space: " + type +"; " + id);
243
				}else{
244
					String species = type.substring(0, i);
245
					typeName.setSpecificEpithet(species);
246
					type = type.substring(i + 1).trim();
247
					
248
					int posBracket = type.indexOf("(", 2);
249
					if (posBracket > 0){
250
						String bracket = type.substring(posBracket);
251
//						logger.warn("Type has bracket("+id+"): " + bracket);
252
						taxon.addAnnotation(Annotation.NewInstance("Type-bracket: " + bracket, Language.DEFAULT()));
253
						type = type.substring(0, posBracket).trim();
254
					}else{
255
						Taxon speciesTaxon = Taxon.NewInstance(typeName, state.getTransactionalSourceReference());
256
						classification.addParentChild(taxon, speciesTaxon, null, null);
257
					}
258
					type = makeTypeNomStatus(typeName, type);
259

    
260
					
261
					makeAuthors(typeName, type, id);
262
				}
263
					
264
				desig.setTypeName(typeName);
265
			}
266
			name.addTypeDesignation(desig, true);
267
		}
268
		
269
		
270
	}
271

    
272

    
273

    
274

    
275
	private String makeTypeNomStatus(BotanicalName typeName, String type) {
276
		if (type.endsWith(", nom. illeg.")){
277
			type = type.replaceAll(", nom. illeg.", "");
278
			typeName.addStatus(NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ILLEGITIMATE()));
279
		}
280
		return type;
281
	}
282

    
283

    
284

    
285

    
286
	private void makeStatus(BotanicalName name, String nomStatusStr, Integer id) throws SQLException {
287
//	      ,[NomenclaturalStatus]
288
		
289
		if (StringUtils.isNotBlank(nomStatusStr)){
290
			NomenclaturalStatusType nomStatusType;
291
			try {
292
				nomStatusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(nomStatusStr);
293
			} catch (UnknownCdmTypeException e) {
294
				if (nomStatusStr.startsWith("nom. rej. prop.")){
295
					nomStatusType = NomenclaturalStatusType.REJECTED_PROP();
296
					logger.info("in favour not supported ("+id+"): " + nomStatusStr);
297
				}else if (nomStatusStr.startsWith("nom. rej. in favour")){
298
					nomStatusType = NomenclaturalStatusType.REJECTED();
299
					logger.info("in favour not supported ("+id+"): " + nomStatusStr);
300
				}else if (nomStatusStr.startsWith("nom. cons. against")){
301
					nomStatusType = NomenclaturalStatusType.CONSERVED();
302
					logger.info("against not supported ("+id+"): " + nomStatusStr);
303
				}else if (nomStatusStr.startsWith("nom. cons. prop. against")){
304
					nomStatusType = NomenclaturalStatusType.CONSERVED_PROP();
305
					logger.info("against not supported ("+id+"): " + nomStatusStr);
306
				}else{
307
					logger.warn("Unknown status type ("+id+"): " + nomStatusStr);
308
					nomStatusType = NomenclaturalStatusType.DOUBTFUL();
309
				}
310
			}
311
			
312
			NomenclaturalStatus status = NomenclaturalStatus.NewInstance(nomStatusType);
313
			name.addStatus(status);
314
		}
315
		
316
	}
317

    
318

    
319

    
320

    
321
	private INomenclaturalReference makeNomRef(CaryoImportState state, ResultSet rs, Integer id) throws SQLException {
322
		INomenclaturalReference result;
323
		String periodicalTitle = rs.getString("PeriodicalTitle");
324
		String volume = rs.getString("PeriodicalVolume");
325
		String bookTitle = rs.getString("BookTitle");
326
		String inAutorStr = rs.getString("InAutor");
327
		String autorenStr = rs.getString("Autoren");
328
		
329
		TeamOrPersonBase<?> author = getNomRefAuthor(autorenStr, id);
330
		if (StringUtils.isNotBlank(periodicalTitle)){
331
			IJournal journal = journalMap.get(periodicalTitle);
332
			if (journal == null){
333
				logger.warn("Journal not found: " + periodicalTitle + ";" + id);
334
			}
335
			IArticle article = ReferenceFactory.newArticle();
336
			article.setInJournal(journal);
337
			article.setVolume(volume);
338
			result = article;
339
		}else if (StringUtils.isNotBlank(bookTitle)){
340
			IBook book = bookMap.get(bookTitle);
341
			if (inAutorStr != null){
342
				IBookSection section = ReferenceFactory.newBookSection();
343
				section.setInBook(book);
344
				TeamOrPersonBase<?> inAuthor = getInAuthor(inAutorStr);
345
				book.setAuthorTeam(inAuthor);
346
				result = section;
347
			}else{
348
				result = book;
349
			}
350
		}else{
351
			logger.warn("No nomRef found: " +  id);
352
			result = null;
353
		}
354
		if (result != null){
355
			result.setAuthorTeam(author);
356
			makeDate(state, rs, result, id);
357
		}
358
		return result;
359
	}
360

    
361
	private void makeDate(CaryoImportState state, ResultSet rs, INomenclaturalReference ref, Integer id) throws SQLException {
362
		TimePeriod tp = TimePeriod.NewInstance();
363
		String pre1 = rs.getString("DatePre1");
364
		String pre2 = rs.getString("DatePre2");
365
		Float year1 = nullSafeFloat(rs, "DateYear1");
366
		Float year2 = nullSafeFloat(rs, "DateYear2");
367
		if (year2 == 0.0 ){
368
			year2 = null;
369
		}
370
		String modi1 = rs.getString("DateModi1");
371
		String modi2 = rs.getString("DateModi2");
372
		String date = rs.getString("Date");
373

    
374
		tp.setStartYear(year1.intValue());
375
		Integer[] preDate1 = getDay(pre1,id);
376
//		tp.setStartMonth(preDate1[1]);
377
//		tp.setStartDay(preDate1[0]);
378
		if (year2 != null){
379
			tp.setEndYear(year2.intValue());
380
		}
381
		Integer[] preDate2 = getDay(pre2, id);
382
//		tp.setEndMonth(preDate2[1]);
383
//		tp.setEndDay(preDate2[0]);
384
		
385
//		if (StringUtils.isNotBlank(modi1) || StringUtils.isNotBlank(modi2)){
386
//			tp.setFreeText(date);
387
//		}
388
		ref.setDatePublished(tp);
389
	}
390

    
391

    
392

    
393

    
394
	private Integer[] getDay(String pre, Integer id) {
395
		Integer[] result = new Integer[2];
396
		if (! StringUtils.isBlank(pre)){
397
			try {
398
				String[] split = pre.split("\\s");
399
				String monthStr;
400
				if (split.length > 2){
401
					logger.warn("L > 2: " + pre);
402
					monthStr = "";
403
				}else if(split.length == 2){
404
					result[0] = Integer.valueOf(split[0]);
405
					monthStr = split[1];
406
				}else{
407
					monthStr = split[0];
408
				}
409
				Integer month;
410
				if ("Jan".equalsIgnoreCase(monthStr)){
411
					month = 1;
412
				}else if ("Feb".equalsIgnoreCase(monthStr)){
413
					month = 2;
414
				}else if ("Mar".equalsIgnoreCase(monthStr)){
415
					month = 3;
416
				}else if ("Apr".equalsIgnoreCase(monthStr)){
417
					month = 4;
418
				}else if ("Mai".equalsIgnoreCase(monthStr)){
419
					month = 5;
420
				}else if ("Jun".equalsIgnoreCase(monthStr)){
421
					month = 6;
422
				}else if ("Jul".equalsIgnoreCase(monthStr)){
423
					month = 7;
424
				}else if ("Aug".equalsIgnoreCase(monthStr)){
425
					month = 8;
426
				}else if ("Sep".equalsIgnoreCase(monthStr)){
427
					month = 9;
428
				}else if ("Oct".equalsIgnoreCase(monthStr)){
429
					month = 10;
430
				}else if ("Nov".equalsIgnoreCase(monthStr)){
431
					month = 11;
432
				}else if ("Dec".equalsIgnoreCase(monthStr)){
433
					month = 12;
434
				}else{
435
					logger.warn("Unknown month ("+id+"): " + monthStr );
436
					month = null;
437
				}
438
				result[1]= month;
439
			} catch (Exception e) {
440
				e.printStackTrace();
441
			}
442
		}
443
		return result;
444
	}
445

    
446
	
447
	private TeamOrPersonBase<?> getInAuthor(String inAutorStr) {
448
		if (StringUtils.isBlank(inAutorStr)){
449
			return null;
450
		}
451
		TeamOrPersonBase<?> inAuthor = inAuthorMap.get(inAutorStr);
452
		if (inAuthor == null){
453
			logger.warn("Inauthor not found: " +  inAutorStr);
454
		}
455
		return inAuthor;
456
	}
457

    
458

    
459

    
460
	private void makeAuthors(BotanicalName name, String autoren, Integer id) {
461
		String[] parsedAuthorTeams = getParsedAuthors(autoren);
462
		name.setBasionymAuthorTeam(getTeam(parsedAuthorTeams[0], id));
463
		name.setExBasionymAuthorTeam(getTeam(parsedAuthorTeams[1], id));
464
		name.setCombinationAuthorTeam(getTeam(parsedAuthorTeams[2], id));
465
		name.setExCombinationAuthorTeam(getTeam(parsedAuthorTeams[3], id));
466
		
467
	}
468
	
469
	private TeamOrPersonBase<?> getNomRefAuthor(String authorStr, Integer id) {
470
		String[] parsedAuthorTeams = getParsedAuthors(authorStr);
471
		TeamOrPersonBase<?> team = getTeam(parsedAuthorTeams[2], id);
472
		return team;
473
	}
474

    
475

    
476
	private TeamOrPersonBase<?> getTeam(String author, Integer id) {
477
		if (StringUtils.isBlank(author)){
478
			return null;
479
		}
480
		TeamOrPersonBase<?> result;
481
		if (personMap.get(author) != null){
482
			result = personMap.get(author);
483
		}else{
484
			result = teamMap.get(author);
485
		}
486
		if (result == null){
487
			logger.warn("Team not found ("+id+"): " + author);
488
		}
489
		return result;
490
	}
491
	
492

    
493
	private void doInAuthors(CaryoImportState state) throws SQLException {
494
		Source source = state.getConfig().getSource();
495
		String sql = "SELECT DISTINCT inAutor FROM " + getTableName() + " WHERE inAutor IS NOT NULL AND inAutor <> '' ";
496
		ResultSet rs = source.getResultSet(sql);
497
		while (rs.next()){
498
			String inAutorStr = rs.getString("inAutor");
499
			if (inAuthorMap.get(inAutorStr) == null){
500
				Team team = Team.NewTitledInstance(inAutorStr, inAutorStr);
501

    
502
				inAuthorMap.put(inAutorStr, team);
503
				getAgentService().save(team);
504
			}
505
		}
506
		
507
	}
508

    
509

    
510
	private void doAuthors(CaryoImportState state) throws SQLException {
511
		Source source = state.getConfig().getSource();
512
		String sql = "SELECT DISTINCT Autoren FROM " + getTableName() + " WHERE Autoren IS NOT NULL AND Autoren <> '' ";
513
		ResultSet rs = source.getResultSet(sql);
514
		doTypeAuthors(state);
515
		while (rs.next()){
516
			String autorenStr = rs.getString("Autoren");
517
			String[] parsedAuthorTeams = getParsedAuthors(autorenStr);
518
			for (String teamStr : parsedAuthorTeams){
519
				doTeam(teamStr);
520
			}
521
		}
522
	}
523

    
524

    
525

    
526

    
527
	private void doTypeAuthors(CaryoImportState state) {
528
		doTeam("Dinter & Derenb.");
529
		doTeam("Marloth");
530
		doTeam("Engl.");
531
		doTeam("Kensit");
532
		doTeam("Sond.");
533
		doTeam("L. f.");
534
		doTeam("Dinter & A. Berger");
535
		doTeam("Schltr.");
536
		doTeam("Dinter & Berger");
537
		doTeam("Poir.");
538
		doTeam("J. C. Wendl.");
539
		doTeam("Baker & Clarke");
540
		doTeam("Vahl");
541
		doTeam("Nicolai");
542
		doTeam("Gürke");
543
		doTeam("Cels");
544
		doTeam("Dams");
545
		doTeam("Coult.");
546
		doTeam("A. Weber");
547
		doTeam("Vaupel");
548
		doTeam("Gay");
549
		doTeam("Pall.");
550
		doTeam("Moq. & Coss.");
551
		doTeam("Durieu & Moq.");
552
		doTeam("Lag. & Rodrigues");
553
		doTeam("M. Martens & Galeotti");
554
		doTeam("Steud.");
555
		doTeam("Aitch. & Hemsl.");
556
		doTeam("Ikonn.-Gal.");
557
		doTeam("Freitag");
558
		doTeam("Regel");
559
		doTeam("Ledeb.");
560
		doTeam("Schur");
561
		doTeam("Asch.");
562
		doTeam("G. Forst.");
563
		doTeam("Gray");
564
		doTeam("Curran");
565
		doTeam("Donn. Sm.");
566
		doTeam("Diels");
567
		doTeam("Colla");
568
		doTeam("Miers");
569
		doTeam("Gillis");
570
		doTeam("Royle");
571
		doTeam("Monv.");
572
		doTeam("Werderm. & Backeb.");
573
		doTeam("Wright");
574
		doTeam("Meyen");
575
		doTeam("Runge");
576
		doTeam("Böd.");
577
		doTeam("Rol.-Goss.");
578
		doTeam("Poselg.");
579
		doTeam("Andreae & Backeberg");
580
		doTeam("Miq.");
581
		doTeam("Rol.");
582
		doTeam("Backeb. & Voll");
583
		doTeam("Engelm. & Bigelow");
584
		doTeam("Pfeiffer & Otto");
585
		doTeam("Humb. & Bonpl.");
586
		doTeam("Schmalh.");
587
		doTeam("Preobr.");
588
		doTeam("Labill.");
589
		doTeam("Barkoudah");
590
		doTeam("Regel & Schmalh.");
591
		doTeam("Cambess.");
592
		doTeam("Pax & K. Hoff.");
593
		doTeam("Bergeret");
594
		doTeam("Walp.");
595
		doTeam("Huds.");
596
		doTeam("Kit.");
597
		doTeam("Schott, Nymann & Kotschy");
598
		doTeam("Boiss. & Buhse");
599
		doTeam("Medik.");
600
		doTeam("Coss. & Germ.");
601
		doTeam("Moss");
602
		doTeam("Pax & Hoffm.");
603
		doTeam("Schischk.");
604
		doTeam("Lipsch.");
605
		doTeam("Maerkl.");
606
		doTeam("Vierh.");
607
		doTeam("Exell");
608
		
609
	}
610

    
611

    
612

    
613

    
614
	/**
615
	 * @param teamStr
616
	 * @return
617
	 */
618
	protected void doTeam(String teamStr) {
619
		if (StringUtils.isBlank(teamStr)){
620
			return;
621
		}
622
		String[] parsedTeam = parseTeam(teamStr);
623
		if (parsedTeam.length == 1){
624
			savePerson(parsedTeam[0]);
625
		}else{
626
			Team team = teamMap.get(teamStr);
627
			if (team == null){
628
				team = Team.NewInstance();
629
				for (String member : parsedTeam){
630
					Person person = savePerson(member);
631
					team.addTeamMember(person);
632
				}
633
				teamMap.put(teamStr, team);
634
				getAgentService().saveOrUpdate(team);
635
			}
636
		}
637
		return;
638
	}
639

    
640
	private String[] parseTeam(String teamStr) {
641
		String[] split = teamStr.split("[&,]");
642
		for (int i = 0; i < split.length; i++){
643
			split[i] = split[i].trim();
644
		}
645
		return split;
646
	}
647

    
648
	private Person savePerson(String personStr) {
649
		Person result = personMap.get(personStr);
650
		if (result == null ){
651
			Person person = Person.NewTitledInstance(personStr);
652
			personMap.put(personStr, person);
653
			getAgentService().save(person);
654
			result = person;
655
		}
656
		return result;
657
	}
658

    
659

    
660

    
661

    
662
	private String[] getParsedAuthors(String autorenStr) {
663
		String[] result = new String[4]; 
664
		String basioFull = null;
665
		String origFull;
666

    
667
			String[]  split = autorenStr.split("\\)");
668
		if (split.length > 1){
669
			basioFull = split[0].replace("(", "").trim();
670
			origFull = split[1].trim();
671
		}else{
672
			origFull = split[0].trim();
673
		}
674
		String[] splitBasio = splitExAuthors(basioFull);
675
		String[] splitOrig = splitExAuthors(origFull);
676
		result[0] = splitBasio[0];
677
		result[1] = splitBasio[1];
678
		result[2] = splitOrig[0];
679
		result[3] = splitOrig[1];
680
		
681
		return result;
682
	}
683

    
684

    
685

    
686

    
687
	private String[] splitExAuthors(String author) {
688
		String[] result = new String[2]; 
689
		if (author != null){
690
			String[]  split = author.split("\\sex\\s");
691
			if (split.length > 1){
692
				result[0] = split[1].trim();
693
				result[1] = split[0].trim();
694
			}else{
695
				result[0] = split[0].trim();
696
			}
697
		}
698
		return result;
699
	}
700

    
701

    
702

    
703

    
704
	private void doBooks(CaryoImportState state) throws SQLException {
705
		Source source = state.getConfig().getSource();
706
		String sql = "SELECT DISTINCT BookTitle FROM " + getTableName() + " WHERE BookTitle IS NOT NULL AND BookTitle <> '' ";
707
		ResultSet rs = source.getResultSet(sql);
708
		while (rs.next()){
709
			String bookStr = rs.getString("BookTitle");
710
			if (bookMap.get(bookStr) == null ){
711
				
712
				IBook book = ReferenceFactory.newBook(); 
713

    
714
				book.setTitle(bookStr);
715
				
716
				bookMap.put(bookStr, book);
717
				getReferenceService().save((Reference<?>)book);
718
			}
719
		}
720
	}
721

    
722

    
723

    
724

    
725
	private void doJournals(CaryoImportState state) throws SQLException {
726
		Source source = state.getConfig().getSource();
727
		String sqlPeriodical = "SELECT DISTINCT PeriodicalTitle FROM " + getTableName() + " WHERE PeriodicalTitle IS NOT NULL AND PeriodicalTitle <> '' ";
728
		ResultSet rs = source.getResultSet(sqlPeriodical);
729
		while (rs.next()){
730
			String periodical = rs.getString("PeriodicalTitle");
731
			if (journalMap.get(periodical) == null ){
732
				
733
				Reference<?> journal = ReferenceFactory.newJournal(); 
734

    
735
				journal.setTitle(periodical);
736
				
737
				journalMap.put(periodical, journal);
738
				getReferenceService().save(journal);
739
			}
740
		}
741
	}
742

    
743

    
744

    
745

    
746
	private void doFamilies(CaryoImportState state) throws SQLException {
747
		Source source = state.getConfig().getSource();
748
		String sqlFamily = "SELECT DISTINCT Family FROM " + getTableName() + " WHERE Family IS NOT NULL";
749
		ResultSet rs = source.getResultSet(sqlFamily);
750
		while (rs.next()){
751
			String family = rs.getString("family");
752
			if (familyMap.get(family) == null ){
753
				
754
				BotanicalName name = BotanicalName.NewInstance(Rank.FAMILY());
755
				name.setGenusOrUninomial(family);
756
				Taxon taxon = Taxon.NewInstance(name, state.getTransactionalSourceReference());
757
				classification.addChildTaxon(taxon, null, null, null);
758
	//			taxon.addSource(id, idNamespace, citation, null);
759
				
760
				familyMap.put(family, taxon);
761
				getTaxonService().save(taxon);
762
			}
763
		}
764
		
765
	}
766

    
767
	private Classification getClassification(CaryoImportState state) {
768
		if (this.classification == null){
769
			String name = state.getConfig().getClassificationName();
770
			Reference<?> reference = state.getTransactionalSourceReference();
771
			this.classification = Classification.NewInstance(name, reference, Language.DEFAULT());
772
			if (state.getConfig().getClassificationUuid() != null){
773
				classification.setUuid(state.getConfig().getClassificationUuid());
774
			}
775
			getClassificationService().save(classification);
776
		}
777
		return this.classification;
778
	}
779

    
780

    
781

    
782

    
783

    
784
	/* (non-Javadoc)
785
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet)
786
	 */
787
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs) {
788
//		String nameSpace;
789
//		Class cdmClass;
790
//		Set<String> idSet;
791
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
792
//		try{
793
//			Set<String> taxonIdSet = new HashSet<String>();
794
//			
795
//			while (rs.next()){
796
////				handleForeignKey(rs, taxonIdSet, "taxonId");
797
//			}
798
//			
799
//			//taxon map
800
//			nameSpace = TAXON_NAMESPACE;
801
//			cdmClass = Taxon.class;
802
//			idSet = taxonIdSet;
803
//			Map<String, Taxon> objectMap = (Map<String, Taxon>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
804
//			result.put(nameSpace, objectMap);
805
//
806
//			
807
//		} catch (SQLException e) {
808
//			throw new RuntimeException(e);
809
//		}
810
		return result;
811
	}
812
	
813
	/* (non-Javadoc)
814
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
815
	 */
816
	@Override
817
	protected boolean doCheck(CaryoImportState state){
818
		return true;
819
	}
820
	
821
	
822
	/* (non-Javadoc)
823
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
824
	 */
825
	protected boolean isIgnore(CaryoImportState state){
826
		return ! state.getConfig().isDoTaxa();
827
	}
828

    
829

    
830

    
831

    
832

    
833

    
834

    
835
}
(3-3/4)