Project

General

Profile

Download (22 KB) Statistics
| Branch: | Tag: | 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.io.IOException;
13
import java.net.URI;
14
import java.net.URISyntaxException;
15
import java.sql.ResultSet;
16
import java.sql.SQLException;
17
import java.util.HashMap;
18
import java.util.HashSet;
19
import java.util.Map;
20
import java.util.Set;
21
import java.util.UUID;
22

    
23
import javax.mail.MethodNotSupportedException;
24

    
25
import org.apache.commons.lang.StringUtils;
26
import org.apache.http.HttpException;
27
import org.apache.log4j.Logger;
28
import org.springframework.stereotype.Component;
29

    
30
import eu.etaxonomy.cdm.common.CdmUtils;
31
import eu.etaxonomy.cdm.common.media.ImageInfo;
32
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
33
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelFactsImportValidator;
34
import eu.etaxonomy.cdm.io.common.IOValidator;
35
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
36
import eu.etaxonomy.cdm.io.common.Source;
37
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
38
import eu.etaxonomy.cdm.model.common.Annotation;
39
import eu.etaxonomy.cdm.model.common.CdmBase;
40
import eu.etaxonomy.cdm.model.common.DescriptionElementSource;
41
import eu.etaxonomy.cdm.model.common.Language;
42
import eu.etaxonomy.cdm.model.common.Marker;
43
import eu.etaxonomy.cdm.model.common.MarkerType;
44
import eu.etaxonomy.cdm.model.common.TermVocabulary;
45
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
46
import eu.etaxonomy.cdm.model.description.Feature;
47
import eu.etaxonomy.cdm.model.description.TaxonDescription;
48
import eu.etaxonomy.cdm.model.description.TextData;
49
import eu.etaxonomy.cdm.model.media.ImageFile;
50
import eu.etaxonomy.cdm.model.media.Media;
51
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
52
import eu.etaxonomy.cdm.model.reference.Reference;
53
import eu.etaxonomy.cdm.model.taxon.Taxon;
54
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
55
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
56

    
57
/**
58
 * @author a.mueller
59
 * @created 20.03.2008
60
 * @version 1.0
61
 */
62
@Component
63
public class BerlinModelFactsImport  extends BerlinModelImportBase {
64
	private static final Logger logger = Logger.getLogger(BerlinModelFactsImport.class);
65

    
66
	public static final String NAMESPACE = "Fact";
67
	
68
	public static final String SEQUENCE_PREFIX = "ORDER: ";
69
	
70
	private int modCount = 10000;
71
	private static final String pluralString = "facts";
72
	private static final String dbTableName = "Fact";
73

    
74
	//FIXME don't use as class variable
75
	private Map<Integer, Feature> featureMap;
76
	
77
	public BerlinModelFactsImport(){
78
		super();
79
	}
80

    
81

    
82
	private TermVocabulary<Feature> getFeatureVocabulary(){
83
		try {
84
			//TODO work around until service method works
85
			TermVocabulary<Feature> featureVocabulary =  BerlinModelTransformer.factCategory2Feature(1).getVocabulary();
86
			//TermVocabulary<Feature> vocabulary = getTermService().getVocabulary(vocabularyUuid);
87
			return featureVocabulary;
88
		} catch (UnknownCdmTypeException e) {
89
			logger.error("Feature vocabulary not available. New vocabulary created");
90
			return TermVocabulary.NewInstance("User Defined Feature Vocabulary", "User Defined Feature Vocabulary", null, null); 
91
		}
92
	}
93
	
94
	private Map<Integer, Feature>  invokeFactCategories(BerlinModelImportState state){
95
		
96
		Map<Integer, Feature>  result = state.getConfig().getFeatureMap();
97
		Source source = state.getConfig().getSource();
98
		
99
		try {
100
			//get data from database
101
			String strQuery = 
102
					" SELECT FactCategory.* " + 
103
					" FROM FactCategory "+
104
                    " WHERE (1=1)";
105
			ResultSet rs = source.getResultSet(strQuery) ;
106

    
107
			
108
			TermVocabulary<Feature> featureVocabulary = getFeatureVocabulary();
109
			int i = 0;
110
			//for each reference
111
			while (rs.next()){
112
				
113
				if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("FactCategories handled: " + (i-1));}
114
				
115
				int factCategoryId = rs.getInt("factCategoryId");
116
				String factCategory = rs.getString("factCategory");
117
				
118
				Feature feature;
119
				try {
120
					feature = BerlinModelTransformer.factCategory2Feature(factCategoryId);
121
				} catch (UnknownCdmTypeException e) {
122
					UUID featureUuid = null;
123
					featureUuid = BerlinModelTransformer.getFeatureUuid(String.valueOf(factCategoryId+"-"+factCategory));
124
					if (featureUuid == null){
125
						logger.warn("New Feature (FactCategoryId: " + factCategoryId + ")");
126
						featureUuid = UUID.randomUUID();
127
					}
128
					feature = getFeature(state, featureUuid, factCategory, factCategory, null, featureVocabulary);
129

    
130
					//TODO
131
//					MaxFactNumber	int	Checked
132
//					ExtensionTableName	varchar(100)	Checked
133
//					Description	nvarchar(1000)	Checked
134
//					locExtensionFormName	nvarchar(80)	Checked
135
//					RankRestrictionFk	int	Checked
136
				}
137
								
138
				result.put(factCategoryId, feature);
139
			}
140
			return result;
141
		} catch (SQLException e) {
142
			logger.error("SQLException:" +  e);
143
			return null;
144
		} catch (UndefinedTransformerMethodException e1) {
145
			logger.error("UndefinedTransformerMethodException:" +  e1);
146
			e1.printStackTrace();
147
			return null;
148
		}
149

    
150
	}
