1
|
/**
|
2
|
* Copyright (C) 2009 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.api.service;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
import static org.junit.Assert.assertNotNull;
|
13
|
|
14
|
import java.io.FileNotFoundException;
|
15
|
import java.util.List;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.apache.log4j.Level;
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.junit.Assert;
|
21
|
import org.junit.Before;
|
22
|
import org.junit.Test;
|
23
|
import org.unitils.dbunit.annotation.DataSet;
|
24
|
import org.unitils.spring.annotation.SpringBeanByType;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
|
27
|
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
|
28
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
29
|
import eu.etaxonomy.cdm.api.service.search.ICdmMassIndexer;
|
30
|
import eu.etaxonomy.cdm.common.UTF8;
|
31
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
32
|
import eu.etaxonomy.cdm.model.common.Language;
|
33
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
34
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
35
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
36
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
37
|
import eu.etaxonomy.cdm.model.description.TextData;
|
38
|
import eu.etaxonomy.cdm.model.location.Country;
|
39
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
40
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
41
|
import eu.etaxonomy.cdm.model.name.Rank;
|
42
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
43
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
44
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
45
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
46
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
47
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
48
|
import eu.etaxonomy.cdm.model.taxon.SynonymType;
|
49
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
50
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
51
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
52
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
53
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
54
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
55
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
56
|
|
57
|
/**
|
58
|
* @author a.kohlbecker
|
59
|
* @since 04.02.2009
|
60
|
*/
|
61
|
public class TaxonServiceSearchTaxaAndNamesTest extends CdmTransactionalIntegrationTest {
|
62
|
|
63
|
private static Logger logger = Logger.getLogger(TaxonServiceSearchTaxaAndNamesTest.class);
|
64
|
|
65
|
private static final String ABIES_BALSAMEA_UUID = "f65d47bd-4f49-4ab1-bc4a-bc4551eaa1a8";
|
66
|
|
67
|
private static final String ABIES_ALBA_UUID = "7dbd5810-a3e5-44b6-b563-25152b8867f4";
|
68
|
|
69
|
private static final String CLASSIFICATION_UUID = "2a5ceebb-4830-4524-b330-78461bf8cb6b";
|
70
|
|
71
|
private static final String CLASSIFICATION_ALT_UUID = "d7c741e3-ae9e-4a7d-a566-9e3a7a0b51ce";
|
72
|
|
73
|
private static final String D_ABIES_BALSAMEA_UUID = "900108d8-e6ce-495e-b32e-7aad3099135e";
|
74
|
|
75
|
private static final String D_ABIES_ALBA_UUID = "ec8bba03-d993-4c85-8472-18b14942464b";
|
76
|
|
77
|
// private static final String D_ABIES_KAWAKAMII_SEC_KOMAROV_UUID = "e9d8c2fd-6409-46d5-9c2e-14a2bbb1b2b1";
|
78
|
|
79
|
@SpringBeanByType
|
80
|
private ITaxonService taxonService;
|
81
|
@SpringBeanByType
|
82
|
private ITermService termService;
|
83
|
@SpringBeanByType
|
84
|
private IClassificationService classificationService;
|
85
|
@SpringBeanByType
|
86
|
private IReferenceService referenceService;
|
87
|
@SpringBeanByType
|
88
|
private IDescriptionService descriptionService;
|
89
|
@SpringBeanByType
|
90
|
private INameService nameService;
|
91
|
@SpringBeanByType
|
92
|
private ICdmMassIndexer indexer;
|
93
|
|
94
|
@SpringBeanByType
|
95
|
private ITaxonNodeService nodeService;
|
96
|
|
97
|
private NamedArea germany;
|
98
|
private NamedArea russia ;
|
99
|
private NamedArea canada ;
|
100
|
|
101
|
@Before
|
102
|
public void setUp() throws Exception {
|
103
|
|
104
|
germany = Country.GERMANY();
|
105
|
russia = Country.RUSSIANFEDERATION();
|
106
|
canada = Country.CANADA();
|
107
|
}
|
108
|
|
109
|
@Test
|
110
|
public void testDbUnitUsageTest() throws Exception {
|
111
|
|
112
|
assertNotNull("taxonService should exist", taxonService);
|
113
|
assertNotNull("nameService should exist", nameService);
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* This test permutes through all search mode combinations.
|
118
|
*
|
119
|
* 7 Accepted Taxa
|
120
|
* 1 Synonym
|
121
|
* 1 misapplied which is also in the set of accepted
|
122
|
* 2 Names without taxa
|
123
|
*
|
124
|
*/
|
125
|
@Test
|
126
|
@DataSet
|
127
|
public final void testFindTaxaAndNames() {
|
128
|
|
129
|
IFindTaxaAndNamesConfigurator conf = FindTaxaAndNamesConfiguratorImpl.NewInstance();
|
130
|
conf.setTitleSearchString("Abies*");
|
131
|
conf.setMatchMode(MatchMode.BEGINNING);
|
132
|
|
133
|
// ---------------------------------------------------------
|
134
|
|
135
|
setTaxaAndNamesModes(conf, true, true, true, true, true);
|
136
|
@SuppressWarnings("rawtypes")
|
137
|
Pager<IdentifiableEntity> pager = taxonService.findTaxaAndNames(conf);
|
138
|
logSearchResults(pager, Level.DEBUG);
|
139
|
assertEquals(10, pager.getRecords().size());
|
140
|
|
141
|
setTaxaAndNamesModes(conf, false, true, true, true, true);
|
142
|
pager = taxonService.findTaxaAndNames(conf);
|
143
|
assertEquals(4, pager.getRecords().size());
|
144
|
|
145
|
setTaxaAndNamesModes(conf, true, false, true, true, true);
|
146
|
pager = taxonService.findTaxaAndNames(conf);
|
147
|
assertEquals(9, pager.getRecords().size());
|
148
|
|
149
|
setTaxaAndNamesModes(conf, false, false, true, true, true);
|
150
|
pager = taxonService.findTaxaAndNames(conf);
|
151
|
//logSearchResults(pager, Level.DEBUG);
|
152
|
assertEquals(3, pager.getRecords().size());
|
153
|
|
154
|
// ---------------------------------------------------------
|
155
|
|
156
|
setTaxaAndNamesModes(conf, true, true, false, true, true);
|
157
|
pager = taxonService.findTaxaAndNames(conf);
|
158
|
logSearchResults(pager, Level.DEBUG);
|
159
|
assertEquals(10, pager.getRecords().size());
|
160
|
|
161
|
setTaxaAndNamesModes(conf, false, true, false, true, true);
|
162
|
pager = taxonService.findTaxaAndNames(conf);
|
163
|
assertEquals("one synonym, two names without taxa and a misapplied name", 4, pager.getRecords().size());
|
164
|
|
165
|
setTaxaAndNamesModes(conf, true, false, false, true, true);
|
166
|
pager = taxonService.findTaxaAndNames(conf);
|
167
|
assertEquals(9, pager.getRecords().size());
|
168
|
|
169
|
setTaxaAndNamesModes(conf, false, false, false, true, true);
|
170
|
pager = taxonService.findTaxaAndNames(conf);
|
171
|
assertEquals(3, pager.getRecords().size());
|
172
|
|
173
|
// =========================================================
|
174
|
|
175
|
setTaxaAndNamesModes(conf, true, true, true, false, true);
|
176
|
pager = taxonService.findTaxaAndNames(conf);
|
177
|
// logSearchResults(pager, Level.DEBUG);
|
178
|
assertEquals(10, pager.getRecords().size());
|
179
|
|
180
|
setTaxaAndNamesModes(conf, false, true, true, false, true);
|
181
|
pager = taxonService.findTaxaAndNames(conf);
|
182
|
logSearchResults(pager, Level.DEBUG);
|
183
|
assertEquals(3, pager.getRecords().size());
|
184
|
|
185
|
setTaxaAndNamesModes(conf, true, false, true, false, true);
|
186
|
pager = taxonService.findTaxaAndNames(conf);
|
187
|
logSearchResults(pager, Level.DEBUG);
|
188
|
assertEquals(9, pager.getRecords().size());
|
189
|
|
190
|
setTaxaAndNamesModes(conf, false, false, true, false, true);
|
191
|
pager = taxonService.findTaxaAndNames(conf);
|
192
|
logSearchResults(pager, Level.DEBUG);
|
193
|
assertEquals(2, pager.getRecords().size());
|
194
|
|
195
|
// ---------------------------------------------------------
|
196
|
|
197
|
setTaxaAndNamesModes(conf, true, true, false, false, true);
|
198
|
pager = taxonService.findTaxaAndNames(conf);
|
199
|
logSearchResults(pager, Level.DEBUG);
|
200
|
assertEquals(10, pager.getRecords().size());
|
201
|
|
202
|
setTaxaAndNamesModes(conf, false, true, false, false, true);
|
203
|
pager = taxonService.findTaxaAndNames(conf);
|
204
|
logSearchResults(pager, Level.DEBUG);
|
205
|
assertEquals(3, pager.getRecords().size());
|
206
|
|
207
|
setTaxaAndNamesModes(conf, true, false, false, false, true);
|
208
|
pager = taxonService.findTaxaAndNames(conf);
|
209
|
logSearchResults(pager, Level.DEBUG);
|
210
|
assertEquals(9, pager.getRecords().size());
|
211
|
|
212
|
// only names without taxa
|
213
|
// - Abies borisii-regis
|
214
|
// - Abies lasio
|
215
|
setTaxaAndNamesModes(conf, false, false, false, false, true);
|
216
|
pager = taxonService.findTaxaAndNames(conf);
|
217
|
logSearchResults(pager, Level.DEBUG);
|
218
|
assertEquals(2, pager.getRecords().size());
|
219
|
|
220
|
// =========================================================
|
221
|
|
222
|
setTaxaAndNamesModes(conf, true, true, true, true, false);
|
223
|
pager = taxonService.findTaxaAndNames(conf);
|
224
|
logSearchResults(pager, Level.DEBUG);
|
225
|
assertEquals(8, pager.getRecords().size());
|
226
|
|
227
|
setTaxaAndNamesModes(conf, false, true, true, true, false);
|
228
|
pager = taxonService.findTaxaAndNames(conf);
|
229
|
logSearchResults(pager, Level.DEBUG);
|
230
|
assertEquals("one synonym and a misapplied name", 2, pager.getRecords().size());
|
231
|
|
232
|
setTaxaAndNamesModes(conf, true, false, true, true, false);
|
233
|
pager = taxonService.findTaxaAndNames(conf);
|
234
|
logSearchResults(pager, Level.DEBUG);
|
235
|
assertEquals(7, pager.getRecords().size());
|
236
|
|
237
|
setTaxaAndNamesModes(conf, false, false, true, true, false);
|
238
|
pager = taxonService.findTaxaAndNames(conf);
|
239
|
logSearchResults(pager, Level.DEBUG);
|
240
|
assertEquals(1, pager.getRecords().size());
|
241
|
|
242
|
// ---------------------------------------------------------
|
243
|
|
244
|
setTaxaAndNamesModes(conf, true, true, false, true, false);
|
245
|
pager = taxonService.findTaxaAndNames(conf);
|
246
|
logSearchResults(pager, Level.DEBUG);
|
247
|
assertEquals(8, pager.getRecords().size());
|
248
|
|
249
|
setTaxaAndNamesModes(conf, false, true, false, true, false);
|
250
|
pager = taxonService.findTaxaAndNames(conf);
|
251
|
logSearchResults(pager, Level.DEBUG);
|
252
|
assertEquals(2, pager.getRecords().size());
|
253
|
|
254
|
setTaxaAndNamesModes(conf, true, false, false, true, false);
|
255
|
pager = taxonService.findTaxaAndNames(conf);
|
256
|
logSearchResults(pager, Level.DEBUG);
|
257
|
assertEquals(7, pager.getRecords().size());
|
258
|
|
259
|
// only misapplied names
|
260
|
// - Abies kawakamii sec. Komarov, V. L., Flora SSSR 29
|
261
|
setTaxaAndNamesModes(conf, false, false, false, true, false);
|
262
|
pager = taxonService.findTaxaAndNames(conf);
|
263
|
logSearchResults(pager, Level.DEBUG);
|
264
|
assertEquals(1, pager.getRecords().size());
|
265
|
|
266
|
// =========================================================
|
267
|
|
268
|
setTaxaAndNamesModes(conf, true, true, true, false, false);
|
269
|
pager = taxonService.findTaxaAndNames(conf);
|
270
|
logSearchResults(pager, Level.DEBUG);
|
271
|
assertEquals(8, pager.getRecords().size());
|
272
|
|
273
|
|
274
|
setTaxaAndNamesModes(conf, false, true, true, false, false);
|
275
|
pager = taxonService.findTaxaAndNames(conf);
|
276
|
logSearchResults(pager, Level.DEBUG);
|
277
|
assertEquals(1, pager.getRecords().size());
|
278
|
|
279
|
setTaxaAndNamesModes(conf, true, false, true, false, false);
|
280
|
pager = taxonService.findTaxaAndNames(conf);
|
281
|
logSearchResults(pager, Level.DEBUG);
|
282
|
assertEquals(7, pager.getRecords().size());
|
283
|
|
284
|
setTaxaAndNamesModes(conf, false, false, true, false, false);
|
285
|
pager = taxonService.findTaxaAndNames(conf);
|
286
|
logSearchResults(pager, Level.DEBUG);
|
287
|
assertEquals(0, pager.getRecords().size());
|
288
|
|
289
|
// ---------------------------------------------------------
|
290
|
|
291
|
setTaxaAndNamesModes(conf, true, true, false, false, false);
|
292
|
pager = taxonService.findTaxaAndNames(conf);
|
293
|
logSearchResults(pager, Level.DEBUG);
|
294
|
assertEquals(8, pager.getRecords().size());
|
295
|
|
296
|
setTaxaAndNamesModes(conf, false, true, false, false, false);
|
297
|
pager = taxonService.findTaxaAndNames(conf);
|
298
|
logSearchResults(pager, Level.DEBUG);
|
299
|
assertEquals(1, pager.getRecords().size());
|
300
|
|
301
|
setTaxaAndNamesModes(conf, true, false, false, false, false);
|
302
|
pager = taxonService.findTaxaAndNames(conf);
|
303
|
logSearchResults(pager, Level.DEBUG);
|
304
|
assertEquals(7, pager.getRecords().size());
|
305
|
|
306
|
setTaxaAndNamesModes(conf, false, false, false, false, false);
|
307
|
pager = taxonService.findTaxaAndNames(conf);
|
308
|
logSearchResults(pager, Level.DEBUG);
|
309
|
assertEquals(0, pager.getRecords().size());
|
310
|
}
|
311
|
|
312
|
/**
|
313
|
* This test permutes through all search mode combinations with classification filter
|
314
|
*
|
315
|
* 1 accepted taxon
|
316
|
* 1 Synonym
|
317
|
* 1 misapplied
|
318
|
* 2 names without taxa
|
319
|
*
|
320
|
*/
|
321
|
@Test
|
322
|
@DataSet
|
323
|
public final void testFindTaxaAndNames_with_classification() {
|
324
|
|
325
|
IFindTaxaAndNamesConfigurator conf = FindTaxaAndNamesConfiguratorImpl.NewInstance();
|
326
|
conf.setTitleSearchString("Abies*");
|
327
|
conf.setClassification(classificationService.load(UUID.fromString(CLASSIFICATION_UUID)));
|
328
|
conf.setMatchMode(MatchMode.BEGINNING);
|
329
|
|
330
|
// ---------------------------------------------------------
|
331
|
|
332
|
setTaxaAndNamesModes(conf, true, true, true, true, true);
|
333
|
@SuppressWarnings("rawtypes")
|
334
|
Pager<IdentifiableEntity> pager = taxonService.findTaxaAndNames(conf);
|
335
|
logSearchResults(pager, Level.DEBUG);
|
336
|
assertEquals(5, pager.getRecords().size());
|
337
|
|
338
|
|
339
|
setTaxaAndNamesModes(conf, false, true, true, true, true);
|
340
|
pager = taxonService.findTaxaAndNames(conf);
|
341
|
logSearchResults(pager, Level.DEBUG);
|
342
|
assertEquals(4, pager.getRecords().size());
|
343
|
|
344
|
setTaxaAndNamesModes(conf, true, false, true, true, true);
|
345
|
pager = taxonService.findTaxaAndNames(conf);
|
346
|
assertEquals(4, pager.getRecords().size());
|
347
|
|
348
|
setTaxaAndNamesModes(conf, false, false, true, true, true);
|
349
|
pager = taxonService.findTaxaAndNames(conf);
|
350
|
//logSearchResults(pager, Level.DEBUG);
|
351
|
assertEquals(3, pager.getRecords().size());
|
352
|
|
353
|
// ---------------------------------------------------------
|
354
|
|
355
|
setTaxaAndNamesModes(conf, true, true, false, true, true);
|
356
|
pager = taxonService.findTaxaAndNames(conf);
|
357
|
assertEquals(5, pager.getRecords().size());
|
358
|
|
359
|
setTaxaAndNamesModes(conf, false, true, false, true, true);
|
360
|
pager = taxonService.findTaxaAndNames(conf);
|
361
|
assertEquals(4, pager.getRecords().size());
|
362
|
|
363
|
setTaxaAndNamesModes(conf, true, false, false, true, true);
|
364
|
pager = taxonService.findTaxaAndNames(conf);
|
365
|
assertEquals(4, pager.getRecords().size());
|
366
|
|
367
|
setTaxaAndNamesModes(conf, false, false, false, true, true);
|
368
|
pager = taxonService.findTaxaAndNames(conf);
|
369
|
assertEquals(3, pager.getRecords().size());
|
370
|
|
371
|
// =========================================================
|
372
|
|
373
|
setTaxaAndNamesModes(conf, true, true, true, false, true);
|
374
|
pager = taxonService.findTaxaAndNames(conf);
|
375
|
// logSearchResults(pager, Level.DEBUG);
|
376
|
assertEquals(4, pager.getRecords().size());
|
377
|
|
378
|
|
379
|
setTaxaAndNamesModes(conf, false, true, true, false, true);
|
380
|
pager = taxonService.findTaxaAndNames(conf);
|
381
|
logSearchResults(pager, Level.DEBUG);
|
382
|
assertEquals(3, pager.getRecords().size());
|
383
|
|
384
|
setTaxaAndNamesModes(conf, true, false, true, false, true);
|
385
|
pager = taxonService.findTaxaAndNames(conf);
|
386
|
logSearchResults(pager, Level.DEBUG);
|
387
|
assertEquals(3, pager.getRecords().size());
|
388
|
|
389
|
setTaxaAndNamesModes(conf, false, false, true, false, true);
|
390
|
pager = taxonService.findTaxaAndNames(conf);
|
391
|
logSearchResults(pager, Level.DEBUG);
|
392
|
assertEquals(2, pager.getRecords().size());
|
393
|
|
394
|
// ---------------------------------------------------------
|
395
|
|
396
|
setTaxaAndNamesModes(conf, true, true, false, false, true);
|
397
|
pager = taxonService.findTaxaAndNames(conf);
|
398
|
logSearchResults(pager, Level.DEBUG);
|
399
|
assertEquals(4, pager.getRecords().size());
|
400
|
|
401
|
setTaxaAndNamesModes(conf, false, true, false, false, true);
|
402
|
pager = taxonService.findTaxaAndNames(conf);
|
403
|
logSearchResults(pager, Level.DEBUG);
|
404
|
assertEquals(3, pager.getRecords().size());
|
405
|
|
406
|
setTaxaAndNamesModes(conf, true, false, false, false, true);
|
407
|
pager = taxonService.findTaxaAndNames(conf);
|
408
|
logSearchResults(pager, Level.DEBUG);
|
409
|
assertEquals(3, pager.getRecords().size());
|
410
|
|
411
|
// only names without taxa
|
412
|
// - Abies borisii-regis
|
413
|
// - Abies lasio
|
414
|
setTaxaAndNamesModes(conf, false, false, false, false, true);
|
415
|
pager = taxonService.findTaxaAndNames(conf);
|
416
|
logSearchResults(pager, Level.DEBUG);
|
417
|
assertEquals(2, pager.getRecords().size());
|
418
|
|
419
|
// =========================================================
|
420
|
|
421
|
setTaxaAndNamesModes(conf, true, true, true, true, false);
|
422
|
pager = taxonService.findTaxaAndNames(conf);
|
423
|
logSearchResults(pager, Level.DEBUG);
|
424
|
assertEquals(3, pager.getRecords().size());
|
425
|
|
426
|
|
427
|
setTaxaAndNamesModes(conf, false, true, true, true, false);
|
428
|
pager = taxonService.findTaxaAndNames(conf);
|
429
|
logSearchResults(pager, Level.DEBUG);
|
430
|
assertEquals(2, pager.getRecords().size());
|
431
|
|
432
|
setTaxaAndNamesModes(conf, true, false, true, true, false);
|
433
|
pager = taxonService.findTaxaAndNames(conf);
|
434
|
logSearchResults(pager, Level.DEBUG);
|
435
|
assertEquals(2, pager.getRecords().size());
|
436
|
|
437
|
setTaxaAndNamesModes(conf, false, false, true, true, false);
|
438
|
pager = taxonService.findTaxaAndNames(conf);
|
439
|
logSearchResults(pager, Level.DEBUG);
|
440
|
assertEquals(1, pager.getRecords().size());
|
441
|
|
442
|
// ---------------------------------------------------------
|
443
|
|
444
|
setTaxaAndNamesModes(conf, true, true, false, true, false);
|
445
|
pager = taxonService.findTaxaAndNames(conf);
|
446
|
logSearchResults(pager, Level.DEBUG);
|
447
|
assertEquals(3, pager.getRecords().size());
|
448
|
|
449
|
setTaxaAndNamesModes(conf, false, true, false, true, false);
|
450
|
pager = taxonService.findTaxaAndNames(conf);
|
451
|
logSearchResults(pager, Level.DEBUG);
|
452
|
assertEquals(2, pager.getRecords().size());
|
453
|
|
454
|
setTaxaAndNamesModes(conf, true, false, false, true, false);
|
455
|
pager = taxonService.findTaxaAndNames(conf);
|
456
|
logSearchResults(pager, Level.DEBUG);
|
457
|
assertEquals(2, pager.getRecords().size());
|
458
|
|
459
|
// only misapplied names
|
460
|
// - Abies kawakamii sec. Komarov, V. L., Flora SSSR 29
|
461
|
setTaxaAndNamesModes(conf, false, false, false, true, false);
|
462
|
pager = taxonService.findTaxaAndNames(conf);
|
463
|
logSearchResults(pager, Level.DEBUG);
|
464
|
assertEquals(1, pager.getRecords().size());
|
465
|
|
466
|
// =========================================================
|
467
|
|
468
|
setTaxaAndNamesModes(conf, true, true, true, false, false);
|
469
|
pager = taxonService.findTaxaAndNames(conf);
|
470
|
logSearchResults(pager, Level.DEBUG);
|
471
|
assertEquals(2, pager.getRecords().size());
|
472
|
|
473
|
|
474
|
setTaxaAndNamesModes(conf, false, true, true, false, false);
|
475
|
pager = taxonService.findTaxaAndNames(conf);
|
476
|
logSearchResults(pager, Level.DEBUG);
|
477
|
assertEquals(1, pager.getRecords().size());
|
478
|
|
479
|
setTaxaAndNamesModes(conf, true, false, true, false, false);
|
480
|
pager = taxonService.findTaxaAndNames(conf);
|
481
|
logSearchResults(pager, Level.DEBUG);
|
482
|
assertEquals(1, pager.getRecords().size());
|
483
|
|
484
|
setTaxaAndNamesModes(conf, false, false, true, false, false);
|
485
|
pager = taxonService.findTaxaAndNames(conf);
|
486
|
logSearchResults(pager, Level.DEBUG);
|
487
|
assertEquals(0, pager.getRecords().size());
|
488
|
|
489
|
// ---------------------------------------------------------
|
490
|
|
491
|
setTaxaAndNamesModes(conf, true, true, false, false, false);
|
492
|
pager = taxonService.findTaxaAndNames(conf);
|
493
|
logSearchResults(pager, Level.DEBUG);
|
494
|
assertEquals(2, pager.getRecords().size());
|
495
|
|
496
|
setTaxaAndNamesModes(conf, false, true, false, false, false);
|
497
|
pager = taxonService.findTaxaAndNames(conf);
|
498
|
logSearchResults(pager, Level.DEBUG);
|
499
|
assertEquals(1, pager.getRecords().size());
|
500
|
|
501
|
setTaxaAndNamesModes(conf, true, false, false, false, false);
|
502
|
pager = taxonService.findTaxaAndNames(conf);
|
503
|
logSearchResults(pager, Level.DEBUG);
|
504
|
assertEquals(1, pager.getRecords().size());
|
505
|
|
506
|
setTaxaAndNamesModes(conf, false, false, false, false, false);
|
507
|
pager = taxonService.findTaxaAndNames(conf);
|
508
|
logSearchResults(pager, Level.DEBUG);
|
509
|
assertEquals(0, pager.getRecords().size());
|
510
|
}
|
511
|
|
512
|
@Test
|
513
|
@DataSet
|
514
|
public final void testFindTaxaAndNames_CommonName() {
|
515
|
// pass 1
|
516
|
IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
|
517
|
configurator.setMatchMode(MatchMode.BEGINNING);
|
518
|
configurator.setDoTaxa(true);
|
519
|
configurator.setDoSynonyms(true);
|
520
|
configurator.setDoNamesWithoutTaxa(true);
|
521
|
configurator.setDoTaxaByCommonNames(true);
|
522
|
configurator.setTitleSearchString("Balsam-Tanne");
|
523
|
|
524
|
@SuppressWarnings("rawtypes")
|
525
|
Pager<IdentifiableEntity> pager = taxonService.findTaxaAndNames(configurator);
|
526
|
|
527
|
@SuppressWarnings("rawtypes")
|
528
|
List<IdentifiableEntity> list = pager.getRecords();
|
529
|
assertEquals(1, list.size());
|
530
|
configurator.setTitleSearchString("Abies*");
|
531
|
configurator.setDoTaxa(false);
|
532
|
configurator.setDoSynonyms(false);
|
533
|
configurator.setDoNamesWithoutTaxa(false);
|
534
|
configurator.setDoTaxaByCommonNames(true);
|
535
|
configurator.setDoMisappliedNames(true);
|
536
|
configurator.setClassification(classificationService.load(UUID.fromString(CLASSIFICATION_UUID)));
|
537
|
pager = taxonService.findTaxaAndNames(configurator);
|
538
|
list = pager.getRecords();
|
539
|
assertEquals(1, list.size());
|
540
|
|
541
|
}
|
542
|
|
543
|
@Test
|
544
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
545
|
public final void testFindTaxaAndNamesWithHybridFormula() {
|
546
|
|
547
|
// pass 1
|
548
|
IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
|
549
|
configurator.setTitleSearchString("Achillea*");
|
550
|
configurator.setMatchMode(MatchMode.BEGINNING);
|
551
|
configurator.setDoTaxa(true);
|
552
|
configurator.setDoSynonyms(true);
|
553
|
configurator.setDoNamesWithoutTaxa(true);
|
554
|
configurator.setDoTaxaByCommonNames(true);
|
555
|
|
556
|
@SuppressWarnings("rawtypes")
|
557
|
Pager<IdentifiableEntity> pager = taxonService.findTaxaAndNames(configurator);
|
558
|
// Assert.assertEquals("Expecting one taxon",1,pager.getRecords().size());
|
559
|
|
560
|
}
|
561
|
|
562
|
/**
|
563
|
* Test method for
|
564
|
* {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#searchByName(java.lang.String, eu.etaxonomy.cdm.model.reference.Reference)}
|
565
|
* .
|
566
|
*/
|
567
|
@Test
|
568
|
@DataSet
|
569
|
public final void testfindTaxaAndNamesForEditor() {
|
570
|
IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
|
571
|
configurator.setTitleSearchString("Abies bor*");
|
572
|
configurator.setMatchMode(MatchMode.BEGINNING);
|
573
|
configurator.setDoTaxa(true);
|
574
|
configurator.setDoSynonyms(false);
|
575
|
configurator.setDoNamesWithoutTaxa(true);
|
576
|
configurator.setDoTaxaByCommonNames(false);
|
577
|
|
578
|
@SuppressWarnings("rawtypes")
|
579
|
List<UuidAndTitleCache<? extends IdentifiableEntity>> list = taxonService.findTaxaAndNamesForEditor(configurator);
|
580
|
|
581
|
Assert.assertEquals("Expecting one entity", 1, list.size());
|
582
|
|
583
|
configurator.setTitleSearchString("silver fir");
|
584
|
configurator.setMatchMode(MatchMode.BEGINNING);
|
585
|
configurator.setDoTaxa(false);
|
586
|
configurator.setDoSynonyms(false);
|
587
|
configurator.setDoNamesWithoutTaxa(true);
|
588
|
configurator.setDoTaxaByCommonNames(true);
|
589
|
|
590
|
list = taxonService.findTaxaAndNamesForEditor(configurator);
|
591
|
|
592
|
Assert.assertEquals("Expecting one entity", 1, list.size());
|
593
|
|
594
|
}
|
595
|
|
596
|
|
597
|
/**
|
598
|
*
|
599
|
* @param conf
|
600
|
* @param doTaxa
|
601
|
* @param doSynonyms
|
602
|
* @param doCommonNames
|
603
|
* @param doMisappliedNames
|
604
|
* @param doNamesWithoutTaxa
|
605
|
* @return
|
606
|
*/
|
607
|
protected IFindTaxaAndNamesConfigurator setTaxaAndNamesModes(
|
608
|
IFindTaxaAndNamesConfigurator conf,
|
609
|
boolean doTaxa,
|
610
|
boolean doSynonyms,
|
611
|
boolean doCommonNames,
|
612
|
boolean doMisappliedNames,
|
613
|
boolean doNamesWithoutTaxa){
|
614
|
|
615
|
conf.setDoTaxa(doTaxa);
|
616
|
conf.setDoSynonyms(doSynonyms);
|
617
|
conf.setDoTaxaByCommonNames(doCommonNames);
|
618
|
conf.setDoMisappliedNames(doMisappliedNames);
|
619
|
conf.setDoNamesWithoutTaxa(doNamesWithoutTaxa);
|
620
|
|
621
|
return conf;
|
622
|
}
|
623
|
|
624
|
/**
|
625
|
* @param pager
|
626
|
*/
|
627
|
protected void logSearchResults(@SuppressWarnings("rawtypes") Pager<IdentifiableEntity> pager, Level level) {
|
628
|
@SuppressWarnings("rawtypes")
|
629
|
List<IdentifiableEntity> list = pager.getRecords();
|
630
|
logger.debug("number of taxa: " + list.size());
|
631
|
|
632
|
if (logger.isDebugEnabled()) {
|
633
|
for (int i = 0; i < list.size(); i++) {
|
634
|
String nameCache = "";
|
635
|
if (list.get(i) instanceof TaxonName) {
|
636
|
nameCache = ((TaxonName)list.get(i)).getNameCache();
|
637
|
} else if (list.get(i) instanceof TaxonBase) {
|
638
|
TaxonName taxonName = ((TaxonBase<?>) list.get(i)).getName();
|
639
|
nameCache = taxonName.getNameCache();
|
640
|
} else {
|
641
|
}
|
642
|
logger.log(level, list.get(i).getClass() + "(" + i + ")" + ": Name Cache = " + nameCache + ", Title Cache = "
|
643
|
+ list.get(i).getTitleCache());
|
644
|
}
|
645
|
}
|
646
|
}
|
647
|
|
648
|
/**
|
649
|
* uncomment @Test annotation to create the dataset for this test
|
650
|
*/
|
651
|
@Override
|
652
|
// @Test
|
653
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="ClearDBDataSet.xml")
|
654
|
public final void createTestDataSet() throws FileNotFoundException {
|
655
|
|
656
|
Classification europeanAbiesClassification = Classification.NewInstance("European Abies");
|
657
|
europeanAbiesClassification.setUuid(UUID.fromString(CLASSIFICATION_UUID));
|
658
|
classificationService.save(europeanAbiesClassification);
|
659
|
|
660
|
Classification alternativeClassification = Classification.NewInstance("Abies alternative");
|
661
|
alternativeClassification.setUuid(UUID.fromString(CLASSIFICATION_ALT_UUID));
|
662
|
classificationService.save(alternativeClassification);
|
663
|
|
664
|
Reference sec = ReferenceFactory.newBook();
|
665
|
sec.setTitleCache("Kohlbecker, A., Testcase standart views, 2013", true);
|
666
|
Reference sec_sensu = ReferenceFactory.newBook();
|
667
|
sec_sensu.setTitleCache("Komarov, V. L., Flora SSSR 29", true);
|
668
|
referenceService.save(sec);
|
669
|
referenceService.save(sec_sensu);
|
670
|
|
671
|
IBotanicalName n_abies = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
672
|
n_abies.setNameCache("Abies", true);
|
673
|
Taxon t_abies = Taxon.NewInstance(n_abies, sec);
|
674
|
taxonService.save(t_abies);
|
675
|
|
676
|
IBotanicalName n_abies_alba = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
677
|
n_abies_alba.setNameCache("Abies alba", true);
|
678
|
Taxon t_abies_alba = Taxon.NewInstance(n_abies_alba, sec);
|
679
|
t_abies_alba.setUuid(UUID.fromString(ABIES_ALBA_UUID));
|
680
|
taxonService.save(t_abies_alba);
|
681
|
|
682
|
IBotanicalName n_abies_subalpina = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
683
|
n_abies_subalpina.setNameCache("Abies subalpina", true);
|
684
|
Synonym s_abies_subalpina = Synonym.NewInstance(n_abies_subalpina, sec);
|
685
|
taxonService.save(s_abies_subalpina);
|
686
|
|
687
|
IBotanicalName n_abies_balsamea = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
688
|
n_abies_balsamea.setNameCache("Abies balsamea", true);
|
689
|
Taxon t_abies_balsamea = Taxon.NewInstance(n_abies_balsamea, sec);
|
690
|
t_abies_balsamea.setUuid(UUID.fromString(ABIES_BALSAMEA_UUID));
|
691
|
t_abies_balsamea.addSynonym(s_abies_subalpina, SynonymType.SYNONYM_OF());
|
692
|
taxonService.save(t_abies_balsamea);
|
693
|
|
694
|
IBotanicalName n_abies_grandis = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
695
|
n_abies_grandis.setNameCache("Abies grandis", true);
|
696
|
Taxon t_abies_grandis = Taxon.NewInstance(n_abies_grandis, sec);
|
697
|
taxonService.save(t_abies_grandis);
|
698
|
|
699
|
IBotanicalName n_abies_kawakamii = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
700
|
n_abies_kawakamii.setNameCache("Abies kawakamii", true);
|
701
|
Taxon t_abies_kawakamii = Taxon.NewInstance(n_abies_kawakamii, sec);
|
702
|
t_abies_kawakamii.getTitleCache();
|
703
|
taxonService.save(t_abies_kawakamii);
|
704
|
|
705
|
//
|
706
|
// 1 Misapplied Name
|
707
|
//
|
708
|
// abies_kawakamii_sensu_komarov as missapplied name for t_abies_balsamea
|
709
|
Taxon t_abies_kawakamii_sensu_komarov = Taxon.NewInstance(n_abies_kawakamii, sec_sensu);
|
710
|
taxonService.save(t_abies_kawakamii_sensu_komarov);
|
711
|
t_abies_kawakamii_sensu_komarov.addTaxonRelation(t_abies_balsamea, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), null, null);
|
712
|
taxonService.saveOrUpdate(t_abies_kawakamii_sensu_komarov);
|
713
|
|
714
|
IBotanicalName n_abies_lasiocarpa = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
715
|
n_abies_lasiocarpa.setNameCache("Abies lasiocarpa", true);
|
716
|
Taxon t_abies_lasiocarpa = Taxon.NewInstance(n_abies_lasiocarpa, sec);
|
717
|
taxonService.save(t_abies_lasiocarpa);
|
718
|
|
719
|
// add 3 taxa to classifications
|
720
|
europeanAbiesClassification.addChildTaxon(t_abies_balsamea, null, null);
|
721
|
alternativeClassification.addChildTaxon(t_abies_lasiocarpa, null, null);
|
722
|
classificationService.saveOrUpdate(europeanAbiesClassification);
|
723
|
classificationService.saveOrUpdate(alternativeClassification);
|
724
|
|
725
|
//
|
726
|
// 2 Names without taxa
|
727
|
//
|
728
|
TaxonName n_abies_borisiiregis = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
729
|
n_abies_borisiiregis.setNameCache("Abies borisii-regis", true);
|
730
|
nameService.save(n_abies_borisiiregis);
|
731
|
|
732
|
TaxonName n_abies_lasio = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
733
|
n_abies_lasio.setNameCache("Abies lasio", true);
|
734
|
nameService.save(n_abies_lasio);
|
735
|
|
736
|
// A hybrid name not from Abies
|
737
|
IBotanicalName n_abies_millefolium_x_Achillea_nobilis = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
738
|
n_abies_millefolium_x_Achillea_nobilis.setNameCache("Achillea millefolium × Achillea nobilis", true);
|
739
|
Taxon t_abies_millefolium_x_Achillea_nobilis = Taxon.NewInstance(n_abies_millefolium_x_Achillea_nobilis, sec);
|
740
|
taxonService.save(t_abies_millefolium_x_Achillea_nobilis);
|
741
|
|
742
|
//
|
743
|
// Description
|
744
|
//
|
745
|
TaxonDescription d_abies_alba = TaxonDescription.NewInstance(t_abies_alba);
|
746
|
TaxonDescription d_abies_balsamea = TaxonDescription.NewInstance(t_abies_balsamea);
|
747
|
|
748
|
d_abies_alba.setUuid(UUID.fromString(D_ABIES_ALBA_UUID));
|
749
|
d_abies_balsamea.setUuid(UUID.fromString(D_ABIES_BALSAMEA_UUID));
|
750
|
|
751
|
|
752
|
// CommonTaxonName
|
753
|
d_abies_alba.addElement(CommonTaxonName.NewInstance("Wei"+UTF8.SHARP_S+"tanne", Language.GERMAN()));
|
754
|
d_abies_alba.addElement(CommonTaxonName.NewInstance("silver fir", Language.ENGLISH()));
|
755
|
d_abies_alba.addElement(Distribution
|
756
|
.NewInstance(
|
757
|
germany,
|
758
|
PresenceAbsenceTerm.NATIVE()));
|
759
|
d_abies_alba.addElement(Distribution
|
760
|
.NewInstance(
|
761
|
russia,
|
762
|
PresenceAbsenceTerm.ABSENT()));
|
763
|
|
764
|
// TextData
|
765
|
d_abies_balsamea
|
766
|
.addElement(TextData
|
767
|
.NewInstance(
|
768
|
"Die Balsam-Tanne (Abies balsamea) ist eine Pflanzenart aus der Gattung der Tannen (Abies). Sie wächst im nordöstlichen Nordamerika, wo sie sowohl Tief- als auch Bergland besiedelt. Sie gilt als relativ anspruchslos gegenüber dem Standort und ist frosthart. In vielen Teilen des natürlichen Verbreitungsgebietes stellt sie die Klimaxbaumart dar.",
|
769
|
Language.GERMAN(), null));
|
770
|
d_abies_balsamea
|
771
|
.addElement(CommonTaxonName
|
772
|
.NewInstance(
|
773
|
"Balsam-Tanne",
|
774
|
Language.GERMAN(), null));
|
775
|
|
776
|
d_abies_balsamea
|
777
|
.addElement(Distribution
|
778
|
.NewInstance(
|
779
|
canada,
|
780
|
PresenceAbsenceTerm.PRESENT()));
|
781
|
|
782
|
d_abies_balsamea
|
783
|
.addElement(Distribution
|
784
|
.NewInstance(
|
785
|
germany,
|
786
|
PresenceAbsenceTerm.NATIVE()));
|
787
|
|
788
|
d_abies_balsamea
|
789
|
.addElement(TextData
|
790
|
.NewInstance(
|
791
|
TaxonServiceSearchTestUtf8Constants.RUSSIAN_ABIES_ALBA_LONG,
|
792
|
Language.RUSSIAN(), null));
|
793
|
d_abies_balsamea
|
794
|
.addElement(CommonTaxonName
|
795
|
.NewInstance(
|
796
|
TaxonServiceSearchTestUtf8Constants.RUSSIAN_ABIES_ALBA_SHORT,
|
797
|
Language.RUSSIAN(), null));
|
798
|
descriptionService.saveOrUpdate(d_abies_balsamea);
|
799
|
|
800
|
setComplete();
|
801
|
endTransaction();
|
802
|
|
803
|
|
804
|
writeDbUnitDataSetFile(new String[] {
|
805
|
"TAXONBASE", "TAXONNAME",
|
806
|
"TAXONRELATIONSHIP",
|
807
|
"REFERENCE", "DESCRIPTIONELEMENTBASE", "DESCRIPTIONBASE",
|
808
|
"AGENTBASE", "HOMOTYPICALGROUP",
|
809
|
"CLASSIFICATION", "TAXONNODE",
|
810
|
"LANGUAGESTRING", "DESCRIPTIONELEMENTBASE_LANGUAGESTRING",
|
811
|
"HIBERNATE_SEQUENCES" // IMPORTANT!!!
|
812
|
});
|
813
|
|
814
|
}
|
815
|
|
816
|
}
|