Project

General

Profile

Download (24.1 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.berlinModel.in;
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
import java.util.UUID;
19

    
20
import org.apache.log4j.Logger;
21
import org.springframework.stereotype.Component;
22

    
23
import eu.etaxonomy.cdm.common.CdmUtils;
24
import eu.etaxonomy.cdm.database.update.DatabaseTypeNotSupportedException;
25
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
26
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelTaxonNameImportValidator;
27
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
28
import eu.etaxonomy.cdm.io.common.IOValidator;
29
import eu.etaxonomy.cdm.io.common.ImportHelper;
30
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
31
import eu.etaxonomy.cdm.io.common.Source;
32
import eu.etaxonomy.cdm.model.agent.Person;
33
import eu.etaxonomy.cdm.model.agent.Team;
34
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
35
import eu.etaxonomy.cdm.model.common.Annotation;
36
import eu.etaxonomy.cdm.model.common.CdmBase;
37
import eu.etaxonomy.cdm.model.common.Extension;
38
import eu.etaxonomy.cdm.model.common.ExtensionType;
39
import eu.etaxonomy.cdm.model.common.Language;
40
import eu.etaxonomy.cdm.model.common.Representation;
41
import eu.etaxonomy.cdm.model.name.IBotanicalName;
42
import eu.etaxonomy.cdm.model.name.ICultivarPlantName;
43
import eu.etaxonomy.cdm.model.name.INonViralName;
44
import eu.etaxonomy.cdm.model.name.IZoologicalName;
45
import eu.etaxonomy.cdm.model.name.Rank;
46
import eu.etaxonomy.cdm.model.name.TaxonName;
47
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
48
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
49
import eu.etaxonomy.cdm.model.reference.Reference;
50
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
51

    
52
/**
53
 * @author a.mueller
54
 * @since 20.03.2008
55
 */
56
@Component
57
public class BerlinModelTaxonNameImport extends BerlinModelImportBase {
58
    private static final long serialVersionUID = -8860800694286602016L;
59

    
60
    private static final boolean BLANK_TO_NULL = true;
61

    
62
	private static final Logger logger = Logger.getLogger(BerlinModelTaxonNameImport.class);
63

    
64
	public static final String NAMESPACE = "TaxonName";
65

    
66
	public static final UUID SOURCE_ACC_UUID = UUID.fromString("c3959b4f-d876-4b7a-a739-9260f4cafd1c");
67

    
68
	private static int modCount = 5000;
69
	private static final String pluralString = "TaxonNames";
70
	private static final String dbTableName = "Name";
71

    
72

    
73
	public BerlinModelTaxonNameImport(){
74
		super(dbTableName, pluralString);
75
	}
76

    
77

    
78
	@Override
79
	protected String getIdQuery(BerlinModelImportState state) {
80
		if (state.getConfig().getNameIdTable()==null ){
81
			return super.getIdQuery(state);
82
		}else{
83
			return "SELECT nameId FROM " + state.getConfig().getNameIdTable() + "";
84
		}
85
	}
86

    
87
	@Override
88
	protected String getRecordQuery(BerlinModelImportConfigurator config) {
89
		Source source = config.getSource();
90

    
91
			String facultativCols = "";
92
			String strFacTable = "RefDetail";
93
			String strFacColumn = "IdInSource";
94
			String strColAlias = null;
95
			if (checkSqlServerColumnExists(source, strFacTable, strFacColumn)){
96
				facultativCols +=  ", " + strFacTable + "." + strFacColumn ;
97
				if (! CdmUtils.Nz(strColAlias).equals("") ){
98
					facultativCols += " AS " + strColAlias;
99
				}
100
			}
101

    
102
		String strRecordQuery =
103
					"SELECT Name.* , RefDetail.RefDetailId, RefDetail.RefFk, " +
104
                      		" RefDetail.FullRefCache, RefDetail.FullNomRefCache, RefDetail.PreliminaryFlag AS RefDetailPrelim, RefDetail.Details, " +
105
                      		" RefDetail.SecondarySources, Rank.RankAbbrev, Rank.Rank " +
106
                      		facultativCols +
107
                    " FROM Name LEFT OUTER JOIN RefDetail ON Name.NomRefDetailFk = RefDetail.RefDetailId AND  " +
108
                    	" Name.NomRefFk = RefDetail.RefFk " +
109
                    	" LEFT OUTER JOIN Rank ON Name.RankFk = Rank.rankID " +
110
                " WHERE name.nameId IN ("+ID_LIST_TOKEN+") ";
111
					//strQuery += " AND RefDetail.PreliminaryFlag = 1 ";
112
					//strQuery += " AND Name.Created_When > '03.03.2004' ";
113
		return strRecordQuery +  "";
114
	}
115

    
116

    
117

    
118
	@Override
119
	protected void doInvoke(BerlinModelImportState state) {
120
		//update rank labels if necessary
121
		String strAbbrev = state.getConfig().getInfrGenericRankAbbrev();
122
		Rank rank = Rank.INFRAGENERICTAXON();
123
		testRankAbbrev(strAbbrev, rank);
124

    
125
		strAbbrev = state.getConfig().getInfrSpecificRankAbbrev();
126
		rank = Rank.INFRASPECIFICTAXON();
127
		testRankAbbrev(strAbbrev, rank);
128

    
129
		super.doInvoke(state);
130
	}
131

    
132
	private void testRankAbbrev(String strAbbrev, Rank rank) {
133
		if (strAbbrev != null){
134
			Representation rep = rank.getRepresentation(Language.ENGLISH());
135
			rep.setAbbreviatedLabel(strAbbrev);
136
			getTermService().saveOrUpdate(rank);
137
		}
138
	}
139

    
140
	@Override
141
	public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) {
142
		String dbAttrName;
143
		String cdmAttrName;
144
		boolean success = true ;
145
		BerlinModelImportConfigurator config = state.getConfig();
146
		Set<TaxonName> namesToSave = new HashSet<>();
147
		Map<String, Team> teamMap = partitioner.getObjectMap(BerlinModelAuthorTeamImport.NAMESPACE);
148

    
149
		ResultSet rs = partitioner.getResultSet();
150

    
151
		try {
152
			int i = 0;
153
			//for each reference
154
			while (rs.next()){
155

    
156
				if ((i++ % modCount) == 0 && i != 1 ){ logger.info("Names handled: " + (i-1));}
157

    
158
				//create TaxonName element
159
				int nameId = rs.getInt("nameId");
160
				Object authorFk = rs.getObject("AuthorTeamFk");
161
				Object exAuthorFk = rs.getObject("ExAuthorTeamFk");
162
				Object basAuthorFk = rs.getObject("BasAuthorTeamFk");
163
				Object exBasAuthorFk = rs.getObject("ExBasAuthorTeamFk");
164
				String strCultivarGroupName = rs.getString("CultivarGroupName");
165
				String strCultivarName = rs.getString("CultivarName");
166
				String nameCache = rs.getString("NameCache");
167
				String fullNameCache = rs.getString("FullNameCache");
168
				String uuid = null;
169
				if (resultSetHasColumn(rs,"UUID")){
170
					uuid = rs.getString("UUID");
171
				}
172

    
173
				try {
174

    
175
					//define rank
176
					boolean useUnknownRank = true;
177
					Rank rank = BerlinModelTransformer.rankId2Rank(rs, useUnknownRank, config.isSwitchSpeciesGroup());
178

    
179
					boolean allowInfraSpecTaxonRank = state.getConfig().isAllowInfraSpecTaxonRank() ;
180
					if (rank == null || rank.equals(Rank.UNKNOWN_RANK()) || (rank.equals(Rank.INFRASPECIFICTAXON()) && ! allowInfraSpecTaxonRank)){
181
						rank = handleProlesAndRaceSublusus(state, rs, rank);
182
					}
183

    
184
					if (rank.getId() == 0){
185
						getTermService().save(rank);
186
						logger.warn("Rank did not yet exist: " +  rank.getTitleCache());
187
					}
188

    
189
					//create TaxonName
190
					TaxonName taxonName;
191
					if (config.getNomenclaturalCode() != null){
192
						taxonName = config.getNomenclaturalCode().getNewTaxonNameInstance(rank);
193
						//check cultivar
194
						if (taxonName.isBotanical()){
195
							if (isNotBlank(strCultivarGroupName) && isNotBlank(strCultivarName)){
196
								taxonName = TaxonNameFactory.NewCultivarInstance(rank);
197
							}
198
						}
199
					}else{
200
						taxonName = TaxonNameFactory.NewNonViralInstance(rank);
201
					}
202
					if (uuid != null){
203
						taxonName.setUuid(UUID.fromString(uuid));
204
					}
205

    
206
					if (rank == null){
207
						//TODO rank should never be null or a more sophisticated algorithm has to be implemented for genus/supraGenericName
208
						logger.warn("Rank is null. Genus epithet was imported. May be wrong");
209
						success = false;
210
					}
211

    
212
					//epithets
213
					if (rank != null && rank.isSupraGeneric()){
214
						dbAttrName = "supraGenericName";
215
					}else{
216
						dbAttrName = "genus";
217
					}
218
					cdmAttrName = "genusOrUninomial";
219
					success &= ImportHelper.addStringValue(rs, taxonName, dbAttrName, cdmAttrName, BLANK_TO_NULL);
220

    
221
					dbAttrName = "genusSubdivisionEpi";
222
					cdmAttrName = "infraGenericEpithet";
223
					success &= ImportHelper.addStringValue(rs, taxonName, dbAttrName, cdmAttrName, BLANK_TO_NULL);
224

    
225
					dbAttrName = "speciesEpi";
226
					cdmAttrName = "specificEpithet";
227
					success &= ImportHelper.addStringValue(rs, taxonName, dbAttrName, cdmAttrName, BLANK_TO_NULL);
228

    
229

    
230
					dbAttrName = "infraSpeciesEpi";
231
					cdmAttrName = "infraSpecificEpithet";
232
					success &= ImportHelper.addStringValue(rs, taxonName, dbAttrName, cdmAttrName, BLANK_TO_NULL);
233

    
234
					dbAttrName = "unnamedNamePhrase";
235
					cdmAttrName = "appendedPhrase";
236
					success &= ImportHelper.addStringValue(rs, taxonName, dbAttrName, cdmAttrName, BLANK_TO_NULL);
237

    
238
					//Details
239
					dbAttrName = "details";
240
					cdmAttrName = "nomenclaturalMicroReference";
241
					success &= ImportHelper.addStringValue(rs, taxonName, dbAttrName, cdmAttrName, BLANK_TO_NULL);
242

    
243
					//nomRef
244
					success &= makeNomenclaturalReference(config, taxonName, nameId, rs, partitioner);
245

    
246
					//Source_Acc
247
					boolean colExists = true;
248
					try {
249
						colExists = state.getConfig().getSource().checkColumnExists("Name", "Source_Acc");
250
					} catch (DatabaseTypeNotSupportedException e) {
251
						logger.debug("Source does not support 'checkColumnExists'");
252
					}
253
					if (colExists){
254
						String sourceAcc = rs.getString("Source_Acc");
255
						if (isNotBlank(sourceAcc)){
256
							ExtensionType sourceAccExtensionType = getExtensionType(state, SOURCE_ACC_UUID, "Source_Acc","Source_Acc","Source_Acc");
257
							Extension.NewInstance(taxonName, sourceAcc, sourceAccExtensionType);
258
						}
259
					}
260

    
261
					//created, notes
262
					boolean excludeUpdated = true;
263
					boolean excludeNotes = true;
264
					success &= doIdCreatedUpdatedNotes(state, taxonName, rs, nameId, NAMESPACE, excludeUpdated, excludeNotes);
265
					handleNameNotes(state, taxonName, rs, nameId);
266

    
267
					//NonViralName
268
					if (taxonName.isNonViral()){
269
						INonViralName nonViralName = taxonName;
270

    
271
						//authorTeams
272
						if (teamMap != null ){
273
							nonViralName.setCombinationAuthorship(getAuthorTeam(teamMap, authorFk, nameId, config));
274
							nonViralName.setExCombinationAuthorship(getAuthorTeam(teamMap, exAuthorFk, nameId, config));
275
							nonViralName.setBasionymAuthorship(getAuthorTeam(teamMap, basAuthorFk, nameId, config));
276
							nonViralName.setExBasionymAuthorship(getAuthorTeam(teamMap, exBasAuthorFk, nameId, config));
277
						}else{
278
							logger.warn("TeamMap is null");
279
							success = false;
280
						}
281
					}//nonviralName
282

    
283

    
284

    
285
					//zoologicalName
286
					if (taxonName.isZoological()){
287
						IZoologicalName zooName = taxonName;
288
						makeZoologialName(rs, zooName, nameId);
289
					}
290
					//botanicalName
291
					else if (taxonName.isBotanical()){
292
						IBotanicalName botName = taxonName;
293
						success &= makeBotanicalNamePart(rs, botName) ;
294

    
295
					}
296

    
297
	//				dbAttrName = "preliminaryFlag";
298
					Boolean preliminaryFlag = rs.getBoolean("PreliminaryFlag");
299
					Boolean hybridFormulaFlag = rs.getBoolean("HybridFormulaFlag");  //hybrid flag does not lead to cache update in Berlin Model
300
					if (preliminaryFlag == true || hybridFormulaFlag == true){
301
						//Computes all caches and sets
302
						taxonName.setTitleCache(fullNameCache, true);
303
						taxonName.setFullTitleCache(taxonName.getFullTitleCache(), true);
304
						if (taxonName.isNonViral()){
305
							INonViralName nvn = taxonName;
306
							nvn.setNameCache(nameCache, true);
307
							nvn.setAuthorshipCache(nvn.getAuthorshipCache(), true);
308
						}
309
					}
310
					namesToSave.add(taxonName);
311

    
312
				}
313
				catch (UnknownCdmTypeException e) {
314
					logger.warn("Name with id " + nameId + " has unknown rankId " + " and could not be saved.");
315
					success = false;
316
				}
317

    
318
			} //while rs.hasNext()
319
		} catch (SQLException e) {
320
			logger.error("SQLException:" +  e);
321
			return false;
322
		}
323

    
324

    
325
//		logger.info( i + " names handled");
326
		getNameService().save(namesToSave);
327
		return success;
328
	}
329

    
330

    
331
	/**
332
     * @param state
333
     * @param taxonName
334
     * @param rs
335
     * @param nameId
336
	 * @throws SQLException
337
     */
338
    private void handleNameNotes(BerlinModelImportState state, TaxonName taxonName, ResultSet rs, int nameId) throws SQLException {
339
        String notesOrig = rs.getString("notes");
340
        String notes = filterNotes(notesOrig, nameId);
341
        if (isNotBlank(notes) && taxonName != null ){
342
            String notesString = String.valueOf(notes);
343
            if (notesString.length() > 65530 ){
344
                notesString = notesString.substring(0, 65530) + "...";
345
                logger.warn("Notes string is longer than 65530 and was truncated: " + taxonName);
346
            }
347
            Annotation notesAnnotation = Annotation.NewInstance(notesString, Language.DEFAULT());
348
            //notesAnnotation.setAnnotationType(AnnotationType.EDITORIAL());
349
            //notes.setCommentator(bmiConfig.getCommentator());
350
            taxonName.addAnnotation(notesAnnotation);
351
        }
352

    
353
    }
354

    
355
    private static final String MCL = "MCL\\s?[0-9]{1,3}(\\-[0-9]{1,4}(\\-[0-9]{1,4}(\\-[0-9]{1,4}(\\-[0-9]{1,3})?)?)?)?";
356
    /**
357
     * @param notes
358
     */
359
    private String filterNotes(String notes, int nameId) {
360
        String result;
361
        if (isBlank(notes)){
362
            result = null;
363
        }else if (notes.matches("Acc:.*")){
364
            if (notes.matches("Acc: .*\\$$") || (notes.matches("Acc: .*"+MCL))){
365
                result = null;
366
            }else if (notes.matches("Acc: .*(\\$|"+MCL+")\\s*\\{.*\\}")){
367
                notes = notes.substring(notes.indexOf("{")+1, notes.length()-1);
368
                result = notes;
369
            }else if (notes.matches("Acc: .*(\\$|"+MCL+")\\s*\\[.*\\]")){
370
                notes = notes.substring(notes.indexOf("[")+1, notes.length()-1);
371
                result = notes;
372
            }else{
373
                logger.warn("Name id: " + nameId + ". Namenote: " + notes);
374
                result = notes;
375
            }
376
        }else if (notes.matches("Syn:.*")){
377
            if (notes.matches("Syn: .*\\$$") || (notes.matches("Syn: .*"+MCL))){
378
                result = null;
379
            }else if (notes.matches("Syn: .*(\\$|"+MCL+")\\s*\\{.*\\}")){
380
                notes = notes.substring(notes.indexOf("{")+1, notes.length()-1);
381
                result = notes;
382
            }else if (notes.matches("Syn: .*(\\$|"+MCL+")\\s*\\[.*\\]")){
383
                notes = notes.substring(notes.indexOf("[")+1, notes.length()-1);
384
                result = notes;
385
            }else{
386
                logger.warn("Name id: " + nameId + ". Namenote: " + notes);
387
                result = notes;
388
            }
389
        }else{
390
            result = notes;
391
        }
392
        return result;
393
    }
394

    
395

    
396
    private Rank handleProlesAndRaceSublusus(BerlinModelImportState state, ResultSet rs, Rank rank) throws SQLException {
397
		Rank result;
398
		String rankAbbrev = rs.getString("RankAbbrev");
399
//		String rankStr = rs.getString("Rank");
400
		if (CdmUtils.nullSafeEqual(rankAbbrev, "prol.") ){
401
			result = Rank.PROLES();
402
		}else if(CdmUtils.nullSafeEqual(rankAbbrev, "race")){
403
			result = Rank.RACE();
404
		}else if(CdmUtils.nullSafeEqual(rankAbbrev, "sublusus")){
405
			result = Rank.SUBLUSUS();
406
		}else{
407
			result = rank;
408
			logger.warn("Unhandled rank: " + rankAbbrev);
409
		}
410
		return result;
411
	}
412

    
413
	@Override
414
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
415
		String nameSpace;
416
		Class<?> cdmClass;
417
		Set<String> idSet;
418

    
419
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
420

    
421
		try{
422
			Set<String> teamIdSet = new HashSet<String>();
423
			Set<String> referenceIdSet = new HashSet<String>();
424
			Set<String> refDetailIdSet = new HashSet<String>();
425
			while (rs.next()){
426
				handleForeignKey(rs, teamIdSet, "AuthorTeamFk");
427
				handleForeignKey(rs, teamIdSet, "ExAuthorTeamFk");
428
				handleForeignKey(rs, teamIdSet, "BasAuthorTeamFk");
429
				handleForeignKey(rs, teamIdSet, "ExBasAuthorTeamFk");
430
				handleForeignKey(rs, referenceIdSet, "nomRefFk");
431
				handleForeignKey(rs, refDetailIdSet, "nomRefDetailFk");
432
			}
433

    
434
			//team map
435
			nameSpace = BerlinModelAuthorTeamImport.NAMESPACE;
436
			cdmClass = Team.class;
437
			idSet = teamIdSet;
438
			Map<String, Person> teamMap = (Map<String, Person>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
439
			result.put(nameSpace, teamMap);
440

    
441
			//reference map
442
			nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
443
			cdmClass = Reference.class;
444
			idSet = referenceIdSet;
445
			Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
446
			result.put(nameSpace, referenceMap);
447

    
448
			//refDetail map
449
			nameSpace = BerlinModelRefDetailImport.REFDETAIL_NAMESPACE;
450
			cdmClass = Reference.class;
451
			idSet = refDetailIdSet;
452
			Map<String, Reference> refDetailMap= (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
453
			result.put(nameSpace, refDetailMap);
454

    
455
		} catch (SQLException e) {
456
			throw new RuntimeException(e);
457
		}
458
		return result;
459
	}
460

    
461
	private boolean makeZoologialName(ResultSet rs, IZoologicalName zooName, int nameId)
462
					throws SQLException{
463
		boolean success = true;
464
		//publicationYear
465
		String authorTeamYear = rs.getString("authorTeamYear");
466
		try {
467
			if (! "".equals(CdmUtils.Nz(authorTeamYear).trim())){
468
				Integer publicationYear  = Integer.valueOf(authorTeamYear.trim());
469
				zooName.setPublicationYear(publicationYear);
470
			}
471
		} catch (NumberFormatException e) {
472
			logger.warn("authorTeamYear could not be parsed for taxonName: "+ nameId);
473
		}
474
		//original publication year
475
		String basAuthorTeamYear = rs.getString("basAuthorTeamYear");
476
		try {
477
			if (! "".equals(CdmUtils.Nz(basAuthorTeamYear).trim())){
478
				Integer OriginalPublicationYear  = Integer.valueOf(basAuthorTeamYear.trim());
479
				zooName.setOriginalPublicationYear(OriginalPublicationYear);
480
			}
481
		} catch (NumberFormatException e) {
482
			logger.warn("basAuthorTeamYear could not be parsed for taxonName: "+ nameId);
483
		}
484
		return success;
485
	}
486

    
487
	private boolean makeBotanicalNamePart(ResultSet rs, IBotanicalName botanicalName)throws SQLException{
488
		boolean success = true;
489
		String dbAttrName;
490
		String cdmAttrName;
491

    
492
		dbAttrName = "HybridFormulaFlag";
493
		cdmAttrName = "isHybridFormula";
494
		success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
495

    
496
		dbAttrName = "MonomHybFlag";
497
		cdmAttrName = "isMonomHybrid";
498
		success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
499

    
500
		dbAttrName = "BinomHybFlag";
501
		cdmAttrName = "isBinomHybrid";
502
		success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
503

    
504
		dbAttrName = "TrinomHybFlag";
505
		cdmAttrName = "isTrinomHybrid";
506
		success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
507

    
508
		try {
509
			String strCultivarGroupName = rs.getString("CultivarGroupName");
510
			String strCultivarName = rs.getString("CultivarName");
511
			if (botanicalName.isCultivar()){
512
				ICultivarPlantName cultivarName = (ICultivarPlantName)botanicalName;
513
				String concatCultivarName = CdmUtils.concat("-", strCultivarName, strCultivarGroupName);
514
				if (isNotBlank(strCultivarGroupName) && isNotBlank(strCultivarName)){
515
					logger.warn("CDM does not support cultivarGroupName and CultivarName together: " + concatCultivarName);
516
				}
517
				cultivarName.setCultivarName(strCultivarGroupName);
518
			}
519
		} catch (SQLException e) {
520
			throw e;
521
		}
522
		return success;
523
	}
524

    
525

    
526
	private boolean makeNomenclaturalReference(IImportConfigurator config, TaxonName taxonNameBase,
527
					int nameId, ResultSet rs, ResultSetPartitioner partitioner) throws SQLException{
528
		Map<String, Reference> refMap = partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE);
529
		Map<String, Reference> refDetailMap = partitioner.getObjectMap(BerlinModelRefDetailImport.REFDETAIL_NAMESPACE);
530

    
531
		Object nomRefFkObj = rs.getObject("NomRefFk");
532
		Object nomRefDetailFkObj = rs.getObject("NomRefDetailFk");
533
		boolean refDetailPrelim = rs.getBoolean("RefDetailPrelim");
534

    
535
		boolean success = true;
536
		//nomenclatural Reference
537
		if (refMap != null){
538
			if (nomRefFkObj != null){
539
				String nomRefFk = String.valueOf(nomRefFkObj);
540
				String nomRefDetailFk = String.valueOf(nomRefDetailFkObj);
541
				//get nomRef
542
				Reference nomReference =
543
					getReferenceFromMaps(refDetailMap, refMap, nomRefDetailFk, nomRefFk);
544

    
545

    
546
				//setNomRef
547
				if (nomReference == null ){
548
					//TODO
549
					if (! config.isIgnoreNull()){
550
						logger.warn("Nomenclatural reference (nomRefFk = " + nomRefFk + ") for TaxonName (nameId = " + nameId + ")"+
551
							" was not found in reference store. Nomenclatural reference was not set!!");
552
					}
553
				}else{
554
					if (! INomenclaturalReference.class.isAssignableFrom(nomReference.getClass())){
555
						logger.warn("Nomenclatural reference (nomRefFk = " + nomRefFk + ") for TaxonName (nameId = " + nameId + ")"+
556
								" is not assignable from INomenclaturalReference. (Class = " + nomReference.getClass()+ ")");
557
					}
558
					nomReference.setNomenclaturallyRelevant(true);
559
					taxonNameBase.setNomenclaturalReference(nomReference);
560
				}
561
			}
562
		}
563
		return success;
564
	}
565

    
566
	private static TeamOrPersonBase getAuthorTeam(Map<String, Team> teamMap, Object teamIdObject, int nameId, BerlinModelImportConfigurator bmiConfig){
567
		if (teamIdObject == null){
568
			return null;
569
		}else {
570
			String teamId = String.valueOf(teamIdObject);
571
			TeamOrPersonBase author = teamMap.get(teamId);
572
			if (author == null){
573
				//TODO
574
				if (!bmiConfig.isIgnoreNull() && ! (teamId.equals(0) && bmiConfig.isIgnore0AuthorTeam()) ){
575
					logger.warn("AuthorTeam (teamId = " + teamId + ") for TaxonName (nameId = " + nameId + ")"+
576
				" was not found in authorTeam store. Relation was not set!!");}
577
				return null;
578
			}else{
579
				return author;
580
			}
581
		}
582
	}
583

    
584
	@Override
585
	protected boolean doCheck(BerlinModelImportState state){
586
		IOValidator<BerlinModelImportState> validator = new BerlinModelTaxonNameImportValidator();
587
		return validator.validate(state);
588
	}
589

    
590
	@Override
591
    protected boolean isIgnore(BerlinModelImportState state){
592
		return ! state.getConfig().isDoTaxonNames();
593
	}
594

    
595

    
596

    
597

    
598

    
599

    
600
//FOR FUTURE USE , DONT DELETE
601
//	new CdmStringMapper("nameId", "nameId"),
602
//	new CdmStringMapper("rankFk", "rankFk"),
603
//	new CdmStringMapper("nameCache", "nameCache"),
604
//	new CdmStringMapper("unnamedNamePhrase", "unnamedNamePhrase"),
605
//	new CdmStringMapper("fullNameCache", "fullNameCache"),
606
//	new CdmStringMapper("preliminaryFlag", "preliminaryFlag"),
607
//	new CdmStringMapper("supragenericName", "supragenericName"),
608
//	new CdmStringMapper("genus", "genus"),
609
//	new CdmStringMapper("genusSubdivisionEpi", "genusSubdivisionEpi"),
610
//	new CdmStringMapper("speciesEpi", "speciesEpi"),
611
//	new CdmStringMapper("infraSpeciesEpi", "infraSpeciesEpi"),
612
//	new CdmStringMapper("authorTeamFk", "authorTeamFk"),
613
//	new CdmStringMapper("exAuthorTeamFk", "exAuthorTeamFk"),
614
//	new CdmStringMapper("basAuthorTeamFk", "basAuthorTeamFk"),
615
//	new CdmStringMapper("exBasAuthorTeamFk", "exBasAuthorTeamFk"),
616
//	new CdmStringMapper("hybridFormulaFlag", "hybridFormulaFlag"),
617
//	new CdmStringMapper("monomHybFlag", "monomHybFlag"),
618
//	new CdmStringMapper("binomHybFlag", "binomHybFlag"),
619
//	new CdmStringMapper("trinomHybFlag", "trinomHybFlag"),
620
//	new CdmStringMapper("cultivarGroupName", "cultivarGroupName"),
621
//	new CdmStringMapper("cultivarName", "cultivarName"),
622
//	new CdmStringMapper("nomRefFk", "nomRefFk"),
623
//	new CdmStringMapper("nomRefDetailFk", "nomRefDetailFk"),
624
//	new CdmStringMapper("nameSourceRefFk", "nameSourceRefFk"),
625
//	new CdmStringMapper("source_Acc", "source_Acc"),
626
//	new CdmStringMapper("created_When", "created_When"),
627
//	new CdmStringMapper("created_Who", "created_Who"),
628
//	new CdmStringMapper("notes", "notes"),
629
//	new CdmStringMapper("parsingComments", "parsingComments"),
630
//	new CdmStringMapper("oldNomRefFk", "oldNomRefFk"),
631
//	new CdmStringMapper("oldNomRefDetailFk", "oldNomRefDetailFk"),
632
//	new CdmStringMapper("updated_Who", "updated_Who"),
633
//	new CdmStringMapper("orthoProjection", "orthoProjection"),
634

    
635

    
636
}
(15-15/21)