Project

General

Profile

« Previous | Next » 

Revision 9c03a941

Added by Andreas Müller about 11 years ago

latest imports for AlgaTerra (DNAFacts)

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/berlinModelImport/AlgaTerraActivator.java
59 59
	static final UUID sourceRefUuid = UUID.fromString("7e1a2500-93a5-40c2-ba34-0213d7822379");
60 60
	
61 61
	static final UUID featureTreeUuid = UUID.fromString("a970168a-36fd-4c7c-931e-87214a965c14");
62
	static final Object[] featureKeyList = new Integer[]{7,201,202,203,204,205,206,207}; 
62
	static final Object[] featureKeyList = new Integer[]{7,201,203,204,206,207}; 
63 63
	static final UUID specimenFeatureTreeUuid = UUID.fromString("ba86246e-d4d0-419f-832e-86d70b1e4bd7");
64 64
	
65 65
	
66
	static final boolean removeRestricted = true;
67
	
66 68
	//check - import
67
	static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
69
	static final CHECK check = CHECK.CHECK_AND_IMPORT;
68 70

  
69 71
	private boolean ignoreNull = true;
70 72
	
......
76 78
	//NomeclaturalCode
77 79
	static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICBN;
78 80
	
79
	static String factFilter = " factCategoryFk NOT IN (7, 202, 1000 ) ";
81
	static String factFilter = " factCategoryFk NOT IN (7, 202, 203, 205, 1000 ) ";
80 82
	
81 83
	
82 84
// ****************** ALL *****************************************
83 85
	
84
//	//authors
85
//	static final boolean doAuthors = true;
86
//	//references
87
//	static final DO_REFERENCES doReferences =  DO_REFERENCES.ALL;
88
//	//names
89
//	static final boolean doTaxonNames = true;
90
//	static final boolean doRelNames = true;
91
//	static final boolean doNameStatus = true;
92
//	static final boolean doTypes = true;  
93
//	
94
//	//taxa
95
//	static final boolean doTaxa = true;
96
//	static final boolean doRelTaxa = true;
97
//	static final boolean doFacts = true;
98
//	
99
//	//alga terra specific
100
//	static final boolean ecoFacts = true;
101
//	static final boolean doFactEcology = true;
102
//	static final boolean doImages = true;
103

  
104
// ************************ NONE **************************************** //
105
	
106 86
	//authors
107
	static final boolean doAuthors = false;
87
	static final boolean doAuthors = true;
108 88
	//references
109 89
	static final DO_REFERENCES doReferences =  DO_REFERENCES.ALL;
110 90
	//names
111
	static final boolean doTaxonNames = false;
112
	static final boolean doRelNames = false;
113
	static final boolean doNameStatus = false;
114
	static final boolean doTypes = false;
115
	static final boolean doNameFacts = false;
91
	static final boolean doTaxonNames = true;
92
	static final boolean doRelNames = true;
93
	static final boolean doNameStatus = true;
94
	static final boolean doTypes = true;  
116 95
	
117 96
	//taxa
118 97
	static final boolean doTaxa = true;
119
	static final boolean doRelTaxa = false;
98
	static final boolean doRelTaxa = true;
120 99
	static final boolean doFacts = true;
121 100
	
122
  //alga terra specific
101
	//alga terra specific
123 102
	static final boolean ecoFacts = true;
124
	static final boolean doFactEcology = false;
103
	static final boolean doFactEcology = true;
125 104
	static final boolean doImages = true;
105
	static final boolean doDna = true;
106

  
107
// ************************ NONE **************************************** //
108
	
109
//	//authors
110
//	static final boolean doAuthors = false;
111
//	//references
112
//	static final DO_REFERENCES doReferences =  DO_REFERENCES.ALL;
113
//	//names
114
//	static final boolean doTaxonNames = false;
115
//	static final boolean doRelNames = false;
116
//	static final boolean doNameStatus = false;
117
//	static final boolean doTypes = false;
118
//	static final boolean doNameFacts = false;
119
//	
120
//	//taxa
121
//	static final boolean doTaxa = true;
122
//	static final boolean doRelTaxa = false;
123
//	static final boolean doFacts = false;
124
//	
125
//  //alga terra specific
126
//	static final boolean ecoFacts = true;
127
//	static final boolean doFactEcology = false;
128
//	static final boolean doImages = false;
129
//	static final boolean doDna = true;
126 130
	
