cleanup some ERMS imports
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / io / plantglossary / PlantGlossaryCsvImport.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 import java.util.UUID;
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.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;
24
25 /**
26 *
27 * @author pplitzner
28 * @since Dec 7, 2018
29 *
30 */
31 @Component
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);
35
36
37 @Override
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";
45
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());
50 logger.info(message);
51 return;
52 }
53
54 State stateTerm = State.NewInstance(null, currentRecord.get(TERM_HEADER), null);
55 stateTerm.setUuid(UUID.fromString(currentRecord.get(TERM_ID_HEADER)));
56
57 String vocName = currentRecord.get(CATEGORY_HEADER);
58 TermVocabulary vocabulary = importState.checkVocabularies(vocName);
59 if(vocabulary==null){
60 vocabulary = TermVocabulary.NewInstance(TermType.State, null, vocName, null, null);
61 importState.addVocabulary(vocabulary);
62 }
63 vocabulary.addTerm(stateTerm);
64
65
66 stateTerm.addSource(IdentifiableSource.NewInstance(OriginalSourceType.Import, importState.getCitation().getTitle(), null, importState.getCitation(), null));
67
68 getVocabularyService().saveOrUpdate(vocabulary);
69 getTermService().saveOrUpdate(stateTerm);
70 }
71
72 }