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 org
.apache
.commons
.lang
.RandomStringUtils
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.junit
.After
;
18 import org
.junit
.AfterClass
;
19 import org
.junit
.Before
;
20 import org
.junit
.BeforeClass
;
21 import org
.junit
.Test
;
22 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
24 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.Statistics
;
25 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsConfigurator
;
26 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsPartEnum
;
27 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsTypeEnum
;
28 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
30 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
31 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
32 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
33 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
34 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
35 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
36 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
37 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
38 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
39 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
40 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
41 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
42 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
43 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
44 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
45 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
46 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
52 @SuppressWarnings({ "rawtypes", "serial" })
53 public class StatisticsServiceImplTest
extends CdmTransactionalIntegrationTest
{
55 // constant if you want to printout the database content to console:
56 // only recommended for a small probe
57 private static final boolean PRINTOUT
= true;
59 // ************constants to set up the expected results for all:
60 // ********************
62 // ............................................
64 // here is the list of the types that will be test counted in the
65 // parts (ALL, CLASSIFICATION)
66 private static final List
<StatisticsTypeEnum
> TYPES
= Arrays
67 .asList(new StatisticsTypeEnum
[] {
68 StatisticsTypeEnum
.CLASSIFICATION
,
69 StatisticsTypeEnum
.ACCEPTED_TAXA
,
70 StatisticsTypeEnum
.ALL_TAXA
,
71 StatisticsTypeEnum
.ALL_REFERENCES
, // this functionality
73 // classifications is still missing for in the Statistics
75 StatisticsTypeEnum
.SYNONYMS
,
76 StatisticsTypeEnum
.TAXON_NAMES
,
77 StatisticsTypeEnum
.NOMECLATURAL_REFERENCES
,
78 StatisticsTypeEnum
.DESCRIPTIVE_SOURCE_REFERENCES
});
80 // private static final String[] TYPES = { "CLASSIFICATION",
82 // "ALL_TAXA", "ALL_REFERENCES" };
84 // ................parts ..............................
86 private static final List
<String
> PARTS
= Arrays
.asList(new String
[] {
87 "ALL", "CLASSIFICATION" });
88 // .........................................................
90 // part= null means search all DB
91 private static final IdentifiableEntity PARTS_ALL
= null;
93 // here is the number of items that will be created for the test count:
94 // please only change the numbers
95 // but do not replace or add a number to any constants on the right.
98 private static final int NO_OF_ACCEPTED_TAXA
= 10;
100 // choose a number (less than NO_OF_ACCEPTED_TAXA)
101 private static final int NO_OF_CLASSIFICATIONS
= 3;
103 // must be less or equal to NO_OF_ACCEPTED_TAXA
104 private static final int NO_OF_SYNONYMS
= 7;
106 // taxa that occure in several classifications:
107 // must NOT be more than NO_OF_ACCEPTED_TAXA
108 private static final int NO_OF_SHARED_TAXA
= 4;
110 // must be NO_OF_ACCEPTED_TAXA + NO_OF_SYNONYMS
111 private static final int NO_OF_ALLTAXA
= NO_OF_ACCEPTED_TAXA
114 // must be NO_OF_ACCEPTED_TAXA+NO_OF_SYNONYMS
115 private static final int NO_OF_TAXON_NAMES
= NO_OF_ACCEPTED_TAXA
118 // this represents an approx. no of the amount that will actually generated!
119 private static final int NO_OF_DESCRIPTIVE_SOURCE_REFERENCES
= 16;
121 // private static final int NO_OF_ALL_REFERENCES = NO_OF_ACCEPTED_TAXA + 0;
123 // must not be more than NO_OF_ACCEPTED_TAXA+NO_OF_SYNONYMS
124 private static final int NO_OF_NOMECLATURAL_REFERENCES
= NO_OF_ACCEPTED_TAXA
125 + NO_OF_SYNONYMS
- 4;
127 // --------------------variables for all ------------------
129 private Long no_of_all_references
= new Long(0);
130 private Long no_of_descriptive_source_references
= new Long(0);
132 // ............................................
134 // log the type enum to an int constant:
135 private Map
<String
, Long
> typeMap_ALL
;
137 // ------------------ variables for CLASSIFICATIONS -----------------------
139 // int[] anArray = new int[NO_OF_CLASSIFICATIONS];
140 private static List
<Long
> no_of_all_taxa_c
= new ArrayList
<Long
>(
141 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
142 private static List
<Long
> no_of_accepted_taxa_c
= new ArrayList
<Long
>(
143 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
144 private static List
<Long
> no_of_synonyms_c
= new ArrayList
<Long
>(
145 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
146 private static List
<Long
> no_of_taxon_names_c
= new ArrayList
<Long
>(
147 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
148 private static List
<Long
> no_of_descriptive_source_references_c
= new ArrayList
<Long
>(
149 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
150 private static List
<Long
> no_of_all_references_c
= new ArrayList
<Long
>(
151 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
152 private static List
<Long
> no_of_nomenclatural_references_c
= new ArrayList
<Long
>(
153 Collections
.nCopies(NO_OF_CLASSIFICATIONS
, new Long(0)));
154 // we do not count classifications in classifications
156 // ........................... constant map ..........................
158 private static final Map
<String
, List
<Long
>> typeCountMap_CLASSIFICATION
= new HashMap
<String
, List
<Long
>>() {
160 put(StatisticsTypeEnum
.CLASSIFICATION
.getLabel(),
161 new ArrayList
<Long
>(Arrays
.asList((Long
) null, null, null)));
162 put(StatisticsTypeEnum
.ALL_TAXA
.getLabel(), no_of_all_taxa_c
);
163 put(StatisticsTypeEnum
.ACCEPTED_TAXA
.getLabel(),
164 no_of_accepted_taxa_c
);
165 put(StatisticsTypeEnum
.SYNONYMS
.getLabel(), no_of_synonyms_c
);
166 put(StatisticsTypeEnum
.TAXON_NAMES
.getLabel(), no_of_taxon_names_c
);
167 put(StatisticsTypeEnum
.DESCRIPTIVE_SOURCE_REFERENCES
.getLabel(),
168 no_of_descriptive_source_references_c
);
169 put(StatisticsTypeEnum
.ALL_REFERENCES
.getLabel(),
170 no_of_all_references_c
);
171 put(StatisticsTypeEnum
.NOMECLATURAL_REFERENCES
.getLabel(),
172 no_of_nomenclatural_references_c
);
176 private static final Logger logger
= Logger
177 .getLogger(StatisticsServiceImplTest
.class);
179 private List
<Classification
> classifications
;
181 // ****************** services: ************************
183 private IStatisticsService service
;
185 private IClassificationService classificationService
;
187 private ITaxonService taxonService
;
189 private IReferenceService referenceService
;
191 private IDescriptionService descriptionService
;
193 // *************** more members: *****************+
196 * @throws java.lang.Exception
199 public static void setUpBeforeClass() throws Exception
{
203 * @throws java.lang.Exception
206 public static void tearDownAfterClass() throws Exception
{
210 * create some testdata
212 * @throws java.lang.Exception
217 public void setUp() throws Exception
{
219 // missing in this example data:
220 // synonyms, that are attached to several taxa (same or different
223 // create NO_OF_CLASSIFICATIONS classifications
224 classifications
= new ArrayList
<Classification
>();
226 for (int i
= 1; i
<= NO_OF_CLASSIFICATIONS
; i
++) {
227 Classification classification
= Classification
228 .NewInstance("European Abies" + i
);
229 classifications
.add(classification
);
230 classificationService
.save(classification
);
232 // create all taxa, references and synonyms and attach them to one or
233 // more classifications
236 int remainder
= NO_OF_ACCEPTED_TAXA
;
237 Reference sec
= ReferenceFactory
.newBook();
238 boolean secondClassificationForTaxonFlag
= false;
239 boolean synonymFlag
= false;
240 boolean tNomRefFlag
= false;
241 boolean sNomRefFlag
= false;
242 boolean tDescrSourceRefFlag
= false;
243 boolean sDescrSourceRefFlag
= false;
245 // variables: counter (pre-loop)
246 int descriptiveElementsPerTaxon
= (NO_OF_DESCRIPTIVE_SOURCE_REFERENCES
/ NO_OF_ACCEPTED_TAXA
) + 1;
249 int classiCounter
= 0, sharedClassification
= 0, synonymCounter
= 0, nomRefCounter
= 0;
251 // iterate over classifications and add taxa
252 for (/* see above */; remainder
> 0
253 && classiCounter
< NO_OF_CLASSIFICATIONS
; /* see below */) {
255 // compute no of taxa to be created in this classification
256 if (classiCounter
>= NO_OF_CLASSIFICATIONS
- 1) { // last
260 taxaInClass
= remainder
;
261 } else { // take half of left taxa for this class:
262 taxaInClass
= remainder
/ 2;
265 // iterate over amount of taxa meant to be in this classification
266 for (int taxonCounter
= 1; taxonCounter
<= taxaInClass
; taxonCounter
++) {
268 // create a String for the Name
269 RandomStringUtils
.randomAlphabetic(10);
270 String randomName
= RandomStringUtils
.randomAlphabetic(5) + " "
271 + RandomStringUtils
.randomAlphabetic(10);
273 // create a name for the taxon
274 BotanicalName name
= BotanicalName
.NewInstance(Rank
.SPECIES());
275 name
.setNameCache(randomName
, true);
277 // create nomenclatural reference for taxon name (if left)
278 if (nomRefCounter
< NO_OF_NOMECLATURAL_REFERENCES
) {
279 // we remember this taxon has a nomenclatural reference:
281 Reference nomRef
= ReferenceFactory
.newBook();
282 name
.setNomenclaturalReference(nomRef
);
283 referenceService
.save(nomRef
);
287 // create a new sec for every other taxon
288 if (taxonCounter
% 2 != 0) {
289 sec
= createSecReference(classiCounter
, taxonCounter
);
293 Taxon taxon
= Taxon
.NewInstance(name
, sec
);
295 // create descriptions, description sources and their references
297 if (no_of_descriptive_source_references
< NO_OF_DESCRIPTIVE_SOURCE_REFERENCES
) {
299 tDescrSourceRefFlag
= true;
301 // create a description and 2 description elements with
302 // references for taxon name
303 TaxonNameDescription nameDescr
= TaxonNameDescription
.NewInstance();
304 CommonTaxonName nameElement
= CommonTaxonName
.NewInstance(
305 "Veilchen" + taxonCounter
, Language
.GERMAN());
306 TextData textElement
= new TextData();
307 Reference nameElementRef
= ReferenceFactory
.newArticle();
308 Reference textElementRef
= ReferenceFactory
.newBookSection();
309 nameElement
.addSource(OriginalSourceType
.PrimaryTaxonomicSource
, null, null, nameElementRef
, "name: ");
310 textElement
.addSource(OriginalSourceType
.PrimaryTaxonomicSource
, null, null, textElementRef
, "text: ");
311 nameDescr
.addElement(nameElement
);
312 nameDescr
.addElement(textElement
);
313 name
.addDescription(nameDescr
);
314 // taxon.getName().addDescription(nameDescr);
315 referenceService
.save(nameElementRef
);
316 referenceService
.save(textElementRef
);
317 descriptionService
.save(nameDescr
);
319 // create descriptions, description sources and their
322 TaxonDescription taxonDescription
= new TaxonDescription();
323 for (int i
= 0; i
< descriptiveElementsPerTaxon
; i
++) {
324 DescriptionElementBase descriptionElement
= new TextData();
325 DescriptionElementSource descriptionElementSource
= DescriptionElementSource
326 .NewInstance(OriginalSourceType
.PrimaryTaxonomicSource
);
327 Reference article
= ReferenceFactory
.newArticle();
329 descriptionElementSource
.setCitation(article
);
330 descriptionElement
.addSource(descriptionElementSource
);
331 taxonDescription
.addElement(descriptionElement
);
332 referenceService
.save(article
);
333 descriptionService
.saveDescriptionElement(descriptionElement
);
336 descriptionService
.save(taxonDescription
);
337 taxon
.addDescription(taxonDescription
);
339 // create a Specimen for taxon with description, descr.
340 // element and referece
342 // Specimen specimen = Specimen.NewInstance();
343 // SpecimenDescription specimenDescription = SpecimenDescription.NewInstance(specimen);
344 // DescriptionElementBase descrElement = new TextData();
345 // Reference specimenRef = ReferenceFactory.newArticle();
346 // descrElement.addSource(null, null, specimenRef, null);
349 // descriptionService.save(specimenDescription);
350 // taxon.add(specimen);
352 no_of_descriptive_source_references
+= descriptiveElementsPerTaxon
+ 2 + 1;
356 // add taxon to classification
357 classifications
.get(classiCounter
).addChildTaxon(taxon
, null, null);
359 // now if there are any left, we create a synonym for the taxon
360 if (synonymCounter
< NO_OF_SYNONYMS
) {
362 randomName
= RandomStringUtils
.randomAlphabetic(5) + " "
363 + RandomStringUtils
.randomAlphabetic(10);
365 name
= BotanicalName
.NewInstance(Rank
.SPECIES());
366 name
.setNameCache(randomName
, true);
368 // create nomenclatural reference for synonym name (if left)
369 if (nomRefCounter
< NO_OF_NOMECLATURAL_REFERENCES
) {
371 Reference nomRef
= ReferenceFactory
.newBook();
372 name
.setNomenclaturalReference(nomRef
);
373 referenceService
.save(nomRef
);
377 if (no_of_descriptive_source_references
< NO_OF_DESCRIPTIVE_SOURCE_REFERENCES
) {
378 sDescrSourceRefFlag
= true;
380 // create a description and 2 description elements with
381 // references for synonym name
382 TaxonNameDescription nameDescr
= TaxonNameDescription
.NewInstance();
383 CommonTaxonName nameElement
= CommonTaxonName
384 .NewInstance("anderes Veilchen" + taxonCounter
,
386 TextData textElement
= new TextData();
387 Reference nameElementRef
= ReferenceFactory
389 Reference textElementRef
= ReferenceFactory
391 nameElement
.addSource(OriginalSourceType
.PrimaryTaxonomicSource
, null, null, nameElementRef
, "name: ");
392 textElement
.addSource(OriginalSourceType
.PrimaryTaxonomicSource
, null, null, textElementRef
, "text: ");
393 nameDescr
.addElement(nameElement
);
394 nameDescr
.addElement(textElement
);
395 name
.addDescription(nameDescr
);
396 // taxon.getName().addDescription(nameDescr);
397 referenceService
.save(nameElementRef
);
398 referenceService
.save(textElementRef
);
399 descriptionService
.save(nameDescr
);
400 no_of_descriptive_source_references
+= 2;
403 // create a new reference for every other synonym:
404 if (taxonCounter
% 2 != 0) {
405 sec
= createSecReference(classiCounter
, taxonCounter
);
407 Synonym synonym
= Synonym
.NewInstance(name
, sec
);
408 taxonService
.save(synonym
);
409 taxon
.addSynonym(synonym
,
410 SynonymRelationshipType
.SYNONYM_OF());
415 // if this is not the last classification and there are
416 // taxa left that should be in more than one classification
417 // we add the taxon to the next class in the list too.
418 if (classiCounter
< NO_OF_CLASSIFICATIONS
419 && sharedClassification
< NO_OF_SHARED_TAXA
) {
420 classifications
.get(classiCounter
+ 1).addChildTaxon(taxon
, null, null);
422 // we remember that this taxon is attached to 2
424 secondClassificationForTaxonFlag
= true;
425 sharedClassification
++;
426 classificationService
.saveOrUpdate(classifications
427 .get(classiCounter
+ 1));
430 taxonService
.save(taxon
);
431 classificationService
.saveOrUpdate(classifications
432 .get(classiCounter
));
434 // count the data created with this taxon:
435 int c
= classiCounter
;
437 if (secondClassificationForTaxonFlag
) {
441 // run the following loop once, if this taxon only belongs to
444 // twice, if it is attached to 2 classifications
445 for (int i
= classiCounter
; i
<= c
; i
++) {
447 // count everything just created for this taxon:
448 increment(no_of_accepted_taxa_c
, i
);
449 increment(no_of_taxon_names_c
, i
);
451 increment(no_of_nomenclatural_references_c
, i
);
454 increment(no_of_nomenclatural_references_c
, i
);
457 increment(no_of_synonyms_c
, i
);
458 increment(no_of_taxon_names_c
, i
);
460 if (taxonCounter
% 2 != 0) {
461 increment(no_of_all_references_c
, i
);
463 increment(no_of_all_references_c
, i
);
466 if (tDescrSourceRefFlag
) {
467 increment(no_of_descriptive_source_references_c
, i
,
468 descriptiveElementsPerTaxon
+ 2);
471 if (sDescrSourceRefFlag
) {
472 increment(no_of_descriptive_source_references_c
, i
, 2);
476 secondClassificationForTaxonFlag
= false;
480 tDescrSourceRefFlag
= false;
481 sDescrSourceRefFlag
= false;
484 // modify variables (post-loop)
486 remainder
-= taxaInClass
;
489 merge(no_of_accepted_taxa_c
, no_of_synonyms_c
, no_of_all_taxa_c
);
490 merge(no_of_all_references_c
, no_of_nomenclatural_references_c
,
491 no_of_all_references_c
);
495 * create and count a new sec Reference
497 * @param classiCounter
498 * @param taxonCounter
501 private Reference
createSecReference(int classiCounter
, int taxonCounter
) {
503 sec
= ReferenceFactory
.newBook();
504 sec
.setTitle("book " + classiCounter
+ "." + taxonCounter
);
505 referenceService
.save(sec
);
506 no_of_all_references
++;
510 private void merge(List
<Long
> no_of_sth1
, List
<Long
> no_of_sth2
,
511 List
<Long
> no_of_sum
) {
513 for (int i
= 0; i
< NO_OF_CLASSIFICATIONS
; i
++) {
514 Long sum
= no_of_sth1
.get(i
) + no_of_sth2
.get(i
);
515 no_of_sum
.set(i
, sum
);
521 * @throws java.lang.Exception
524 public void tearDown() throws Exception
{
527 // ****************** tests *****************
530 * {@link eu.etaxonomy.cdm.api.service.StatisticsServiceImpl#getCountStatistics(java.util.List)}
534 public void testGetCountStatistics() {
536 // create maps to compare the testresults with:
537 List
<Map
<String
, Number
>> expectedCountmapList
= new ArrayList
<Map
<String
, Number
>>();
538 if (PARTS
.contains("ALL")) {
539 expectedCountmapList
.add(createExpectedCountMap_ALL());
541 if (PARTS
.contains("CLASSIFICATION")) {
543 .addAll(createExpectedCountMaps_CLASSIFICATION());
546 // create configurator needed to call
547 // StatisticsService.getCountStatistics:
548 List
<StatisticsConfigurator
> configuratorList
= createConfiguratorList(
549 (String
[]) PARTS
.toArray(), TYPES
);
551 // run method of StatisticsService
552 List
<Statistics
> statisticsList
= service
553 .getCountStatistics(configuratorList
);
555 // print out the: expected and the result:
557 logger
.info("expected: ");
559 for (Map
<String
, Number
> map
: expectedCountmapList
) {
560 logger
.info(map
.toString());
562 logger
.info("statistics: ");
563 for (Statistics statistics
: statisticsList
) {
564 logger
.info(statistics
.getCountMap().toString());
568 // check the result with the expected values:
569 // as we cannot be sure the order of the statisticsList
570 // matches the order of the expectedCountmapList
571 // we have to work arround a little:
572 for (Statistics statistics
: statisticsList
) {
573 Boolean orCompare
= false;
574 for (Map
<String
, Number
> map
: expectedCountmapList
) {
575 orCompare
= orCompare
|| statistics
.getCountMap().equals(map
);
577 // assertTrue(orCompare);
589 private void print() {
590 for (Classification classification
: classifications
) {
591 System
.out
.println("Classification:" + classification
.toString());
592 for (TaxonNode node
: classification
.getAllNodes()) {
593 System
.out
.println("\tTaxon: " + node
.getTaxon().toString());
594 System
.out
.println(" \t(Name: "
595 + node
.getTaxon().getName().toString() + ")");
596 if (node
.getTaxon().getName().getNomenclaturalReference() != null) {
597 System
.out
.println(" \t(Nomencl. Ref.: "
598 + node
.getTaxon().getName()
599 .getNomenclaturalReference().getId() + ")");
601 for (Synonym synonym
: node
.getTaxon().getSynonyms()) {
602 System
.out
.println("\t\tSynonym: " + synonym
.toString());
603 System
.out
.println(" \t\t(Name: "
604 + synonym
.getName().toString() + ")");
605 if (synonym
.getName().getNomenclaturalReference() != null) {
606 System
.out
.println(" \t\t(Nomencl. Ref.: "
607 + synonym
.getName().getNomenclaturalReference()
610 System
.out
.println();
615 System
.out
.println();
616 System
.out
.println("end!");
620 // ************************** private methods ****************************+
624 * @param inClassification
627 private void increment(List
<Long
> no_of_sth
, int inClassification
,
629 no_of_sth
.set(inClassification
, (no_of_sth
.get(inClassification
))
633 private void increment(List
<Long
> no_of_sth
, int inClassification
) {
634 increment(no_of_sth
, inClassification
, 1);
637 private Map
<String
, Number
> createExpectedCountMap_ALL() {
638 Map
<String
, Number
> countMap
= new HashMap
<String
, Number
>();
640 for (StatisticsTypeEnum type
: TYPES
) {
641 // System.out.println(""+typeMap_ALL.get(type.getLabel()));
642 countMap
.put(type
.getLabel(), typeMap_ALL
.get(type
.getLabel()));
647 private List
<Map
<String
, Number
>> createExpectedCountMaps_CLASSIFICATION() {
649 List
<Map
<String
, Number
>> mapList
= new ArrayList
<Map
<String
, Number
>>();
651 for (int i
= 0; i
< NO_OF_CLASSIFICATIONS
; i
++) {
653 Map
<String
, Number
> countMap
= new HashMap
<String
, Number
>();
655 for (StatisticsTypeEnum type
: TYPES
) {
656 countMap
.put(type
.getLabel(),
657 typeCountMap_CLASSIFICATION
.get(type
.getLabel()).get(i
));
660 mapList
.add(countMap
);
669 private void createMap_ALL() {
670 typeMap_ALL
= new HashMap
<String
, Long
>() {
672 put(StatisticsTypeEnum
.CLASSIFICATION
.getLabel(),
673 Long
.valueOf(NO_OF_CLASSIFICATIONS
));
674 put(StatisticsTypeEnum
.ALL_TAXA
.getLabel(),
675 Long
.valueOf(NO_OF_ALLTAXA
));
676 put(StatisticsTypeEnum
.ACCEPTED_TAXA
.getLabel(),
677 Long
.valueOf(NO_OF_ACCEPTED_TAXA
));
678 put(StatisticsTypeEnum
.SYNONYMS
.getLabel(),
679 Long
.valueOf(NO_OF_SYNONYMS
));
680 put(StatisticsTypeEnum
.TAXON_NAMES
.getLabel(),
681 Long
.valueOf(NO_OF_TAXON_NAMES
));
682 // put(StatisticsTypeEnum.DESCRIPTIVE_SOURCE_REFERENCES.getLabel(),
683 // Long.valueOf(NO_OF_DESCRIPTIVE_SOURCE_REFERENCES));
684 put(StatisticsTypeEnum
.DESCRIPTIVE_SOURCE_REFERENCES
.getLabel(),
685 Long
.valueOf(no_of_descriptive_source_references
));
686 // put(StatisticsTypeEnum.ALL_REFERENCES.getLabel(),
687 // Long.valueOf(NO_OF_ALL_REFERENCES));
688 put(StatisticsTypeEnum
.ALL_REFERENCES
.getLabel(),
689 no_of_all_references
);
690 put(StatisticsTypeEnum
.NOMECLATURAL_REFERENCES
.getLabel(),
691 Long
.valueOf(NO_OF_NOMECLATURAL_REFERENCES
));
696 private List
<StatisticsConfigurator
> createConfiguratorList(String
[] part
,
697 List
<StatisticsTypeEnum
> types
) {
699 ArrayList
<StatisticsConfigurator
> configuratorList
= new ArrayList
<StatisticsConfigurator
>();
701 // 1. get types for configurators:
702 // in our case all the configurators will have the same types
703 // so we calculate the types once and save them in a helperConfigurator
704 StatisticsConfigurator helperConfigurator
= new StatisticsConfigurator();
707 for (StatisticsTypeEnum type
: types
) {
708 helperConfigurator
.addType(type
);
711 for (StatisticsTypeEnum enumValue
: StatisticsTypeEnum
.values()) {
712 helperConfigurator
.addType(enumValue
);
716 // 2. determine the entities and put each of them in a configurator:
718 // if no part was given:
720 helperConfigurator
.addFilter(PARTS_ALL
);
721 configuratorList
.add(helperConfigurator
);
723 // else parse list of parts and create configurator for each:
725 for (String string
: part
) {
726 if (string
.equals(StatisticsPartEnum
.ALL
.toString())) {
727 helperConfigurator
.addFilter(PARTS_ALL
);
728 configuratorList
.add(helperConfigurator
);
729 } else if (string
.equals(StatisticsPartEnum
.CLASSIFICATION
731 List
<Classification
> classificationsList
= classificationService
732 .listClassifications(null, 0, null, null);
733 for (Classification classification
: classificationsList
) {
735 StatisticsConfigurator newConfigurator
= new StatisticsConfigurator();
736 newConfigurator
.setType(helperConfigurator
.getType());
737 newConfigurator
.getFilter().addAll(
738 helperConfigurator
.getFilter());
739 newConfigurator
.addFilter(classification
);
740 configuratorList
.add(newConfigurator
);
747 return configuratorList
;