1 package eu
.etaxonomy
.cdm
.api
.service
;
3 import java
.util
.ArrayList
;
6 import org
.apache
.log4j
.Logger
;
7 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
8 import org
.springframework
.stereotype
.Service
;
9 import org
.springframework
.transaction
.annotation
.Transactional
;
11 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.Statistics
;
12 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsConfigurator
;
13 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsTypeEnum
;
14 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
15 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
16 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
17 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
21 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionDao
;
22 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITaxonNameDao
;
23 import eu
.etaxonomy
.cdm
.persistence
.dao
.reference
.IReferenceDao
;
24 import eu
.etaxonomy
.cdm
.persistence
.dao
.statistics
.IStatisticsDao
;
25 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.IClassificationDao
;
26 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonDao
;
30 * @author s.buers Service to provide statistic data of the database elements
35 public class StatisticsServiceImpl
implements IStatisticsService
{
37 private static final Logger logger
= Logger
38 .getLogger(StatisticsServiceImpl
.class);
42 // this does not make sense, we just count nothing if no type is given.
43 // the one who calls this service should check that there are types given!
44 // private static final StatisticsTypeEnum DEFAULT_TYPE=StatisticsTypeEnum.ALL_TAXA;
45 //TODO create a list with all types.
47 // this constant can also be used by the ones that use the service
49 private static final IdentifiableEntity
<?
> ALL_DB
= null;
53 public IdentifiableEntity
<?
> getFilterALL_DB(){
57 private ArrayList
<Statistics
> statisticsList
;
60 private ITaxonDao taxonDao
;
63 private ITaxonNameDao taxonNameDao
;
66 private IClassificationDao classificationDao
;
69 private IReferenceDao referenceDao
;
72 private IStatisticsDao statisticsDao
;
75 private IDescriptionDao descriptionDao
;
78 * counts all the elements referenced in the configurator from the part of
79 * the database referenced in the configurator
81 * @param configurators
82 * @return be aware that a Statistics.countMap might contain "null"
83 * {@link Number} values, if the count failed (, if the value is "0"
84 * the count succeeded in counting zero elements.)
88 public List
<Statistics
> getCountStatistics(
89 List
<StatisticsConfigurator
> configurators
) {
91 statisticsList
= new ArrayList
<>();
93 for (StatisticsConfigurator statisticsConfigurator
: configurators
) {
94 // create a Statistics element for each configurator
95 countStatisticsPart(statisticsConfigurator
);
97 return this.statisticsList
;
101 private void countStatisticsPart(StatisticsConfigurator configurator
) {
102 // get last element of configurator.filter (the node that is the root
104 IdentifiableEntity
<?
> filter
= configurator
.getFilter().get(
105 (configurator
.getFilter().size()) - 1);
106 if (filter
== getFilterALL_DB()) {
107 countAll(configurator
);
108 } else { // check for classtype classification
109 countPart(configurator
, filter
);
114 private void countAll(StatisticsConfigurator configurator
) {
115 Statistics statistics
= new Statistics(configurator
);
117 for (StatisticsTypeEnum type
: configurator
.getType()) {
122 counter
= taxonDao
.count(TaxonBase
.class);
125 counter
= taxonDao
.count(Synonym
.class);
128 counter
= taxonDao
.count(Taxon
.class);
131 counter
= referenceDao
.count(eu
.etaxonomy
.cdm
.model
.reference
.Reference
.class);
132 counter
-=statisticsDao
.countNomenclaturalReferences();
135 case NOMENCLATURAL_REFERENCES
:
137 counter
= statisticsDao
.countNomenclaturalReferences();
141 counter
= classificationDao
.count(Classification
.class);
146 counter
= taxonNameDao
.count(TaxonName
.class);
149 case DESCRIPTIVE_SOURCE_REFERENCES
:
151 counter
= statisticsDao
.countDescriptiveSourceReferences();
156 counter
= descriptionDao
.count(DescriptionBase
.class);
161 statistics
.addCount(type
, counter
);
163 statisticsList
.add(statistics
);
167 private void countPart(StatisticsConfigurator configurator
,
168 IdentifiableEntity filter
) {
169 // TODO maybe remove redundant parameter filter
170 Statistics statistics
= new Statistics(configurator
);
174 if (filter
instanceof Classification
) {
176 for (StatisticsTypeEnum type
: configurator
.getType()) {
180 logger
.info("there should not be any classification "
181 + "nested in an other classification");
182 // so we set counter to 1, as a classification itself is one classification
183 counter
= new Long(1);
186 counter
= statisticsDao
.countTaxaInClassification(
187 Taxon
.class, (Classification
) filter
);
191 counter
= statisticsDao
.countTaxaInClassification(
192 TaxonBase
.class, (Classification
) filter
);
195 counter
= statisticsDao
.countTaxaInClassification(
196 Synonym
.class, (Classification
) filter
);
199 counter
= statisticsDao
200 .countTaxonNames((Classification
) filter
);
203 // counter = statisticsDao.countReferencesInClassification((Classification) filter);
204 counter
= statisticsDao
.countReferencesInClassificationWithUuids((Classification
) filter
);
205 counter
+=statisticsDao
206 .countDescriptive(true, (Classification
) filter
);
208 case DESCRIPTIVE_SOURCE_REFERENCES
:
209 counter
= statisticsDao
210 .countDescriptive(true, (Classification
) filter
);
213 counter
= statisticsDao
214 .countDescriptive(false, (Classification
) filter
);
216 case NOMENCLATURAL_REFERENCES
:
217 counter
= statisticsDao
218 .countNomenclaturalReferences((Classification
) filter
);
223 statistics
.addCount(type
, counter
);
225 } else if(filter
instanceof Taxon
) {
226 //TODO get all taxa of the tree:
229 statisticsDao
.getTaxonTree(filter
);
232 // we just return null as count for the statistics
233 // element, if the filter is neither classification nor null.
236 statisticsList
.add(statistics
);