1
|
/**
|
2
|
* Copyright (C) 2008 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*/
|
6
|
|
7
|
package eu.etaxonomy.cdm.app.common;
|
8
|
|
9
|
import java.util.ArrayList;
|
10
|
import java.util.GregorianCalendar;
|
11
|
import java.util.List;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.springframework.transaction.TransactionStatus;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.application.CdmApplicationDefaultController;
|
17
|
import eu.etaxonomy.cdm.common.AccountStore;
|
18
|
import eu.etaxonomy.cdm.database.CdmDataSource;
|
19
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
20
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
21
|
import eu.etaxonomy.cdm.io.jaxb.DataSet;
|
22
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
23
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
24
|
import eu.etaxonomy.cdm.model.agent.InstitutionalMembership;
|
25
|
import eu.etaxonomy.cdm.model.agent.Person;
|
26
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
27
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
28
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
29
|
import eu.etaxonomy.cdm.model.common.VersionableEntity;
|
30
|
import eu.etaxonomy.cdm.model.description.Feature;
|
31
|
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
|
32
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
33
|
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
|
34
|
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
|
35
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
36
|
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
|
37
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
38
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
39
|
import eu.etaxonomy.cdm.model.location.Country;
|
40
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
41
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
42
|
import eu.etaxonomy.cdm.model.name.Rank;
|
43
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
44
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
45
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
46
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
47
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
48
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
49
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
50
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
|
51
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
52
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
53
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
54
|
|
55
|
/**
|
56
|
* @author a.babadshanjan
|
57
|
* @created 28.10.2008
|
58
|
*/
|
59
|
public class TestDatabase {
|
60
|
|
61
|
private static final String server = "192.168.2.10";
|
62
|
private static final String username = "edit";
|
63
|
|
64
|
private static final Logger logger = Logger.getLogger(TestDatabase.class);
|
65
|
|
66
|
public static ICdmDataSource CDM_DB(String dbname) {
|
67
|
|
68
|
logger.info("Setting DB " + dbname);
|
69
|
String password = AccountStore.readOrStorePassword(dbname, server, username, null);
|
70
|
ICdmDataSource datasource = CdmDataSource.NewMySqlInstance(server, dbname, username, password, NomenclaturalCode.ICNAFP);
|
71
|
return datasource;
|
72
|
}
|
73
|
|
74
|
public static CdmApplicationDefaultController
|
75
|
initDb(ICdmDataSource db, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading) {
|
76
|
|
77
|
logger.info("Initializing database '" + db.getName() + "'");
|
78
|
|
79
|
CdmApplicationDefaultController appCtrInit = null;
|
80
|
appCtrInit = CdmApplicationDefaultController.NewInstance(db, dbSchemaValidation, omitTermLoading);
|
81
|
|
82
|
return appCtrInit;
|
83
|
}
|
84
|
|
85
|
public static void loadTestData(String dbname, CdmApplicationDefaultController appCtr) {
|
86
|
|
87
|
logger.info("Loading test data into " + dbname);
|
88
|
|
89
|
TransactionStatus txStatus = appCtr.startTransaction();
|
90
|
DataSet dataSet = buildDataSet();
|
91
|
|
92
|
appCtr.getTermService().save(dataSet.getTerms());
|
93
|
appCtr.getTaxonService().save(dataSet.getTaxonBases());
|
94
|
|
95
|
appCtr.commitTransaction(txStatus);
|
96
|
appCtr.close();
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* This method constructs a small sample classification to test JAXB marshaling.
|
101
|
* The sample tree contains four taxa. The root taxon has two children taxa, and
|
102
|
* there is one "free" taxon without a parent and children.
|
103
|
*/
|
104
|
private static DataSet buildDataSet() {
|
105
|
|
106
|
List<AgentBase> agents = new ArrayList<AgentBase>();
|
107
|
List<VersionableEntity> agentData = new ArrayList<VersionableEntity>();
|
108
|
//List<Agent> agentData = new ArrayList<Agent>();
|
109
|
|
110
|
//List<TermBase> terms = new ArrayList<TermBase>();
|
111
|
List<DefinedTermBase> terms = new ArrayList<DefinedTermBase>();
|
112
|
List<Reference> references = new ArrayList<Reference>();
|
113
|
List<TaxonNameBase> taxonomicNames = new ArrayList<TaxonNameBase>();
|
114
|
List<TaxonBase> taxonBases = new ArrayList<TaxonBase>();
|
115
|
|
116
|
List<Feature> features = new ArrayList<Feature>();
|
117
|
|
118
|
Feature feature1 = Feature.BIOLOGY_ECOLOGY();
|
119
|
|
120
|
TaxonNameDescription taxNameDescription = TaxonNameDescription.NewInstance();
|
121
|
// taxNameDescription.addFeature(feature1); //was removed from model in 3.3
|
122
|
QuantitativeData element = QuantitativeData.NewInstance();
|
123
|
StatisticalMeasurementValue statisticalValue = StatisticalMeasurementValue.NewInstance();
|
124
|
statisticalValue.setType(StatisticalMeasure.MAX());
|
125
|
statisticalValue.setValue((float) 2.1);
|
126
|
element.addStatisticalValue(statisticalValue);
|
127
|
taxNameDescription.addElement(element);
|
128
|
|
129
|
SpecimenOrObservationBase<?> specimen = DerivedUnit.NewPreservedSpecimenInstance();
|
130
|
|
131
|
specimen.setIndividualCount(12);
|
132
|
|
133
|
|
134
|
Feature featureIndAss = Feature.INDIVIDUALS_ASSOCIATION();
|
135
|
TaxonNameDescription newTaxNameDesc = TaxonNameDescription.NewInstance();
|
136
|
// newTaxNameDesc.addFeature(featureIndAss); //was removed from model in 3.3
|
137
|
IndividualsAssociation indAss = IndividualsAssociation.NewInstance();
|
138
|
indAss.setAssociatedSpecimenOrObservation(specimen);
|
139
|
|
140
|
newTaxNameDesc.addElement(indAss);
|
141
|
|
142
|
|
143
|
|
144
|
|
145
|
// List<Synonym> synonyms = new ArrayList<Synonym>();
|
146
|
List<AnnotatableEntity> homotypicalGroups;
|
147
|
|
148
|
Reference<?> citRef, sec;
|
149
|
BotanicalName name1, name2, name21, nameRoot1, nameFree, synName11, synName12, synName2, synNameFree;
|
150
|
BotanicalName nameRoot2, nameR2_1, nameR2_2;
|
151
|
Taxon child1, child2, child21, root1T, root2T, freeT;
|
152
|
Taxon childR2_1, childR2_2;
|
153
|
TaxonNode child1Node, child2Node, child21Node, root1TNode, root2TNode, freeTNode;
|
154
|
TaxonNode childR2_1Node, childR2_2Node;
|
155
|
Classification taxTree, taxTree2;
|
156
|
Synonym syn11, syn12, syn2, synFree;
|
157
|
Rank rankSpecies, rankSubspecies, rankGenus;
|
158
|
|
159
|
// agents
|
160
|
// - persons, institutions
|
161
|
|
162
|
Person linne = new Person("Carl", "Linne", "L.");
|
163
|
linne.setTitleCache("Linne & Karl", true);
|
164
|
GregorianCalendar birth = new GregorianCalendar(1707, 4, 23);
|
165
|
GregorianCalendar death = new GregorianCalendar(1778, 0, 10);
|
166
|
TimePeriod period = TimePeriod.NewInstance(birth, death);
|
167
|
linne.setLifespan(period);
|
168
|
|
169
|
// Keyword keyword = Keyword.NewInstance("plantarum", "lat", "");
|
170
|
// linne.addKeyword(keyword);
|
171
|
|
172
|
Institution institute = Institution.NewInstance();
|
173
|
|
174
|
agents.add(linne);
|
175
|
agents.add(institute);
|
176
|
|
177
|
// agent data
|
178
|
// - contacts, addresses, memberships
|
179
|
|
180
|
//Contact contact1 = new Contact();
|
181
|
//contact1.setEmail("someone@somewhere.org");
|
182
|
InstitutionalMembership membership
|
183
|
= new InstitutionalMembership(institute, linne, period, "Biodiversity", "Head");
|
184
|
//agentData.add(contact1);
|
185
|
|
186
|
agentData.add(membership);
|
187
|
|
188
|
// terms
|
189
|
// - ranks, keywords
|
190
|
|
191
|
rankSpecies = Rank.SPECIES();
|
192
|
rankSubspecies = Rank.SUBSPECIES();
|
193
|
rankGenus = Rank.GENUS();
|
194
|
|
195
|
// terms.add(keyword);
|
196
|
|
197
|
// taxonomic names
|
198
|
|
199
|
nameRoot1 = BotanicalName.NewInstance(rankGenus,"Calendula",null,null,null,linne,null,"p.100", null);
|
200
|
nameRoot1.addDescription(taxNameDescription);
|
201
|
nameRoot1.addDescription(newTaxNameDesc);
|
202
|
name1 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"arvensis",null,linne,null,"p.1", null);
|
203
|
synName11 = BotanicalName.NewInstance(rankSpecies,"Caltha",null,"arvensis",null,linne,null,"p.11", null);
|
204
|
synName12 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"sancta",null,linne,null,"p.12", null);
|
205
|
|
206
|
name2 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"lanzae",null,linne,null,"p.2", null);
|
207
|
synName2 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"echinata",null,linne,null,"p.2", null);
|
208
|
|
209
|
name21 = BotanicalName.NewInstance(rankSubspecies,"Calendula",null,"lanzea","something",linne,null,"p.1", null);
|
210
|
//name211 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"lanzea",null,linne,null,"p.1", null);
|
211
|
//name212 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"lanzea",null,linne,null,"p.1", null);
|
212
|
|
213
|
nameRoot2 =
|
214
|
BotanicalName.NewInstance(rankGenus,"Sonchus",null,null,null,linne,null,"p.200", null);
|
215
|
nameR2_1 = BotanicalName.NewInstance(rankSpecies,"Sonchus",null,"child1",null,linne,null,"p.1", null);
|
216
|
nameR2_2 = BotanicalName.NewInstance(rankSpecies,"Sonchus",null,"child2",null,linne,null,"p.2", null);
|
217
|
|
218
|
nameFree = BotanicalName.NewInstance(rankSpecies,"Cichorium",null,"intybus",null,linne,null,"p.200", null);
|
219
|
synNameFree = BotanicalName.NewInstance(rankSpecies,"Cichorium",null,"balearicum",null,linne,null,"p.2", null);
|
220
|
|
221
|
taxonomicNames.add(nameRoot1);
|
222
|
taxonomicNames.add(name1);
|
223
|
taxonomicNames.add(synName11);
|
224
|
taxonomicNames.add(synName12);
|
225
|
taxonomicNames.add(name2);
|
226
|
taxonomicNames.add(name21);
|
227
|
taxonomicNames.add(synName2);
|
228
|
taxonomicNames.add(nameFree);
|
229
|
taxonomicNames.add(synNameFree);
|
230
|
taxonomicNames.add(nameRoot2);
|
231
|
|
232
|
// references
|
233
|
sec = ReferenceFactory.newBook();
|
234
|
sec.setAuthorTeam(linne);
|
235
|
sec.setTitleCache("Plant Specification & Taxonomy", true);
|
236
|
references.add(sec);
|
237
|
|
238
|
citRef = ReferenceFactory.newDatabase();
|
239
|
citRef.setAuthorTeam(linne);
|
240
|
citRef.setTitleCache("BioCASE", true);
|
241
|
references.add(citRef);
|
242
|
|
243
|
// taxa
|
244
|
|
245
|
root1T = Taxon.NewInstance(nameRoot1, sec);
|
246
|
root2T = Taxon.NewInstance(nameRoot2, sec);
|
247
|
freeT = Taxon.NewInstance(nameFree, sec);
|
248
|
child1 = Taxon.NewInstance(name1, sec);
|
249
|
child2 = Taxon.NewInstance(name2, sec);
|
250
|
child21 = Taxon.NewInstance(name21, sec);
|
251
|
childR2_1 = Taxon.NewInstance(nameR2_1, sec);
|
252
|
childR2_2 = Taxon.NewInstance(nameR2_2, sec);
|
253
|
|
254
|
//TaxonInteractions
|
255
|
|
256
|
TaxonInteraction descBase = TaxonInteraction.NewInstance();
|
257
|
descBase.setTaxon2(root1T);
|
258
|
Feature hostplant = Feature.HOSTPLANT();
|
259
|
|
260
|
descBase.setFeature(hostplant);
|
261
|
TaxonDescription taxDesc = TaxonDescription.NewInstance();
|
262
|
taxDesc.addElement(descBase);
|
263
|
root2T.addDescription(taxDesc);
|
264
|
|
265
|
//locations
|
266
|
|
267
|
taxDesc = TaxonDescription.NewInstance();
|
268
|
Feature locationFeature = Feature.DISTRIBUTION();
|
269
|
|
270
|
|
271
|
//locationFeature.
|
272
|
Country area = Country.NewInstance("", "locationTest", null);
|
273
|
area.setType(NamedAreaType.NATURAL_AREA());
|
274
|
|
275
|
//Country woC= Country.NewInstance();
|
276
|
area.addCountry(Country.AFGHANISTAN());
|
277
|
taxDesc.addGeoScope(area);
|
278
|
// taxDesc.addFeature(locationFeature); //was removed from model in 3.3
|
279
|
root1T.addDescription(taxDesc);
|
280
|
|
281
|
|
282
|
// synonyms
|
283
|
|
284
|
synFree = Synonym.NewInstance(synNameFree, sec);
|
285
|
syn11 = Synonym.NewInstance(synName11, sec);
|
286
|
syn12 = Synonym.NewInstance(synName12, sec);
|
287
|
syn2 = Synonym.NewInstance(synName2, sec);
|
288
|
|
289
|
child1.addSynonym(syn11, SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF());
|
290
|
child1.addSynonym(syn12, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
|
291
|
child2.addSynonym(syn2, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
|
292
|
freeT.addSynonym(synFree, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
|
293
|
|
294
|
taxonBases.add(synFree);
|
295
|
taxonBases.add(syn11);
|
296
|
taxonBases.add(syn12);
|
297
|
taxonBases.add(syn2);
|
298
|
|
299
|
// taxonomic children
|
300
|
|
301
|
//TODO: Adapt to classification
|
302
|
taxTree = Classification.NewInstance("TestTree");
|
303
|
|
304
|
root1TNode = taxTree.addChildTaxon(root1T, sec, null);
|
305
|
child1Node = root1TNode.addChildTaxon(child1, null, null);
|
306
|
child2Node = root1TNode.addChildTaxon(child2, null, null);
|
307
|
child21Node = child2Node.addChildTaxon(child21, null, null);
|
308
|
|
309
|
taxTree2 = Classification.NewInstance("TestTree2");
|
310
|
|
311
|
root2TNode = taxTree2.addChildTaxon(root2T, sec, null);
|
312
|
root2TNode.addChildTaxon(child1, sec, "p.1010").setSynonymToBeUsed(syn11);
|
313
|
root2TNode.addChildTaxon(child2, null, null);
|
314
|
|
315
|
/*
|
316
|
root1T.addTaxonomicChild(child1, sec, "p.1010");
|
317
|
root1T.addTaxonomicChild(child2, sec, "p.1020");
|
318
|
child2.addTaxonomicChild(child21, sec, "p.2000");
|
319
|
|
320
|
root2T.addTaxonomicChild(child1, sec, "p.1010");
|
321
|
root2T.addTaxonomicChild(child2, sec, "p.1020");
|
322
|
*/
|
323
|
//
|
324
|
|
325
|
|
326
|
taxonBases.add(root1T);
|
327
|
taxonBases.add(root2T);
|
328
|
taxonBases.add(freeT);
|
329
|
taxonBases.add(child1);
|
330
|
taxonBases.add(child2);
|
331
|
taxonBases.add(child21);
|
332
|
taxonBases.add(childR2_1);
|
333
|
taxonBases.add(childR2_2);
|
334
|
|
335
|
DataSet dataSet = new DataSet();
|
336
|
|
337
|
logger.warn("WARNING: TestDatabase has been commented in parts. Mainly, must be adapted to classification.");
|
338
|
|
339
|
dataSet.setTerms(terms);
|
340
|
dataSet.setAgents(agents);
|
341
|
// dataSet.setAgentData(agentData); //TODO
|
342
|
dataSet.setReferences(references);
|
343
|
dataSet.setTaxonomicNames(taxonomicNames);
|
344
|
dataSet.setTaxonBases(taxonBases);
|
345
|
|
346
|
|
347
|
return dataSet;
|
348
|
|
349
|
}
|
350
|
}
|