127 131
	
128 132
	public void invoke(String[] args){
......
151 155
		config.setDoEcoFacts(ecoFacts);
152 156
		config.setDoImages(doImages);
153 157
		config.setDoFactEcology(doFactEcology);
158
		config.setDoDna(doDna);
154 159
		
155 160
		config.setSourceRefUuid(sourceRefUuid);
156 161
		config.setIgnoreNull(ignoreNull);
162
		config.setRemoveRestricted(removeRestricted);
157 163
		
158 164
		config.setIncludeFlatClassifications(includeFlatClassifications);
159 165
		config.setIncludeAllNonMisappliedRelatedClassifications(includeAllNonMisappliedRelatedClassifications);
......
209 215
		FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
210 216
		tree.getRoot().addChild(distributionNode, 2);
211 217
		
212
		//needed ??
213
		FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
214
		tree.getRoot().addChild(imageNode);
218
//		//needed ??
219
//		FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
220
//		tree.getRoot().addChild(imageNode);
215 221
		
216 222
		app.getFeatureTreeService().saveOrUpdate(tree);
217 223
	}
app-import/src/main/java/eu/etaxonomy/cdm/io/algaterra/AlgaTerraDnaImport.java
9 9

  
10 10
package eu.etaxonomy.cdm.io.algaterra;
11 11

  
12
import java.net.URI;
12 13
import java.sql.ResultSet;
13 14
import java.sql.SQLException;
15
import java.text.ParseException;
14 16
import java.util.HashMap;
15 17
import java.util.HashSet;
18
import java.util.Locale;
16 19
import java.util.Map;
17 20
import java.util.Set;
18 21

  
19 22
import org.apache.commons.lang.StringUtils;
20 23
import org.apache.log4j.Logger;
24
import org.joda.time.DateTime;
25
import org.joda.time.format.DateTimeFormat;
26
import org.joda.time.format.DateTimeFormatter;
27
import org.springframework.format.datetime.joda.DateTimeParser;
21 28
import org.springframework.stereotype.Component;
22 29

  
23 30
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade.DerivedUnitType;
24 31
import eu.etaxonomy.cdm.io.algaterra.validation.AlgaTerraDnaImportValidator;
25 32
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
26 33
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
34
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelTaxonImport;
27 35
import eu.etaxonomy.cdm.io.common.IOValidator;
28 36
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
37
import eu.etaxonomy.cdm.model.common.Annotation;
38
import eu.etaxonomy.cdm.model.common.AnnotationType;
29 39
import eu.etaxonomy.cdm.model.common.CdmBase;
30
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
40
import eu.etaxonomy.cdm.model.common.Language;
41
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
42
import eu.etaxonomy.cdm.model.description.TaxonDescription;
31 43
import eu.etaxonomy.cdm.model.molecular.DnaSample;
44
import eu.etaxonomy.cdm.model.molecular.GenBankAccession;
32 45
import eu.etaxonomy.cdm.model.molecular.Locus;
33 46
import eu.etaxonomy.cdm.model.molecular.Sequence;
34
import eu.etaxonomy.cdm.model.occurrence.Collection;
47
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
48
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
49
import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
35 50
import eu.etaxonomy.cdm.model.occurrence.FieldObservation;
36 51
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
37 52
import eu.etaxonomy.cdm.model.reference.Reference;
53
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
54
import eu.etaxonomy.cdm.model.taxon.Taxon;
55
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
38 56

  
39 57

  
40 58
/**
......
61 79
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getIdQuery()
62 80
	 */
63 81
	@Override
