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.plantglossary.kew;
|
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.reference.OriginalSourceType;
|
21
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
22
|
import eu.etaxonomy.cdm.model.term.TermType;
|
23
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
24
|
|
25
|
/**
|
26
|
*
|
27
|
* @author pplitzner
|
28
|
* @since Jan 25, 2019
|
29
|
*
|
30
|
*/
|
31
|
@Component
|
32
|
public class KewPlantGlossaryImport extends CsvImportBase<KewPlantGlossaryCsvImportConfigurator, KewPlantGlossaryCsvImportState, File>{
|
33
|
private static final long serialVersionUID = -5600766240192189822L;
|
34
|
private static Logger logger = Logger.getLogger(KewPlantGlossaryImport.class);
|
35
|
|
36
|
final String HEADER_LABEL = "term";
|
37
|
final String HEADER_DEFINITION = "definition";
|
38
|
final String HEADER_TYPE = "type";
|
39
|
|
40
|
@Override
|
41
|
protected void handleSingleLine(KewPlantGlossaryCsvImportState importState) {
|
42
|
|
43
|
Map<String, String> currentRecord = importState.getCurrentRecord();
|
44
|
|
45
|
if(CdmUtils.isBlank(currentRecord.get(HEADER_TYPE)) || !currentRecord.get(HEADER_TYPE).equals("1")){
|
46
|
// only structures (type=1) are imported
|
47
|
return;
|
48
|
}
|
49
|
|
50
|
String termLabel = currentRecord.get(HEADER_LABEL);
|
51
|
//check if already present
|
52
|
if(importState.isTermPresent(termLabel, getTermService())){
|
53
|
return;
|
54
|
}
|
55
|
|
56
|
DefinedTerm structure = DefinedTerm.NewInstance(TermType.Structure, currentRecord.get(HEADER_DEFINITION), termLabel, null);
|
57
|
structure.setIdInVocabulary(termLabel);
|
58
|
|
59
|
TermVocabulary vocabulary = importState.getStructureVoc();
|
60
|
vocabulary.addTerm(structure);
|
61
|
|
62
|
IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Import, importState.getCitation().getTitle(), null, importState.getCitation(), null);
|
63
|
source.setIdInSource(termLabel);
|
64
|
structure.addSource(source);
|
65
|
|
66
|
getVocabularyService().saveOrUpdate(vocabulary);
|
67
|
getTermService().saveOrUpdate(structure);
|
68
|
}
|
69
|
|
70
|
}
|