Project

General

Profile

Download (22.2 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.algaterra;
11

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

    
20
import org.apache.commons.lang.StringUtils;
21
import org.apache.log4j.Logger;
22
import org.joda.time.DateTime;
23
import org.springframework.stereotype.Component;
24

    
25
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
26
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
27
import eu.etaxonomy.cdm.io.algaterra.validation.AlgaTerraTypeImportValidator;
28
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase;
29
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
30
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
31
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelRefDetailImport;
32
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelReferenceImport;
33
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelTaxonNameImport;
34
import eu.etaxonomy.cdm.io.common.IOValidator;
35
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
36
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
37
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
38
import eu.etaxonomy.cdm.model.common.Annotation;
39
import eu.etaxonomy.cdm.model.common.AnnotationType;
40
import eu.etaxonomy.cdm.model.common.CdmBase;
41
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
42
import eu.etaxonomy.cdm.model.common.Language;
43
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
44
import eu.etaxonomy.cdm.model.common.User;
45
import eu.etaxonomy.cdm.model.name.BotanicalName;
46
import eu.etaxonomy.cdm.model.name.Rank;
47
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
48
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
49
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
50
import eu.etaxonomy.cdm.model.occurrence.Collection;
51
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
52
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
53
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
54
import eu.etaxonomy.cdm.model.reference.Reference;
55

    
56
/**
57
 * @author a.mueller
58
 * @created 20.03.2008
59
 */
60
@Component
61
public class AlgaTerraTypeImport  extends AlgaTerraSpecimenImportBase {
62
	private static final Logger logger = Logger.getLogger(AlgaTerraTypeImport.class);
63

    
64
	
65
	private static int modCount = 5000;
66
	private static final String pluralString = "types";
67
	private static final String dbTableName = "TypeDesignation";  //??  
68

    
69
	protected String getLocalityString(){
70
		return "TypeLocality";
71
	}
72
	
73
	public AlgaTerraTypeImport(){
74
		super(dbTableName, pluralString);
75
	}
76
	
77
	
78
	@Override
79
	protected String getIdQuery(BerlinModelImportState state) {
80
		String result = " SELECT TypeDesignationId "  
81
				+ " FROM TypeDesignation " 
82
				+ " ORDER BY NameFk ";
83
		return result;
84
	}
85

    
86
	@Override
87
	protected String getRecordQuery(BerlinModelImportConfigurator config) {
88
			String strQuery =    
89
					
90
			" SELECT ts.*, ts.TypeSpecimenId as unitId, td.*, gz.ID as GazetteerId, gz.L2Code, gz.L3Code, gz.L4Code, gz.ISOCountry, gz.Country, ts.WaterBody, " + 
91
               " ts.RefFk as tsRefFk, ts.RefDetailFk as tsRefDetailFk, td.RefFk as tdRefFk, td.RefDetailFk as tdRefDetailFk, " +
92
               " RefDet.Details as tdRefDetails, " +
93
               " td.created_When tdCreated_When, tsd.created_When tsdCreated_When, td.updated_when tdUpdated_when" +
94
               " td.created_who tdCreated_who, tsd.created_who tdCreated_who, td.updated_who tdUpdated_who,  " +
95
            " FROM TypeSpecimenDesignation tsd  " 
96
            	+ " LEFT OUTER JOIN TypeSpecimen AS ts ON tsd.TypeSpecimenFk = ts.TypeSpecimenId " 
97
            	+ " FULL OUTER JOIN TypeDesignation td ON  td.TypeDesignationId = tsd.TypeDesignationFk "
98
            	+ " LEFT OUTER JOIN TDWGGazetteer gz ON ts.TDWGGazetteerFk = gz.ID "
99
            	+ " LEFT OUTER JOIN RefDetail refDet ON td.RefDetailFk = refDet.RefDetailId AND td.RefFk = refDet.RefFk "
100
		+ 	" WHERE (td.TypeDesignationId IN (" + ID_LIST_TOKEN + ")  )"  
101
          + " ORDER BY NameFk "
102
            ;
103
		return strQuery;
104
	}
105

    
106
	@Override
107
	public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState bmState) {
108
		boolean success = true;
109
		
110
		AlgaTerraImportState state = (AlgaTerraImportState)bmState;
111
		
112
		//TODO check that no duplicate vocabularies will be created, also remove redundant code here
113
//		and in Specimen importer
114
		try {
115
			makeVocabulariesAndFeatures(state);
116
		} catch (SQLException e1) {
117
			logger.warn("Exception occurred when trying to create Type specimen vocabularies: " + e1.getMessage());
118
			e1.printStackTrace();
119
		}
120
		
121
		
122
		
123
		Set<TaxonNameBase> namesToSave = new HashSet<TaxonNameBase>();
124
		
125
		Map<String, TaxonNameBase> taxonNameMap = (Map<String, TaxonNameBase>) partitioner.getObjectMap(BerlinModelTaxonNameImport.NAMESPACE);
126
		Map<String, DerivedUnit> ecoFactMap = (Map<String, DerivedUnit>) partitioner.getObjectMap(AlgaTerraEcoFactImport.ECO_FACT_FIELD_OBSERVATION_NAMESPACE);
127
		Map<String, DerivedUnit> typeSpecimenMap = (Map<String, DerivedUnit>) partitioner.getObjectMap(TYPE_SPECIMEN_FIELD_OBSERVATION_NAMESPACE);
128
		Map<String, Reference> refMap = (Map<String, Reference>) partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE);
129
		Map<String, Reference> refDetailMap = partitioner.getObjectMap(BerlinModelRefDetailImport.REFDETAIL_NAMESPACE);
130
		
131
		
132
		ResultSet rs = partitioner.getResultSet();
133

    
134
		try {
135
			
136
			int i = 0;
137

    
138
			//for each reference
139
            while (rs.next()){
140
                
141
        		if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("Type designations handled: " + (i-1));}
142
				
143
				int nameId = rs.getInt("nameFk");
144
				int typeSpecimenId = rs.getInt("TypeSpecimenId");
145
				int typeDesignationId = rs.getInt("TypeDesignationId");
146
				Integer typeStatusFk =  nullSafeInt(rs, "typeStatusFk");
147
				Integer ecoFactId = nullSafeInt(rs, "ecoFactFk");
148
				Integer tdRefFk = nullSafeInt(rs, "tdRefFk");
149
				Integer tdRefDetailFk = nullSafeInt(rs, "tdRefDetailFk");
150
				String tdRefDetails = rs.getString("tdRefDetails");
151
				Boolean restrictedFlag = nullSafeBoolean(rs, "RestrictedFlag");
152
				
153
				String typeSpecimenPhrase = rs.getString("TypeSpecimnePhrase");
154
				
155
				
156
				
157
				boolean isIcon = typeSpecimenPhrase.toLowerCase().startsWith("[icon");
158
				
159
				try {
160
					
161
					//source ref
162
					Reference<?> sourceRef = state.getTransactionalSourceReference();
163
				
164
					//facade
165
					SpecimenOrObservationType type = SpecimenOrObservationType.PreservedSpecimen;
166
					if (isIcon){
167
						//TODO handle images correctly for these specimen
168
						type = SpecimenOrObservationType.StillImage;
169
					}else if (typeStatusFk.equals(39)){
170
						type =  SpecimenOrObservationType.LivingSpecimen;
171
					}
172
					
173
					DerivedUnitFacade facade = getDerivedUnit(state, typeSpecimenId, typeSpecimenMap, type, ecoFactMap, ecoFactId, sourceRef);
174
					
175
					//field observation
176
					handleFieldObservationSpecimen(rs, facade, state, partitioner);
177
					
178
					//TODO divide like in EcoFact (if necessary)
179
					handleTypeSpecimenSpecificSpecimen(rs,facade, state, refMap, typeSpecimenId);
180
					
181
					handleFirstDerivedSpecimen(rs, facade, state, partitioner);
182
					
183
					
184
					//Designation
185
					TaxonNameBase<?,?> name = getTaxonName(state, taxonNameMap, nameId);
186
					SpecimenTypeDesignation designation = SpecimenTypeDesignation.NewInstance();
187
					SpecimenTypeDesignationStatus status = getSpecimenTypeDesignationStatusByKey(typeStatusFk);
188
					if (typeStatusFk.equals(39)){
189
						designation.addAnnotation(Annotation.NewInstance("Type status: Authentic strain", AnnotationType.EDITORIAL(), Language.DEFAULT()));
190
					}
191
					
192
					designation.setTypeSpecimen(facade.innerDerivedUnit());
193
					designation.setTypeStatus(status);
194
					if (tdRefFk != null){
195
						Reference<?> typeDesigRef = getReferenceFromMaps(refDetailMap, refMap, String.valueOf(tdRefDetailFk), String.valueOf(tdRefFk));
196
						if (typeDesigRef == null){
197
							logger.warn("Type designation reference not found in maps: " + tdRefFk);
198
						}else{
199
							designation.setCitation(typeDesigRef);
200
						}
201
					}
202
					if (isNotBlank(tdRefDetails)){
203
						designation.setCitationMicroReference(tdRefDetails);
204
					}
205
					
206
					//ID: Type designations do not allow OriginalSources
207
					designation.addAnnotation(Annotation.NewInstance("Id in BerlinModel-TypeDesignation: " + String.valueOf(typeDesignationId), AnnotationType.TECHNICAL(), Language.UNDETERMINED()));
208
					
209
					if (restrictedFlag != null &&restrictedFlag.equals(true)){
210
						logger.warn("Restricted Flag is expected to be null or 0. TypeDesignationId" + typeDesignationId);
211
					}
212
					
213
					//Created, Updated
214
					this.doCreatedUpdated(state, designation, rs);
215
					
216
					if (name != null){
217
						name.addTypeDesignation(designation, true); //TODO check if true is correct
218
					}else{
219
						logger.warn("Name could not be found for type designation " + typeDesignationId);
220
					}
221
					namesToSave.add(name); 
222
					
223

    
224
				} catch (Exception e) {
225
					logger.warn("Exception in TypeDesignation: TypeDesignationId " + typeDesignationId + ". " + e.getMessage());
226
					e.printStackTrace();
227
				} 
228
                
229
            }
230
           
231
//            logger.warn("Specimen: " + countSpecimen + ", Descriptions: " + countDescriptions );
232

    
233
			logger.warn("Names to save: " + namesToSave.size());
234
			getNameService().save(namesToSave);	
235
			
236
			return success;
237
		} catch (SQLException e) {
238
			logger.error("SQLException:" +  e);
239
			return false;
240
		}
