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