4 package eu
.etaxonomy
.cdm
.api
.service
;
6 import static org
.junit
.Assert
.assertTrue
;
8 import java
.util
.ArrayList
;
9 import java
.util
.Arrays
;
10 import java
.util
.Collections
;
11 import java
.util
.HashMap
;
12 import java
.util
.List
;
15 import javax
.validation
.constraints
.AssertTrue
;
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
.dbunit
.annotation
.DataSet
;
25 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
27 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.Statistics
;
28 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsConfigurator
;
29 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsPartEnum
;
30 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsTypeEnum
;
31 import eu
.etaxonomy
.cdm
.model
.common
.DescriptionElementSource
;
32 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
33 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
34 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
35 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
36 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
37 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
38 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
39 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
40 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
41 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
42 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
43 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
44 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
45 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
46 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
47 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
48 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
49 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
50 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
51 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
52 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
58 @SuppressWarnings({ "rawtypes", "serial" })
59 public class StatisticsServiceImplTest
extends CdmTransactionalIntegrationTest
{
61 // constant if you want to printout the database content to console:
62 // only recommended for a small probe
63 private static final boolean PRINTOUT
= true;
65 // ************constants to set up the expected results for all:
66 // ********************
68 // ............................................
70 // here is the list of the types that will be test counted in the
71 // parts (ALL, CLASSIFICATION)
72 private static final List
<StatisticsTypeEnum
> TYPES
= Arrays
73 .asList(new StatisticsTypeEnum
[] {
74 StatisticsTypeEnum
.CLASSIFICATION
,
75 StatisticsTypeEnum
.ACCEPTED_TAXA
,
76 StatisticsTypeEnum
.ALL_TAXA
,
77 StatisticsTypeEnum
.ALL_REFERENCES
, // this functionality
79 // classifications is still missing for in the Statistics
81 StatisticsTypeEnum
.SYNONYMS
,
82 StatisticsTypeEnum
.TAXON_NAMES
,
83 StatisticsTypeEnum
.NOMECLATURAL_REFERENCES
,
84 StatisticsTypeEnum
.DESCRIPTIVE_SOURCE_REFERENCES
});
86 // private static final String[] TYPES = { "CLASSIFICATION",
88 // "ALL_TAXA", "ALL_REFERENCES" };
90 // ................parts ..............................
92 private static final List
<String
> PARTS
= Arrays
.asList(new String
[] {
93 "ALL", "CLASSIFICATION" });
94 // .........................................................
96 // part= null means search all DB
97 private static final IdentifiableEntity PARTS_ALL
= null;
99 // here is the number of items that will be created for the test count:
100 // please only change the numbers
101 // but do not replace or add a number to any constants on the right.
104 private static final int NO_OF_ACCEPTED_TAXA
= 10;
106 // choose a number (less than NO_OF_ACCEPTED_TAXA)
107 private static final int NO_OF_CLASSIFICATIONS
= 3;
109 // must be less or equal to NO_OF_ACCEPTED_TAXA
110 private static final int NO_OF_SYNONYMS
= 7;
112 // taxa that occure in several classifications:
113 // must NOT be more than NO_OF_ACCEPTED_TAXA
114 private static final int NO_OF_SHARED_TAXA
= 4;
116 // must be NO_OF_ACCEPTED_TAXA + NO_OF_SYNONYMS
117 private static final int NO_OF_ALLTAXA
= NO_OF_ACCEPTED_TAXA
120 // must be NO_OF_ACCEPTED_TAXA+NO_OF_SYNONYMS
121 private static final int NO_OF_TAXON_NAMES
= NO_OF_ACCEPTED_TAXA
124 // this represents an approx. no of the amount that will actually generated!
125 private static final int NO_OF_DESCRIPTIVE_SOURCE_REFERENCES
= 16;
127 // private static final int NO_OF_ALL_REFERENCES = NO_OF_ACCEPTED_TAXA + 0;
129 // must not be more than NO_OF_ACCEPTED_TAXA+NO_OF_SYNONYMS
130 private static final int NO_OF_NOMECLATURAL_REFERENCES
= NO_OF_ACCEPTED_TAXA
131 + NO_OF_SYNONYMS
- 4;
133 // --------------------variables for all ------------------
135 private Long no_of_all_references
= new Long(0);
136 private Long no_of_descriptive_source_references
= new Long(0);
138 // ............................................
140 // log the type enum to an int constant:
141 private Map
<String
, Long
> typeMap_ALL
;
143 // ------------------ variables for CLASSIFICATIONS -----------------------
145 // int[] anArray = new int[NO_OF_CLASSIFICATIONS];
146 private static List
<Long
> no_of_all_taxa_c
= new ArrayList
<Long
>(
147 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
148 private static List
<Long
> no_of_accepted_taxa_c
= new ArrayList
<Long
>(
149 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
150 private static List
<Long
> no_of_synonyms_c
= new ArrayList
<Long
>(
151 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
152 private static List
<Long
> no_of_taxon_names_c
= new ArrayList
<Long
>(
153 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
154 private static List
<Long
> no_of_descriptive_source_references_c
= new ArrayList
<Long
>(
155 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
156 private static List
<Long
> no_of_all_references_c
= new ArrayList
<Long
>(
157 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
158 private static List
<Long
> no_of_nomenclatural_references_c
= new ArrayList
<Long
>(
159 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
160 // we do not count classifications in classifications
162 // ........................... constant map ..........................
164 private static final Map
<String
, List
<Long
>> typeCountMap_CLASSIFICATION
= new HashMap
<String
, List
<Long
>>() {
166 put(StatisticsTypeEnum
.CLASSIFICATION
.getLabel(),
167 new ArrayList
<Long
>(Arrays
.asList((Long
) null, null, null)));
168 put(StatisticsTypeEnum
.ALL_TAXA
.getLabel(), no_of_all_taxa_c
);
169 put(StatisticsTypeEnum
.ACCEPTED_TAXA
.getLabel(),
170 no_of_accepted_taxa_c
);
171 put(StatisticsTypeEnum
.SYNONYMS
.getLabel(), no_of_synonyms_c
);
172 put(StatisticsTypeEnum
.TAXON_NAMES
.getLabel(), no_of_taxon_names_c
);
173 put(StatisticsTypeEnum
.DESCRIPTIVE_SOURCE_REFERENCES
.getLabel(),
174 no_of_descriptive_source_references_c
);
175 put(StatisticsTypeEnum
.ALL_REFERENCES
.getLabel(),
176 no_of_all_references_c
);
177 put(StatisticsTypeEnum
.NOMECLATURAL_REFERENCES
.getLabel(),
178 no_of_nomenclatural_references_c
);
182 private static final Logger logger
= Logger
183 .getLogger(StatisticsServiceImplTest
.class);
185 private List
<Classification
> classifications
;
187 // ****************** services: ************************
189 private IStatisticsService service
;
191 private IClassificationService classificationService
;
193 private ITaxonService taxonService
;
195 private IReferenceService referenceService
;
197 private IDescriptionService descriptionService
;
199 // *************** more members: *****************+
202 * @throws java.lang.Exception
205 public static void setUpBeforeClass() throws Exception
{
209 * @throws java.lang.Exception
212 public static void tearDownAfterClass() throws Exception
{
216 * create some testdata
218 * @throws java.lang.Exception
223 public void setUp() throws Exception
{
225 // missing in this example data:
226 // synonyms, that are attached to several taxa (same or different
229 // create NO_OF_CLASSIFICATIONS classifications
230 classifications
= new ArrayList
<Classification
>();
232 for (int i
= 1; i
<= NO_OF_CLASSIFICATIONS
; i
++) {
233 Classification classification
= Classification
234 .NewInstance("European Abies" + i
);
235 classifications
.add(classification
);
236 classificationService
.save(classification
);
238 // create all taxa, references and synonyms and attach them to one or
239 // more classifications
242 int remainder
= NO_OF_ACCEPTED_TAXA
;
243 Reference sec
= ReferenceFactory
.newBook();
244 boolean secondClassificationForTaxonFlag
= false;
245 boolean synonymFlag
= false;
246 boolean tNomRefFlag
= false;
247 boolean sNomRefFlag
= false;
248 boolean tDescrSourceRefFlag
= false;
249 boolean sDescrSourceRefFlag
= false;
251 // variables: counter (pre-loop)
252 int descriptiveElementsPerTaxon
= (NO_OF_DESCRIPTIVE_SOURCE_REFERENCES
/ NO_OF_ACCEPTED_TAXA
) + 1;
255 int classiCounter
= 0, sharedClassification
= 0, synonymCounter
= 0, nomRefCounter
= 0;
257 // iterate over classifications and add taxa
258 for (/* see above */; remainder
> 0
259 && classiCounter
< NO_OF_CLASSIFICATIONS
; /* see below */) {
261 // compute no of taxa to be created in this classification
262 if (classiCounter
>= NO_OF_CLASSIFICATIONS
- 1) { // last
266 taxaInClass
= remainder
;
267 } else { // take half of left taxa for this class:
268 taxaInClass
= remainder
/ 2;
271 // iterate over amount of taxa meant to be in this classification
272 for (int taxonCounter
= 1; taxonCounter
<= taxaInClass
; taxonCounter
++) {
274 // create a String for the Name
275 RandomStringUtils
.randomAlphabetic(10);
276 String randomName
= RandomStringUtils
.randomAlphabetic(5) + " "
277 + RandomStringUtils
.randomAlphabetic(10);
279 // create a name for the taxon
280 BotanicalName name
= BotanicalName
.NewInstance(Rank
.SPECIES());
281 name
.setNameCache(randomName
, true);
283 // create nomenclatural reference for taxon name (if left)
284 if (nomRefCounter
< NO_OF_NOMECLATURAL_REFERENCES
) {
285 // we remember this taxon has a nomenclatural reference:
287 Reference nomRef
= ReferenceFactory
.newBook();
288 name
.setNomenclaturalReference(nomRef
);
289 referenceService
.save(nomRef
);
293 // create a new sec for every other taxon
294 if (taxonCounter
% 2 != 0) {
295 sec
= createSecReference(classiCounter
, taxonCounter
);
299 Taxon taxon
= Taxon
.NewInstance(name
, sec
);
301 // create descriptions, description sources and their references
303 if (no_of_descriptive_source_references
< NO_OF_DESCRIPTIVE_SOURCE_REFERENCES
) {
305 tDescrSourceRefFlag
= true;
307 // create a description and 2 description elements with
308 // references for taxon name
309 TaxonNameDescription nameDescr
= new TaxonNameDescription();
310 CommonTaxonName nameElement
= CommonTaxonName
.NewInstance(
311 "Veilchen" + taxonCounter
, Language
.GERMAN());
312 TextData textElement
= new TextData();
313 Reference nameElementRef
= ReferenceFactory
.newArticle();
314 Reference textElementRef
= ReferenceFactory
316 nameElement
.addSource(null, null, nameElementRef
, "name: ");
317 textElement
.addSource(null, null, textElementRef
, "text: ");
318 nameDescr
.addElement(nameElement
);
319 nameDescr
.addElement(textElement
);
320 name
.addDescription(nameDescr
);
321 // taxon.getName().addDescription(nameDescr);
322 referenceService
.save(nameElementRef
);
323 referenceService
.save(textElementRef
);
324 descriptionService
.save(nameDescr
);
326 // create descriptions, description sources and their
329 TaxonDescription taxonDescription
= new TaxonDescription();
330 for (int i
= 0; i
< descriptiveElementsPerTaxon
; i
++) {
331 DescriptionElementBase descriptionElement
= new TextData();
332 DescriptionElementSource descriptionElementSource
= DescriptionElementSource
334 Reference article
= ReferenceFactory
.newArticle();
336 descriptionElementSource
.setCitation(article
);
337 descriptionElement
.addSource(descriptionElementSource
);
338 taxonDescription
.addElement(descriptionElement
);
339 referenceService
.save(article
);
341 .saveDescriptionElement(descriptionElement
);
344 descriptionService
.save(taxonDescription
);
345 taxon
.addDescription(taxonDescription
);
347 // create a Specimen for taxon with description, descr.
348 // element and referece
350 // Specimen specimen = Specimen.NewInstance();
351 // SpecimenDescription specimenDescription = SpecimenDescription.NewInstance(specimen);
352 // DescriptionElementBase descrElement = new TextData();
353 // Reference specimenRef = ReferenceFactory.newArticle();
354 // descrElement.addSource(null, null, specimenRef, null);
357 // descriptionService.save(specimenDescription);
358 // taxon.add(specimen);
360 no_of_descriptive_source_references
+= descriptiveElementsPerTaxon
+ 2 + 1;
364 // add taxon to classification
365 classifications
.get(classiCounter
).addChildTaxon(taxon
, null,
368 // now if there are any left, we create a synonym for the taxon
369 if (synonymCounter
< NO_OF_SYNONYMS
) {
371 randomName
= RandomStringUtils
.randomAlphabetic(5) + " "
372 + RandomStringUtils
.randomAlphabetic(10);
374 name
= BotanicalName
.NewInstance(Rank
.SPECIES());
375 name
.setNameCache(randomName
, true);
377 // create nomenclatural reference for synonym name (if left)
378 if (nomRefCounter
< NO_OF_NOMECLATURAL_REFERENCES
) {
380 Reference nomRef
= ReferenceFactory
.newBook();
381 name
.setNomenclaturalReference(nomRef
);
382 referenceService
.save(nomRef
);
386 if (no_of_descriptive_source_references
< NO_OF_DESCRIPTIVE_SOURCE_REFERENCES
) {
387 sDescrSourceRefFlag
= true;
389 // create a description and 2 description elements with
390 // references for synonym name
391 TaxonNameDescription nameDescr
= new TaxonNameDescription();
392 CommonTaxonName nameElement
= CommonTaxonName
393 .NewInstance("anderes Veilchen" + taxonCounter
,
395 TextData textElement
= new TextData();
396 Reference nameElementRef
= ReferenceFactory
398 Reference textElementRef
= ReferenceFactory
400 nameElement
.addSource(null, null, nameElementRef
,
402 textElement
.addSource(null, null, textElementRef
,
404 nameDescr
.addElement(nameElement
);
405 nameDescr
.addElement(textElement
);
406 name
.addDescription(nameDescr
);
407 // taxon.getName().addDescription(nameDescr);
408 referenceService
.save(nameElementRef
);
409 referenceService
.save(textElementRef
);
410 descriptionService
.save(nameDescr
);
411 no_of_descriptive_source_references
+= 2;
414 // create a new reference for every other synonym:
415 if (taxonCounter
% 2 != 0) {
416 sec
= createSecReference(classiCounter
, taxonCounter
);
418 Synonym synonym
= Synonym
.NewInstance(name
, sec
);
419 taxonService
.save(synonym
);
420 taxon
.addSynonym(synonym
,
421 SynonymRelationshipType
.SYNONYM_OF());
426 // if this is not the last classification and there are
427 // taxa left that should be in more than one classification
428 // we add the taxon to the next class in the list too.
429 if (classiCounter
< NO_OF_CLASSIFICATIONS
430 && sharedClassification
< NO_OF_SHARED_TAXA
) {
431 classifications
.get(classiCounter
+ 1).addChildTaxon(taxon
,
434 // we remember that this taxon is attached to 2
436 secondClassificationForTaxonFlag
= true;
437 sharedClassification
++;
438 classificationService
.saveOrUpdate(classifications
439 .get(classiCounter
+ 1));
442 taxonService
.save(taxon
);
443 classificationService
.saveOrUpdate(classifications
444 .get(classiCounter
));
446 // count the data created with this taxon:
447 int c
= classiCounter
;
449 if (secondClassificationForTaxonFlag
) {
453 // run the following loop once, if this taxon only belongs to
456 // twice, if it is attached to 2 classifications
457 for (int i
= classiCounter
; i
<= c
; i
++) {
459 // count everything just created for this taxon:
460 increment(no_of_accepted_taxa_c
, i
);
461 increment(no_of_taxon_names_c
, i
);
463 increment(no_of_nomenclatural_references_c
, i
);
466 increment(no_of_nomenclatural_references_c
, i
);
469 increment(no_of_synonyms_c
, i
);
470 increment(no_of_taxon_names_c
, i
);
472 if (taxonCounter
% 2 != 0) {
473 increment(no_of_all_references_c
, i
);
475 increment(no_of_all_references_c
, i
);
478 if (tDescrSourceRefFlag
) {
479 increment(no_of_descriptive_source_references_c
, i
,
480 descriptiveElementsPerTaxon
+ 2);
483 if (sDescrSourceRefFlag
) {
484 increment(no_of_descriptive_source_references_c
, i
, 2);
488 secondClassificationForTaxonFlag
= false;
492 tDescrSourceRefFlag
= false;
493 sDescrSourceRefFlag
= false;
496 // modify variables (post-loop)
498 remainder
-= taxaInClass
;
501 merge(no_of_accepted_taxa_c
, no_of_synonyms_c
, no_of_all_taxa_c
);
502 merge(no_of_all_references_c
, no_of_nomenclatural_references_c
,
503 no_of_all_references_c
);
507 * create and count a new sec Reference
509 * @param classiCounter
510 * @param taxonCounter
513 private Reference
createSecReference(int classiCounter
, int taxonCounter
) {
515 sec
= ReferenceFactory
.newBook();
516 sec
.setTitle("book " + classiCounter
+ "." + taxonCounter
);
517 referenceService
.save(sec
);
518 no_of_all_references
++;
522 private void merge(List
<Long
> no_of_sth1
, List
<Long
> no_of_sth2
,
523 List
<Long
> no_of_sum
) {
525 for (int i
= 0; i
< NO_OF_CLASSIFICATIONS
; i
++) {
526 Long sum
= no_of_sth1
.get(i
) + no_of_sth2
.get(i
);
527 no_of_sum
.set(i
, sum
);
533 * @throws java.lang.Exception
536 public void tearDown() throws Exception
{
539 // ****************** tests *****************
542 * {@link eu.etaxonomy.cdm.api.service.StatisticsServiceImpl#getCountStatistics(java.util.List)}
546 public void testGetCountStatistics() {
548 // create maps to compare the testresults with:
549 List
<Map
<String
, Number
>> expectedCountmapList
= new ArrayList
<Map
<String
, Number
>>();
550 if (PARTS
.contains("ALL")) {
551 expectedCountmapList
.add(createExpectedCountMap_ALL());
553 if (PARTS
.contains("CLASSIFICATION")) {
555 .addAll(createExpectedCountMaps_CLASSIFICATION());
558 // create configurator needed to call
559 // StatisticsService.getCountStatistics:
560 List
<StatisticsConfigurator
> configuratorList
= createConfiguratorList(
561 (String
[]) PARTS
.toArray(), TYPES
);
563 // run method of StatisticsService
564 List
<Statistics
> statisticsList
= service
565 .getCountStatistics(configuratorList
);
567 // print out the: expected and the result:
569 logger
.info("expected: ");
571 for (Map
<String
, Number
> map
: expectedCountmapList
) {
572 logger
.info(map
.toString());
574 logger
.info("statistics: ");
575 for (Statistics statistics
: statisticsList
) {
576 logger
.info(statistics
.getCountMap().toString());
580 // check the result with the expected values:
581 // as we cannot be sure the order of the statisticsList
582 // matches the order of the expectedCountmapList
583 // we have to work arround a little:
584 for (Statistics statistics
: statisticsList
) {
585 Boolean orCompare
= false;
586 for (Map
<String
, Number
> map
: expectedCountmapList
) {
587 orCompare
= orCompare
|| statistics
.getCountMap().equals(map
);
589 // assertTrue(orCompare);
601 private void print() {
602 for (Classification classification
: classifications
) {
603 System
.out
.println("Classification:" + classification
.toString());
604 for (TaxonNode node
: classification
.getAllNodes()) {
605 System
.out
.println("\tTaxon: " + node
.getTaxon().toString());
606 System
.out
.println(" \t(Name: "
607 + node
.getTaxon().getName().toString() + ")");
608 if (node
.getTaxon().getName().getNomenclaturalReference() != null) {
609 System
.out
.println(" \t(Nomencl. Ref.: "
610 + node
.getTaxon().getName()
611 .getNomenclaturalReference().getId() + ")");
613 for (Synonym synonym
: node
.getTaxon().getSynonyms()) {
614 System
.out
.println("\t\tSynonym: " + synonym
.toString());
615 System
.out
.println(" \t\t(Name: "
616 + synonym
.getName().toString() + ")");
617 if (synonym
.getName().getNomenclaturalReference() != null) {
618 System
.out
.println(" \t\t(Nomencl. Ref.: "
619 + synonym
.getName().getNomenclaturalReference()
622 System
.out
.println();
627 System
.out
.println();
628 System
.out
.println("end!");
632 // ************************** private methods ****************************+
636 * @param inClassification
639 private void increment(List
<Long
> no_of_sth
, int inClassification
,
641 no_of_sth
.set(inClassification
, (no_of_sth
.get(inClassification
))
645 private void increment(List
<Long
> no_of_sth
, int inClassification
) {
646 increment(no_of_sth
, inClassification
, 1);
649 private Map
<String
, Number
> createExpectedCountMap_ALL() {
650 Map
<String
, Number
> countMap
= new HashMap
<String
, Number
>();
652 for (StatisticsTypeEnum type
: TYPES
) {
653 // System.out.println(""+typeMap_ALL.get(type.getLabel()));
654 countMap
.put(type
.getLabel(), typeMap_ALL
.get(type
.getLabel()));
659 private List
<Map
<String
, Number
>> createExpectedCountMaps_CLASSIFICATION() {
661 List
<Map
<String
, Number
>> mapList
= new ArrayList
<Map
<String
, Number
>>();
663 for (int i
= 0; i
< NO_OF_CLASSIFICATIONS
; i
++) {
665 Map
<String
, Number
> countMap
= new HashMap
<String
, Number
>();
667 for (StatisticsTypeEnum type
: TYPES
) {
668 countMap
.put(type
.getLabel(),
669 typeCountMap_CLASSIFICATION
.get(type
.getLabel()).get(i
));
672 mapList
.add(countMap
);
681 private void createMap_ALL() {
682 typeMap_ALL
= new HashMap
<String
, Long
>() {
684 put(StatisticsTypeEnum
.CLASSIFICATION
.getLabel(),
685 Long
.valueOf(NO_OF_CLASSIFICATIONS
));
686 put(StatisticsTypeEnum
.ALL_TAXA
.getLabel(),
687 Long
.valueOf(NO_OF_ALLTAXA
));
688 put(StatisticsTypeEnum
.ACCEPTED_TAXA
.getLabel(),
689 Long
.valueOf(NO_OF_ACCEPTED_TAXA
));
690 put(StatisticsTypeEnum
.SYNONYMS
.getLabel(),
691 Long
.valueOf(NO_OF_SYNONYMS
));
692 put(StatisticsTypeEnum
.TAXON_NAMES
.getLabel(),
693 Long
.valueOf(NO_OF_TAXON_NAMES
));
694 // put(StatisticsTypeEnum.DESCRIPTIVE_SOURCE_REFERENCES.getLabel(),
695 // Long.valueOf(NO_OF_DESCRIPTIVE_SOURCE_REFERENCES));
696 put(StatisticsTypeEnum
.DESCRIPTIVE_SOURCE_REFERENCES
.getLabel(),
697 Long
.valueOf(no_of_descriptive_source_references
));
698 // put(StatisticsTypeEnum.ALL_REFERENCES.getLabel(),
699 // Long.valueOf(NO_OF_ALL_REFERENCES));
700 put(StatisticsTypeEnum
.ALL_REFERENCES
.getLabel(),
701 no_of_all_references
);
702 put(StatisticsTypeEnum
.NOMECLATURAL_REFERENCES
.getLabel(),
703 Long
.valueOf(NO_OF_NOMECLATURAL_REFERENCES
));
708 private List
<StatisticsConfigurator
> createConfiguratorList(String
[] part
,
709 List
<StatisticsTypeEnum
> types
) {
711 ArrayList
<StatisticsConfigurator
> configuratorList
= new ArrayList
<StatisticsConfigurator
>();
713 // 1. get types for configurators:
714 // in our case all the configurators will have the same types
715 // so we calculate the types once and save them in a helperConfigurator
716 StatisticsConfigurator helperConfigurator
= new StatisticsConfigurator();
719 for (StatisticsTypeEnum type
: types
) {
720 helperConfigurator
.addType(type
);
723 for (StatisticsTypeEnum enumValue
: StatisticsTypeEnum
.values()) {
724 helperConfigurator
.addType(enumValue
);
728 // 2. determine the entities and put each of them in a configurator:
730 // if no part was given:
732 helperConfigurator
.addFilter(PARTS_ALL
);
733 configuratorList
.add(helperConfigurator
);
735 // else parse list of parts and create configurator for each:
737 for (String string
: part
) {
738 if (string
.equals(StatisticsPartEnum
.ALL
.toString())) {
739 helperConfigurator
.addFilter(PARTS_ALL
);
740 configuratorList
.add(helperConfigurator
);
741 } else if (string
.equals(StatisticsPartEnum
.CLASSIFICATION
743 List
<Classification
> classificationsList
= classificationService
744 .listClassifications(null, 0, null, null);
745 for (Classification classification
: classificationsList
) {
747 StatisticsConfigurator newConfigurator
= new StatisticsConfigurator();
748 newConfigurator
.setType(helperConfigurator
.getType());
749 newConfigurator
.getFilter().addAll(
750 helperConfigurator
.getFilter());
751 newConfigurator
.addFilter(classification
);
752 configuratorList
.add(newConfigurator
);
759 return configuratorList
;