151

    
152
	/* (non-Javadoc)
153
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#doInvoke(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState)
154
	 */
155
	@Override
156
	protected void doInvoke(BerlinModelImportState state) {
157
		featureMap = invokeFactCategories(state);
158
		super.doInvoke(state);
159
		return;
160
	}
161
		
162
	
163

    
164
	/* (non-Javadoc)
165
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getIdQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState)
166
	 */
167
	@Override
168
	protected String getIdQuery(BerlinModelImportState state) {
169
		String result = super.getIdQuery(state);
170
		if (StringUtils.isNotBlank(state.getConfig().getFactFilter())){
171
			result += " WHERE " + state.getConfig().getFactFilter();
172
		}else{
173
			result = super.getIdQuery(state);
174
		}
175
		result += getOrderBy(state.getConfig());
176
		return result;
177
	}
178

    
179
	
180

    
181
	/* (non-Javadoc)
182
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getRecordQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator)
183
	 */
184
	@Override
185
	protected String getRecordQuery(BerlinModelImportConfigurator config) {
186
			String strQuery = 
187
					" SELECT Fact.*, PTaxon.RIdentifier as taxonId, RefDetail.Details " + 
188
					" FROM Fact " +
189
                      	" INNER JOIN PTaxon ON Fact.PTNameFk = PTaxon.PTNameFk AND Fact.PTRefFk = PTaxon.PTRefFk " +
190
                      	" LEFT OUTER JOIN RefDetail ON Fact.FactRefDetailFk = RefDetail.RefDetailId AND Fact.FactRefFk = RefDetail.RefFk " +
191
              	" WHERE (FactId IN (" + ID_LIST_TOKEN + "))";
192
			    strQuery += getOrderBy(config);
193
				
194
		return strQuery;
195
	}
196

    
197

    
198
	private String getOrderBy(BerlinModelImportConfigurator config) {
199
		String result;
200
		try{
201
			if (config.getSource().checkColumnExists("Fact", "Sequence")){
202
				result = " ORDER By Fact.Sequence, Fact.FactId";
203
			}else{
204
				result = " ORDER By Fact.FactId";
205
			}
206
		} catch (MethodNotSupportedException e) {
207
			logger.info("checkColumnExists not supported");
208
			result = " ORDER By Fact.FactId";
209
		}
210
		return result;
211
	}
212
	
