Project

General

Profile

Download (2.57 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;
10

    
11
import java.io.File;
12
import java.net.URI;
13
import java.util.Map;
14

    
15
import org.apache.log4j.Logger;
16
import org.springframework.stereotype.Component;
17

    
18
import eu.etaxonomy.cdm.common.CdmUtils;
19
import eu.etaxonomy.cdm.io.csv.in.CsvImportBase;
20
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
21
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
22
import eu.etaxonomy.cdm.model.term.DefinedTerm;
23
import eu.etaxonomy.cdm.model.term.TermType;
24
import eu.etaxonomy.cdm.model.term.TermVocabulary;
25

    
26
/**
27
 *
28
 * @author pplitzner
29
 * @since Dec 7, 2018
30
 *
31
 */
32
@Component
33
public class PlantGlossaryCategoryAsPropertiesImport extends CsvImportBase<PlantGlossaryCsvImportConfigurator, PlantGlossaryCsvImportState, File>{
34
    private static final long serialVersionUID = -5600766240192189822L;
35
    private static Logger logger = Logger.getLogger(PlantGlossaryCategoryAsPropertiesImport.class);
36

    
37
    @Override
38
    protected void handleSingleLine(PlantGlossaryCsvImportState importState) {
39
        final String HEADER_LABEL = "rdfs:label";
40
        final String HEADER_DESCRIPTION = "skos:definition";
41
        final String HEADER_URI = "category_URI";
42
        final String HEADER_NOTES = "skos:notes";
43

    
44
        Map<String, String> currentRecord = importState.getCurrentRecord();
45

    
46
        String label = currentRecord.get(HEADER_LABEL);
47
        if(CdmUtils.isBlank(label)){
48
            // this line does not contain any vocabulary information
49
            return;
50
        }
51
        if(importState.isTermPresent(label, getTermService())) {
52
            return;
53
        }
54

    
55
        String description = currentRecord.get(HEADER_DESCRIPTION);
56
        String uri = currentRecord.get(HEADER_URI);
57
        DefinedTerm property = DefinedTerm.NewInstance(TermType.Property, description, label, null);
58
        property.setUri(URI.create(uri));
59
        property.setIdInVocabulary(label);
60

    
61
        TermVocabulary vocabulary = importState.getPropertyVoc();
62
        vocabulary.addTerm(property);
63

    
64
        IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Import, importState.getCitation().getTitle(), null, importState.getCitation(), null);
65
        source.setIdInSource(label);
66
        property.addSource(source);
67

    
68
        getVocabularyService().saveOrUpdate(vocabulary);
69
        getTermService().saveOrUpdate(property);
70
    }
71

    
72
}
(2-2/6)