1
|
/**
|
2
|
* Copyright (C) 2017 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
|
package eu.etaxonomy.cdm.io.prometheus;
|
10
|
|
11
|
import java.io.File;
|
12
|
import java.util.Map;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.springframework.stereotype.Component;
|
16
|
|
17
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
18
|
import eu.etaxonomy.cdm.io.csv.in.CsvImportBase;
|
19
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
20
|
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
|
21
|
import eu.etaxonomy.cdm.model.description.Feature;
|
22
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
23
|
|
24
|
/**
|
25
|
*
|
26
|
* @author pplitzner
|
27
|
* @date 18.02.2019
|
28
|
*
|
29
|
*/
|
30
|
@Component
|
31
|
public class PrometheusPropertiesImport extends CsvImportBase<PrometheusPropertiesCsvImportConfigurator, PrometheusPropertiesCsvImportState, File>{
|
32
|
private static final long serialVersionUID = -5600766240192189822L;
|
33
|
private static Logger logger = Logger.getLogger(PrometheusPropertiesImport.class);
|
34
|
|
35
|
final String HEADER_LABEL = "NEW_QUALITATIVE_PROPERTIES - NEW_QUALITATIVE_PROPERTY - term";
|
36
|
|
37
|
@Override
|
38
|
protected void handleSingleLine(PrometheusPropertiesCsvImportState importState) {
|
39
|
|
40
|
Map<String, String> currentRecord = importState.getCurrentRecord();
|
41
|
|
42
|
String termLabel = currentRecord.get(HEADER_LABEL);
|
43
|
//check if already present
|
44
|
if(CdmUtils.isBlank(termLabel) || importState.isTermPresent(termLabel, getTermService())){
|
45
|
return;
|
46
|
}
|
47
|
|
48
|
Feature structure = Feature.NewInstance(null, termLabel, null);
|
49
|
structure.setIdInVocabulary(termLabel);
|
50
|
|
51
|
TermVocabulary vocabulary = importState.getPropertiesVoc();
|
52
|
vocabulary.addTerm(structure);
|
53
|
|
54
|
IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Import, importState.getCitation().getTitle(), null, importState.getCitation(), null);
|
55
|
source.setIdInSource(termLabel);
|
56
|
structure.addSource(source);
|
57
|
|
58
|
getVocabularyService().saveOrUpdate(vocabulary);
|
59
|
getTermService().saveOrUpdate(structure);
|
60
|
}
|
61
|
|
62
|
}
|