1
|
package eu.etaxonomy.cdm.persistence.dao.hibernate.statistics;
|
2
|
|
3
|
import static org.junit.Assert.assertTrue;
|
4
|
|
5
|
import java.io.FileNotFoundException;
|
6
|
import java.util.ArrayList;
|
7
|
import java.util.Arrays;
|
8
|
import java.util.Collections;
|
9
|
import java.util.HashMap;
|
10
|
import java.util.List;
|
11
|
import java.util.Map;
|
12
|
import java.util.Random;
|
13
|
import java.util.Set;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.commons.lang.RandomStringUtils;
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.junit.After;
|
19
|
import org.junit.Before;
|
20
|
import org.junit.Test;
|
21
|
import org.unitils.spring.annotation.SpringBeanByType;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.common.Language;
|
24
|
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
|
25
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
26
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
27
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
28
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
29
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
30
|
import eu.etaxonomy.cdm.model.description.TextData;
|
31
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
32
|
import eu.etaxonomy.cdm.model.name.Rank;
|
33
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
34
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
35
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
36
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
37
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
38
|
import eu.etaxonomy.cdm.model.taxon.SynonymType;
|
39
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
40
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
41
|
import eu.etaxonomy.cdm.model.view.context.AuditEventContextHolder;
|
42
|
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao;
|
43
|
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionElementDao;
|
44
|
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
|
45
|
import eu.etaxonomy.cdm.persistence.dao.statistics.IStatisticsDao;
|
46
|
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;
|
47
|
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
|
48
|
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao;
|
49
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
50
|
|
51
|
public class StatisticsDaoHibernateImplTest
|
52
|
extends CdmTransactionalIntegrationTest {
|
53
|
|
54
|
@SuppressWarnings("unused")
|
55
|
private static final Logger logger = Logger.getLogger(StatisticsDaoHibernateImplTest.class);
|
56
|
|
57
|
private static final boolean PRINTOUT = true;
|
58
|
|
59
|
@SpringBeanByType
|
60
|
private IStatisticsDao statisticsDao;
|
61
|
|
62
|
private UUID nodeUuid;
|
63
|
|
64
|
private List<Classification> classifications;
|
65
|
|
66
|
|
67
|
|
68
|
// choose a number
|
69
|
private static final int NO_OF_ACCEPTED_TAXA = 10;
|
70
|
|
71
|
// choose a number (less than NO_OF_ACCEPTED_TAXA)
|
72
|
private static final int NO_OF_CLASSIFICATIONS = 3;
|
73
|
|
74
|
// must be less or equal to NO_OF_ACCEPTED_TAXA
|
75
|
private static final int NO_OF_SYNONYMS = 7;
|
76
|
|
77
|
// taxa that occure in several classifications:
|
78
|
// must NOT be more than NO_OF_ACCEPTED_TAXA
|
79
|
private static final int NO_OF_SHARED_TAXA = 4;
|
80
|
|
81
|
// must be NO_OF_ACCEPTED_TAXA + NO_OF_SYNONYMS
|
82
|
private static final int NO_OF_ALLTAXA = NO_OF_ACCEPTED_TAXA
|
83
|
+ NO_OF_SYNONYMS;
|
84
|
|
85
|
// must be NO_OF_ACCEPTED_TAXA+NO_OF_SYNONYMS
|
86
|
private static final int NO_OF_TAXON_NAMES = NO_OF_ACCEPTED_TAXA
|
87
|
+ NO_OF_SYNONYMS;
|
88
|
|
89
|
// this represents an approx. no of the amount that will actually generated!
|
90
|
private static final int NO_OF_DESCRIPTIVE_SOURCE_REFERENCES = 16;
|
91
|
|
92
|
// private static final int NO_OF_ALL_REFERENCES = NO_OF_ACCEPTED_TAXA + 0;
|
93
|
|
94
|
// must not be more than NO_OF_ACCEPTED_TAXA+NO_OF_SYNONYMS
|
95
|
private static final int NO_OF_NOMENCLATURAL_REFERENCES = NO_OF_ACCEPTED_TAXA
|
96
|
+ NO_OF_SYNONYMS - 4;
|
97
|
|
98
|
// --------------------variables for all ------------------
|
99
|
|
100
|
private Long no_of_all_references = new Long(0);
|
101
|
private Long no_of_descriptive_source_references = new Long(0);
|
102
|
|
103
|
// ............................................
|
104
|
|
105
|
// log the type enum to an int constant:
|
106
|
private Map<String, Long> typeMap_ALL;
|
107
|
|
108
|
// ------------------ variables for CLASSIFICATIONS -----------------------
|
109
|
|
110
|
// int[] anArray = new int[NO_OF_CLASSIFICATIONS];
|
111
|
private static List<Long> no_of_all_taxa_c = new ArrayList<Long>(
|
112
|
Collections.nCopies(NO_OF_CLASSIFICATIONS, new Long(0)));
|
113
|
private static List<Long> no_of_accepted_taxa_c = new ArrayList<Long>(
|
114
|
Collections.nCopies(NO_OF_CLASSIFICATIONS, new Long(0)));
|
115
|
private static List<Long> no_of_synonyms_c = new ArrayList<Long>(
|
116
|
Collections.nCopies(NO_OF_CLASSIFICATIONS, new Long(0)));
|
117
|
private static List<Long> no_of_taxon_names_c = new ArrayList<Long>(
|
118
|
Collections.nCopies(NO_OF_CLASSIFICATIONS, new Long(0)));
|
119
|
private static List<Long> no_of_descriptive_source_references_c = new ArrayList<Long>(
|
120
|
Collections.nCopies(NO_OF_CLASSIFICATIONS, new Long(0)));
|
121
|
private static List<Long> no_of_all_references_c = new ArrayList<Long>(
|
122
|
Collections.nCopies(NO_OF_CLASSIFICATIONS, new Long(0)));
|
123
|
private static List<Long> no_of_nomenclatural_references_c = new ArrayList<Long>(
|
124
|
Collections.nCopies(NO_OF_CLASSIFICATIONS, new Long(0)));
|
125
|
// we do not count classifications in classifications
|
126
|
|
127
|
// ........................... constant map ..........................
|
128
|
|
129
|
private static final Map<String, List<Long>> typeCountMap_CLASSIFICATION = new HashMap<String, List<Long>>() {
|
130
|
{
|
131
|
put("CLASSIFICATION",
|
132
|
new ArrayList<Long>(Arrays.asList((Long) null, null, null)));
|
133
|
put("ALL_TAXA", no_of_all_taxa_c);
|
134
|
put("ACCEPTED_TAXA", no_of_accepted_taxa_c);
|
135
|
put("SYNONYMS", no_of_synonyms_c);
|
136
|
put("TAXON_NAMES", no_of_taxon_names_c);
|
137
|
put("DESCRIPTIVE_SOURCE_REFERENCES",
|
138
|
no_of_descriptive_source_references_c);
|
139
|
put("ALL_REFERENCES", no_of_all_references_c);
|
140
|
put("NOMENCLATURAL_REFERENCES", no_of_nomenclatural_references_c);
|
141
|
}
|
142
|
};
|
143
|
|
144
|
// ****************** services: ************************
|
145
|
@SpringBeanByType
|
146
|
private IStatisticsDao service;
|
147
|
@SpringBeanByType
|
148
|
private IClassificationDao classificationDao;
|
149
|
@SpringBeanByType
|
150
|
private ITaxonDao taxonDao;
|
151
|
@SpringBeanByType
|
152
|
private IReferenceDao referenceDao;
|
153
|
@SpringBeanByType
|
154
|
private IDescriptionDao descriptionDao;
|
155
|
@SpringBeanByType
|
156
|
private IDescriptionElementDao descriptionElementDao;
|
157
|
@SpringBeanByType
|
158
|
private ITaxonNodeDao taxonNodeDao;
|
159
|
|
160
|
|
161
|
@Before
|
162
|
public void setUp() {
|
163
|
// nodeUuid =UUID.fromString("46cd7e78-f7d5-4c31-937b-2bc5074618c4");
|
164
|
nodeUuid = UUID.fromString("0b5846e5-b8d2-4ca9-ac51-099286ea4adc");
|
165
|
|
166
|
AuditEventContextHolder.clearContext();
|
167
|
|
168
|
}
|
169
|
|
170
|
@After
|
171
|
public void tearDown() {
|
172
|
AuditEventContextHolder.clearContext();
|
173
|
}
|
174
|
|
175
|
@Test
|
176
|
// @DataSet
|
177
|
public void testGetAllChildNodes() {
|
178
|
List<UUID> result;
|
179
|
createDataSet();
|
180
|
for (Classification classification : classifications) {
|
181
|
TaxonNode root;
|
182
|
root= createTaxTree(classification);
|
183
|
|
184
|
result=statisticsDao.getAllChildNodeIds(root.getUuid());
|
185
|
System.out.println("classification "+ classification.getName()+": ");
|
186
|
System.out.println("result: "+result.toString());
|
187
|
System.out.println("");
|
188
|
}
|
189
|
if (PRINTOUT) {
|
190
|
print();
|
191
|
}
|
192
|
// result=statisticsDao.getAllTaxonIds(nodeUuid);
|
193
|
// statisticsDao.getAllTaxonIds();
|
194
|
assertTrue(true);
|
195
|
// fail("Not yet implemented");
|
196
|
}
|
197
|
|
198
|
private void createDataSet() {
|
199
|
// create NO_OF_CLASSIFICATIONS classifications
|
200
|
classifications = new ArrayList<Classification>();
|
201
|
|
202
|
for (int i = 1; i <= NO_OF_CLASSIFICATIONS; i++) {
|
203
|
Classification classification = Classification
|
204
|
.NewInstance("European Abies" + i);
|
205
|
classifications.add(classification);
|
206
|
classificationDao.save(classification);
|
207
|
}
|
208
|
// create all taxa, references and synonyms and attach them to one or
|
209
|
// more classifications
|
210
|
|
211
|
// variables: flags
|
212
|
int remainder = NO_OF_ACCEPTED_TAXA;
|
213
|
Reference sec = ReferenceFactory.newBook();
|
214
|
boolean secondClassificationForTaxonFlag = false;
|
215
|
boolean synonymFlag = false;
|
216
|
boolean tNomRefFlag = false;
|
217
|
boolean sNomRefFlag = false;
|
218
|
boolean tDescrSourceRefFlag = false;
|
219
|
boolean sDescrSourceRefFlag = false;
|
220
|
|
221
|
// variables: counter (pre-loop)
|
222
|
int descriptiveElementsPerTaxon = (NO_OF_DESCRIPTIVE_SOURCE_REFERENCES / NO_OF_ACCEPTED_TAXA) + 1;
|
223
|
|
224
|
int taxaInClass;
|
225
|
int classiCounter = 0, sharedClassification = 0, synonymCounter = 0, nomRefCounter = 0;
|
226
|
|
227
|
// iterate over classifications and add taxa
|
228
|
for (/* see above */; remainder > 0
|
229
|
&& classiCounter < NO_OF_CLASSIFICATIONS; /* see below */) {
|
230
|
|
231
|
// compute no of taxa to be created in this classification
|
232
|
if (classiCounter >= NO_OF_CLASSIFICATIONS - 1) { // last
|
233
|
// classification
|
234
|
// gets all left
|
235
|
// taxa
|
236
|
taxaInClass = remainder;
|
237
|
} else { // take half of left taxa for this class:
|
238
|
taxaInClass = remainder / 2;
|
239
|
}
|
240
|
|
241
|
// iterate over amount of taxa meant to be in this classification
|
242
|
for (int taxonCounter = 1; taxonCounter <= taxaInClass; taxonCounter++) {
|
243
|
|
244
|
// create a String for the Name
|
245
|
RandomStringUtils.randomAlphabetic(10);
|
246
|
String randomName = RandomStringUtils.randomAlphabetic(5) + " "
|
247
|
+ RandomStringUtils.randomAlphabetic(10);
|
248
|
|
249
|
// create a name for the taxon
|
250
|
BotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
251
|
name.setNameCache(randomName, true);
|
252
|
|
253
|
// create nomenclatural reference for taxon name (if left)
|
254
|
if (nomRefCounter < NO_OF_NOMENCLATURAL_REFERENCES) {
|
255
|
// we remember this taxon has a nomenclatural reference:
|
256
|
tNomRefFlag = true;
|
257
|
Reference nomRef = ReferenceFactory.newBook();
|
258
|
name.setNomenclaturalReference(nomRef);
|
259
|
referenceDao.save(nomRef);
|
260
|
nomRefCounter++;
|
261
|
}
|
262
|
|
263
|
// create a new sec for every other taxon
|
264
|
if (taxonCounter % 2 != 0) {
|
265
|
sec = createSecReference(classiCounter, taxonCounter);
|
266
|
}
|
267
|
|
268
|
// create the taxon
|
269
|
Taxon taxon = Taxon.NewInstance(name, sec);
|
270
|
|
271
|
// create descriptions, description sources and their references
|
272
|
|
273
|
if (no_of_descriptive_source_references < NO_OF_DESCRIPTIVE_SOURCE_REFERENCES) {
|
274
|
|
275
|
tDescrSourceRefFlag = true;
|
276
|
|
277
|
// create a description and 2 description elements with
|
278
|
// references for taxon name
|
279
|
TaxonNameDescription nameDescr = TaxonNameDescription.NewInstance();
|
280
|
CommonTaxonName nameElement = CommonTaxonName.NewInstance(
|
281
|
"Veilchen" + taxonCounter, Language.GERMAN());
|
282
|
TextData textElement = new TextData();
|
283
|
Reference nameElementRef = ReferenceFactory.newArticle();
|
284
|
Reference textElementRef = ReferenceFactory
|
285
|
.newBookSection();
|
286
|
nameElement.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, nameElementRef, "name: ");
|
287
|
textElement.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, textElementRef, "text: ");
|
288
|
nameDescr.addElement(nameElement);
|
289
|
nameDescr.addElement(textElement);
|
290
|
name.addDescription(nameDescr);
|
291
|
// taxon.getName().addDescription(nameDescr);
|
292
|
referenceDao.save(nameElementRef);
|
293
|
referenceDao.save(textElementRef);
|
294
|
descriptionDao.save(nameDescr);
|
295
|
|
296
|
// create descriptions, description sources and their
|
297
|
// references
|
298
|
// for taxon
|
299
|
TaxonDescription taxonDescription = new TaxonDescription();
|
300
|
for (int i = 0; i < descriptiveElementsPerTaxon; i++) {
|
301
|
DescriptionElementBase descriptionElement = new TextData();
|
302
|
DescriptionElementSource descriptionElementSource = DescriptionElementSource
|
303
|
.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
|
304
|
Reference article = ReferenceFactory.newArticle();
|
305
|
|
306
|
descriptionElementSource.setCitation(article);
|
307
|
descriptionElement.addSource(descriptionElementSource);
|
308
|
taxonDescription.addElement(descriptionElement);
|
309
|
referenceDao.save(article);
|
310
|
descriptionElementDao.save(descriptionElement);
|
311
|
|
312
|
}
|
313
|
descriptionDao.save(taxonDescription);
|
314
|
taxon.addDescription(taxonDescription);
|
315
|
|
316
|
// create a Specimen for taxon with description, descr.
|
317
|
// element and referece
|
318
|
//
|
319
|
// Specimen specimen = Specimen.NewInstance();
|
320
|
// SpecimenDescription specimenDescription =
|
321
|
// SpecimenDescription.NewInstance(specimen);
|
322
|
// DescriptionElementBase descrElement = new TextData();
|
323
|
// Reference specimenRef = ReferenceFactory.newArticle();
|
324
|
// descrElement.addSource(null, null, specimenRef, null);
|
325
|
//
|
326
|
//
|
327
|
// descriptionService.save(specimenDescription);
|
328
|
// taxon.add(specimen);
|
329
|
|
330
|
no_of_descriptive_source_references += descriptiveElementsPerTaxon + 2 + 1;
|
331
|
|
332
|
}
|
333
|
|
334
|
// add taxon to classification
|
335
|
classifications.get(classiCounter).addChildTaxon(taxon, null, null);
|
336
|
|
337
|
// now if there are any left, we create a synonym for the taxon
|
338
|
if (synonymCounter < NO_OF_SYNONYMS) {
|
339
|
synonymFlag = true;
|
340
|
randomName = RandomStringUtils.randomAlphabetic(5) + " "
|
341
|
+ RandomStringUtils.randomAlphabetic(10);
|
342
|
// name for synonym
|
343
|
name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
344
|
name.setNameCache(randomName, true);
|
345
|
|
346
|
// create nomenclatural reference for synonym name (if left)
|
347
|
if (nomRefCounter < NO_OF_NOMENCLATURAL_REFERENCES) {
|
348
|
sNomRefFlag = true;
|
349
|
Reference nomRef = ReferenceFactory.newBook();
|
350
|
name.setNomenclaturalReference(nomRef);
|
351
|
referenceDao.save(nomRef);
|
352
|
nomRefCounter++;
|
353
|
}
|
354
|
|
355
|
if (no_of_descriptive_source_references < NO_OF_DESCRIPTIVE_SOURCE_REFERENCES) {
|
356
|
sDescrSourceRefFlag = true;
|
357
|
|
358
|
// create a description and 2 description elements with
|
359
|
// references for synonym name
|
360
|
TaxonNameDescription nameDescr = TaxonNameDescription.NewInstance();
|
361
|
CommonTaxonName nameElement = CommonTaxonName
|
362
|
.NewInstance("anderes Veilchen" + taxonCounter,
|
363
|
Language.GERMAN());
|
364
|
TextData textElement = new TextData();
|
365
|
Reference nameElementRef = ReferenceFactory.newArticle();
|
366
|
Reference textElementRef = ReferenceFactory.newBookSection();
|
367
|
nameElement.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, nameElementRef,"name: ");
|
368
|
textElement.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, textElementRef,"text: ");
|
369
|
nameDescr.addElement(nameElement);
|
370
|
nameDescr.addElement(textElement);
|
371
|
name.addDescription(nameDescr);
|
372
|
// taxon.getName().addDescription(nameDescr);
|
373
|
referenceDao.save(nameElementRef);
|
374
|
referenceDao.save(textElementRef);
|
375
|
descriptionDao.save(nameDescr);
|
376
|
no_of_descriptive_source_references += 2;
|
377
|
}
|
378
|
|
379
|
// create a new reference for every other synonym:
|
380
|
if (taxonCounter % 2 != 0) {
|
381
|
sec = createSecReference(classiCounter, taxonCounter);
|
382
|
}
|
383
|
Synonym synonym = Synonym.NewInstance(name, sec);
|
384
|
taxonDao.save(synonym);
|
385
|
taxon.addSynonym(synonym,
|
386
|
SynonymType.SYNONYM_OF());
|
387
|
|
388
|
synonymCounter++;
|
389
|
}
|
390
|
|
391
|
// if this is not the last classification and there are
|
392
|
// taxa left that should be in more than one classification
|
393
|
// we add the taxon to the next class in the list too.
|
394
|
if (classiCounter < NO_OF_CLASSIFICATIONS
|
395
|
&& sharedClassification < NO_OF_SHARED_TAXA) {
|
396
|
classifications.get(classiCounter + 1).addChildTaxon(taxon, null, null);
|
397
|
|
398
|
// we remember that this taxon is attached to 2
|
399
|
// classifications:
|
400
|
secondClassificationForTaxonFlag = true;
|
401
|
sharedClassification++;
|
402
|
classificationDao.saveOrUpdate(classifications
|
403
|
.get(classiCounter + 1));
|
404
|
}
|
405
|
|
406
|
taxonDao.save(taxon);
|
407
|
classificationDao.saveOrUpdate(classifications
|
408
|
.get(classiCounter));
|
409
|
|
410
|
// count the data created with this taxon:
|
411
|
int c = classiCounter;
|
412
|
|
413
|
if (secondClassificationForTaxonFlag) {
|
414
|
c++;
|
415
|
}
|
416
|
|
417
|
// run the following loop once, if this taxon only belongs to
|
418
|
// one
|
419
|
// classification.
|
420
|
// twice, if it is attached to 2 classifications
|
421
|
for (int i = classiCounter; i <= c; i++) {
|
422
|
|
423
|
// count everything just created for this taxon:
|
424
|
increment(no_of_accepted_taxa_c, i);
|
425
|
increment(no_of_taxon_names_c, i);
|
426
|
if (tNomRefFlag) {
|
427
|
increment(no_of_nomenclatural_references_c, i);
|
428
|
}
|
429
|
if (sNomRefFlag) {
|
430
|
increment(no_of_nomenclatural_references_c, i);
|
431
|
}
|
432
|
if (synonymFlag) {
|
433
|
increment(no_of_synonyms_c, i);
|
434
|
increment(no_of_taxon_names_c, i);
|
435
|
}
|
436
|
if (taxonCounter % 2 != 0) {
|
437
|
increment(no_of_all_references_c, i);
|
438
|
if (synonymFlag) {
|
439
|
increment(no_of_all_references_c, i);
|
440
|
}
|
441
|
}
|
442
|
if (tDescrSourceRefFlag) {
|
443
|
increment(no_of_descriptive_source_references_c, i,
|
444
|
descriptiveElementsPerTaxon + 2);
|
445
|
}
|
446
|
|
447
|
if (sDescrSourceRefFlag) {
|
448
|
increment(no_of_descriptive_source_references_c, i, 2);
|
449
|
}
|
450
|
}
|
451
|
// put flags back:
|
452
|
secondClassificationForTaxonFlag = false;
|
453
|
tNomRefFlag = false;
|
454
|
sNomRefFlag = false;
|
455
|
synonymFlag = false;
|
456
|
tDescrSourceRefFlag = false;
|
457
|
sDescrSourceRefFlag = false;
|
458
|
}
|
459
|
|
460
|
// modify variables (post-loop)
|
461
|
classiCounter++;
|
462
|
remainder -= taxaInClass;
|
463
|
|
464
|
}
|
465
|
merge(no_of_accepted_taxa_c, no_of_synonyms_c, no_of_all_taxa_c);
|
466
|
merge(no_of_all_references_c, no_of_nomenclatural_references_c,
|
467
|
no_of_all_references_c);
|
468
|
|
469
|
// TODO Auto-generated method stub
|
470
|
|
471
|
}
|
472
|
|
473
|
/**
|
474
|
* create and count a new sec Reference
|
475
|
*
|
476
|
* @param classiCounter
|
477
|
* @param taxonCounter
|
478
|
* @return
|
479
|
*/
|
480
|
private Reference createSecReference(int classiCounter, int taxonCounter) {
|
481
|
Reference sec;
|
482
|
sec = ReferenceFactory.newBook();
|
483
|
sec.setTitle("book " + classiCounter + "." + taxonCounter);
|
484
|
referenceDao.save(sec);
|
485
|
no_of_all_references++;
|
486
|
return sec;
|
487
|
}
|
488
|
|
489
|
/**
|
490
|
* @param no_of_sth
|
491
|
* @param inClassification
|
492
|
* @param increase
|
493
|
*/
|
494
|
private void increment(List<Long> no_of_sth, int inClassification,
|
495
|
int increase) {
|
496
|
no_of_sth.set(inClassification, (no_of_sth.get(inClassification))
|
497
|
+ increase);
|
498
|
}
|
499
|
|
500
|
private void increment(List<Long> no_of_sth, int inClassification) {
|
501
|
increment(no_of_sth, inClassification, 1);
|
502
|
}
|
503
|
|
504
|
private void merge(List<Long> no_of_sth1, List<Long> no_of_sth2,
|
505
|
List<Long> no_of_sum) {
|
506
|
|
507
|
for (int i = 0; i < NO_OF_CLASSIFICATIONS; i++) {
|
508
|
Long sum = no_of_sth1.get(i) + no_of_sth2.get(i);
|
509
|
no_of_sum.set(i, sum);
|
510
|
|
511
|
}
|
512
|
}
|
513
|
|
514
|
private TaxonNode createTaxTree(Classification classification) {
|
515
|
Random rand = new Random();
|
516
|
|
517
|
Set<TaxonNode> nodes = classification.getAllNodes();
|
518
|
ArrayList<TaxonNode> children = new ArrayList<>();
|
519
|
TaxonNode parent = nodes.iterator().next();
|
520
|
|
521
|
TaxonNode root = parent;
|
522
|
nodes.remove(parent);
|
523
|
while (!nodes.isEmpty()) {
|
524
|
int n = rand.nextInt(2) + 1;
|
525
|
for (int i = 1; i <= n && !(nodes.isEmpty()); i++) {
|
526
|
TaxonNode nextNode = nodes.iterator().next();
|
527
|
nextNode = parent.addChildNode(nextNode, null, null);
|
528
|
children.add(nextNode);
|
529
|
nodes.remove(nextNode);
|
530
|
}
|
531
|
|
532
|
parent = children.get(0);
|
533
|
children.remove(0);
|
534
|
}
|
535
|
|
536
|
return root;
|
537
|
}
|
538
|
|
539
|
/**
|
540
|
*
|
541
|
*/
|
542
|
private void print() {
|
543
|
for (Classification classification : classifications) {
|
544
|
System.out.println("Classification:" + classification.toString());
|
545
|
for (TaxonNode node : classification.getAllNodes()) {
|
546
|
System.out.println("\tTaxon: " + node.getTaxon().toString()+" node UUID: "+ node.getUuid());
|
547
|
System.out.println(" \t(Name: "
|
548
|
+ node.getTaxon().getName().toString() + ")");
|
549
|
System.out.print("\tChildren: ");
|
550
|
for (TaxonNode childNode : node.getChildNodes()) {
|
551
|
System.out.print(/*childNode.getTaxon().getName() + */" node UUID: "+ node.getUuid()+" ");
|
552
|
}
|
553
|
System.out.println();
|
554
|
|
555
|
if (node.getTaxon().getName().getNomenclaturalReference() != null) {
|
556
|
System.out.println(" \t(Nomencl. Ref.: "
|
557
|
+ node.getTaxon().getName()
|
558
|
.getNomenclaturalReference().getId() + ")");
|
559
|
}
|
560
|
for (Synonym synonym : node.getTaxon().getSynonyms()) {
|
561
|
System.out.println("\t\tSynonym: " + synonym.toString());
|
562
|
System.out.println(" \t\t(Name: "
|
563
|
+ synonym.getName().toString() + ")");
|
564
|
if (synonym.getName().getNomenclaturalReference() != null) {
|
565
|
System.out.println(" \t\t(Nomencl. Ref.: "
|
566
|
+ synonym.getName().getNomenclaturalReference()
|
567
|
.getId() + ")");
|
568
|
}
|
569
|
System.out.println();
|
570
|
}
|
571
|
}
|
572
|
|
573
|
}
|
574
|
System.out.println();
|
575
|
System.out.println("end!");
|
576
|
|
577
|
}
|
578
|
|
579
|
/* (non-Javadoc)
|
580
|
* @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
|
581
|
*/
|
582
|
@Override
|
583
|
public void createTestDataSet() throws FileNotFoundException {
|
584
|
// TODO Auto-generated method stub
|
585
|
|
586
|
}
|
587
|
}
|