adapt app-import to v5.45
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / io / plantglossary / PlantGlossaryCategoryImport.java
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.util.Map;
13
14 import org.apache.logging.log4j.LogManager;
15 import org.apache.logging.log4j.Logger;
16 import org.springframework.stereotype.Component;
17
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;
29
30 /**
31 * @author pplitzner
32 * @since Dec 7, 2018
33 */
34 @Component
35 public class PlantGlossaryCategoryImport extends CsvImportBase<PlantGlossaryCsvImportConfigurator, PlantGlossaryCsvImportState, File>{
36
37 private static final long serialVersionUID = -5600766240192189822L;
38 @SuppressWarnings("unused")
39 private static final Logger logger = LogManager.getLogger();
40
41 @Override
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";
47
48 Map<String, String> currentRecord = importState.getCurrentRecord();
49
50 String vocName = currentRecord.get(HEADER_LABEL);
51 if(CdmUtils.isBlank(vocName)){
52 // this line does not contain any vocabulary information
53 return;
54 }
55
56 TermVocabulary existingVocabulary = importState.checkVocabularies(vocName, getVocabularyService());
57 if(existingVocabulary!=null){
58 return;
59 }
60
61 TermVocabulary<State> stateVoc = TermVocabulary.NewInstance(
62 TermType.State, State.class,
63 currentRecord.get(HEADER_DESCRIPTION),
64 vocName,
65 null,
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()));
69
70 importState.addVocabulary(stateVoc);
71
72 IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Import, importState.getCitation().getTitle(), null, importState.getCitation(), null);
73 source.setIdInSource(vocName);
74 stateVoc.addSource(source);
75
76 getVocabularyService().saveOrUpdate(stateVoc);
77 }
78
79 }