Project

General

Profile

Download (24.4 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.CdmBase;
30
import eu.etaxonomy.cdm.model.common.Language;
31
import eu.etaxonomy.cdm.model.common.TimePeriod;
32
import eu.etaxonomy.cdm.model.name.BotanicalName;
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.reference.IArticle;
38
import eu.etaxonomy.cdm.model.reference.IBook;
39
import eu.etaxonomy.cdm.model.reference.IBookSection;
40
import eu.etaxonomy.cdm.model.reference.IJournal;
41
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
42
import eu.etaxonomy.cdm.model.reference.Reference;
43
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
44
import eu.etaxonomy.cdm.model.taxon.Classification;
45
import eu.etaxonomy.cdm.model.taxon.Synonym;
46
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
47
import eu.etaxonomy.cdm.model.taxon.Taxon;
48
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
49
import eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy;
50
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
51
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
52
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
53

    
54

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

    
68

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

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

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

    
101

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

    
115

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

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

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

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

    
199
	
200
	private INonViralNameParser parser = NonViralNameParserImpl.NewInstance();
201
	private void handleBasionym(CaryoImportState state, ResultSet rs, Taxon taxon, String basioStr, Integer id) {
202
		if (StringUtils.isNotBlank(basioStr)){
203
			BotanicalName name = (BotanicalName) taxon.getName();
204
			BotanicalName basionym = BotanicalName.PARSED_NAME(basioStr);
205
			name.addBasionym(basionym);
206
			Synonym syn = Synonym.NewInstance(basionym, state.getTransactionalSourceReference());
207
			taxon.addSynonym(syn, SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF());
208
			getTaxonService().save(syn);
209
		}
210
		
211
	}
212

    
213

    
214

    
215

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

    
256
					
257
					makeAuthors(typeName, type, id);
258
				}
259
					
260
				desig.setTypeName(typeName);
261
			}
262
			name.addTypeDesignation(desig, true);
263
		}
264
		
265
		
266
	}
267

    
268

    
269

    
270

    
271
	private String makeTypeNomStatus(BotanicalName typeName, String type) {
272
		if (type.endsWith(", nom. illeg.")){
273
			type = type.replaceAll(", nom. illeg.", "");
274
			typeName.addStatus(NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ILLEGITIMATE()));
275
		}
276
		return type;
277
	}
278

    
279

    
280

    
281

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

    
314

    
315

    
316

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

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

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

    
387

    
388

    
389

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

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

    
454

    
455

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

    
471

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

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

    
498
				inAuthorMap.put(inAutorStr, team);
499
				getAgentService().save(team);
500
			}
501
		}
502
		
503
	}
504

    
505

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

    
520

    
521

    
522

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

    
607

    
608

    
609

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

    
636
	private String[] parseTeam(String teamStr) {
637
		String[] split = teamStr.split("[&,]");
638
		for (int i = 0; i < split.length; i++){
639
			split[i] = split[i].trim();
640
		}
641
		return split;
642
	}
643

    
644
	private Person savePerson(String personStr) {
645
		Person result = personMap.get(personStr);
646
		if (result == null ){
647
			Person person = Person.NewTitledInstance(personStr);
648
			personMap.put(personStr, person);
649
			getAgentService().save(person);
650
			result = person;
651
		}
652
		return result;
653
	}
654

    
655

    
656

    
657

    
658
	private String[] getParsedAuthors(String autorenStr) {
659
		String[] result = new String[4]; 
660
		String basioFull = null;
661
		String origFull;
662

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

    
680

    
681

    
682

    
683
	private String[] splitExAuthors(String author) {
684
		String[] result = new String[2]; 
685
		if (author != null){
686
			String[]  split = author.split("\\sex\\s");
687
			if (split.length > 1){
688
				//TODO richtige Reihenfolge ?
689
				result[0] = split[1].trim();
690
				result[1] = split[0].trim();
691
			}else{
692
				result[0] = split[0].trim();
693
			}
694
		}
695
		return result;
696
	}
697

    
698

    
699

    
700

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

    
711
				book.setTitle(bookStr);
712
				
713
				bookMap.put(bookStr, book);
714
				getReferenceService().save((Reference<?>)book);
715
			}
716
		}
717
	}
718

    
719

    
720

    
721

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

    
732
				journal.setTitle(periodical);
733
				
734
				journalMap.put(periodical, journal);
735
				getReferenceService().save(journal);
736
			}
737
		}
738
	}
739

    
740

    
741

    
742

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

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

    
777

    
778

    
779

    
780

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

    
826

    
827

    
828

    
829

    
830

    
831

    
832
}
(3-3/4)