1
|
package eu.etaxonomy.cdm.model;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.GregorianCalendar;
|
5
|
import java.util.HashSet;
|
6
|
import java.util.List;
|
7
|
import java.util.Set;
|
8
|
|
9
|
import junit.framework.Assert;
|
10
|
|
11
|
import org.junit.Before;
|
12
|
import org.junit.Test;
|
13
|
|
14
|
import eu.etaxonomy.cdm.jaxb.DataSet;
|
15
|
import eu.etaxonomy.cdm.model.agent.Agent;
|
16
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
17
|
import eu.etaxonomy.cdm.model.agent.InstitutionalMembership;
|
18
|
import eu.etaxonomy.cdm.model.agent.Person;
|
19
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
20
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
21
|
import eu.etaxonomy.cdm.model.common.Keyword;
|
22
|
import eu.etaxonomy.cdm.model.common.Language;
|
23
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
24
|
import eu.etaxonomy.cdm.model.common.Representation;
|
25
|
import eu.etaxonomy.cdm.model.common.TermBase;
|
26
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
27
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
28
|
import eu.etaxonomy.cdm.model.common.VersionableEntity;
|
29
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
30
|
import eu.etaxonomy.cdm.model.name.Rank;
|
31
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
32
|
import eu.etaxonomy.cdm.model.reference.Book;
|
33
|
import eu.etaxonomy.cdm.model.reference.Database;
|
34
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
35
|
import eu.etaxonomy.cdm.model.reference.StrictReferenceBase;
|
36
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
37
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
|
38
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
39
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
40
|
|
41
|
public class DataSetTest {
|
42
|
|
43
|
private DataSet dataSet;
|
44
|
private List<Agent> agents;
|
45
|
private List<VersionableEntity> agentData;
|
46
|
//private List<TermBase> terms;
|
47
|
private List<DefinedTermBase> terms;
|
48
|
private List<TermVocabulary<DefinedTermBase>> termVocabularies;
|
49
|
private List<ReferenceBase> references;
|
50
|
private List<TaxonNameBase> taxonomicNames;
|
51
|
private List<Taxon> taxa;
|
52
|
private List<Synonym> synonyms;
|
53
|
private List<AnnotatableEntity> homotypicalGroups;
|
54
|
private Set<TaxonRelationship> taxonRelationships;
|
55
|
private Set<RelationshipBase> relationshipBases;
|
56
|
|
57
|
@Before
|
58
|
public void onSetUp() throws Exception {
|
59
|
dataSet = new DataSet();
|
60
|
}
|
61
|
|
62
|
@Test
|
63
|
public void testCdmDocumentBuilderInit() {
|
64
|
Assert.assertNotNull(dataSet);
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* This method constructs a small sample taxonomic tree to test JAXB marshaling.
|
69
|
* The sample tree contains four taxa. The root taxon has two children taxa, and
|
70
|
* there is one "free" taxon without a parent and children.
|
71
|
*/
|
72
|
public void buildData(boolean persistentContext) {
|
73
|
|
74
|
agents = new ArrayList<Agent>();
|
75
|
agentData = new ArrayList<VersionableEntity>();
|
76
|
//terms = new ArrayList<TermBase>();
|
77
|
terms = new ArrayList<DefinedTermBase>();
|
78
|
termVocabularies = new ArrayList<TermVocabulary<DefinedTermBase>>();
|
79
|
references = new ArrayList<ReferenceBase>();
|
80
|
taxonomicNames = new ArrayList<TaxonNameBase>();
|
81
|
taxa = new ArrayList<Taxon>();
|
82
|
synonyms = new ArrayList<Synonym>();
|
83
|
taxonRelationships = new HashSet();
|
84
|
|
85
|
StrictReferenceBase citRef, sec;
|
86
|
BotanicalName name1, name2, nameRoot, nameFree, synName11, synName12, synName2, synNameFree;
|
87
|
Taxon child1, child2, rootT, freeT;
|
88
|
Synonym syn11, syn12, syn2, synFree;
|
89
|
Rank rankSpecies, rankSubspecies, rankGenus;
|
90
|
|
91
|
// agents
|
92
|
// - persons, institutions
|
93
|
|
94
|
Person linne = new Person("Carl", "Linné", "L.");
|
95
|
GregorianCalendar birth = new GregorianCalendar(1707, 4, 23);
|
96
|
GregorianCalendar death = new GregorianCalendar(1778, 0, 10);
|
97
|
TimePeriod period = new TimePeriod(birth, death);
|
98
|
linne.setLifespan(period);
|
99
|
|
100
|
Language lang = Language.ENGLISH();
|
101
|
TermVocabulary termvoc = new TermVocabulary();
|
102
|
lang.setVocabulary(termvoc);
|
103
|
Keyword keyword = Keyword.NewInstance("plantarum", lang.getLabel(), "");
|
104
|
Representation rep = keyword.getRepresentation(lang);
|
105
|
rep.setLanguage(lang);
|
106
|
|
107
|
linne.addKeyword(keyword);
|
108
|
|
109
|
Institution institute = Institution.NewInstance();
|
110
|
|
111
|
agents.add(linne);
|
112
|
agents.add(institute);
|
113
|
|
114
|
// agent data
|
115
|
// - contacts, addresses, memberships
|
116
|
|
117
|
//Contact contact1 = new Contact();
|
118
|
//contact1.setEmail("someone@somewhere.org");
|
119
|
InstitutionalMembership membership
|
120
|
= new InstitutionalMembership(institute, linne, period, "Biodiversity", "Head");
|
121
|
//agentData.add(contact1);
|
122
|
|
123
|
agentData.add(membership);
|
124
|
|
125
|
// terms
|
126
|
// - ranks, keywords
|
127
|
|
128
|
if (persistentContext == true) {
|
129
|
|
130
|
rankSpecies = Rank.SPECIES();
|
131
|
rankSubspecies = Rank.SUBSPECIES();
|
132
|
rankGenus = Rank.GENUS();
|
133
|
|
134
|
} else {
|
135
|
rankSpecies = new Rank ();
|
136
|
rankSubspecies = new Rank();
|
137
|
rankGenus = new Rank();
|
138
|
}
|
139
|
|
140
|
// Do something like this? If yes, FIXME: Stack overflow.
|
141
|
// try {
|
142
|
// rankSpecies = Rank.getRankByName("Species");
|
143
|
// rankSubspecies = Rank.getRankByName("Subspecies");
|
144
|
// rankGenus = Rank.getRankByName("Genus");
|
145
|
//
|
146
|
// } catch (UnknownCdmTypeException ex) {
|
147
|
// ex.printStackTrace();
|
148
|
// }
|
149
|
|
150
|
terms.add(rankSpecies);
|
151
|
terms.add(rankSubspecies);
|
152
|
terms.add(rankGenus);
|
153
|
terms.add(lang);
|
154
|
|
155
|
terms.add(keyword);
|
156
|
|
157
|
termVocabularies.add(termvoc);
|
158
|
|
159
|
// taxonomic names
|
160
|
|
161
|
nameRoot = BotanicalName.NewInstance(rankGenus,"Calendula",null,null,null,linne,null,"p.100", null);
|
162
|
|
163
|
name1 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"arvensis",null,linne,null,"p.1", null);
|
164
|
synName11 = BotanicalName.NewInstance(rankSpecies,"Caltha",null,"arvensis",null,linne,null,"p.11", null);
|
165
|
synName12 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"sancta",null,linne,null,"p.12", null);
|
166
|
|
167
|
name2 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"lanzae",null,linne,null,"p.2", null);
|
168
|
synName2 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"echinata",null,linne,null,"p.2", null);
|
169
|
|
170
|
nameFree = BotanicalName.NewInstance(rankSpecies,"Cichorium",null,"intybus",null,linne,null,"p.200", null);
|
171
|
synNameFree = BotanicalName.NewInstance(rankSpecies,"Cichorium",null,"balearicum",null,linne,null,"p.2", null);
|
172
|
|
173
|
taxonomicNames.add(nameRoot);
|
174
|
taxonomicNames.add(name1);
|
175
|
taxonomicNames.add(synName11);
|
176
|
taxonomicNames.add(synName12);
|
177
|
taxonomicNames.add(name2);
|
178
|
taxonomicNames.add(synName2);
|
179
|
taxonomicNames.add(nameFree);
|
180
|
taxonomicNames.add(synNameFree);
|
181
|
|
182
|
// references
|
183
|
|
184
|
sec = Book.NewInstance();
|
185
|
sec.setAuthorTeam(linne);
|
186
|
sec.setTitleCache("Plant Speciation");
|
187
|
references.add(sec);
|
188
|
|
189
|
citRef = Database.NewInstance();
|
190
|
citRef.setAuthorTeam(linne);
|
191
|
citRef.setTitleCache("BioCASE");
|
192
|
references.add(citRef);
|
193
|
|
194
|
// taxa
|
195
|
|
196
|
rootT = Taxon.NewInstance(nameRoot, sec);
|
197
|
freeT = Taxon.NewInstance(nameFree, sec);
|
198
|
child1 = Taxon.NewInstance(name1, sec);
|
199
|
child2 = Taxon.NewInstance(name2, sec);
|
200
|
|
201
|
// synonyms
|
202
|
|
203
|
synFree = Synonym.NewInstance(synNameFree, sec);
|
204
|
syn11 = Synonym.NewInstance(synName11, sec);
|
205
|
syn12 = Synonym.NewInstance(synName12, sec);
|
206
|
syn2 = Synonym.NewInstance(synName2, sec);
|
207
|
|
208
|
child1.addSynonym(syn11, SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF());
|
209
|
child1.addSynonym(syn12, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
|
210
|
child2.addSynonym(syn2, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
|
211
|
freeT.addSynonym(synFree, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
|
212
|
|
213
|
synonyms.add(synFree);
|
214
|
synonyms.add(syn11);
|
215
|
synonyms.add(syn12);
|
216
|
synonyms.add(syn2);
|
217
|
|
218
|
// relationships
|
219
|
|
220
|
|
221
|
// taxonomic children
|
222
|
|
223
|
rootT.addTaxonomicChild(child1, sec, "p.998");
|
224
|
rootT.addTaxonomicChild(child2, sec, "p.987");
|
225
|
|
226
|
taxa.add(rootT);
|
227
|
taxa.add(freeT);
|
228
|
taxa.add(child1);
|
229
|
taxa.add(child2);
|
230
|
|
231
|
// List<Taxon> taxa;
|
232
|
// Object obj = (Object)taxa;
|
233
|
// Collection<TaxonBase> taxonBases = (Collection<TaxonBase>)obj;
|
234
|
|
235
|
// Set<TaxonRelationship> taxonRelationships;
|
236
|
taxonRelationships = rootT.getTaxonRelations();
|
237
|
Object obj = taxonRelationships;
|
238
|
relationshipBases = (Set<RelationshipBase>)obj;
|
239
|
|
240
|
}
|
241
|
|
242
|
public DataSet buildDataSet(boolean persistentContext) {
|
243
|
|
244
|
buildData(persistentContext);
|
245
|
|
246
|
dataSet.setAgents(agents);
|
247
|
dataSet.setAgentData(agentData);
|
248
|
dataSet.setTerms(terms);
|
249
|
dataSet.setTermVocabularies(termVocabularies);
|
250
|
dataSet.setReferences(references);
|
251
|
dataSet.setTaxonomicNames(taxonomicNames);
|
252
|
dataSet.setTaxa(taxa);
|
253
|
dataSet.setSynonyms(synonyms);
|
254
|
dataSet.setRelationships(relationshipBases);
|
255
|
|
256
|
return dataSet;
|
257
|
}
|
258
|
|
259
|
public DataSet buildDataSet(DataSet dataSet, boolean persistentContext) {
|
260
|
|
261
|
buildData(persistentContext);
|
262
|
|
263
|
dataSet.setAgents(agents);
|
264
|
dataSet.setAgentData(agentData);
|
265
|
dataSet.setTerms(terms);
|
266
|
dataSet.setTermVocabularies(termVocabularies);
|
267
|
dataSet.setReferences(references);
|
268
|
dataSet.setTaxonomicNames(taxonomicNames);
|
269
|
dataSet.setTaxa(taxa);
|
270
|
dataSet.setSynonyms(synonyms);
|
271
|
|
272
|
return dataSet;
|
273
|
}
|
274
|
}
|