241
	}
242
	
243
	/**
244
	 * same as {@link BerlinModelImportBase#doCreatedUpdatedNotes}, but handles multiple similar fields
245
	 * @throws SQLException 
246
	 */
247
	private void doCreatedUpdated(BerlinModelImportState state, AnnotatableEntity annotatableEntity, ResultSet rs) throws SQLException{
248
		BerlinModelImportConfigurator config = state.getConfig();
249
		Object createdWhen = rs.getObject("tsdCreated_When");
250
		Object tdCreatedWhen = rs.getObject("tdCreated_When");
251
		if (tdCreatedWhen != null){
252
			createdWhen = tdCreatedWhen;
253
		}
254
		
255
		String createdWho = rs.getString("tsdCreated_Who");
256
		String tdCreatedWho = rs.getString("tdCreated_Who");
257
		if (tdCreatedWho != null){
258
			createdWho = tdCreatedWho;
259
		}
260
		
261
		Object updatedWhen = rs.getObject("tdUpdated_When");
262
		String updatedWho = rs.getString("tdUpdated_who");
263
		
264
		//Created When, Who, Updated When Who
265
		if (config.getEditor() == null || config.getEditor().equals(EDITOR.NO_EDITORS)){
266
			//do nothing
267
		}else if (config.getEditor().equals(EDITOR.EDITOR_AS_ANNOTATION)){
268
			String createdAnnotationString = "Berlin Model record was created By: " + String.valueOf(createdWho) + " (" + String.valueOf(createdWhen) + ") ";
269
			if (updatedWhen != null && updatedWho != null){
270
				createdAnnotationString += " and updated By: " + String.valueOf(updatedWho) + " (" + String.valueOf(updatedWhen) + ")";
271
			}
272
			Annotation annotation = Annotation.NewInstance(createdAnnotationString, Language.DEFAULT());
273
			annotation.setCommentator(config.getCommentator());
274
			annotation.setAnnotationType(AnnotationType.TECHNICAL());
275
			annotatableEntity.addAnnotation(annotation);
276
		}else if (config.getEditor().equals(EDITOR.EDITOR_AS_EDITOR)){
277
			User creator = getUser(state, createdWho);
278
			User updator = getUser(state, updatedWho);
279
			DateTime created = getDateTime(createdWhen);
280
			DateTime updated = getDateTime(updatedWhen);
281
			annotatableEntity.setCreatedBy(creator);
282
			annotatableEntity.setUpdatedBy(updator);
283
			annotatableEntity.setCreated(created);
284
			annotatableEntity.setUpdated(updated);
285
		}else {
286
			logger.warn("Editor type not yet implemented: " + config.getEditor());
287
		}
288
	}