64
	protected String getIdQuery(BerlinModelImportState state) {
82
	protected String getIdQuery(BerlinModelImportState bmState) {
83
		AlgaTerraImportState state = (AlgaTerraImportState)bmState;
65 84
		String result = " SELECT df.DNAFactId " + 
66
				" FROM DNAFact df INNER JOIN Fact f ON  f.ExtensionFk = df.DNAFactID " +
67
				" ORDER BY df.DNAFactID ";
85
				" FROM DNAFact df " +
86
					" INNER JOIN Fact f ON  f.ExtensionFk = df.DNAFactID " +
87
					" WHERE f.FactCategoryFk = 203 ";
88
		if (state.getAlgaTerraConfigurator().isRemoveRestricted()){
89
				result = result + " AND df.ProtectedFlag = 0 ";
90
		}
91
		result += " ORDER BY df.DNAFactID ";
68 92
		return result;
69 93
	}
70 94

  
......
74 98
	@Override
75 99
	protected String getRecordQuery(BerlinModelImportConfigurator config) {
76 100
			String strQuery =   
77
	            " SELECT * " +
101
	            " SELECT df.*, pt.RIdentifier as taxonId, f.FactId, f.restrictedFlag, ecoFact.ecoFactId as ecoFactId " +
78 102
	            " FROM DNAFact df INNER JOIN Fact f ON  f.ExtensionFk = df.DNAFactID " +
79
	              " WHERE (df.DNAFactId IN (" + ID_LIST_TOKEN + ")  )"  
103
	            	" LEFT OUTER JOIN PTaxon pt ON f.PTNameFk = pt.PTNameFk AND f.PTRefFk = pt.PTRefFk " + 
104
	            	" LEFT OUTER JOIN EcoFact ecoFact ON ecoFact.CultureStrain = df.CultureStrainNo " +
105
	              " WHERE f.FactCategoryFk = 203 AND (df.DNAFactId IN (" + ID_LIST_TOKEN + ")  )"  
80 106
	            + " ORDER BY DNAFactID "
81 107
            ;
82 108
		return strQuery;
......
95 121
			logger.warn("Exception occurred when trying to create Ecofact vocabularies: " + e1.getMessage());
96 122
			e1.printStackTrace();
97 123
		}
98
		Set<SpecimenOrObservationBase> objectsToSave = new HashSet<SpecimenOrObservationBase>();
124
		Set<SpecimenOrObservationBase> samplesToSave = new HashSet<SpecimenOrObservationBase>();
125
		Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>();
99 126
		
100
		//TODO do we still need this map? EcoFacts are not handled separate from Facts.
101
		//However, they have duplicates on derived unit level. Also check duplicateFk. 
102 127
		Map<String, FieldObservation> ecoFactFieldObservationMap = (Map<String, FieldObservation>) partitioner.getObjectMap(ECO_FACT_FIELD_OBSERVATION_NAMESPACE);
103 128
		
104 129
		ResultSet rs = partitioner.getResultSet();
130
		
131
		Map<String, Reference> referenceMap = new HashMap<String, Reference>();
132
		
105 133

  
106 134
		try {
107 135
			
......
113 141
        		if ((i++ % modCount) == 0 && i!= 1 ){ logger.info(pluralString + " handled: " + (i-1));}
114 142
				
115 143
				int dnaFactId = rs.getInt("DNAFactId");
116
				int ecoFactFk = nullSafeInt(rs, "EcoFactFk");
117
				String sequenceStr = rs.getString("PlainSequence");
118 144
				String keywordsStr = rs.getString("Keywords");
119 145
				String locusStr = rs.getString("Locus");
120 146
				String definitionStr = rs.getString("Definition");
121 147
				
148
				
122 149
				try {
123 150
					
124 151
					//source ref
125 152
					Reference<?> sourceRef = state.getTransactionalSourceReference();
126 153
				
127
					//facade
154
					//import date
155
					DateTime importDateTime = makeImportDateTime(rs);
156
					
157
					//DNA Sample
128 158
					DnaSample dnaSample = DnaSample.NewInstance();
159
					dnaSample.setCreated(importDateTime);
129 160
					
130
					Sequence sequence = Sequence.NewInstance(sequenceStr);
131
					dnaSample.addSequences(sequence);
161
					//ecoFactFk
162
					makeDerivationFromEcoFact(state, rs, dnaSample, samplesToSave, dnaFactId);
132 163
					
133
					Locus locus = Locus.NewInstance(locusStr, definitionStr);
164
					//sequence
165
					Sequence sequence = makeSequence(rs, dnaSample, dnaFactId, importDateTime);
134 166
					
167
					//locus
168
					Locus locus = Locus.NewInstance(keywordsStr, definitionStr);
169
					locus.setCreated(importDateTime);
135 170
					sequence.setLocus(locus);
136 171
					
172
					//GenBank Accession
173
					makeGenBankAccession(rs, sequence, importDateTime, dnaFactId);
137 174
					
175
					//Comment
176
					String commentStr = rs.getString("Comment");
177
					if (isNotBlank(commentStr)){
178
						Annotation annotation = Annotation.NewInstance(commentStr, AnnotationType.EDITORIAL(), Language.DEFAULT());
179
						annotation.setCreated(importDateTime);
180
						sequence.addAnnotation(annotation);
181
					}
138 182
					
139
//					handleFirstDerivedSpecimen(rs, facade, state, partitioner);
140
//					handleEcoFactSpecificDerivedUnit(rs,facade, state);
183
					//Indiv.Assoc.
184
					makeIndividualsAssociation(partitioner, rs, state, taxaToSave, dnaSample);
185
					
186
					//TODO titleCache
187
					//prelim implementation:
188
					String cultStrain = rs.getString("CultureStrainNo");
189
					String title = String.format("DNA Sample for %s at %s", cultStrain, keywordsStr);
190
					dnaSample.setTitleCache(title, true);
141 191

  
192
					//TODO preliminary implementation
193
					String referenceStr = rs.getString("FactReference");
194
					if (isNotBlank(referenceStr)){
195
						Reference<?> ref = referenceMap.get(referenceStr);
196
						if (ref == null){
197
							ref = ReferenceFactory.newGeneric();
198
							ref.setTitleCache(referenceStr, true);
199
							referenceMap.put(referenceStr, ref);
200
						}
201
						sequence.setPublishedIn(ref);
202
					}
142 203
					
143
					objectsToSave.add(dnaSample); 
204
					//save
205
					samplesToSave.add(dnaSample); 
144 206
					
145 207

  
146 208
				} catch (Exception e) {
......
150 212
                
151 213
            }
152 214
           
153
//            logger.warn("Specimen: " + countSpecimen + ", Descriptions: " + countDescriptions );
154

  
155
			logger.warn("Taxa to save: " + objectsToSave.size());
156
			getOccurrenceService().save(objectsToSave);	
215
			logger.warn("DNASample or EcoFacts to save: " + samplesToSave.size());
216
			getOccurrenceService().saveOrUpdate(samplesToSave);	
217
			logger.warn("Taxa to save: " + samplesToSave.size());
218
			getTaxonService().saveOrUpdate(taxaToSave);
157 219
			
158 220
			return success;
159 221
		} catch (SQLException e) {
......
161 223
			return false;
162 224
		}
163 225
	}