213

    
214
	/* (non-Javadoc)
215
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#doPartition(eu.etaxonomy.cdm.io.berlinModel.in.ResultSetPartitioner, eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState)
216
	 */
217
	public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) {
218
		boolean success = true ;
219
		BerlinModelImportConfigurator config = state.getConfig();
220
		Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>();
221
		Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>) partitioner.getObjectMap(BerlinModelTaxonImport.NAMESPACE);
222
		Map<String, Reference> biblioRefMap = (Map<String, Reference>) partitioner.getObjectMap(BerlinModelReferenceImport.BIBLIO_REFERENCE_NAMESPACE);
223
		Map<String, Reference> nomRefMap = (Map<String, Reference>) partitioner.getObjectMap(BerlinModelReferenceImport.NOM_REFERENCE_NAMESPACE);
224

    
225
		ResultSet rs = partitioner.getResultSet();
226
		
227
		Reference<?> sourceRef = state.getTransactionalSourceReference();
228
			
229
		try{
230
			int i = 0;
231
			//for each fact
232
			while (rs.next()){
233
				try{
234
					if ((i++ % modCount) == 0){ logger.info("Facts handled: " + (i-1));}
235
					
236
					int factId = rs.getInt("factId");
237
					Object taxonIdObj = rs.getObject("taxonId");
238
					long taxonId = rs.getLong("taxonId");
239
					Object factRefFkObj = rs.getObject("factRefFk");
240
					Object categoryFkObj = rs.getObject("factCategoryFk");
241
					Integer categoryFk = rs.getInt("factCategoryFk");
242
					String details = rs.getString("Details");
243
					String fact = CdmUtils.Nz(rs.getString("Fact"));
244
					String notes = CdmUtils.Nz(rs.getString("notes"));
245
					Boolean doubtfulFlag = rs.getBoolean("DoubtfulFlag");
246
					
247
					TaxonBase<?> taxonBase = getTaxon(taxonMap, taxonIdObj, taxonId);
248
					Feature feature = getFeature(featureMap, categoryFkObj, categoryFk) ;
249
					
250
					if (taxonBase == null){
251
						logger.warn("Taxon for Fact " + factId + " does not exist in store");
252
						success = false;
253
					}else{
254
						TaxonDescription taxonDescription;
255
						if ( (taxonDescription = getMyTaxonDescripion(taxonBase, state, categoryFk, taxonIdObj, taxonId, factId, fact, sourceRef)) == null){
256
							success = false;
257
							continue;
258
						}
259
					
260
						//textData
261
						TextData textData = null;
262
						boolean newTextData = true;
263
	
264
						// For Cichorieae DB: If fact category is 31 (Systematics) and there is already a Systematics TextData 
265
						// description element append the fact text to the existing TextData
266
						if(categoryFk == 31) {
267
							Set<DescriptionElementBase> descriptionElements = taxonDescription.getElements();
268
							for (DescriptionElementBase descriptionElement : descriptionElements) {
269
								String featureString = descriptionElement.getFeature().getRepresentation(Language.DEFAULT()).getLabel();
270
								if (descriptionElement instanceof TextData && featureString.equals("Systematics")) { // TODO: test
271
									textData = (TextData)descriptionElement;
272
									String factTextStr = textData.getText(Language.DEFAULT());
273
									// FIXME: Removing newlines doesn't work
274
									if (factTextStr.contains("\\r\\n")) {
275
										factTextStr = factTextStr.replaceAll("\\r\\n","");
276
									}
277
									StringBuilder factText = new StringBuilder(factTextStr);
278
									factText.append(fact);
279
									fact = factText.toString();
280
									newTextData = false;
281
									break;
282
								}
283
							}
284
						}
285
						
286
						if(newTextData == true)	{ 
287
							textData = TextData.NewInstance(); 
288
						}
289
						
290
						//for diptera database
291
						if (categoryFk == 99 && notes.contains("<OriginalName>")){
292
//							notes = notes.replaceAll("<OriginalName>", "");
293
//							notes = notes.replaceAll("</OriginalName>", "");
294
							fact = notes + ": " +  fact ;
295
						}
296
						//for E+M maps
297
						if (categoryFk == 14 && state.getConfig().isRemoveHttpMapsAnchor() && fact.contains("<a href")){
298
							//example <a href="http://euromed.luomus.fi/euromed_map.php?taxon=280629&size=medium">distribution</a>
299
							fact = fact.replace("<a href=\"", "").replace("\">distribution</a>", "");
300
						}
301
						
302
						//TODO textData.putText(fact, bmiConfig.getFactLanguage());  //doesn't work because  bmiConfig.getFactLanguage() is not not a persistent Language Object
303
						//throws  in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: eu.etaxonomy.cdm.model.common.Language; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: eu.etaxonomy.cdm.model.common.Language
304
						if (! taxonDescription.isImageGallery()){
305
							textData.putText(Language.DEFAULT(), fact);
306
							textData.setFeature(feature);
307
						}
308
						
309
						//reference
310
						Reference citation = null;
311
						String factRefFk = String.valueOf(factRefFkObj);
312
						if (factRefFkObj != null){
313
							citation = getReferenceOnlyFromMaps(biblioRefMap, nomRefMap, factRefFk);	
314
							}
315
						if (citation == null && (factRefFkObj != null)){
316
								logger.warn("Citation not found in referenceMap: " + factRefFk);
317
							success = false;
318
							}
319
						if (citation != null || CdmUtils.isNotEmpty(details)){
320
							DescriptionElementSource originalSource = DescriptionElementSource.NewInstance();
321
							originalSource.setCitation(citation);
322
							originalSource.setCitationMicroReference(details);
323
							textData.addSource(originalSource);
324
						}
325
						taxonDescription.addElement(textData);
326
						//doubtfulFlag
327
						if (doubtfulFlag){
328
							textData.addMarker(Marker.NewInstance(MarkerType.IS_DOUBTFUL(), true));
329
						}
330
						//publisheFlag
331
						String strPublishFlag = "publishFlag";
332
						boolean publishFlagExists = state.getConfig().getSource().checkColumnExists(dbTableName, strPublishFlag);
333
						if (publishFlagExists){
334
							Boolean publishFlag = rs.getBoolean(strPublishFlag);
335
							textData.addMarker(Marker.NewInstance(MarkerType.PUBLISH(), publishFlag));
336
						}
337
						
338
						//Sequence
339
						Integer sequence = rs.getInt("Sequence");
340
						if (sequence != null && sequence != 999){
341
							String strSequence = String.valueOf(sequence);
342
							strSequence = SEQUENCE_PREFIX + strSequence;
343
							//TODO make it an Extension when possible
344
							//Extension datesExtension = Extension.NewInstance(textData, strSequence, ExtensionType.ORDER());
345
							Annotation annotation = Annotation.NewInstance(strSequence, Language.DEFAULT());
346
							textData.addAnnotation(annotation);
347
						}
348
						
349
						//						if (categoryFkObj == FACT_DESCRIPTION){
350
	//						//;
351
	//					}else if (categoryFkObj == FACT_OBSERVATION){
352
	//						//;
353
	//					}else if (categoryFkObj == FACT_DISTRIBUTION_EM){
354
	//						//
355
	//					}else {
356
	//						//TODO
357
	//						//logger.warn("FactCategory " + categoryFk + " not yet implemented");
358
	//					}
359
						
360
						//notes
361
						doCreatedUpdatedNotes(state, textData, rs);
362
						
363
						//TODO
364
						//Designation References -> unclear how to map to CDM
365
						//factId -> OriginalSource for descriptionElements not yet implemented
366
						
367
						//sequence -> textData is not an identifiable entity therefore extensions are not possible
368
						//fact category better
369
						
370
						taxaToSave.add(taxonBase);
371
					}
372
				} catch (Exception re){
373
					logger.error("An exception occurred during the facts import");
374
					re.printStackTrace();
375
					success = false;
376
				}
377
				//put
378
			}
379
			logger.info("Facts handled: " + (i-1));
380
			logger.info("Taxa to save: " + taxaToSave.size());
381
			getTaxonService().save(taxaToSave);	
382
		}catch(SQLException e){
383
			throw new RuntimeException(e);
384
		}