289
	
290

    
291
	private DateTime getDateTime(Object timeString){
292
		if (timeString == null){
293
			return null;
294
		}
295
		DateTime dateTime = null;
296
		if (timeString instanceof Timestamp){
297
			Timestamp timestamp = (Timestamp)timeString;
298
			dateTime = new DateTime(timestamp);
299
		}else{
300
			logger.warn("time ("+timeString+") is not a timestamp. Datetime set to current date. ");
301
			dateTime = new DateTime();
302
		}
303
		return dateTime;
304
	}
305
	
306
	
307
	protected String getDerivedUnitNameSpace(){
308
		return TYPE_SPECIMEN_DERIVED_UNIT_NAMESPACE;
309
	}
310
	
311
	protected String getFieldObservationNameSpace(){
312
		return TYPE_SPECIMEN_FIELD_OBSERVATION_NAMESPACE;
313
	}
314

    
315
	/**
316
	 * @param state 
317
	 * @param taxonNameMap
318
	 * @param nameId
319
	 * @return
320
	 */
321
	private TaxonNameBase<?,?> getTaxonName(AlgaTerraImportState state, Map<String, TaxonNameBase> taxonNameMap, int nameId) {
322
		TaxonNameBase<?,?> result;
323
		if (state.getConfig().isDoTaxonNames()){
324
			result = taxonNameMap.get(String.valueOf(nameId));
325
		}else{
326
			//for testing
327
			result = BotanicalName.NewInstance(Rank.SPECIES());
328
		}
329
		return result;
330
	}