226

  
227

  
228
	private void makeDerivationFromEcoFact(AlgaTerraImportState state, ResultSet rs, DnaSample dnaSample, Set<SpecimenOrObservationBase> samplesToSave, Integer dnaFactId) throws SQLException {
229
		Integer ecoFactFk = nullSafeInt(rs, "ecoFactId");
230
		if (ecoFactFk != null){
231
			
232
			DerivedUnitBase<?> ecoFact = (DerivedUnitBase<?>)state.getRelatedObject(ECO_FACT_DERIVED_UNIT_NAMESPACE, ecoFactFk.toString());
233
			if (ecoFact == null){
234
				logger.warn("EcoFact is null for ecoFactFk: " + ecoFactFk + ", DnaFactId: " + dnaFactId);
235
			}else{
236
				DerivationEvent.NewSimpleInstance(ecoFact, dnaSample, DerivationEventType.DNA_EXTRACTION());
237
				samplesToSave.add(ecoFact);
238
			}
239
		}
240
		
241
		
242
		
243
	}
244

  
245

  
246

  
247
	private void makeIndividualsAssociation(ResultSetPartitioner partitioner, ResultSet rs, AlgaTerraImportState state, Set<TaxonBase> taxaToSave, DnaSample dnaSample) throws SQLException{
248
		Reference<?> sourceRef = state.getTransactionalSourceReference();
249
		Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>) partitioner.getObjectMap(BerlinModelTaxonImport.NAMESPACE);
