2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.io
.plantglossary
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.springframework
.stereotype
.Component
;
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
.common
.TermType
;
26 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
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);
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";
46 Map
<String
, String
> currentRecord
= importState
.getCurrentRecord();
48 String vocName
= currentRecord
.get(HEADER_LABEL
);
49 if(CdmUtils
.isBlank(vocName
)){
50 // this line does not contain any vocabulary information
54 TermVocabulary existingVocabulary
= importState
.checkVocabularies(vocName
, getVocabularyService());
55 if(existingVocabulary
!=null){
59 TermVocabulary
<?
> stateVoc
= TermVocabulary
.NewInstance(
61 currentRecord
.get(HEADER_DESCRIPTION
),
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()));
68 importState
.addVocabulary(stateVoc
);
70 stateVoc
.addSource(IdentifiableSource
.NewInstance(OriginalSourceType
.Import
, importState
.getCitation().getTitle(), null, importState
.getCitation(), null));
72 getVocabularyService().saveOrUpdate(stateVoc
);