Project

General

Profile

« Previous | Next » 

Revision abe5586a

Added by Andreas Müller over 11 years ago

update for Caryophallales import

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoTaxonImport.java
16 16
import java.util.Map;
17 17
import java.util.Set;
18 18

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

  
22 23
import eu.etaxonomy.cdm.io.common.DbImportBase;
23 24
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
24 25
import eu.etaxonomy.cdm.io.common.Source;
26
import eu.etaxonomy.cdm.model.agent.Person;
27
import eu.etaxonomy.cdm.model.agent.Team;
25 28
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
26 29
import eu.etaxonomy.cdm.model.common.CdmBase;
27 30
import eu.etaxonomy.cdm.model.common.Language;
31
import eu.etaxonomy.cdm.model.common.TimePeriod;
28 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;
29 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;
30 42
import eu.etaxonomy.cdm.model.reference.Reference;
43
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
31 44
import eu.etaxonomy.cdm.model.taxon.Classification;
45
import eu.etaxonomy.cdm.model.taxon.Synonym;
46
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
32 47
import eu.etaxonomy.cdm.model.taxon.Taxon;
33 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;
34 53

  
35 54

  
36 55
/**
......
45 64
	private int modCount = 10000;
46 65
	private static final String pluralString = "taxa";
47 66
	private static final String dbTableName = "CARYOPHYLLALES";
48
	private static final String FAMILY = "Family";
49
	private static final String PERSON = "Person";
50
	private static final String TEAM = "Team";
51
	private static final String JOURNAL = "Journal";
52
	private static final String BOOK = "Book";
67

  
53 68

  
54 69
	
55 70
	private Map<String, Taxon> familyMap = new HashMap<String, Taxon>();
56
	private Map<String, TeamOrPersonBase> personMap = new HashMap<String, TeamOrPersonBase>();
57
	private Map<String, TeamOrPersonBase> teamMap = new HashMap<String, TeamOrPersonBase>();
58
	private Map<String, Reference> journalMap = new HashMap<String, Reference>();
59
	private Map<String, Reference> bookMap = new HashMap<String, Reference>();
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>();
60 76
	
61 77
	
62 78
	private Classification classification;
63 79

  
64 80
	
81
	
65 82
	public CaryoTaxonImport(){
66
		super(pluralString, dbTableName);
83
		super(dbTableName, pluralString);
67 84
	}
68 85

  
69 86
	
......
76 93
	protected String getIdQuery(CaryoImportState state) {
77 94
		String strRecordQuery = 
78 95
			" SELECT ID " + 
79
			" FROM " + dbTableName; 
96
			" FROM " + dbTableName +
97
			" ORDER BY id "; 
80 98
		return strRecordQuery;	
81 99
	}
82 100

  
......
87 105
	@Override
88 106
	protected String getRecordQuery(CaryoImportConfigurator config) {
89 107
		String strRecordQuery = 
90
			" SELECT cs.* " + 
108
			" SELECT t.* " + 
91 109
			" FROM " + getTableName() + " t " +
92 110
			" WHERE ( t.ID IN (" + ID_LIST_TOKEN + ") )";
93 111
		return strRecordQuery;
......
112 130
		try {
113 131
			doFamilies(state);
114 132
			doAuthors(state);
133
			doInAuthors(state);
115 134
			doJournals(state);
116 135
			doBooks(state);
117 136
			
118 137
			ResultSet rs = partitioner.getResultSet();
119 138
			
120 139
			int i = 0;
140
    		Reference<?> sec = state.getTransactionalSourceReference();
121 141

  
122 142
			//for each reference
123 143
            while (rs.next()){
124 144
                
125 145
        		if ((i++ % modCount) == 0 && i!= 1 ){ logger.info(pluralString + " handled: " + (i-1));}
126 146
				
127
        		Integer taxonId = rs.getInt("IDcurrentspec");
128
        		
129
        		
130
        		//String dtSpcJahr -> ignore !
131
        		//empty: fiSpcLiteratur
132
        		
133
        		//TODO
134
        		//fiSpcspcgrptax
135
        		
136
        	
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
				
137 163
        		
138
				try {
139
					
140
					
141
//					classification.addParentChild(nextHigherTaxon, species, sourceRef, null);
142
//					
143
//					
144
//					this.doIdCreatedUpdatedNotes(state, species, rs, taxonId, TAXON_NAMESPACE);
145
//					
146
//					objectsToSave.add(species); 
147
					
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);
148 186

  
149
				} catch (Exception e) {
150
					logger.warn("Exception in current_species: IDcurrentspec " + taxonId + ". " + e.getMessage());
151
//					e.printStackTrace();
152
				} 
153
                
154 187
            }
155 188
           
156
//            logger.warn("Specimen: " + countSpecimen + ", Descriptions: " + countDescriptions );
157

  
158 189
			logger.warn(pluralString + " to save: " + objectsToSave.size());
159 190
			getTaxonService().save(objectsToSave);	
160 191
			
......
165 196
		}
166 197
	}
167 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

  
168 454

  
169 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
	}
170 470

  
171 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
	
172 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);
173 497

  
174
	private void doAuthors(CaryoImportState state) {
175
		// TODO Auto-generated method stub
498
				inAuthorMap.put(inAutorStr, team);
499
				getAgentService().save(team);
500
			}
501
		}
176 502
		
177 503
	}
178 504

  
179 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

  
180 520

  
181 521

  
182
	private void doBooks(CaryoImportState state) {
183
		// TODO Auto-generated method stub
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");
184 604
		
185 605
	}
186 606

  
187 607

  
188 608

  
189 609

  
190
	private void doJournals(CaryoImportState state) {
191
		// TODO Auto-generated method stub
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];
192 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
		}
193 738
	}
194 739

  
195 740

  
......
197 742

  
198 743
	private void doFamilies(CaryoImportState state) throws SQLException {
199 744
		Source source = state.getConfig().getSource();
200
		String sqlFamily = "SELECT DISTINCT family FROM table WHERE family IS NOT NULL";
745
		String sqlFamily = "SELECT DISTINCT Family FROM " + getTableName() + " WHERE Family IS NOT NULL";
201 746
		ResultSet rs = source.getResultSet(sqlFamily);
202 747
		while (rs.next()){
203 748
			String family = rs.getString("family");
204
			BotanicalName name = BotanicalName.NewInstance(Rank.FAMILY());
205
			name.setGenusOrUninomial(family);
206
			Taxon taxon = Taxon.NewInstance(name, state.getTransactionalSourceReference());
207
			classification.addChildTaxon(taxon, null, null, null);
208
//			taxon.addSource(id, idNamespace, citation, null);
209
			
210
			
211
			familyMap.put(family, taxon);
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
			}
212 760
		}
213 761
		
214 762
	}
......
224 772
			getClassificationService().save(classification);
225 773
		}
226 774
		return this.classification;
227
		
228 775
	}
229 776

  
230 777

  

Also available in: Unified diff