1 package eu
.etaxonomy
.cdm
.api
.service
;
3 import java
.util
.Arrays
;
4 import java
.util
.HashSet
;
9 import org
.apache
.log4j
.Logger
;
10 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
11 import org
.springframework
.stereotype
.Service
;
12 import org
.springframework
.transaction
.annotation
.Transactional
;
14 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.Statistics
;
15 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsConfigurator
;
16 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsPartEnum
;
17 import eu
.etaxonomy
.cdm
.api
.service
.statistics
.StatisticsTypeEnum
;
18 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
19 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
20 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
21 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
22 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
23 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
24 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
25 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
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
.persistence
.dao
.description
.IDescriptionDao
;
30 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionElementDao
;
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
.taxon
.IClassificationDao
;
34 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonDao
;
38 * @author s.buers Service to provide statistic data of the database elements
43 public class StatisticsServiceImpl
implements IStatisticsService
{
45 private static final Logger logger
= Logger
46 .getLogger(StatisticsServiceImpl
.class);
48 private static final List
<String
> DESCRIPTION_SOURCE_REF_STRATEGIE
= Arrays
49 .asList(new String
[] { "sources.citation" });
50 // "descriptionSources", "citation"
52 private static final List
<String
> DESCR_ELEMENT_REF_STRATEGIE
= Arrays
53 .asList(new String
[] { "sources.citation", });;
55 private StatisticsConfigurator configurator
;
57 private Statistics statistics
;
60 private ITaxonDao taxonDao
;
63 private ITaxonNameDao taxonNameDao
;
66 private IClassificationDao classificationDao
;
69 private IReferenceDao referenceDao
;
72 private IDescriptionDao descriptionDao
;
75 private IDescriptionElementDao descrElementDao
;
78 * counts all the elements referenced in the configurator from the part of
79 * the database referenced in the configurator
83 public Statistics
getCountStatistics(StatisticsConfigurator configurator
) {
84 this.configurator
= configurator
;
85 this.statistics
= new Statistics(configurator
);
86 // TODO use "about" parameter of Statistics element
88 return this.statistics
;
89 // return new Statistics(null);
92 private void calculateParts() {
93 for (StatisticsPartEnum part
: configurator
.getPart()) {
108 private void countAll() {
110 for (StatisticsTypeEnum type
: configurator
.getType()) {
115 number
+= taxonDao
.count(Taxon
.class);
117 number
+= taxonDao
.count(Synonym
.class);
120 number
+= taxonDao
.count(Taxon
.class);
123 number
+= referenceDao
124 .count(eu
.etaxonomy
.cdm
.model
.reference
.Reference
.class);
127 case NOMECLATURAL_REFERENCES
:
128 number
+= (referenceDao
.getAllNomenclaturalReferences()).size();
132 number
+= classificationDao
.count(Classification
.class);
137 number
+= taxonNameDao
.count(TaxonNameBase
.class);
140 // case DESCRIPTIVE_SOURCE_REFERENCES:
141 // TODO create statistics DAO
142 // number += getDescriptiveSourceReferences();
145 statistics
.addCount(type
, number
);
150 private Integer
getDescriptiveSourceReferences() {
153 // count references from each description:
154 // TODO test this function or write dao and delete it
156 // // we need the set to get off the doubles:
159 * TODO >>> better performance and more reliabale deduplication with
160 * Set<UUID> referenceUuids = new HashSet<UUID>();
162 Set
<UUID
> referenceUuids
= new HashSet
<UUID
>();
163 Set
<eu
.etaxonomy
.cdm
.model
.reference
.Reference
<?
>> references
= new HashSet
<eu
.etaxonomy
.cdm
.model
.reference
.Reference
<?
>>();
164 // TODO second param 0?:
167 * TODO >>>> it should not be necessary to use init stratgies >>>>
168 * listDescriptions(null, null, null, null, null, null, null, null);
169 * would list all descriptions
171 List
<DescriptionBase
> descriptions
= descriptionDao
.listDescriptions(
172 TaxonDescription
.class, null, null, null, null, null, null,
173 DESCRIPTION_SOURCE_REF_STRATEGIE
);
174 descriptions
.addAll(descriptionDao
.listDescriptions(
175 TaxonNameDescription
.class, null, null, null, null, null, null,
176 DESCRIPTION_SOURCE_REF_STRATEGIE
));
177 descriptions
.addAll(descriptionDao
.listDescriptions(
178 SpecimenDescription
.class, null, null, null, null, null, null,
179 DESCRIPTION_SOURCE_REF_STRATEGIE
));
181 for (DescriptionBase
<?
> description
: descriptions
) {
183 // get all sources of the description
184 Set
<IdentifiableSource
> sources
= description
.getSources();
185 for (IdentifiableSource source
: sources
) {
186 if (source
.getCitation() != null)
188 references
.add(source
.getCitation());
192 * TODO >>>> get all description elements from the description
194 * e.g: for (DescriptionElementBase element :
195 * description.getElements()) { for (DescriptionElementSource source
196 * : element.getSources()) {
202 // this part still provokes an error:
203 // count references from each description element:
204 List
<DescriptionElementBase
> descrElements
= descrElementDao
.list(null,
205 0, null, DESCR_ELEMENT_REF_STRATEGIE
);
206 for (DescriptionElementBase descriptionElement
: descrElements
) {
207 Set
<DescriptionElementSource
> elementSources
= descriptionElement
209 for (DescriptionElementSource source
: elementSources
) {
210 if (source
.getCitation() != null)
211 references
.add(source
.getCitation());
215 return references
.size();