Project

General

Profile

Download (2.37 KB) Statistics
| Branch: | Revision:
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.common.OriginalSourceType;
21
import eu.etaxonomy.cdm.model.common.TermVocabulary;
22
import eu.etaxonomy.cdm.model.description.Feature;
23

    
24
/**
25
 *
26
 * @author pplitzner
27
 * @since Jan 25, 2019
28
 *
29
 */
30
@Component
31
public class KewPlantGlossaryImport extends CsvImportBase<KewPlantGlossaryCsvImportConfigurator, KewPlantGlossaryCsvImportState, File>{
32
    private static final long serialVersionUID = -5600766240192189822L;
33
    private static Logger logger = Logger.getLogger(KewPlantGlossaryImport.class);
34

    
35
    final String HEADER_LABEL = "term";
36
    final String HEADER_DEFINITION = "definition";
37
    final String HEADER_TYPE = "type";
38

    
39
    @Override
40
    protected void handleSingleLine(KewPlantGlossaryCsvImportState importState) {
41

    
42
        Map<String, String> currentRecord = importState.getCurrentRecord();
43

    
44
        if(CdmUtils.isBlank(currentRecord.get(HEADER_TYPE)) || !currentRecord.get(HEADER_TYPE).equals("1")){
45
            // only structures (type=1) are imported
46
            return;
47
        }
48

    
49
        String termLabel = currentRecord.get(HEADER_LABEL);
50
        //check if already present
51
        if(importState.isTermPresent(termLabel, getTermService())){
52
            return;
53
        }
54

    
55
        Feature structure = Feature.NewInstance(currentRecord.get(HEADER_DEFINITION), termLabel, null);
56
        structure.setIdInVocabulary(termLabel);
57

    
58
        TermVocabulary vocabulary = importState.getStructureVoc();
59
        vocabulary.addTerm(structure);
60

    
61
        IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Import, importState.getCitation().getTitle(), null, importState.getCitation(), null);
62
        source.setIdInSource(termLabel);
63
        structure.addSource(source);
64

    
65
        getVocabularyService().saveOrUpdate(vocabulary);
66
        getTermService().saveOrUpdate(structure);
67
    }
68

    
69
}
(4-4/4)