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
;
13 import java
.util
.UUID
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.springframework
.stereotype
.Component
;
18 import eu
.etaxonomy
.cdm
.io
.csv
.in
.CsvImportBase
;
19 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
20 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
21 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
22 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
23 import eu
.etaxonomy
.cdm
.model
.description
.State
;
32 public class PlantGlossaryCsvImport
extends CsvImportBase
<PlantGlossaryCsvImportConfigurator
, PlantGlossaryCsvImportState
, File
>{
33 private static final long serialVersionUID
= -5600766240192189822L;
34 private static Logger logger
= Logger
.getLogger(PlantGlossaryCsvImport
.class);
38 protected void handleSingleLine(PlantGlossaryCsvImportState importState
) {
39 final String TERM_HEADER
= "term";
40 final String CATEGORY_HEADER
= "category";
41 final String HAS_SYN_HEADER
= "hasSyn";
42 final String SOURCE_HEADER
= "sourceDataset";
43 final String TERM_ID_HEADER
= "termID";
44 final String REMARK_HEADER
= "remarks";
46 Map
<String
, String
> currentRecord
= importState
.getCurrentRecord();
47 if(!currentRecord
.get(REMARK_HEADER
).equals("active")){
48 String message
= String
.format(
49 "Line %s has obsolete data and was skipped", importState
.getLine());
54 State stateTerm
= State
.NewInstance(null, currentRecord
.get(TERM_HEADER
), null);
55 stateTerm
.setUuid(UUID
.fromString(currentRecord
.get(TERM_ID_HEADER
)));
57 String vocName
= currentRecord
.get(CATEGORY_HEADER
);
58 TermVocabulary vocabulary
= importState
.checkVocabularies(vocName
);
60 vocabulary
= TermVocabulary
.NewInstance(TermType
.State
, null, vocName
, null, null);
61 importState
.addVocabulary(vocabulary
);
63 vocabulary
.addTerm(stateTerm
);
66 stateTerm
.addSource(IdentifiableSource
.NewInstance(OriginalSourceType
.Import
, importState
.getCitation().getTitle(), null, importState
.getCitation(), null));
68 getVocabularyService().saveOrUpdate(vocabulary
);
69 getTermService().saveOrUpdate(stateTerm
);