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.kew;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
|
14
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
15
|
import eu.etaxonomy.cdm.io.csv.in.CsvImportState;
|
16
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
17
|
import eu.etaxonomy.cdm.model.agent.Person;
|
18
|
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
|
19
|
import eu.etaxonomy.cdm.model.description.Feature;
|
20
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
21
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
22
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
23
|
import eu.etaxonomy.cdm.model.term.TermType;
|
24
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
25
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
26
|
|
27
|
/**
|
28
|
*
|
29
|
* @author pplitzner
|
30
|
* @since Jan 25, 2019
|
31
|
*
|
32
|
*/
|
33
|
public class KewPlantGlossaryCsvImportState extends CsvImportState<KewPlantGlossaryCsvImportConfigurator> {
|
34
|
|
35
|
private List<TermVocabulary> existingVocabularies = new ArrayList<>();
|
36
|
private List<UuidAndTitleCache<DefinedTermBase>> existingTerms = new ArrayList<>();
|
37
|
private final Reference citation;
|
38
|
private final TermVocabulary<Feature> structureVoc;
|
39
|
|
40
|
|
41
|
protected KewPlantGlossaryCsvImportState(KewPlantGlossaryCsvImportConfigurator config) {
|
42
|
super(config);
|
43
|
structureVoc = TermVocabulary.NewInstance(TermType.Feature);
|
44
|
structureVoc.setLabel("Structures");
|
45
|
|
46
|
citation = ReferenceFactory.newBook();
|
47
|
citation.setTitle("The Kew Plant Glossary, an illustrated dictionary of plant terms");
|
48
|
citation.setAuthorship(Person.NewInstance(null, "J. Beentje", null, "Henk"));
|
49
|
VerbatimTimePeriod datePublished = VerbatimTimePeriod.NewVerbatimInstance();
|
50
|
datePublished.setStartYear(2010);
|
51
|
citation.setDatePublished(datePublished);
|
52
|
Institution institution = Institution.NewNamedInstance("Royal Botanic Gardens, Kew");
|
53
|
citation.setInstitution(institution);
|
54
|
citation.setIsbn("978-1-84246-422-9");
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public void resetSession(){
|
59
|
super.resetSession();
|
60
|
}
|
61
|
|
62
|
public boolean isTermPresent(String termName, ITermService termService) {
|
63
|
if(existingTerms.isEmpty()){
|
64
|
existingTerms = termService.getUuidAndTitleCache(null, "*");
|
65
|
}
|
66
|
return existingTerms.stream().anyMatch(term->term.getTitleCache().equals(termName));
|
67
|
}
|
68
|
|
69
|
TermVocabulary<Feature> getStructureVoc() {
|
70
|
return structureVoc;
|
71
|
}
|
72
|
|
73
|
Reference getCitation() {
|
74
|
return citation;
|
75
|
}
|
76
|
|
77
|
}
|