Project

General

Profile

Download (23 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.net.URI;
13
import java.sql.ResultSet;
14
import java.sql.SQLException;
15
import java.util.HashMap;
16
import java.util.HashSet;
17
import java.util.Map;
18
import java.util.Set;
19
import java.util.UUID;
20

    
21
import org.apache.commons.lang.StringUtils;
22
import org.apache.log4j.Logger;
23
import org.springframework.stereotype.Component;
24
import org.springframework.transaction.TransactionStatus;
25

    
26
import eu.etaxonomy.cdm.io.algaterra.validation.AlgaTerraMorphologyImportValidator;
27
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
28
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
29
import eu.etaxonomy.cdm.io.common.IOValidator;
30
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
31
import eu.etaxonomy.cdm.io.common.Source;
32
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
33
import eu.etaxonomy.cdm.model.common.CdmBase;
34
import eu.etaxonomy.cdm.model.common.DefinedTerm;
35
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
36
import eu.etaxonomy.cdm.model.common.TermType;
37
import eu.etaxonomy.cdm.model.common.TermVocabulary;
38
import eu.etaxonomy.cdm.model.description.CategoricalData;
39
import eu.etaxonomy.cdm.model.description.DescriptionBase;
40
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
41
import eu.etaxonomy.cdm.model.description.Feature;
42
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
43
import eu.etaxonomy.cdm.model.description.QuantitativeData;
44
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
45
import eu.etaxonomy.cdm.model.description.State;
46
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
47
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
48
import eu.etaxonomy.cdm.model.description.TextData;
49
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
50
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
51
import eu.etaxonomy.cdm.model.reference.Reference;
52

    
53

    
54
/**
55
 * @author a.mueller
56
 * @created 01.09.2012
57
 */
58
@Component
59
public class AlgaTerraMorphologyImport  extends AlgaTerraSpecimenImportBase {
60
	private static final Logger logger = Logger.getLogger(AlgaTerraMorphologyImport.class);
61

    
62

    
63
	private static int modCount = 5000;
64
	private static final String pluralString = "morpho facts";
65
	private static final String dbTableName = "MorphoFact";
66

    
67

    
68
	public AlgaTerraMorphologyImport(){
69
		super(dbTableName, pluralString);
70
	}
71

    
72

    
73
	@Override
74
	protected String getIdQuery(BerlinModelImportState state) {
75
		String result = " SELECT MorphoFactId " +
76
				" FROM MorphoFact  " +
77
				" ORDER BY MorphoFact.MorphoFactId ";
78
		return result;
79
	}
80

    
81

    
82
	@Override
83
	protected String getRecordQuery(BerlinModelImportConfigurator config) {
84
			String strQuery =
85
            " SELECT mf.*, mf.MorphoFactId as unitId, ecoFact.ecoFactId as ecoFactId,  size.* " +
86
            " FROM MorphoFact mf " +
87
            	" LEFT OUTER JOIN MorphoSizeRange size ON mf.SizeRangeFk = size.SizeRangeId " +
88
            	" LEFT OUTER JOIN MorphoValveDescription valve1Desc ON mf.Valve1DescriptionFk = valve1Desc.ValveDescriptionId " +
89
            	" LEFT OUTER JOIN MorphoValveDescription valve2Desc ON mf.Valve2DescriptionFk = valve2Desc.ValveDescriptionId " +
90
            	" LEFT OUTER JOIN EcoFact ecoFact ON ecoFact.CultureStrain = mf.CultureStrainNo " +
91
              " WHERE (mf.MorphoFactId IN (" + ID_LIST_TOKEN + ")  )"
92
            + " ORDER BY mf.MorphoFactId "
93
            ;
94
		return strQuery;
95
	}
96

    
97

    
98
	private Map<String, TermVocabulary<State>> vocabularyMap = new HashMap<String, TermVocabulary<State>>();
99
	private Map<String, Feature> featureMap = new HashMap<String, Feature>();
100
	private Map<String, Map<Integer, State>> algaTerraMorphoStates = new HashMap<String, Map<Integer, State>>();
101
	private TermVocabulary<Feature> algaTerraMorphoFeatures = TermVocabulary
102
			.NewInstance(TermType.Feature, "Alga Terra Morphology Features", "AT Morphology Features", null, null);
103

    
104
	private void doMorphoListen(AlgaTerraImportState state) throws SQLException{
105

    
106
		TransactionStatus txStatus = this.startTransaction();
107

    
108
		getVocabularyService().save(algaTerraMorphoFeatures);
109

    
110
		//chloroplast position
111
		String baseName = "Chloroplast Position";
112
		UUID uuidStateVocabulary = AlgaTerraImportTransformer.uuidVocChloroplastPosition;
113
		boolean isOrdered = false;
114
		makeFeatureAndVocabulary(state, vocabularyMap, featureMap, algaTerraMorphoStates,
115
				algaTerraMorphoFeatures, baseName, uuidStateVocabulary, isOrdered);
116

    
117
		//Chloroplast Shape
118
		baseName = "Chloroplast Shape";
119
		uuidStateVocabulary = AlgaTerraImportTransformer.uuidVocChloroplastShape;
120
		isOrdered = false;
121
		makeFeatureAndVocabulary(state, vocabularyMap, featureMap, algaTerraMorphoStates,
122
				algaTerraMorphoFeatures, baseName, uuidStateVocabulary, isOrdered);
123

    
124
		//Chloroplast Shape
125
		baseName = "Chloroplast Structure";
126
		uuidStateVocabulary = AlgaTerraImportTransformer.uuidVocChloroplastStructure;
127
		isOrdered = false;
128
		makeFeatureAndVocabulary(state, vocabularyMap, featureMap, algaTerraMorphoStates,
129
				algaTerraMorphoFeatures, baseName, uuidStateVocabulary, isOrdered);
130

    
131
		//Growth Form
132
		baseName = "Growth Form";
133
		uuidStateVocabulary = AlgaTerraImportTransformer.uuidVocGrowthForm;
134
		isOrdered = false;
135
		makeFeatureAndVocabulary(state, vocabularyMap, featureMap, algaTerraMorphoStates,
136
				algaTerraMorphoFeatures, baseName, uuidStateVocabulary, isOrdered);
137

    
138
		//Organisation Level
139
		baseName = "Organisation Level";
140
		uuidStateVocabulary = AlgaTerraImportTransformer.uuidVocOrganisationLevel;
141
		isOrdered = false;
142
		makeFeatureAndVocabulary(state, vocabularyMap, featureMap, algaTerraMorphoStates,
143
				algaTerraMorphoFeatures, baseName, uuidStateVocabulary, isOrdered);
144

    
145

    
146
		//Raphe
147
		baseName = "Raphe";
148
		uuidStateVocabulary = AlgaTerraImportTransformer.uuidVocRaphe;
149
		isOrdered = false;
150
		makeFeatureAndVocabulary(state, vocabularyMap, featureMap, algaTerraMorphoStates,
151
				algaTerraMorphoFeatures, baseName, uuidStateVocabulary, isOrdered);
152

    
153
		//Shape
154
		baseName = "Shape";
155
		uuidStateVocabulary = AlgaTerraImportTransformer.uuidVocShape;
156
		isOrdered = false;
157
		makeFeatureAndVocabulary(state, vocabularyMap, featureMap, algaTerraMorphoStates,
158
				algaTerraMorphoFeatures, baseName, uuidStateVocabulary, isOrdered);
159

    
160
		//Symmetrie
161
		baseName = "Symmetry";
162
		uuidStateVocabulary = AlgaTerraImportTransformer.uuidVocSymmetry;
163
		isOrdered = false;
164
		makeFeatureAndVocabulary(state, vocabularyMap, featureMap, algaTerraMorphoStates,
165
				algaTerraMorphoFeatures, baseName, uuidStateVocabulary, isOrdered);
166

    
167
		getVocabularyService().saveOrUpdate(algaTerraMorphoFeatures);
168

    
169
		this.commitTransaction(txStatus);
170
	}
171

    
172

    
173
	private void makeFeatureAndVocabulary(AlgaTerraImportState state,
174
			Map<String, TermVocabulary<State>> vocabularyMap,
175
			Map<String, Feature> featureMap, Map<String, Map<Integer, State>> allMorphoStates,
176
			TermVocabulary<Feature> algaTerraMorphoFeatures, String baseName,
177
			UUID uuidStateVocabulary, boolean isOrdered)
178
			throws SQLException {
179

    
180
		Source source = state.getAlgaTerraConfigurator().getSource();
181

    
182
		Map<Integer, State> morphoStates = new HashMap<Integer, State>();
183
		allMorphoStates.put(baseName, morphoStates);
184

    
185
		String baseNameCamel = baseName.replace(" ", "");
186

    
187
		//make feature
188
		handleSingleFeature(state, featureMap, algaTerraMorphoFeatures,	baseName);
189

    
190
		//make term vocabulary
191
		String vocDescription = "The vocabulary for the " + baseName + " in AlgaTerra";
192
		String vocLabel = baseName;
193
		String vocAbbrevLabel = null;
194
		URI termSourceUri = null;
195
		TermVocabulary<State> voc = getVocabulary(TermType.State, uuidStateVocabulary,vocDescription, vocLabel, vocAbbrevLabel, termSourceUri, isOrdered, null);
196
		vocabularyMap.put(vocLabel, voc);
197

    
198
		String idField = baseNameCamel + "Id";
199
		String sql =  "SELECT " + idField + "," + baseNameCamel + ", Description FROM Morpho" + baseNameCamel;
200
		ResultSet rs = source.getResultSet(sql);
201
		while (rs.next()){
202
			Integer id = rs.getInt(idField);
203
			String label = rs.getString(baseNameCamel);
204
			String description = rs.getString("Description");
205
			State term = State.NewInstance(description, label, null);
206
			voc.addTerm(term);
207
			term.addSource(OriginalSourceType.Import, String.valueOf(id), baseNameCamel, state.getTransactionalSourceReference() , null);
208
			morphoStates.put(id, term);
209
		}
210
		getVocabularyService().saveOrUpdate(voc);
211
	}
212

    
213

    
214
	private Feature handleSingleFeature(AlgaTerraImportState state,
215
			Map<String, Feature> featureMap,
216
			TermVocabulary<Feature> algaTerraMorphoFeatures, String baseName) {
217

    
218
		String baseNameCamel = baseName.replace(" ", "");
219

    
220
		UUID uuidFeature = null;
221
		try {
222
			uuidFeature = AlgaTerraImportTransformer.getFeatureUuid(baseName);
223
		} catch (UndefinedTransformerMethodException e) {
224
			throw new RuntimeException(e);
225
		}
226
		Feature feature = getFeature(state, uuidFeature, baseName, baseName, null, algaTerraMorphoFeatures);
227
		algaTerraMorphoFeatures.addTerm(feature);
228
		featureMap.put(baseNameCamel, feature);
229
		return feature;
230
	}
231

    
232
	private void doNonListenFeatures(AlgaTerraImportState state) throws SQLException{
233
		String baseName = "Apices";
234
		handleSingleFeature(state, featureMap, algaTerraMorphoFeatures, baseName);
235

    
236
		baseName = "Chloroplast Number";
237
		handleSingleFeature(state, featureMap, algaTerraMorphoFeatures, baseName);
238

    
239
		baseName = "Pyrenoid";
240
		handleSingleFeature(state, featureMap, algaTerraMorphoFeatures, baseName);
241

    
242
		baseName = "Cell Wall";
243
		handleSingleFeature(state, featureMap, algaTerraMorphoFeatures, baseName);
244

    
245
		baseName = "Reproductive Stages";
246
		handleSingleFeature(state, featureMap, algaTerraMorphoFeatures, baseName);
247

    
248
		makeValveFeatures(state, featureMap, algaTerraMorphoFeatures);
249

    
250
	}
251

    
252

    
253

    
254

    
255
	private void makeValveFeatures(AlgaTerraImportState state,
256
			Map<String, Feature> featureMap2,
257
			TermVocabulary<Feature> algaTerraMorphoFeatures2) {
258

    
259
		String baseName = "Valve 1";
260
		handleSingleValve(state, featureMap, algaTerraMorphoFeatures, baseName);
261

    
262
		baseName = "Valve 2";
263
		handleSingleValve(state, featureMap, algaTerraMorphoFeatures, baseName);
264

    
265
	}
266

    
267

    
268
	private void handleSingleValve(AlgaTerraImportState state,
269
			Map<String, Feature> featureMap2,
270
			TermVocabulary<Feature> algaTerraMorphoFeatures2, String valveStr) {
271

    
272
		Feature featureValve = handleSingleFeature(state, featureMap, algaTerraMorphoFeatures, valveStr);
273

    
274
		String baseName = "Striae Frequency";
275
		Feature featureSub = handleSingleFeature(state, featureMap, algaTerraMorphoFeatures, baseName + " " + valveStr);
276
		//TODO is partOf correct here? see also below
277
		featureSub.setPartOf(featureValve);
278

    
279
		baseName = "Striae Orientation Mid"; //Mid Valve
280
		featureSub = handleSingleFeature(state, featureMap, algaTerraMorphoFeatures, baseName + " " + valveStr);
281
		featureSub.setPartOf(featureValve);
282

    
283
		baseName = "Striae Orientation Apices";
284
		featureSub = handleSingleFeature(state, featureMap, algaTerraMorphoFeatures, baseName + " " + valveStr);
285
		featureSub.setPartOf(featureValve);
286

    
287
		baseName = "Central Area";
288
		featureSub = handleSingleFeature(state, featureMap, algaTerraMorphoFeatures, baseName + " " + valveStr);
289
		featureSub.setPartOf(featureValve);
290

    
291
		baseName = "Axial Area";
292
		featureSub = handleSingleFeature(state, featureMap, algaTerraMorphoFeatures, baseName + " " + valveStr);
293
		featureSub.setPartOf(featureValve);
294

    
295
		baseName = "has Raphe";
296
		featureSub = handleSingleFeature(state, featureMap, algaTerraMorphoFeatures, baseName + " " + valveStr);
297
		featureSub.setPartOf(featureValve);
298
	}
299

    
300

    
301
	@Override
302
	protected void doInvoke(BerlinModelImportState state) {
303
		AlgaTerraImportState atState = (AlgaTerraImportState)state;
304
		try {
305
			doMorphoListen(atState);
306
			doNonListenFeatures(atState);
307
		} catch (SQLException e) {
308
			throw new RuntimeException(e);
309
		}
310
		super.doInvoke(state);
311
	}
312

    
313

    
314
	@Override
315
	public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState bmState) {
316
		boolean success = true;
317

    
318
		AlgaTerraImportState state = (AlgaTerraImportState)bmState;
319
		Set<SpecimenOrObservationBase> objectsToSave = new HashSet<SpecimenOrObservationBase>();
320

    
321
		ResultSet rs = partitioner.getResultSet();
322

    
323
		try {
324

    
325
			int i = 0;
326

    
327
			//for each reference
328
            while (rs.next()){
329

    
330
        		if ((i++ % modCount) == 0 && i!= 1 ){ logger.info(pluralString + " handled: " + (i-1));}
331

    
332
				int morphoFactId = rs.getInt("MorphoFactId");
333
				String cultureStrainNo = rs.getString("CultureStrainNo");
334

    
335
				try {
336

    
337
					//source ref
338
					Reference sourceRef = state.getTransactionalSourceReference();
339

    
340
					//ecoFact
341
					DerivedUnit ecoFact = makeDerivationFromEcoFact(state, rs, morphoFactId);
342
					if (ecoFact != null){
343
						SpecimenDescription desc = SpecimenDescription.NewInstance();
344
						desc.setTitleCache("Morphology for " + cultureStrainNo , true);
345

    
346
						ecoFact.addDescription(desc);
347

    
348
						String baseLabel = "Organisation Level";
349
						handleStateTerm(state, rs, baseLabel, desc);
350

    
351
						baseLabel = "Growth Form";
352
						handleStateTerm(state, rs, baseLabel, desc);
353

    
354
						baseLabel = "Shape";
355
						handleStateTerm(state, rs, baseLabel, desc);
356

    
357
						baseLabel = "Symmetry";
358
						handleStateTerm(state, rs, baseLabel, desc);
359

    
360
						baseLabel = "Raphe";
361
						handleStateTerm(state, rs, baseLabel, desc);
362

    
363
						baseLabel = "Chloroplast Shape";
364
						handleStateTerm(state, rs, baseLabel, desc);
365

    
366
						baseLabel = "Chloroplast Structure";
367
						handleStateTerm(state, rs, baseLabel, desc);
368

    
369
						baseLabel = "Chloroplast Position";
370
						handleStateTerm(state, rs, baseLabel, desc);
371

    
372
						baseLabel = "Apices";
373
						handleTextData(state, rs, baseLabel, desc);
374

    
375
						baseLabel = "Chloroplast Number";
376
						handleTextData(state, rs, baseLabel, desc);
377

    
378
						baseLabel = "Pyrenoid";
379
						handleTextData(state, rs, baseLabel, desc);
380

    
381
						baseLabel = "Cell Wall";
382
						handleTextData(state, rs, baseLabel, desc);
383

    
384
						baseLabel = "Reproductive Stages";
385
						handleTextData(state, rs, baseLabel, desc);
386

    
387
						//TODO to which object to add this information
388
						this.doId(state, desc, morphoFactId, dbTableName);
389
						String notes = rs.getString("Notes");
390
						this.doNotes(desc, notes);
391

    
392
			            objectsToSave.add(ecoFact);
393
					}else if (cultureStrainNo != null) {
394
						logger.warn("cultureStrainNo (" + cultureStrainNo + ") exists but no ecoFact found for morphoFact " + morphoFactId);
395
					}else{
396
						logger.info("No cultureStrainNo defined for morphoFact " + morphoFactId);
397
					}
398
				} catch (Exception e) {
399
					logger.warn("Exception in morphoFact: morphoFactId " + morphoFactId + ". " + e.getMessage());
400
					e.printStackTrace();
401
				}
402

    
403
            }
404

    
405
            //TODO DataEntryBy,
406
            //GrowthFormExplanation, ShapeExplanation, RapheExplanation, ChloroplastExplanation,
407
            //SizeRangeFk, SizeRangeExplanation,
408
            //Valve1RapheFlag, Valve1DescriptionFk,
409
            //Valve2RapheFlag, Valve2DescriptionFk,
410
            //StriaeFrequencyExplanation,
411
            //PyrenoidExplanation,
412

    
413
            //Not required:  OrganisationLevelExplanation, ValveLinearShape, ValveShape, SymmetryExplanation,
414
            //Rimoportula, Fultoportula, Description, CultureCollection
415

    
416
			logger.warn("Specimen to save: " + objectsToSave.size());
417
			getOccurrenceService().save(objectsToSave);
418

    
419
			return success;
420
		} catch (SQLException e) {
421
			logger.error("SQLException:" +  e);
422
			return false;
423
		}
424
	}
425

    
426
	private DerivedUnit makeDerivationFromEcoFact(AlgaTerraImportState state, ResultSet rs, Integer morphoFactId) throws SQLException {
427
		Integer ecoFactFk = nullSafeInt(rs, "ecoFactId");
428
		if (ecoFactFk != null){
429

    
430
			DerivedUnit ecoFact = (DerivedUnit)state.getRelatedObject(ECO_FACT_DERIVED_UNIT_NAMESPACE, ecoFactFk.toString());
431
			if (ecoFact == null){
432
				logger.warn("EcoFact is null for ecoFactFk: " + ecoFactFk + ", morphoFactId: " + morphoFactId);
433
				return null;
434
			}else{
435
				return ecoFact;
436
			}
437
		}else{
438
			return null;
439
		}
440
	}
441

    
442
	private void handleTextData(AlgaTerraImportState state, ResultSet rs,
443
			String baseLabel, SpecimenDescription desc) throws SQLException {
444
		String baseLabelCamel = baseLabel.replace(" ", "");
445

    
446
		String value = rs.getString(baseLabelCamel);
447
		if (value != null){
448
			Feature feature = this.featureMap.get(baseLabelCamel);
449
			if (feature == null){
450
				logger.warn("Feature is null");
451
			}
452
			TextData textData = TextData.NewInstance(feature);
453
			desc.addElement(textData);
454
		}
455
	}
456

    
457

    
458
	private void handleStateTerm(AlgaTerraImportState algaTerraState, ResultSet rs,
459
			String baseLabel, SpecimenDescription desc) throws SQLException {
460

    
461
		String baseLabelCamel = baseLabel.replace(" ", "");
462
		Integer id = nullSafeInt(rs, baseLabelCamel + "Fk");
463
		if (id != null){
464
			Feature feature = this.featureMap.get(baseLabelCamel);
465
			State state = getState(baseLabel, id);
466
			if (feature == null || state == null){
467
				logger.warn("Feature or state is null");
468
			}
469
			DescriptionElementBase deb = CategoricalData.NewInstance(state, feature);
470
			desc.addElement(deb);
471
		}
472
	}
473

    
474

    
475
	private State getState(String baseLabel, Integer id) {
476
		Map<Integer, State> stateMap = this.algaTerraMorphoStates.get(baseLabel);
477
		return stateMap.get(id);
478
	}
479

    
480

    
481
	@Override
482
    protected String getDerivedUnitNameSpace(){
483
		return ECO_FACT_DERIVED_UNIT_NAMESPACE;
484
	}
485

    
486
	@Override
487
    protected String getFieldObservationNameSpace(){
488
		return ECO_FACT_FIELD_OBSERVATION_NAMESPACE;
489
	}
490

    
491

    
492

    
493
	private void makeParameter(AlgaTerraImportState state, ResultSet rs, DescriptionBase<?> descriptionBase) throws SQLException {
494
		for (int i = 1; i <= 10; i++){
495
			String valueStr = rs.getString(String.format("P%dValue", i));
496
			String unitStr = rs.getString(String.format("P%dUnit", i));
497
			String parameter = rs.getString(String.format("P%dParameter", i));
498
			String method = rs.getString(String.format("P%dMethod", i));
499

    
500
			//method
501
			if (StringUtils.isNotBlank(method)){
502
				logger.warn("Methods not yet handled: " + method);
503
			}
504
			//parameter
505
			TermVocabulary<Feature> vocParameter = getVocabulary(TermType.Feature, uuidVocParameter, "Feature vocabulary for AlgaTerra measurement parameters", "Parameters", null, null, false, Feature.COMMON_NAME());
506
			if (StringUtils.isNotBlank(parameter)){
507
				UUID featureUuid = getParameterFeatureUuid(state, parameter);
508
				Feature feature = getFeature(state, featureUuid, parameter, parameter, null, vocParameter);
509
				QuantitativeData quantData = QuantitativeData.NewInstance(feature);
510

    
511
				//unit
512
				MeasurementUnit unit = getMeasurementUnit(state, unitStr);
513
				quantData.setUnit(unit);
514
				try {
515

    
516
					Set<DefinedTerm> valueModifier = new HashSet<DefinedTerm>();
517
					valueStr = normalizeAndModifyValue(state, valueStr, valueModifier);
518
					//value
519
					Float valueFlt = Float.valueOf(valueStr);  //TODO maybe change model to Double ??
520

    
521
					StatisticalMeasure measureSingleValue = getStatisticalMeasure(state, uuidStatMeasureSingleValue, "Value", "Single measurement value", null, null);
522
					StatisticalMeasurementValue value = StatisticalMeasurementValue.NewInstance(measureSingleValue, valueFlt);
523
					quantData.addStatisticalValue(value);
524
					descriptionBase.addElement(quantData);
525

    
526
				} catch (NumberFormatException e) {
527
					logger.warn(String.format("Value '%s' can't be converted to double. Parameter %s not imported.", valueStr, parameter));
528
				}
529
			}else if (isNotBlank(valueStr) || isNotBlank(unitStr) ){
530
				logger.warn("There is value or unit without parameter: " + i);
531
			}
532

    
533

    
534
		}
535

    
536
	}
537

    
538
	private String normalizeAndModifyValue(AlgaTerraImportState state, String valueStr, Set<DefinedTerm> valueModifier) {
539
		valueStr = valueStr.replace(",", ".");
540
		if (valueStr.startsWith("<")){
541
			TermVocabulary<DefinedTerm> measurementValueModifierVocabulary = getVocabulary(TermType.Modifier, uuidMeasurementValueModifier, "Measurement value modifier", "Measurement value modifier", null, null, false, DefinedTerm.NewModifierInstance(null, null, null));
542
			DefinedTerm modifier = getModifier(state, uuidModifierLowerThan, "Lower", "Lower than the given measurement value", "<", measurementValueModifierVocabulary);
543
			valueModifier.add(modifier);
544
			valueStr = valueStr.replace("<", "");
545
		}
546
		if (valueStr.startsWith(">")){
547
			TermVocabulary<DefinedTerm> measurementValueModifierVocabulary = getVocabulary(TermType.Modifier, uuidMeasurementValueModifier, "Measurement value modifier", "Measurement value modifier", null, null, false, DefinedTerm.NewModifierInstance(null, null, null));
548
			DefinedTerm modifier = getModifier(state, uuidModifierGreaterThan, "Lower", "Lower than the given measurement value", "<", measurementValueModifierVocabulary);
549
			valueModifier.add(modifier);
550
			valueStr = valueStr.replace(">", "");
551
		}
552
		return valueStr;
553
	}
554

    
555

    
556

    
557
	private UUID getParameterFeatureUuid(AlgaTerraImportState state, String key) {
558
		try {
559
			return AlgaTerraImportTransformer.getFeatureUuid(key);
560
		} catch (UndefinedTransformerMethodException e) {
561
			throw new RuntimeException(e);
562
		}
563
	}
564

    
565

    
566

    
567
	/**
568
	 * TODO move to InputTransformerBase
569
	 * @param state
570
	 * @param unitStr
571
	 * @return
572
	 */
573
	private MeasurementUnit getMeasurementUnit(AlgaTerraImportState state, String unitStr) {
574
		if (StringUtils.isNotBlank(unitStr)){
575
			UUID uuid = AlgaTerraImportTransformer.getMeasurementUnitUuid(unitStr);
576
			if (uuid != null){
577
				return getMeasurementUnit(state, uuid, unitStr, unitStr, unitStr, null);
578
			}else{
579
				logger.warn("MeasurementUnit was not recognized");
580
				return null;
581
			}
582
		}else{
583
			return null;
584
		}
585
	}
586

    
587

    
588
	@Override
589
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
590
		String nameSpace;
591
		Class<?> cdmClass;
592
		Set<String> idSet;
593
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
594

    
595
		try{
596
			Set<String> ecoFactFkSet = new HashSet<String>();
597

    
598
			while (rs.next()){
599
				handleForeignKey(rs, ecoFactFkSet, "ecoFactId");
600
			}
601

    
602
			//eco fact derived unit map
603
			nameSpace = AlgaTerraFactEcologyImport.ECO_FACT_DERIVED_UNIT_NAMESPACE;
604
			cdmClass = DerivedUnit.class;
605
			idSet = ecoFactFkSet;
606
			Map<String, DerivedUnit> derivedUnitMap = (Map<String, DerivedUnit>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
607
			result.put(nameSpace, derivedUnitMap);
608

    
609
		} catch (SQLException e) {
610
			throw new RuntimeException(e);
611
		}
612
		return result;
613
	}
614

    
615
	@Override
616
	protected boolean doCheck(BerlinModelImportState state){
617
		IOValidator<BerlinModelImportState> validator = new AlgaTerraMorphologyImportValidator();
618
		return validator.validate(state);
619
	}
620

    
621
	@Override
622
	protected boolean isIgnore(BerlinModelImportState state){
623
		return ! ((AlgaTerraImportState)state).getAlgaTerraConfigurator().isDoMorphology();
624
	}
625

    
626
}
(9-9/15)