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.io.csv.in.CsvImportBase;
|
19
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
20
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
21
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
22
|
import eu.etaxonomy.cdm.model.common.Language;
|
23
|
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
|
24
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
25
|
import eu.etaxonomy.cdm.model.description.State;
|
26
|
|
27
|
/**
|
28
|
*
|
29
|
* @author pplitzner
|
30
|
* @since Dec 7, 2018
|
31
|
*
|
32
|
*/
|
33
|
@Component
|
34
|
public class PlantGlossaryStateImport extends CsvImportBase<PlantGlossaryCsvImportConfigurator, PlantGlossaryCsvImportState, File>{
|
35
|
private static final long serialVersionUID = -5600766240192189822L;
|
36
|
private static Logger logger = Logger.getLogger(PlantGlossaryStateImport.class);
|
37
|
|
38
|
final String HEADER_LABEL = "dcterms:identifier";
|
39
|
final String HEADER_DEFINITION = "definition";
|
40
|
final String HEADER_CATEGORY = "vann:termGroup";
|
41
|
final String HEADER_NOTES = "skos:example";
|
42
|
final String SOURCE_HEADER = "sourceDataset";
|
43
|
final String HEADER_URI = "term_URI";
|
44
|
|
45
|
@Override
|
46
|
protected void handleSingleLine(PlantGlossaryCsvImportState importState) {
|
47
|
|
48
|
Map<String, String> currentRecord = importState.getCurrentRecord();
|
49
|
|
50
|
String termLabel = currentRecord.get(HEADER_LABEL);
|
51
|
//check if already present
|
52
|
if(importState.isTermPresent(termLabel, getTermService())){
|
53
|
return;
|
54
|
}
|
55
|
|
56
|
State stateTerm = State.NewInstance(currentRecord.get(HEADER_DEFINITION), termLabel, null);
|
57
|
stateTerm.setUri(URI.create(currentRecord.get(HEADER_URI)));
|
58
|
stateTerm.addAnnotation(Annotation.NewInstance(currentRecord.get(HEADER_NOTES), AnnotationType.EDITORIAL(), Language.ENGLISH()));
|
59
|
|
60
|
String vocName = currentRecord.get(HEADER_CATEGORY);
|
61
|
// TODO how should we handle multiple possible categories?
|
62
|
// for now we just take the first one
|
63
|
if(vocName.contains(",")){
|
64
|
vocName = vocName.split(",")[0];
|
65
|
}
|
66
|
TermVocabulary vocabulary = importState.checkVocabularies(vocName, getVocabularyService());
|
67
|
if(vocabulary==null){
|
68
|
logger.error("No vocabulary found for term: "+stateTerm+" with vocName: "+vocName);
|
69
|
return;
|
70
|
}
|
71
|
vocabulary.addTerm(stateTerm);
|
72
|
|
73
|
stateTerm.addSource(IdentifiableSource.NewInstance(OriginalSourceType.Import, importState.getCitation().getTitle(), null, importState.getCitation(), null));
|
74
|
|
75
|
getVocabularyService().saveOrUpdate(vocabulary);
|
76
|
getTermService().saveOrUpdate(stateTerm);
|
77
|
}
|
78
|
|
79
|
}
|