2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.api
.service
;
11 import java
.util
.ArrayList
;
12 import java
.util
.List
;
14 import org
.apache
.logging
.log4j
.LogManager
;
15 import org
.apache
.logging
.log4j
.Logger
;
16 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
17 import org
.springframework
.stereotype
.Service
;
18 import org
.springframework
.transaction
.annotation
.Transactional
;
20 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.Statistics
;
21 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsConfigurator
;
22 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsTypeEnum
;
23 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
24 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
25 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
30 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionDao
;
31 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITaxonNameDao
;
32 import eu
.etaxonomy
.cdm
.persistence
.dao
.reference
.IReferenceDao
;
33 import eu
.etaxonomy
.cdm
.persistence
.dao
.statistics
.IStatisticsDao
;
34 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.IClassificationDao
;
35 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonDao
;
38 * @author s.buers Service to provide statistic data of the database elements
42 public class StatisticsServiceImpl
implements IStatisticsService
{
44 private static final Logger logger
= LogManager
.getLogger(StatisticsServiceImpl
.class);
46 // this does not make sense, we just count nothing if no type is given.
47 // the one who calls this service should check that there are types given!
48 // private static final StatisticsTypeEnum DEFAULT_TYPE=StatisticsTypeEnum.ALL_TAXA;
49 //TODO create a list with all types.
51 // this constant can also be used by the ones that use the service
53 private static final IdentifiableEntity
<?
> ALL_DB
= null;
57 public IdentifiableEntity
<?
> getFilterALL_DB(){
61 private ArrayList
<Statistics
> statisticsList
;
64 private ITaxonDao taxonDao
;
67 private ITaxonNameDao taxonNameDao
;
70 private IClassificationDao classificationDao
;
73 private IReferenceDao referenceDao
;
76 private IStatisticsDao statisticsDao
;
79 private IDescriptionDao descriptionDao
;
82 * counts all the elements referenced in the configurator from the part of
83 * the database referenced in the configurator
85 * @param configurators
86 * @return be aware that a Statistics.countMap might contain "null"
87 * {@link Number} values, if the count failed (, if the value is "0"
88 * the count succeeded in counting zero elements.)
92 public List
<Statistics
> getCountStatistics(
93 List
<StatisticsConfigurator
> configurators
) {
95 statisticsList
= new ArrayList
<>();
97 for (StatisticsConfigurator statisticsConfigurator
: configurators
) {
98 // create a Statistics element for each configurator
99 countStatisticsPart(statisticsConfigurator
);
101 return this.statisticsList
;
105 private void countStatisticsPart(StatisticsConfigurator configurator
) {
106 // get last element of configurator.filter (the node that is the root
108 IdentifiableEntity
<?
> filter
= configurator
.getFilter().get(
109 (configurator
.getFilter().size()) - 1);
110 if (filter
== getFilterALL_DB()) {
111 countAll(configurator
);
112 } else { // check for classtype classification
113 countPart(configurator
, filter
);
118 private void countAll(StatisticsConfigurator configurator
) {
119 Statistics statistics
= new Statistics(configurator
);
121 for (StatisticsTypeEnum type
: configurator
.getType()) {
126 counter
= taxonDao
.count(TaxonBase
.class);
129 counter
= taxonDao
.count(Synonym
.class);
132 counter
= taxonDao
.count(Taxon
.class);
135 counter
= referenceDao
.count(eu
.etaxonomy
.cdm
.model
.reference
.Reference
.class);
136 counter
-=statisticsDao
.countNomenclaturalReferences();
139 case NOMENCLATURAL_REFERENCES
:
141 counter
= statisticsDao
.countNomenclaturalReferences();
145 counter
= classificationDao
.count(Classification
.class);
150 counter
= taxonNameDao
.count(TaxonName
.class);
153 case DESCRIPTIVE_SOURCE_REFERENCES
:
155 counter
= statisticsDao
.countDescriptiveSourceReferences();
160 counter
= descriptionDao
.count(DescriptionBase
.class);
165 statistics
.addCount(type
, counter
);
167 statisticsList
.add(statistics
);
171 private void countPart(StatisticsConfigurator configurator
,
172 IdentifiableEntity filter
) {
173 // TODO maybe remove redundant parameter filter
174 Statistics statistics
= new Statistics(configurator
);
178 if (filter
instanceof Classification
) {
180 for (StatisticsTypeEnum type
: configurator
.getType()) {
184 logger
.info("there should not be any classification "
185 + "nested in an other classification");
186 // so we set counter to 1, as a classification itself is one classification
187 counter
= new Long(1);
190 counter
= statisticsDao
.countTaxaInClassification(
191 Taxon
.class, (Classification
) filter
);
195 counter
= statisticsDao
.countTaxaInClassification(
196 TaxonBase
.class, (Classification
) filter
);
199 counter
= statisticsDao
.countTaxaInClassification(
200 Synonym
.class, (Classification
) filter
);
203 counter
= statisticsDao
204 .countTaxonNames((Classification
) filter
);
207 // counter = statisticsDao.countReferencesInClassification((Classification) filter);
208 counter
= statisticsDao
.countReferencesInClassificationWithUuids((Classification
) filter
);
209 counter
+=statisticsDao
210 .countDescriptive(true, (Classification
) filter
);
212 case DESCRIPTIVE_SOURCE_REFERENCES
:
213 counter
= statisticsDao
214 .countDescriptive(true, (Classification
) filter
);
217 counter
= statisticsDao
218 .countDescriptive(false, (Classification
) filter
);
220 case NOMENCLATURAL_REFERENCES
:
221 counter
= statisticsDao
222 .countNomenclaturalReferences((Classification
) filter
);
227 statistics
.addCount(type
, counter
);
229 } else if(filter
instanceof Taxon
) {
230 //TODO get all taxa of the tree:
233 statisticsDao
.getTaxonTree(filter
);
236 // we just return null as count for the statistics
237 // element, if the filter is neither classification nor null.
240 statisticsList
.add(statistics
);