385
		return success;
386
	}
387

    
388
	private TaxonDescription getMyTaxonDescripion(TaxonBase taxonBase, BerlinModelImportState state, Integer categoryFk, Object taxonIdObj, long taxonId, int factId, String fact, Reference<?> sourceRef) {
389
		Taxon taxon = null;
390
		if ( taxonBase instanceof Taxon ) {
391
			taxon = (Taxon) taxonBase;
392
		}else{
393
			logger.warn("TaxonBase " + (taxonIdObj==null?"(null)":taxonIdObj) + " for Fact " + factId + " was not of type Taxon but: " + taxonBase.getClass().getSimpleName());
394
			return null;
395
		}
396
		
397
		TaxonDescription taxonDescription = null;
398
		Set<TaxonDescription> descriptionSet= taxon.getDescriptions();
399
		
400
		boolean isImage = false;
401
		Media media = null;
402
		//for diptera images
403
		if (categoryFk == 51){  //TODO check also FactCategory string
404
			isImage = true;
405
			media = Media.NewInstance();
406
			taxonDescription = makeImage(state, fact, media, descriptionSet, taxon);
407
			
408
			
409
			
410
			if (taxonDescription == null){
411
				return null;
412
			}
413
			
414
			TextData textData = null;
415
			for (DescriptionElementBase el:  taxonDescription.getElements()){
416
				if (el.isInstanceOf(TextData.class)){
417
					textData = CdmBase.deproxy(el, TextData.class);
418
				}
419
			}
420
			if (textData == null){
421
				textData = TextData.NewInstance(Feature.IMAGE());
422
				taxonDescription.addElement(textData);
423
			}
424
			textData.addMedia(media);
425
		}
426
		//all others (no image) -> getDescription
427
		else{ 
428
			for (TaxonDescription desc: descriptionSet){
429
				if (! desc.isImageGallery()){
430
					taxonDescription = desc;
431
				}
432
			}
433
			if (taxonDescription == null){
434
				taxonDescription = TaxonDescription.NewInstance();
435
				taxonDescription.setTitleCache(sourceRef == null ? null : sourceRef.getTitleCache(), true);
436
				taxon.addDescription(taxonDescription);
437
			}
438
		}
439
		return taxonDescription;
440
	}