250
		Integer taxonId = rs.getInt("taxonId");
251
		Integer factId = rs.getInt("factId");
252
		Taxon taxon = getTaxon(state, taxonId, taxonMap, factId);
253
		TaxonDescription desc = getTaxonDescription(state, taxon, sourceRef);
254
		IndividualsAssociation assoc = IndividualsAssociation.NewInstance(dnaSample);
255
		desc.addElement(assoc);
256
		taxaToSave.add(taxon);
257
	}
164 258
	
259

  
260
	/**
261
	 * @param rs
262
	 * @return
263
	 * @throws SQLException
264
	 * @throws ParseException
265
	 */
266
	private DateTime makeImportDateTime(ResultSet rs) throws SQLException,
267
			ParseException {
268
		DateTime importDateTime = null;
269
		String importDateTimeStr = rs.getString("ImportDateTime");
270
		if (isNotBlank(importDateTimeStr)){
271
			importDateTimeStr = importDateTimeStr.substring(0,10);
272
			DateTimeFormatter dayFormatter = DateTimeFormat.forPattern("dd.MM.yyyy");
273

  
274
//						DateTimeFormatter formatter = new DateTimeFormatterBuilder().
275
//								append;
276
			DateTimeParser p = new DateTimeParser(dayFormatter);
277
			importDateTime = p.parse(importDateTimeStr, Locale.GERMANY);
278
			
279
		}
280
		return importDateTime;
281
	}
282

  
283

  
284

  
285
	private Sequence makeSequence(ResultSet rs, DnaSample dnaSample, int dnaFactId, DateTime importDateTime) throws SQLException {
286
		String sequenceStr = rs.getString("PlainSequence");
287
		Integer originalLen = null;
288
		Integer seqLen = nullSafeInt(rs, "SeqLen");
289
		if (seqLen == null){
290
			if (sequenceStr != null){
291
				seqLen = sequenceStr.length();
292
			}
293
		}
294
		
295
		if (sequenceStr != null){
296
			originalLen = sequenceStr.length();
297
			if (originalLen > 255){
298
				logger.warn("Sequence truncated. Id: " + dnaFactId);
299
				sequenceStr = sequenceStr.substring(0, 255);
300
			}
301
		}else{
302
			logger.warn("PlainSequence is null. Id: " + dnaFactId);
303
		}
304
		Sequence sequence = Sequence.NewInstance(sequenceStr);
305
		sequence.setLength(seqLen);
306
		if (! originalLen.equals(seqLen)){
307
			logger.warn("SeqLen (" + seqLen+ ") and OriginalLen ("+originalLen+") differ for dnaFact: "  + dnaFactId);
308
		}
309
		
310
		sequence.setCreated(importDateTime);
311
		dnaSample.addSequences(sequence);
312
		return sequence;
313
	}
314

  
315

  
316

  
317
	/**
318
	 * @param sequence2 
319
	 * @param rs 
320
	 * @param accessionStr
321
	 * @param notesStr
322
	 * @param sequence
323
	 * @param importDateTime 
324
	 * @return
325
	 * @throws SQLException 
326
	 */
327
	private void makeGenBankAccession(ResultSet rs, Sequence sequence, DateTime importDateTime, Integer dnaFactId) throws SQLException {
328
		String accessionStr = rs.getString("Accession");
329
		String notesStr = rs.getString("Notes");
330
		String versionStr = rs.getString("Version");
331
		
332
		URI genBankUri = null;
333
		if (StringUtils.isNotBlank(notesStr)){
334
			if (notesStr.startsWith("http")){
335
				genBankUri = URI.create(notesStr);
336
			}else{
337
				logger.warn("Notes do not start with URI: " +  notesStr);
338
			}
339
		}
340
		
341
		if (isNotBlank(accessionStr) || genBankUri != null){
342
			if (accessionStr != null && accessionStr.trim().equals("")){
343
				accessionStr = null;
344
			}
345
			if (isGenBankAccessionNumber(accessionStr, versionStr, genBankUri, dnaFactId) || genBankUri != null){
346
				GenBankAccession accession = GenBankAccession.NewInstance(accessionStr);
347
				accession.setUri(genBankUri);
348
				accession.setCreated(importDateTime);
349
				sequence.addGenBankAccession(accession);				
350
			}
351
		}
352
	}