331

    
332
	private void handleTypeSpecimenSpecificSpecimen(ResultSet rs, DerivedUnitFacade facade, AlgaTerraImportState state, Map<String, Reference> refMap, int typeSpecimenId) throws SQLException {
333
		
334
		
335
		//TODO
336
		
337
		
338
		
339
		DerivedUnit derivedUnit = facade.innerDerivedUnit();
340
		
341
		//collection
342
		String barcode = rs.getString("Barcode");
343
		if (StringUtils.isNotBlank(barcode)){
344
			facade.setBarcode(barcode);
345
		}
346
		
347
		//RefFk + RefDetailFk
348
		Integer  refFk = nullSafeInt(rs, "tsRefFk");
349
		if (refFk != null){
350
			
351
			Reference<?> ref = refMap.get(String.valueOf(refFk));
352
			if (ref == null){
353
				logger.warn("TypeSpecimen reference (" + refFk + ")not found in biblioRef. TypeSpecimenId: " + typeSpecimenId);
354
			}else{
355
				IdentifiableSource source = IdentifiableSource.NewPrimarySourceInstance(ref, null);
356
				derivedUnit.addSource(source);
357
			}
358
		}
359
		
360
		Integer refDetailFk = nullSafeInt(rs, "tsRefDetailFk");
361
		if (refDetailFk != null){
362
			logger.warn("TypeSpecimen.RefDetailFk should always be NULL but wasn't: " + typeSpecimenId);
363
		}
364
		
365
		
366
		
367
	}
368

    
369
	/**
370
	 * @param state
371
	 * @param ecoFactId
372
	 * @param derivedUnitMap
373
	 * @param type 
374
	 * @param ecoFactId2 
375
	 * @param ecoFactMap 
376
	 * @param sourceRef 
377
	 * @return
378
	 */
379
	private DerivedUnitFacade getDerivedUnit(AlgaTerraImportState state, int typeSpecimenId, Map<String, DerivedUnit> typeSpecimenMap, SpecimenOrObservationType type, Map<String, DerivedUnit> ecoFactMap, Integer ecoFactId2, Reference<?> sourceRef) {
380
		//TODO implement ecoFact map - if not all null anymore
381
		String typeKey = String.valueOf(typeSpecimenId);
382
		DerivedUnit derivedUnit = typeSpecimenMap.get(typeKey);
383
		DerivedUnitFacade facade;
384
		if (derivedUnit == null){
385
			facade = DerivedUnitFacade.NewInstance(type);
386
			typeSpecimenMap.put(typeKey, derivedUnit);
387
		}else{
388
			try {
389
				facade = DerivedUnitFacade.NewInstance(derivedUnit);
390
				facade.addSource(IdentifiableSource.NewDataImportInstance(typeKey, "TypeSpecimen", sourceRef));
391
			} catch (DerivedUnitFacadeNotSupportedException e) {
392
				logger.error(e.getMessage());
393
				facade = DerivedUnitFacade.NewInstance(type);
394
			}
395
		}
396
		
397
		return facade;
398
	}
