4 package eu
.etaxonomy
.cdm
.api
.service
;
6 import static org
.junit
.Assert
.assertTrue
;
8 import java
.io
.FileNotFoundException
;
9 import java
.util
.ArrayList
;
10 import java
.util
.Arrays
;
11 import java
.util
.Collections
;
12 import java
.util
.HashMap
;
13 import java
.util
.List
;
16 import org
.apache
.commons
.collections
.functors
.ForClosure
;
17 import org
.apache
.commons
.lang
.RandomStringUtils
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.junit
.After
;
20 import org
.junit
.AfterClass
;
21 import org
.junit
.Before
;
22 import org
.junit
.BeforeClass
;
23 import org
.junit
.Test
;
24 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
26 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.Statistics
;
27 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsConfigurator
;
28 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsPartEnum
;
29 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsTypeEnum
;
30 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
31 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
32 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
33 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
34 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
35 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
36 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
37 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
38 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
39 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
40 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
41 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
42 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
43 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
44 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
45 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
46 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
47 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
48 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
54 @SuppressWarnings({ "rawtypes", "serial" })
55 public class StatisticsServiceImplTest
extends CdmTransactionalIntegrationTest
{
57 // constant if you want to printout the database content to console:
58 // only recommended for a small probe
59 private static final boolean PRINTOUT
= true;
61 // ************constants to set up the expected results for all:
62 // ********************
64 // ............................................
66 // here is the list of the types that will be test counted in the
67 // parts (ALL, CLASSIFICATION)
68 private static final List
<StatisticsTypeEnum
> TYPES
= Arrays
69 .asList(new StatisticsTypeEnum
[] {
70 StatisticsTypeEnum
.CLASSIFICATION
,
71 StatisticsTypeEnum
.ACCEPTED_TAXA
,
72 StatisticsTypeEnum
.ALL_TAXA
,
73 StatisticsTypeEnum
.ALL_REFERENCES
, // this functionality
75 // classifications is still missing for in the Statistics
77 StatisticsTypeEnum
.SYNONYMS
,
78 StatisticsTypeEnum
.TAXON_NAMES
,
79 StatisticsTypeEnum
.NOMENCLATURAL_REFERENCES
,
80 StatisticsTypeEnum
.DESCRIPTIVE_SOURCE_REFERENCES
});
82 // private static final String[] TYPES = { "CLASSIFICATION",
84 // "ALL_TAXA", "ALL_REFERENCES" };
86 // ................parts ..............................
88 private static final List
<String
> PARTS
= Arrays
.asList(new String
[] {
89 "ALL", "CLASSIFICATION" });
90 // .........................................................
92 // part= null means search all DB
93 private static final IdentifiableEntity PARTS_ALL
= null;
95 // here is the number of items that will be created for the test count:
96 // please only change the numbers
97 // but do not replace or add a number to any constants on the right.
100 private static final int NO_OF_ACCEPTED_TAXA
= 10;
102 // choose a number (less than NO_OF_ACCEPTED_TAXA)
103 private static final int NO_OF_CLASSIFICATIONS
= 3;
105 // must be less or equal to NO_OF_ACCEPTED_TAXA
106 private static final int NO_OF_SYNONYMS
= 7;
108 // taxa that occure in several classifications:
109 // must NOT be more than NO_OF_ACCEPTED_TAXA
110 private static final int NO_OF_SHARED_TAXA
= 4;
112 // must be NO_OF_ACCEPTED_TAXA + NO_OF_SYNONYMS
113 private static final int NO_OF_ALLTAXA
= NO_OF_ACCEPTED_TAXA
116 // must be NO_OF_ACCEPTED_TAXA+NO_OF_SYNONYMS
117 private static final int NO_OF_TAXON_NAMES
= NO_OF_ACCEPTED_TAXA
120 // this represents an approx. no of the amount that will actually generated!
121 private static final int NO_OF_DESCRIPTIVE_SOURCE_REFERENCES
= 16;
123 // private static final int NO_OF_ALL_REFERENCES = NO_OF_ACCEPTED_TAXA + 0;
125 // must not be more than NO_OF_ACCEPTED_TAXA+NO_OF_SYNONYMS
126 private static final int NO_OF_NOMENCLATURAL_REFERENCES
= NO_OF_ACCEPTED_TAXA
127 + NO_OF_SYNONYMS
- 4;
129 // --------------------variables for all ------------------
131 private Long no_of_all_references
= new Long(0);
132 private Long no_of_descriptive_source_references
= new Long(0);
134 // ............................................
136 // log the type enum to an int constant:
137 private Map
<String
, Long
> typeMap_ALL
;
139 // ------------------ variables for CLASSIFICATIONS -----------------------
141 // int[] anArray = new int[NO_OF_CLASSIFICATIONS];
142 private static List
<Long
> no_of_all_taxa_c
= new ArrayList
<Long
>(
143 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
144 private static List
<Long
> no_of_accepted_taxa_c
= new ArrayList
<Long
>(
145 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
146 private static List
<Long
> no_of_synonyms_c
= new ArrayList
<Long
>(
147 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
148 private static List
<Long
> no_of_taxon_names_c
= new ArrayList
<Long
>(
149 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
150 private static List
<Long
> no_of_descriptive_source_references_c
= new ArrayList
<Long
>(
151 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
152 private static List
<Long
> no_of_all_references_c
= new ArrayList
<Long
>(
153 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
154 private static List
<Long
> no_of_nomenclatural_references_c
= new ArrayList
<Long
>(
155 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
156 // we do not count classifications in classifications
158 // ........................... constant map ..........................
160 private static final Map
<String
, List
<Long
>> typeCountMap_CLASSIFICATION
= new HashMap
<String
, List
<Long
>>() {
162 put(StatisticsTypeEnum
.CLASSIFICATION
.getLabel(),
163 new ArrayList
<Long
>(Arrays
.asList((Long
) null, null, null)));
164 put(StatisticsTypeEnum
.ALL_TAXA
.getLabel(), no_of_all_taxa_c
);
165 put(StatisticsTypeEnum
.ACCEPTED_TAXA
.getLabel(),
166 no_of_accepted_taxa_c
);
167 put(StatisticsTypeEnum
.SYNONYMS
.getLabel(), no_of_synonyms_c
);
168 put(StatisticsTypeEnum
.TAXON_NAMES
.getLabel(), no_of_taxon_names_c
);
169 put(StatisticsTypeEnum
.DESCRIPTIVE_SOURCE_REFERENCES
.getLabel(),
170 no_of_descriptive_source_references_c
);
171 put(StatisticsTypeEnum
.ALL_REFERENCES
.getLabel(),
172 no_of_all_references_c
);
173 put(StatisticsTypeEnum
.NOMENCLATURAL_REFERENCES
.getLabel(),
174 no_of_nomenclatural_references_c
);
178 private static final Logger logger
= Logger
179 .getLogger(StatisticsServiceImplTest
.class);
181 private List
<Classification
> classifications
;
183 // ****************** services: ************************
185 private IStatisticsService service
;
187 private IClassificationService classificationService
;
189 private ITaxonService taxonService
;
191 private IReferenceService referenceService
;
193 private IDescriptionService descriptionService
;
195 // *************** more members: *****************+
197 // **********vars to count what i create *********
199 MyCounter countAll
= new MyCounter();
200 ArrayList
<MyCounter
> classificationCounters
= new ArrayList
<MyCounter
>();
203 * @throws java.lang.Exception
206 public static void setUpBeforeClass() throws Exception
{
210 * @throws java.lang.Exception
213 public static void tearDownAfterClass() throws Exception
{
217 * create some testdata
219 * @throws java.lang.Exception
224 public void setUp() throws Exception
{
226 // missing in this example data:
227 // synonyms, that are attached to several taxa (same or different
230 // create NO_OF_CLASSIFICATIONS classifications
231 classifications
= new ArrayList
<Classification
>();
233 for (int i
= 1; i
<= NO_OF_CLASSIFICATIONS
; i
++) {
234 Classification classification
= Classification
235 .NewInstance("European Abies" + i
);
236 classifications
.add(classification
);
237 classificationService
.save(classification
);
238 (countAll
.classifications
)++;
239 classificationCounters
.add(new MyCounter());
242 // create all taxa, references and synonyms and attach them to one or
243 // more classifications
246 int remainder
= NO_OF_ACCEPTED_TAXA
;
247 Reference sec
= ReferenceFactory
.newBook();
248 boolean secondClassificationForTaxonFlag
= false;
249 boolean synonymFlag
= false;
250 boolean tNomRefFlag
= false;
251 boolean sNomRefFlag
= false;
252 boolean tDescrSourceRefFlag
= false;
253 boolean sDescrSourceRefFlag
= false;
255 // variables: counter (pre-loop)
256 int descriptiveElementsPerTaxon
= (NO_OF_DESCRIPTIVE_SOURCE_REFERENCES
/ NO_OF_ACCEPTED_TAXA
) + 1;
259 int classiCounter
= 0, sharedClassification
= 0, synonymCounter
= 0, nomRefCounter
= 0;
261 // iterate over classifications and add taxa
262 for (/* see above */; remainder
> 0
263 && classiCounter
< NO_OF_CLASSIFICATIONS
; /* see below */) {
265 // compute no of taxa to be created in this classification
266 if (classiCounter
>= NO_OF_CLASSIFICATIONS
- 1) { // last
270 taxaInClass
= remainder
;
271 } else { // take half of left taxa for this class:
272 taxaInClass
= remainder
/ 2;
275 // iterate over amount of taxa meant to be in this classification
276 for (int taxonCounter
= 1; taxonCounter
<= taxaInClass
; taxonCounter
++) {
278 // create a String for the Name
279 RandomStringUtils
.randomAlphabetic(10);
280 String randomName
= RandomStringUtils
.randomAlphabetic(5) + " "
281 + RandomStringUtils
.randomAlphabetic(10);
283 MyCounter taxonContextCounter
= new MyCounter();
284 // create a name for the taxon
285 BotanicalName name
= BotanicalName
.NewInstance(Rank
.SPECIES());
286 name
.setNameCache(randomName
, true);
288 // create nomenclatural reference for taxon name (if left)
289 if (nomRefCounter
< NO_OF_NOMENCLATURAL_REFERENCES
) {
290 // we remember this taxon has a nomenclatural reference:
292 Reference nomRef
= ReferenceFactory
.newBook();
293 name
.setNomenclaturalReference(nomRef
);
294 referenceService
.save(nomRef
);
295 (taxonContextCounter
.allReferences
)++;
296 (taxonContextCounter
.nomenclRef
)++;
300 // create a new sec for every other taxon
301 if (taxonCounter
% 2 != 0) {
302 sec
= createSecReference(classiCounter
, taxonCounter
);
306 Taxon taxon
= Taxon
.NewInstance(name
, sec
);
308 // create descriptions, description sources and their references
310 if (no_of_descriptive_source_references
< NO_OF_DESCRIPTIVE_SOURCE_REFERENCES
) {
312 tDescrSourceRefFlag
= true;
314 // create a description and 2 description elements with
315 // references for taxon name
316 TaxonNameDescription nameDescr
= TaxonNameDescription
318 CommonTaxonName nameElement
= CommonTaxonName
.NewInstance(
319 "Veilchen" + taxonCounter
, Language
.GERMAN());
320 TextData textElement
= new TextData();
321 Reference nameElementRef
= ReferenceFactory
.newArticle();
322 Reference textElementRef
= ReferenceFactory
324 nameElement
.addSource(
325 OriginalSourceType
.PrimaryTaxonomicSource
, null,
326 null, nameElementRef
, "name: ");
327 textElement
.addSource(
328 OriginalSourceType
.PrimaryTaxonomicSource
, null,
329 null, textElementRef
, "text: ");
330 nameDescr
.addElement(nameElement
);
331 nameDescr
.addElement(textElement
);
332 name
.addDescription(nameDescr
);
333 // taxon.getName().addDescription(nameDescr);
334 referenceService
.save(nameElementRef
);
335 referenceService
.save(textElementRef
);
336 (taxonContextCounter
.descrSourceRef
)++;
337 (taxonContextCounter
.descrSourceRef
)++;
338 descriptionService
.save(nameDescr
);
339 (taxonContextCounter
.descriptions
)++;
342 // create descriptions, description sources and their
345 TaxonDescription taxonDescription
= new TaxonDescription();
346 for (int i
= 0; i
< descriptiveElementsPerTaxon
; i
++) {
347 DescriptionElementBase descriptionElement
= new TextData();
348 DescriptionElementSource descriptionElementSource
= DescriptionElementSource
349 .NewInstance(OriginalSourceType
.PrimaryTaxonomicSource
);
350 Reference article
= ReferenceFactory
.newArticle();
352 descriptionElementSource
.setCitation(article
);
353 descriptionElement
.addSource(descriptionElementSource
);
354 taxonDescription
.addElement(descriptionElement
);
355 referenceService
.save(article
);
356 (taxonContextCounter
.descrSourceRef
)++;
358 .saveDescriptionElement(descriptionElement
);
361 descriptionService
.save(taxonDescription
);
362 (taxonContextCounter
.descriptions
)++;
363 taxon
.addDescription(taxonDescription
);
365 // create a Specimen for taxon with description, descr.
366 // element and referece
368 // Specimen specimen = Specimen.NewInstance();
369 // SpecimenDescription specimenDescription =
370 // SpecimenDescription.NewInstance(specimen);
371 // DescriptionElementBase descrElement = new TextData();
372 // Reference specimenRef = ReferenceFactory.newArticle();
373 // descrElement.addSource(null, null, specimenRef, null);
376 // descriptionService.save(specimenDescription);
377 // taxon.add(specimen);
379 no_of_descriptive_source_references
+= descriptiveElementsPerTaxon
+ 2 + 1;
383 // add taxon to classification
384 classifications
.get(classiCounter
).addChildTaxon(taxon
, null,
387 // now if there are any left, we create a synonym for the taxon
388 if (synonymCounter
< NO_OF_SYNONYMS
) {
390 randomName
= RandomStringUtils
.randomAlphabetic(5) + " "
391 + RandomStringUtils
.randomAlphabetic(10);
393 name
= BotanicalName
.NewInstance(Rank
.SPECIES());
394 name
.setNameCache(randomName
, true);
396 // create nomenclatural reference for synonym name (if left)
397 if (nomRefCounter
< NO_OF_NOMENCLATURAL_REFERENCES
) {
399 Reference nomRef
= ReferenceFactory
.newBook();
400 name
.setNomenclaturalReference(nomRef
);
401 referenceService
.save(nomRef
);
402 (taxonContextCounter
.nomenclRef
)++;
406 if (no_of_descriptive_source_references
< NO_OF_DESCRIPTIVE_SOURCE_REFERENCES
) {
407 sDescrSourceRefFlag
= true;
409 // create a description and 2 description elements with
410 // references for synonym name
411 TaxonNameDescription nameDescr
= TaxonNameDescription
413 CommonTaxonName nameElement
= CommonTaxonName
414 .NewInstance("anderes Veilchen" + taxonCounter
,
416 TextData textElement
= new TextData();
417 Reference nameElementRef
= ReferenceFactory
419 Reference textElementRef
= ReferenceFactory
421 nameElement
.addSource(
422 OriginalSourceType
.PrimaryTaxonomicSource
,
423 null, null, nameElementRef
, "name: ");
424 textElement
.addSource(
425 OriginalSourceType
.PrimaryTaxonomicSource
,
426 null, null, textElementRef
, "text: ");
427 nameDescr
.addElement(nameElement
);
428 nameDescr
.addElement(textElement
);
429 name
.addDescription(nameDescr
);
430 // taxon.getName().addDescription(nameDescr);
431 referenceService
.save(nameElementRef
);
432 referenceService
.save(textElementRef
);
433 descriptionService
.save(nameDescr
);
434 no_of_descriptive_source_references
+= 2;
435 (taxonContextCounter
.nomenclRef
)++;
438 // create a new reference for every other synonym:
439 if (taxonCounter
% 2 != 0) {
440 sec
= createSecReference(classiCounter
, taxonCounter
);
442 Synonym synonym
= Synonym
.NewInstance(name
, sec
);
443 taxonService
.save(synonym
);
444 (taxonContextCounter
.synonyms
)++;
445 (taxonContextCounter
.allTaxa
)++;
446 taxon
.addSynonym(synonym
,
447 SynonymRelationshipType
.SYNONYM_OF());
452 // if this is not the last classification and there are
453 // taxa left that should be in more than one classification
454 // we add the taxon to the next class in the list too.
456 (taxonContextCounter
.aceptedTaxa
)++;
457 (taxonContextCounter
.allTaxa
)++;
458 if (classiCounter
< NO_OF_CLASSIFICATIONS
459 && sharedClassification
< NO_OF_SHARED_TAXA
) {
460 classifications
.get(classiCounter
+ 1).addChildTaxon(taxon
,
463 // we remember that this taxon is attached to 2
465 secondClassificationForTaxonFlag
= true;
466 sharedClassification
++;
467 classificationService
.saveOrUpdate(classifications
468 .get(classiCounter
+ 1));
470 (classificationCounters
.get(classiCounter
+ 1))
471 .addAll(taxonContextCounter
);
475 taxonService
.save(taxon
);
476 (classificationCounters
.get(classiCounter
))
477 .addAll(taxonContextCounter
);
478 classificationService
.saveOrUpdate(classifications
479 .get(classiCounter
));
480 (countAll
.classifications
)++;
482 // count the data created with this taxon:
483 int c
= classiCounter
;
485 if (secondClassificationForTaxonFlag
) {
489 // run the following loop once, if this taxon only belongs to
492 // twice, if it is attached to 2 classifications
493 for (int i
= classiCounter
; i
<= c
; i
++) {
495 // count everything just created for this taxon:
496 increment(no_of_accepted_taxa_c
, i
);
497 increment(no_of_taxon_names_c
, i
);
499 increment(no_of_nomenclatural_references_c
, i
);
502 increment(no_of_nomenclatural_references_c
, i
);
505 increment(no_of_synonyms_c
, i
);
506 increment(no_of_taxon_names_c
, i
);
508 if (taxonCounter
% 2 != 0) {
509 increment(no_of_all_references_c
, i
);
511 increment(no_of_all_references_c
, i
);
514 if (tDescrSourceRefFlag
) {
515 increment(no_of_descriptive_source_references_c
, i
,
516 descriptiveElementsPerTaxon
+ 2);
519 if (sDescrSourceRefFlag
) {
520 increment(no_of_descriptive_source_references_c
, i
, 2);
524 secondClassificationForTaxonFlag
= false;
528 tDescrSourceRefFlag
= false;
529 sDescrSourceRefFlag
= false;
532 // modify variables (post-loop)
534 remainder
-= taxaInClass
;
537 merge(no_of_accepted_taxa_c
, no_of_synonyms_c
, no_of_all_taxa_c
);
538 merge(no_of_all_references_c
, no_of_nomenclatural_references_c
,
539 no_of_all_references_c
);
543 * create and count a new sec Reference
545 * @param classiCounter
546 * @param taxonCounter
549 private Reference
createSecReference(int classiCounter
, int taxonCounter
) {
551 sec
= ReferenceFactory
.newBook();
552 sec
.setTitle("book " + classiCounter
+ "." + taxonCounter
);
553 referenceService
.save(sec
);
554 no_of_all_references
++;
558 private void merge(List
<Long
> no_of_sth1
, List
<Long
> no_of_sth2
,
559 List
<Long
> no_of_sum
) {
561 for (int i
= 0; i
< NO_OF_CLASSIFICATIONS
; i
++) {
562 Long sum
= no_of_sth1
.get(i
) + no_of_sth2
.get(i
);
563 no_of_sum
.set(i
, sum
);
569 * @throws java.lang.Exception
572 public void tearDown() throws Exception
{
575 // ****************** tests *****************
578 * {@link eu.etaxonomy.cdm.api.service.StatisticsServiceImpl#getCountStatistics(java.util.List)}
582 public void testGetCountStatistics() {
584 // create maps to compare the testresults with:
585 List
<Map
<String
, Number
>> expectedCountmapList
= new ArrayList
<Map
<String
, Number
>>();
586 if (PARTS
.contains("ALL")) {
587 expectedCountmapList
.add(createExpectedCountMap_ALL());
589 if (PARTS
.contains("CLASSIFICATION")) {
591 .addAll(createExpectedCountMaps_CLASSIFICATION());
594 // create configurator needed to call
595 // StatisticsService.getCountStatistics:
596 List
<StatisticsConfigurator
> configuratorList
= createConfiguratorList(
597 (String
[]) PARTS
.toArray(), TYPES
);
599 // run method of StatisticsService
600 List
<Statistics
> statisticsList
= service
601 .getCountStatistics(configuratorList
);
603 // print out the: expected and the result:
605 logger
.info("expected: ");
607 for (Map
<String
, Number
> map
: expectedCountmapList
) {
608 logger
.info(map
.toString());
610 logger
.info("expected2:");
611 logger
.info(countAll
.toString());
612 logger
.info(classificationCounters
.toString());
613 logger
.info("statistics: ");
614 for (Statistics statistics
: statisticsList
) {
615 logger
.info(statistics
.getCountMap().toString());
619 // check the result with the expected values:
620 // as we cannot be sure the order of the statisticsList
621 // matches the order of the expectedCountmapList
622 // we have to work arround a little:
623 for (Statistics statistics
: statisticsList
) {
624 Boolean orCompare
= false;
625 for (Map
<String
, Number
> map
: expectedCountmapList
) {
626 orCompare
= orCompare
|| statistics
.getCountMap().equals(map
);
628 // assertTrue(orCompare);
640 private void print() {
641 for (Classification classification
: classifications
) {
642 System
.out
.println("Classification:" + classification
.toString());
643 for (TaxonNode node
: classification
.getAllNodes()) {
644 System
.out
.println("\tTaxon: " + node
.getTaxon().toString());
645 System
.out
.println(" \t(Name: "
646 + node
.getTaxon().getName().toString() + ")");
647 if (node
.getTaxon().getName().getNomenclaturalReference() != null) {
648 System
.out
.println(" \t(Nomencl. Ref.: "
649 + node
.getTaxon().getName()
650 .getNomenclaturalReference().getId() + ")");
652 for (Synonym synonym
: node
.getTaxon().getSynonyms()) {
653 System
.out
.println("\t\tSynonym: " + synonym
.toString());
654 System
.out
.println(" \t\t(Name: "
655 + synonym
.getName().toString() + ")");
656 if (synonym
.getName().getNomenclaturalReference() != null) {
657 System
.out
.println(" \t\t(Nomencl. Ref.: "
658 + synonym
.getName().getNomenclaturalReference()
661 System
.out
.println();
666 System
.out
.println();
667 System
.out
.println("end!");
671 // ************************** private methods ****************************+
675 * @param inClassification
678 private void increment(List
<Long
> no_of_sth
, int inClassification
,
680 no_of_sth
.set(inClassification
, (no_of_sth
.get(inClassification
))
684 private void increment(List
<Long
> no_of_sth
, int inClassification
) {
685 increment(no_of_sth
, inClassification
, 1);
688 private Map
<String
, Number
> createExpectedCountMap_ALL() {
689 Map
<String
, Number
> countMap
= new HashMap
<String
, Number
>();
691 for (StatisticsTypeEnum type
: TYPES
) {
692 // System.out.println(""+typeMap_ALL.get(type.getLabel()));
693 countMap
.put(type
.getLabel(), typeMap_ALL
.get(type
.getLabel()));
698 private List
<Map
<String
, Number
>> createExpectedCountMaps_CLASSIFICATION() {
700 List
<Map
<String
, Number
>> mapList
= new ArrayList
<Map
<String
, Number
>>();
702 for (int i
= 0; i
< NO_OF_CLASSIFICATIONS
; i
++) {
704 Map
<String
, Number
> countMap
= new HashMap
<String
, Number
>();
706 for (StatisticsTypeEnum type
: TYPES
) {
707 countMap
.put(type
.getLabel(),
708 typeCountMap_CLASSIFICATION
.get(type
.getLabel()).get(i
));
711 mapList
.add(countMap
);
720 private void createMap_ALL() {
721 typeMap_ALL
= new HashMap
<String
, Long
>() {
723 put(StatisticsTypeEnum
.CLASSIFICATION
.getLabel(),
724 Long
.valueOf(NO_OF_CLASSIFICATIONS
));
725 put(StatisticsTypeEnum
.ALL_TAXA
.getLabel(),
726 Long
.valueOf(NO_OF_ALLTAXA
));
727 put(StatisticsTypeEnum
.ACCEPTED_TAXA
.getLabel(),
728 Long
.valueOf(NO_OF_ACCEPTED_TAXA
));
729 put(StatisticsTypeEnum
.SYNONYMS
.getLabel(),
730 Long
.valueOf(NO_OF_SYNONYMS
));
731 put(StatisticsTypeEnum
.TAXON_NAMES
.getLabel(),
732 Long
.valueOf(NO_OF_TAXON_NAMES
));
733 // put(StatisticsTypeEnum.DESCRIPTIVE_SOURCE_REFERENCES.getLabel(),
734 // Long.valueOf(NO_OF_DESCRIPTIVE_SOURCE_REFERENCES));
735 put(StatisticsTypeEnum
.DESCRIPTIVE_SOURCE_REFERENCES
.getLabel(),
736 Long
.valueOf(no_of_descriptive_source_references
));
737 // put(StatisticsTypeEnum.ALL_REFERENCES.getLabel(),
738 // Long.valueOf(NO_OF_ALL_REFERENCES));
739 put(StatisticsTypeEnum
.ALL_REFERENCES
.getLabel(),
740 no_of_all_references
);
741 put(StatisticsTypeEnum
.NOMENCLATURAL_REFERENCES
.getLabel(),
742 Long
.valueOf(NO_OF_NOMENCLATURAL_REFERENCES
));
747 private List
<StatisticsConfigurator
> createConfiguratorList(String
[] part
,
748 List
<StatisticsTypeEnum
> types
) {
750 ArrayList
<StatisticsConfigurator
> configuratorList
= new ArrayList
<StatisticsConfigurator
>();
752 // 1. get types for configurators:
753 // in our case all the configurators will have the same types
754 // so we calculate the types once and save them in a helperConfigurator
755 StatisticsConfigurator helperConfigurator
= new StatisticsConfigurator();
758 for (StatisticsTypeEnum type
: types
) {
759 helperConfigurator
.addType(type
);
762 for (StatisticsTypeEnum enumValue
: StatisticsTypeEnum
.values()) {
763 helperConfigurator
.addType(enumValue
);
767 // 2. determine the entities and put each of them in a configurator:
769 // if no part was given:
771 helperConfigurator
.addFilter(PARTS_ALL
);
772 configuratorList
.add(helperConfigurator
);
774 // else parse list of parts and create configurator for each:
776 for (String string
: part
) {
777 if (string
.equals(StatisticsPartEnum
.ALL
.toString())) {
778 helperConfigurator
.addFilter(PARTS_ALL
);
779 configuratorList
.add(helperConfigurator
);
780 } else if (string
.equals(StatisticsPartEnum
.CLASSIFICATION
782 List
<Classification
> classificationsList
= classificationService
783 .listClassifications(null, 0, null, null);
784 for (Classification classification
: classificationsList
) {
786 StatisticsConfigurator newConfigurator
= new StatisticsConfigurator();
787 newConfigurator
.setType(helperConfigurator
.getType());
788 newConfigurator
.getFilter().addAll(
789 helperConfigurator
.getFilter());
790 newConfigurator
.addFilter(classification
);
791 configuratorList
.add(newConfigurator
);
798 return configuratorList
;
801 public class MyCounter
{
802 protected long classifications
= 0;
803 protected long allTaxa
= 0;
804 protected long aceptedTaxa
= 0;
805 protected long taxonNames
= 0;
806 protected long synonyms
= 0;
807 protected long descrSourceRef
= 0;
808 protected long nomenclRef
= 0;
809 protected long allReferences
= 0;
810 protected long descriptions
= 0;
812 public void addAll(MyCounter otherCounter
) {
813 classifications
+= otherCounter
.classifications
;
814 allTaxa
+= otherCounter
.allTaxa
;
815 aceptedTaxa
+= otherCounter
.aceptedTaxa
;
816 taxonNames
+= otherCounter
.taxonNames
;
817 synonyms
+= otherCounter
.synonyms
;
818 descrSourceRef
+= otherCounter
.descrSourceRef
;
819 nomenclRef
+= otherCounter
.nomenclRef
;
820 allReferences
+= otherCounter
.allReferences
;
821 descriptions
+= otherCounter
.descriptions
;
824 public void reset() {
837 public String
toString() {
838 return "{Taxon_names=" + taxonNames
+ ", Synonyms=" + synonyms
839 + ", Accepted_taxa=" + aceptedTaxa
840 + ", Nomenclatural_references=" + nomenclRef
841 + ", Classifications=" + classifications
842 + ", Descriptive_source_references=" + descrSourceRef
843 + ", References=" + allReferences
+ ", All_taxa=" + allTaxa
849 * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
852 public void createTestDataSet() throws FileNotFoundException
{
853 // TODO Auto-generated method stub