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.net.URI;
|
12
|
import java.net.URISyntaxException;
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.List;
|
16
|
import java.util.Set;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
19
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
20
|
import eu.etaxonomy.cdm.io.csv.in.CsvImportState;
|
21
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
22
|
import eu.etaxonomy.cdm.model.agent.Person;
|
23
|
import eu.etaxonomy.cdm.model.agent.Team;
|
24
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
25
|
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
|
26
|
import eu.etaxonomy.cdm.model.common.TermType;
|
27
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
28
|
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
|
29
|
import eu.etaxonomy.cdm.model.description.Feature;
|
30
|
import eu.etaxonomy.cdm.model.description.State;
|
31
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
32
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
33
|
|
34
|
/**
|
35
|
*
|
36
|
* @author pplitzner
|
37
|
* @since Dec 7, 2018
|
38
|
*
|
39
|
*/
|
40
|
public class PlantGlossaryCsvImportState extends CsvImportState<PlantGlossaryCsvImportConfigurator> {
|
41
|
|
42
|
private TermVocabulary<Feature> propertyVoc;
|
43
|
private List<TermVocabulary> existingVocabularies = new ArrayList<>();
|
44
|
private List<State> existingTerms = new ArrayList<>();
|
45
|
private Set<TermVocabulary> vocabularies = new HashSet<>();
|
46
|
private final Reference citation;
|
47
|
|
48
|
|
49
|
protected PlantGlossaryCsvImportState(PlantGlossaryCsvImportConfigurator config) {
|
50
|
super(config);
|
51
|
citation = ReferenceFactory.newGeneric();
|
52
|
citation.setTitle("FloraTerms");
|
53
|
Team team = Team.NewInstance();
|
54
|
team.addTeamMember(Person.NewInstance(null, "Cui", null, "Hong"));
|
55
|
team.addTeamMember(Person.NewInstance(null, "Cole", null, "Heather"));
|
56
|
team.addTeamMember(Person.NewInstance(null, "Endara", null, "Lorena"));
|
57
|
team.addTeamMember(Person.NewInstance(null, "Macklin", null, "James"));
|
58
|
team.addTeamMember(Person.NewInstance(null, "Sachs", null, "Joel"));
|
59
|
citation.setAuthorship(team);
|
60
|
VerbatimTimePeriod datePublished = VerbatimTimePeriod.NewVerbatimInstance();
|
61
|
datePublished.setStartYear(2014);
|
62
|
datePublished.setStartMonth(6);
|
63
|
datePublished.setStartDay(13);
|
64
|
citation.setDatePublished(datePublished);
|
65
|
Institution institution = Institution.NewNamedInstance("OTO System");
|
66
|
institution.addUrl(URI.create("http://biosemantics.arizona.edu/OTO/"));
|
67
|
citation.setInstitution(institution);
|
68
|
URI uri;
|
69
|
try {
|
70
|
uri = new URI("https://terms.tdwg.org/wiki/FloraTerms");
|
71
|
citation.setUri(uri);
|
72
|
} catch (URISyntaxException e) {
|
73
|
}
|
74
|
|
75
|
propertyVoc = TermVocabulary.NewInstance(TermType.Feature, Feature.class);
|
76
|
propertyVoc.setLabel("Plant Glossary Properties");
|
77
|
propertyVoc.addSource(IdentifiableSource.NewInstance(OriginalSourceType.Import, citation.getTitle(), null, citation, null));
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public void resetSession(){
|
82
|
super.resetSession();
|
83
|
}
|
84
|
|
85
|
public TermVocabulary<Feature> getPropertyVoc() {
|
86
|
return propertyVoc;
|
87
|
}
|
88
|
|
89
|
void addVocabulary(TermVocabulary vocabulary) {
|
90
|
vocabularies.add(vocabulary);
|
91
|
}
|
92
|
|
93
|
TermVocabulary checkVocabularies(String vocName, IVocabularyService vocabularyService){
|
94
|
if(existingVocabularies.isEmpty()){
|
95
|
existingVocabularies = vocabularyService.list(TermVocabulary.class, null, null, null, null);
|
96
|
}
|
97
|
for (TermVocabulary termVocabulary : vocabularies) {
|
98
|
if(termVocabulary.getLabel().equals(vocName)){
|
99
|
return termVocabulary;
|
100
|
}
|
101
|
}
|
102
|
return null;
|
103
|
}
|
104
|
|
105
|
public boolean isTermPresent(String termName, ITermService termService) {
|
106
|
if(existingTerms.isEmpty()){
|
107
|
existingTerms = termService.list(State.class, null, null, null, null);
|
108
|
}
|
109
|
return existingTerms.stream().map(term->term.getLabel()).anyMatch(label->label.equals(termName));
|
110
|
}
|
111
|
|
112
|
Reference getCitation() {
|
113
|
return citation;
|
114
|
}
|
115
|
|
116
|
}
|