399
//	private DerivedUnitType makeDerivedUnitType(String recordBasis) {
400
//		DerivedUnitType result = null;
401
//		if (StringUtils.isBlank(recordBasis)){
402
//			result = DerivedUnitType.DerivedUnit;
403
//		} else if (recordBasis.equalsIgnoreCase("FossileSpecimen")){
404
//			result = DerivedUnitType.Fossil;
405
//		}else if (recordBasis.equalsIgnoreCase("HumanObservation")){
406
//			result = DerivedUnitType.Observation;
407
//		}else if (recordBasis.equalsIgnoreCase("Literature")){
408
//			logger.warn("Literature record basis not yet supported");
409
//			result = DerivedUnitType.DerivedUnit;
410
//		}else if (recordBasis.equalsIgnoreCase("LivingSpecimen")){
411
//			result = DerivedUnitType.LivingBeing;
412
//		}else if (recordBasis.equalsIgnoreCase("MachineObservation")){
413
//			logger.warn("MachineObservation record basis not yet supported");
414
//			result = DerivedUnitType.Observation;
415
//		}else if (recordBasis.equalsIgnoreCase("PreservedSpecimen")){
416
//			result = DerivedUnitType.Specimen;
417
//		}
418
//		return result;
419
//	}
420

    
421
	
422
	private SpecimenTypeDesignationStatus getSpecimenTypeDesignationStatusByKey(Integer typeStatusFk) {
423
		if (typeStatusFk == null){ return null;
424
		}else if (typeStatusFk == 1) { return SpecimenTypeDesignationStatus.HOLOTYPE();
425
		}else if (typeStatusFk == 2) { return SpecimenTypeDesignationStatus.LECTOTYPE();
426
		}else if (typeStatusFk == 3) { return SpecimenTypeDesignationStatus.NEOTYPE();
427
		}else if (typeStatusFk == 4) { return SpecimenTypeDesignationStatus.EPITYPE();
428
		}else if (typeStatusFk == 5) { return SpecimenTypeDesignationStatus.ISOLECTOTYPE();
429
		}else if (typeStatusFk == 6) { return SpecimenTypeDesignationStatus.ISONEOTYPE();
430
		}else if (typeStatusFk == 7) { return SpecimenTypeDesignationStatus.ISOTYPE();
431
		}else if (typeStatusFk == 8) { return SpecimenTypeDesignationStatus.PARANEOTYPE();
432
		}else if (typeStatusFk == 9) { return SpecimenTypeDesignationStatus.PARATYPE();
433
		}else if (typeStatusFk == 10) { return SpecimenTypeDesignationStatus.SECOND_STEP_LECTOTYPE();
434
		}else if (typeStatusFk == 11) { return SpecimenTypeDesignationStatus.SECOND_STEP_NEOTYPE();
435
		}else if (typeStatusFk == 12) { return SpecimenTypeDesignationStatus.SYNTYPE();
436
		}else if (typeStatusFk == 13) { return SpecimenTypeDesignationStatus.PARALECTOTYPE();
437
		}else if (typeStatusFk == 14) { return SpecimenTypeDesignationStatus.ISOEPITYPE();
438
		}else if (typeStatusFk == 21) { return SpecimenTypeDesignationStatus.ICONOTYPE();
439
		}else if (typeStatusFk == 22) { return SpecimenTypeDesignationStatus.PHOTOTYPE();
440
		}else if (typeStatusFk == 30) { return SpecimenTypeDesignationStatus.TYPE();
441
		}else if (typeStatusFk == 38) { return SpecimenTypeDesignationStatus.ISOEPITYPE();
442
		}else if (typeStatusFk == 39) { return SpecimenTypeDesignationStatus.ORIGINAL_MATERIAL();
443
		}else if (typeStatusFk == 40) { return SpecimenTypeDesignationStatus.ORIGINAL_MATERIAL();
444
		}else{
445
			logger.warn("typeStatusFk undefined for " +  typeStatusFk);
446
			return SpecimenTypeDesignationStatus.TYPE();
447
		}
448
		
449
	}
450

    
451
	