353
	
354
	private boolean isGenBankAccessionNumber(String accessionStr, String versionStr, URI genBankUri, Integer dnaFactId) {
355
		boolean isGenBankAccessionNumber = accessionStr.matches("[A-Z]{2}\\d{6}");
356
		boolean versionHasGenBankPart = versionStr.matches(".*GI:.*");
357
		if (isGenBankAccessionNumber && versionHasGenBankPart){
358
			return true;
359
		}else {
360
			if (genBankUri != null){
361
				logger.warn("GenBank Uri exists but accession or version have been identified to use GenBank syntax. DNAFactID: " + dnaFactId);	
362
			}
363
			if(isGenBankAccessionNumber || versionHasGenBankPart){
364
				logger.warn("Either accession ("+ accessionStr +") or version ("+versionStr+") use GenBank syntax but the other does not. DNAFactID: " + dnaFactId);	
365
			}
366
			return false;
367
		}
368
	}
369

  
370

  
371

  
165 372
	protected String getDerivedUnitNameSpace(){
166 373
		return ECO_FACT_DERIVED_UNIT_NAMESPACE;
167 374
	}
......
203 410
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
204 411
		
205 412
		try{
206
			Set<String> fieldObservationIdSet = new HashSet<String>();
207
			Set<String> termsIdSet = new HashSet<String>();
208
			Set<String> collectionIdSet = new HashSet<String>();
413
			Set<String> taxonIdSet = new HashSet<String>();
414
			
415
			Set<String> ecoFactFkSet = new HashSet<String>();
209 416
			
210 417
			while (rs.next()){
211
//				handleForeignKey(rs, fieldObservationIdSet, "DuplicateFk");
212
//				handleForeignKey(rs, termsIdSet, "LifeFormFk");
213
//				handleForeignKey(rs, collectionIdSet, "CollectionFk");
418
				handleForeignKey(rs, taxonIdSet, "taxonId");
419
				handleForeignKey(rs, ecoFactFkSet, "ecoFactId");
420

  
214 421
			}
215 422
			
216
			//field observation map for duplicates
217
			nameSpace = AlgaTerraDnaImport.ECO_FACT_FIELD_OBSERVATION_NAMESPACE;
218
			cdmClass = FieldObservation.class;
219
			idSet = fieldObservationIdSet;
220
			Map<String, FieldObservation> fieldObservationMap = (Map<String, FieldObservation>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
221
			result.put(nameSpace, fieldObservationMap);
222

  
223
			//collections
224
			nameSpace = AlgaTerraCollectionImport.NAMESPACE_COLLECTION;
225
			cdmClass = Collection.class;
226
			idSet = collectionIdSet;
227
			Map<String, Collection> collectionMap = (Map<String, Collection>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
228
			result.put(nameSpace, collectionMap);
229

  
230
			//sub-collections
231
			nameSpace = AlgaTerraCollectionImport.NAMESPACE_SUBCOLLECTION;
232
			cdmClass = Collection.class;
233
			idSet = collectionIdSet;
234
			Map<String, Collection> subCollectionMap = (Map<String, Collection>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
235
			result.put(nameSpace, subCollectionMap);
236

  
237
			//terms
238
			nameSpace = AlgaTerraDnaImport.TERMS_NAMESPACE;
239
			cdmClass = FieldObservation.class;
240
			idSet = termsIdSet;
241
			Map<String, DefinedTermBase> termMap = (Map<String, DefinedTermBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
242
			result.put(nameSpace, termMap);
423
			//taxon map
424
			nameSpace = BerlinModelTaxonImport.NAMESPACE;
425
			cdmClass = TaxonBase.class;
426
			idSet = taxonIdSet;
427
			Map<String, TaxonBase> objectMap = (Map<String, TaxonBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
428
			result.put(nameSpace, objectMap);
429
			
430

  
431
			//eco fact derived unit map
432
			nameSpace = AlgaTerraFactEcologyImport.ECO_FACT_DERIVED_UNIT_NAMESPACE;
433
			cdmClass = DerivedUnitBase.class;
434
			idSet = ecoFactFkSet;
435
			Map<String, DerivedUnitBase> derivedUnitMap = (Map<String, DerivedUnitBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
436
			result.put(nameSpace, derivedUnitMap);
243 437
			
244 438
		} catch (SQLException e) {
245 439
			throw new RuntimeException(e);
app-import/src/main/java/eu/etaxonomy/cdm/io/algaterra/AlgaTerraFactEcologyImport.java
22 22
import org.springframework.stereotype.Component;
23 23

  
24 24
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
25
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy;
26 25
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade.DerivedUnitType;
26
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy;
27 27
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
28 28
import eu.etaxonomy.cdm.io.algaterra.validation.AlgaTerraSpecimenImportValidator;
29 29
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
......
38 38
import eu.etaxonomy.cdm.model.description.Feature;
39 39
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
40 40
import eu.etaxonomy.cdm.model.description.TaxonDescription;
41
import eu.etaxonomy.cdm.model.name.BotanicalName;
42
import eu.etaxonomy.cdm.model.name.Rank;
43 41
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
44 42
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
45 43
import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
......
326 324

  
327 325

  
328 326

  
329
	/**
330
	 * @param state
331
	 * @param newTaxonId
332
	 * @param taxonMap
333
	 * @param factId
334
	 * @return
335
	 */
336
	private Taxon getTaxon(AlgaTerraImportState state, int taxonId, Map<String, TaxonBase> taxonMap, int factId) {
337
		TaxonBase<?> taxonBase = taxonMap.get(String.valueOf(taxonId));
338
		
339
		//TODO for testing
340
		if (taxonBase == null && ! state.getConfig().isDoTaxa()){
341
			taxonBase = Taxon.NewInstance(BotanicalName.NewInstance(Rank.SPECIES()), null);
342
		}
343
		
344
		Taxon taxon;
345
		if ( taxonBase instanceof Taxon ) {
346
			taxon = (Taxon) taxonBase;
347
		} else if (taxonBase != null) {
348
			logger.warn("TaxonBase (" + taxonId + ") for Fact(Specimen) with factId " + factId + " was not of type Taxon but: " + taxonBase.getClass().getSimpleName());
349
			return null;
350
		} else {
351
			logger.warn("TaxonBase (" + taxonId + ") for Fact(Specimen) with factId " + factId + " is null.");
352
			return null;
353
		}
354
		return taxon;
355
	}
356
	
357 327
	/* (non-Javadoc)
358 328
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet)
359 329
	 */
app-import/src/main/java/eu/etaxonomy/cdm/io/algaterra/AlgaTerraImportConfigurator.java
22 22
import eu.etaxonomy.cdm.io.common.Source;
23 23

  
24 24
/**
25
 * @author pesiimport
25
 * @author a.mueller
26 26
 *
27 27
 */
28 28
public class AlgaTerraImportConfigurator extends BerlinModelImportConfigurator {
29 29

  
30

  
30 31
	private boolean doEcoFacts = true;
31 32
	private boolean doFactEcology = true;
32 33
	
......
34 35
	
35 36
	private boolean doDna = true;
36 37
	
38
	private boolean removeRestricted = false;  //if true, all records with protected or restricted flag will be filtered
39
	
37 40
	private String imageBaseUrl = "http://www.algaterra.org/ATDB/Figures/";
38 41
	
39 42
	public static AlgaTerraImportConfigurator NewInstance(Source berlinModelSource, ICdmDataSource destination){
......
126 129
		this.doDna = doDna;
127 130
	}
128 131

  
132
	public boolean isRemoveRestricted() {
133
		return removeRestricted;
134
	}
135
	
136
	public void setRemoveRestricted(boolean removeRestricted) {
137
		this.removeRestricted = removeRestricted;
138
	}
139

  
129 140

  
130 141
}

Also available in: Unified diff