441

    
442

    
443
	/* (non-Javadoc)
444
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet)
445
	 */
446
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs) {
447
		String nameSpace;
448
		Class cdmClass;
449
		Set<String> idSet;
450
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
451
			
452
		try{
453
			Set<String> taxonIdSet = new HashSet<String>();
454
			Set<String> referenceIdSet = new HashSet<String>();
455
			Set<String> refDetailIdSet = new HashSet<String>();
456
			while (rs.next()){
457
				handleForeignKey(rs, taxonIdSet, "taxonId");
458
				handleForeignKey(rs, referenceIdSet, "FactRefFk");
459
				handleForeignKey(rs, referenceIdSet, "PTDesignationRefFk");
460
				handleForeignKey(rs, refDetailIdSet, "FactRefDetailFk");
461
				handleForeignKey(rs, refDetailIdSet, "PTDesignationRefDetailFk");
462
		}
463
			
464
			//taxon map
465
			nameSpace = BerlinModelTaxonImport.NAMESPACE;
466
			cdmClass = TaxonBase.class;
467
			idSet = taxonIdSet;
468
			Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
469
			result.put(nameSpace, taxonMap);
470

    
471

    
472
			//nom reference map
473
			nameSpace = BerlinModelReferenceImport.NOM_REFERENCE_NAMESPACE;
474
			cdmClass = Reference.class;
475
			idSet = referenceIdSet;
476
			Map<String, Reference> nomReferenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
477
			result.put(nameSpace, nomReferenceMap);
478

    
479
			//biblio reference map
480
			nameSpace = BerlinModelReferenceImport.BIBLIO_REFERENCE_NAMESPACE;
481
			cdmClass = Reference.class;
482
			idSet = referenceIdSet;
483
			Map<String, Reference> biblioReferenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
484
			result.put(nameSpace, biblioReferenceMap);
485
			
486
			//nom refDetail map
487
			nameSpace = BerlinModelRefDetailImport.NOM_REFDETAIL_NAMESPACE;
488
			cdmClass = Reference.class;
489
			idSet = refDetailIdSet;
490
			Map<String, Reference> nomRefDetailMap= (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
491
			result.put(nameSpace, nomRefDetailMap);
492
			
493
			//biblio refDetail map
494
			nameSpace = BerlinModelRefDetailImport.BIBLIO_REFDETAIL_NAMESPACE;
495
			cdmClass = Reference.class;
496
			idSet = refDetailIdSet;
497
			Map<String, Reference> biblioRefDetailMap= (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
498
			result.put(nameSpace, biblioRefDetailMap);
499
	
500
		} catch (SQLException e) {
501
			throw new RuntimeException(e);
502
	}
503
		return result;
504
	}
505
	
506
	
507
	/**
508
	 * @param state 
509
	 * @param media 
510
	 * @param media 
511
	 * @param descriptionSet 
512
	 * 
513
	 */
514
	private TaxonDescription makeImage(BerlinModelImportState state, String fact, Media media, Set<TaxonDescription> descriptionSet, Taxon taxon) {
515
		TaxonDescription taxonDescription = null;
516
		Reference sourceRef = state.getTransactionalSourceReference();
517
		Integer size = null; 
518
		ImageInfo imageInfo = null;
519
		URI uri;
520
		try {
521
			uri = new URI(fact.trim());
522
		} catch (URISyntaxException e) {
523
			logger.warn("URISyntaxException. Image could not be imported: " + fact);
524
			return null;
525
		}
526
		try {
527
			imageInfo = ImageInfo.NewInstance(uri, 0);
528
		} catch (IOException e) {
529
			logger.error("IOError reading image metadata." , e);
530
		} catch (HttpException e) {
531
			logger.error("HttpException reading image metadata." , e);
532
		}
533
		MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance(imageInfo.getMimeType(), null);
534
		media.addRepresentation(mediaRepresentation);
535
		ImageFile image = ImageFile.NewInstance(uri, size, imageInfo);
536
		mediaRepresentation.addRepresentationPart(image);
537
		
538
		taxonDescription = taxon.getOrCreateImageGallery(sourceRef == null ? null :sourceRef.getTitleCache());
539
		
540
		return taxonDescription;
541
	}
542

    
543
	private TaxonBase getTaxon(Map<String, TaxonBase> taxonMap, Object taxonIdObj, Long taxonId){
544
		if (taxonIdObj != null){
545
			return taxonMap.get(String.valueOf(taxonId));
546
		}else{
547
			return null;
548
		}
549
		
550
	}
551
	
552
	private Feature getFeature(Map<Integer, Feature>  featureMap, Object categoryFkObj, Integer categoryFk){
553
		if (categoryFkObj != null){
554
			return featureMap.get(categoryFk); 
555
		}else{
556
			return null;
557
		}
558
		
559
	}
560
	
561

    
562
	/* (non-Javadoc)
563
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
564
	 */
565
	@Override
566
	protected boolean doCheck(BerlinModelImportState state){
567
		IOValidator<BerlinModelImportState> validator = new BerlinModelFactsImportValidator();
568
		return validator.validate(state);
569
	}
570
				
571
	/* (non-Javadoc)
572
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getTableName()
573
	 */
574
	@Override
575
	protected String getTableName() {
576
		return dbTableName;
577
			}
578
	
579
	/* (non-Javadoc)
580
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getPluralString()
581
	 */
582
	@Override
583
	public String getPluralString() {
584
		return pluralString;
585
		}
586
	
587
	/* (non-Javadoc)
588
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
589
	 */
590
	protected boolean isIgnore(BerlinModelImportState state){
591
		return ! state.getConfig().isDoFacts();
592
	}
593

    
594

    
595

    
596
}
(4-4/21)