452
	@Override
453
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
454
		String nameSpace;
455
		Class<?> cdmClass;
456
		Set<String> idSet;
457
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
458
		
459
		try{
460
			Set<String> nameIdSet = new HashSet<String>();
461
			Set<String> ecoFieldObservationIdSet = new HashSet<String>();
462
			Set<String> typeSpecimenIdSet = new HashSet<String>();
463
//			Set<String> termsIdSet = new HashSet<String>();
464
			Set<String> collectionIdSet = new HashSet<String>();
465
			Set<String> referenceIdSet = new HashSet<String>();
466
			Set<String> refDetailIdSet = new HashSet<String>();
467
			
468
			while (rs.next()){
469
				handleForeignKey(rs, nameIdSet, "nameFk");
470
				handleForeignKey(rs, ecoFieldObservationIdSet, "ecoFactFk");
471
				handleForeignKey(rs, typeSpecimenIdSet, "TypeSpecimenId");
472
				handleForeignKey(rs, collectionIdSet, "CollectionFk");
473
				handleForeignKey(rs, referenceIdSet, "tsRefFk");
474
				handleForeignKey(rs, referenceIdSet, "tdRefFk");
475
				handleForeignKey(rs, refDetailIdSet, "tdRefDetailFk");
476
			}
477
			
478
			//name map
479
			nameSpace = BerlinModelTaxonNameImport.NAMESPACE;
480
			cdmClass = TaxonNameBase.class;
481
			idSet = nameIdSet;
482
			Map<String, TaxonNameBase> objectMap = (Map<String, TaxonNameBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
483
			result.put(nameSpace, objectMap);
484

    
485
			//eco fact field observation map
486
			nameSpace = AlgaTerraTypeImport.ECO_FACT_FIELD_OBSERVATION_NAMESPACE;
487
			cdmClass = FieldUnit.class;
488
			idSet = ecoFieldObservationIdSet;
489
			Map<String, FieldUnit> fieldObservationMap = (Map<String, FieldUnit>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
490
			result.put(nameSpace, fieldObservationMap);
491

    
492
			//type specimen map
493
			nameSpace = AlgaTerraTypeImport.TYPE_SPECIMEN_FIELD_OBSERVATION_NAMESPACE;
494
			cdmClass = FieldUnit.class;
495
			idSet = typeSpecimenIdSet;
496
			Map<String, FieldUnit> typeSpecimenMap = (Map<String, FieldUnit>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
497
			result.put(nameSpace, typeSpecimenMap);
498

    
499

    
500
			//collections
501
			nameSpace = AlgaTerraCollectionImport.NAMESPACE_COLLECTION;
502
			cdmClass = Collection.class;
503
			idSet = collectionIdSet;
504
			Map<String, Collection> collectionMap = (Map<String, Collection>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
505
			result.put(nameSpace, collectionMap);
506

    
507
			//sub-collections
508
			nameSpace = AlgaTerraCollectionImport.NAMESPACE_SUBCOLLECTION;
509
			cdmClass = Collection.class;
510
			idSet = collectionIdSet;
511
			Map<String, Collection> subCollectionMap = (Map<String, Collection>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
512
			result.put(nameSpace, subCollectionMap);
513

    
514
			//reference map
515
			nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
516
			cdmClass = Reference.class;
517
			idSet = referenceIdSet;
518
			Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
519
			result.put(nameSpace, referenceMap);
520
			
521
			//refDetail map
522
			nameSpace = BerlinModelRefDetailImport.REFDETAIL_NAMESPACE;
523
			cdmClass = Reference.class;
524
			idSet = refDetailIdSet;
525
			Map<String, Reference> refDetailMap= (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
526
			result.put(nameSpace, refDetailMap);
527
	
528
			
529
			
530
		} catch (SQLException e) {
531
			throw new RuntimeException(e);
532
		}
533
		return result;
534
	}
535

    
536
	/* (non-Javadoc)
537
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
538
	 */
539
	@Override
540
	protected boolean doCheck(BerlinModelImportState state){
541
		IOValidator<BerlinModelImportState> validator = new AlgaTerraTypeImportValidator();
542
		return validator.validate(state);
543
	}
544

    
545

    
546
	/* (non-Javadoc)
547
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
548
	 */
549
	protected boolean isIgnore(BerlinModelImportState state){
550
		return ! state.getConfig().isDoTypes();
551
	}
552
	
553
}
(14-14/15)