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.common.OriginalSourceType;
|
22
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
23
|
import eu.etaxonomy.cdm.model.description.Feature;
|
24
|
|
25
|
/**
|
26
|
*
|
27
|
* @author pplitzner
|
28
|
* @since Dec 7, 2018
|
29
|
*
|
30
|
*/
|
31
|
@Component
|
32
|
public class PlantGlossaryCategoryAsPropertiesImport extends CsvImportBase<PlantGlossaryCsvImportConfigurator, PlantGlossaryCsvImportState, File>{
|
33
|
private static final long serialVersionUID = -5600766240192189822L;
|
34
|
private static Logger logger = Logger.getLogger(PlantGlossaryCategoryAsPropertiesImport.class);
|
35
|
|
36
|
@Override
|
37
|
protected void handleSingleLine(PlantGlossaryCsvImportState importState) {
|
38
|
final String HEADER_LABEL = "rdfs:label";
|
39
|
final String HEADER_DESCRIPTION = "skos:definition";
|
40
|
final String HEADER_URI = "category_URI";
|
41
|
final String HEADER_NOTES = "skos:notes";
|
42
|
|
43
|
Map<String, String> currentRecord = importState.getCurrentRecord();
|
44
|
|
45
|
String label = currentRecord.get(HEADER_LABEL);
|
46
|
if(CdmUtils.isBlank(label)){
|
47
|
// this line does not contain any vocabulary information
|
48
|
return;
|
49
|
}
|
50
|
if(importState.isTermPresent(label, getTermService())) {
|
51
|
return;
|
52
|
}
|
53
|
|
54
|
String description = currentRecord.get(HEADER_DESCRIPTION);
|
55
|
String uri = currentRecord.get(HEADER_URI);
|
56
|
Feature property = Feature.NewInstance(description, label, null);
|
57
|
property.setUri(URI.create(uri));
|
58
|
property.setIdInVocabulary(label);
|
59
|
|
60
|
TermVocabulary vocabulary = importState.getPropertyVoc();
|
61
|
vocabulary.addTerm(property);
|
62
|
|
63
|
IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Import, importState.getCitation().getTitle(), null, importState.getCitation(), null);
|
64
|
source.setIdInSource(label);
|
65
|
property.addSource(source);
|
66
|
|
67
|
getVocabularyService().saveOrUpdate(vocabulary);
|
68
|
getTermService().saveOrUpdate(property);
|
69
|
}
|
70
|
|
71
|
}
|