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
;
14 import org
.apache
.logging
.log4j
.LogManager
;
15 import org
.apache
.logging
.log4j
.Logger
;
16 import org
.springframework
.stereotype
.Component
;
18 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
19 import eu
.etaxonomy
.cdm
.common
.URI
;
20 import eu
.etaxonomy
.cdm
.io
.csv
.in
.CsvImportBase
;
21 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
22 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
23 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
24 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
25 import eu
.etaxonomy
.cdm
.model
.description
.State
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceType
;
27 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
28 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
35 public class PlantGlossaryCategoryImport
extends CsvImportBase
<PlantGlossaryCsvImportConfigurator
, PlantGlossaryCsvImportState
, File
>{
37 private static final long serialVersionUID
= -5600766240192189822L;
38 @SuppressWarnings("unused")
39 private static final Logger logger
= LogManager
.getLogger();
42 protected void handleSingleLine(PlantGlossaryCsvImportState importState
) {
43 final String HEADER_LABEL
= "rdfs:label";
44 final String HEADER_DESCRIPTION
= "skos:definition";
45 final String HEADER_URI
= "category_URI";
46 final String HEADER_NOTES
= "skos:notes";
48 Map
<String
, String
> currentRecord
= importState
.getCurrentRecord();
50 String vocName
= currentRecord
.get(HEADER_LABEL
);
51 if(CdmUtils
.isBlank(vocName
)){
52 // this line does not contain any vocabulary information
56 TermVocabulary existingVocabulary
= importState
.checkVocabularies(vocName
, getVocabularyService());
57 if(existingVocabulary
!=null){
61 TermVocabulary
<State
> stateVoc
= TermVocabulary
.NewInstance(
62 TermType
.State
, State
.class,
63 currentRecord
.get(HEADER_DESCRIPTION
),
66 importState
.getCitation().getUri());
67 stateVoc
.setUri(URI
.create(currentRecord
.get(HEADER_URI
)));
68 stateVoc
.addAnnotation(Annotation
.NewInstance(currentRecord
.get(HEADER_NOTES
), AnnotationType
.EDITORIAL(), Language
.ENGLISH()));
70 importState
.addVocabulary(stateVoc
);
72 IdentifiableSource source
= IdentifiableSource
.NewInstance(OriginalSourceType
.Import
, importState
.getCitation().getTitle(), null, importState
.getCitation(), null);
73 source
.setIdInSource(vocName
);
74 stateVoc
.addSource(source
);
76 getVocabularyService().saveOrUpdate(stateVoc
);