Revision e7211ef5
Added by Sybille Bürs over 11 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/statistics/StatisticsDaoHibernateImpl.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
@Override |
23 | 23 |
public Long countNomenclaturalReferences() { |
24 |
Query query = getSession() |
|
25 |
.createQuery( |
|
26 |
"select count(distinct nomenclaturalReference) from TaxonNameBase"); |
|
24 |
return countNomenclaturalReferences(""); |
|
25 |
} |
|
27 | 26 |
|
28 |
return (Long) query.uniqueResult();
|
|
27 |
private Long countNomenclaturalReferences(String where) {
|
|
29 | 28 |
|
29 |
Query query = getSession().createQuery( |
|
30 |
"select count(distinct nomenclaturalReference) from TaxonNameBase" |
|
31 |
+ where); |
|
32 |
return (Long) query.uniqueResult(); |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public Long countNomenclaturalReferences(Class clazz){ |
|
37 |
return countNomenclaturalReferences("where" + clazz.getSimpleName()); |
|
30 | 38 |
} |
31 | 39 |
|
32 | 40 |
/** |
... | ... | |
42 | 50 |
"select distinct descriptionSources from DescriptionBase"); |
43 | 51 |
// org.hibernate.type.Type[] types= query.getReturnTypes(); |
44 | 52 |
List<DescriptionElementSource> queryList = query.list(); |
45 |
Set <DescriptionElementSource> sourcesSet = new HashSet<DescriptionElementSource>();
|
|
53 |
Set<DescriptionElementSource> sourcesSet = new HashSet<DescriptionElementSource>(); |
|
46 | 54 |
sourcesSet.addAll(query.list()); |
47 | 55 |
if (queryList == null/* || queryList.isEmpty() */) { |
48 | 56 |
return null; |
... | ... | |
58 | 66 |
// eliminate doubles |
59 | 67 |
|
60 | 68 |
query = getSession().createQuery( |
61 |
// "select count(distinct citation) from (select distinct sources from DescriptionElementBase)");
|
|
69 |
// "select count(distinct citation) from (select distinct sources from DescriptionElementBase)");
|
|
62 | 70 |
"select distinct sources from DescriptionElementBase"); |
63 |
|
|
71 |
|
|
64 | 72 |
// count=(Long)query.uniqueResult(); |
65 | 73 |
org.hibernate.type.Type[] types = query.getReturnTypes(); |
66 | 74 |
// Object object =query.uniqueResult(); |
... | ... | |
74 | 82 |
// count += queryList.size(); |
75 | 83 |
// //// |
76 | 84 |
} |
77 |
// Set<DescriptionElementSource> sourceSet = new HashSet<DescriptionElementSource>(); |
|
85 |
// Set<DescriptionElementSource> sourceSet = new |
|
86 |
// HashSet<DescriptionElementSource>(); |
|
78 | 87 |
Set<Reference> referenceSet = new HashSet<Reference>(); |
79 | 88 |
for (DescriptionElementSource descriptionElementSource : queryList) { |
80 |
if(descriptionElementSource.getCitation()!=null){
|
|
89 |
if (descriptionElementSource.getCitation() != null) {
|
|
81 | 90 |
referenceSet.add(descriptionElementSource.getCitation()); |
82 | 91 |
} |
83 | 92 |
} |
84 |
|
|
85 |
// sourceSet.addAll(queryList);
|
|
86 |
// count += sourceSet.size();
|
|
87 |
count+=referenceSet.size();
|
|
88 |
|
|
93 |
|
|
94 |
// sourceSet.addAll(queryList);
|
|
95 |
// count += sourceSet.size();
|
|
96 |
count += referenceSet.size();
|
|
97 |
|
|
89 | 98 |
return count; |
90 | 99 |
} |
91 | 100 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/statistics/IStatisticsDao.java | ||
---|---|---|
7 | 7 |
|
8 | 8 |
|
9 | 9 |
public Long countDescriptiveSourceReferences(); |
10 |
|
|
11 |
|
|
12 |
Long countNomenclaturalReferences(Class clazz); |
|
10 | 13 |
} |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/StatisticsController.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.cdm.remote.controller; |
2 | 2 |
|
3 | 3 |
import java.io.IOException; |
4 |
import java.util.ArrayList; |
|
4 | 5 |
import java.util.List; |
5 | 6 |
|
6 | 7 |
import javax.servlet.http.HttpServletRequest; |
... | ... | |
27 | 28 |
* |
28 | 29 |
*/ |
29 | 30 |
@Controller |
30 |
@RequestMapping(value = { "/statistic" }) |
|
31 |
@RequestMapping(value = { "/statistics" })
|
|
31 | 32 |
public class StatisticsController { |
32 | 33 |
|
33 | 34 |
private static final Logger logger = Logger |
... | ... | |
69 | 70 |
ModelAndView mv = new ModelAndView(); |
70 | 71 |
|
71 | 72 |
createConfigurator(part, type); |
73 |
//TODO: |
|
72 | 74 |
// service.getStatistics(configurator); |
73 |
Statistics statistics = service.getCountStatistics(configurator); |
|
75 |
List<StatisticsConfigurator> configuratorList =new ArrayList<StatisticsConfigurator>(); |
|
76 |
configuratorList.add(configurator); |
|
77 |
List<Statistics> statistics = service.getCountStatistics(configuratorList); |
|
74 | 78 |
logger.info("doStatistics() - " + request.getServletPath()); |
75 | 79 |
|
76 | 80 |
mv.addObject(statistics); |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IStatisticsService.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.cdm.api.service; |
2 | 2 |
|
3 |
import java.util.List; |
|
4 |
|
|
3 | 5 |
import eu.etaxonomy.cdm.api.service.statistics.Statistics; |
4 | 6 |
import eu.etaxonomy.cdm.api.service.statistics.StatisticsConfigurator; |
5 | 7 |
|
... | ... | |
10 | 12 |
public interface IStatisticsService { |
11 | 13 |
|
12 | 14 |
|
13 |
Statistics getCountStatistics(StatisticsConfigurator configurator); |
|
15 |
// List<Statistics> getCountStatistics(StatisticsConfigurator configurator); |
|
16 |
|
|
17 |
List<Statistics> getCountStatistics( |
|
18 |
List<StatisticsConfigurator> configurator); |
|
14 | 19 |
|
15 | 20 |
|
16 | 21 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/StatisticsServiceImpl.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.cdm.api.service; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
3 | 4 |
import java.util.Arrays; |
4 | 5 |
import java.util.HashSet; |
5 | 6 |
import java.util.List; |
... | ... | |
54 | 55 |
private static final List<String> DESCR_ELEMENT_REF_STRATEGIE = Arrays |
55 | 56 |
.asList(new String[] { "sources.citation", });; |
56 | 57 |
|
57 |
private StatisticsConfigurator configurator;
|
|
58 |
private List<StatisticsConfigurator> configurators;
|
|
58 | 59 |
|
59 |
private Statistics statistics;
|
|
60 |
private ArrayList<Statistics> statisticsList;
|
|
60 | 61 |
|
61 | 62 |
@Autowired |
62 | 63 |
private ITaxonDao taxonDao; |
... | ... | |
75 | 76 |
|
76 | 77 |
@Autowired |
77 | 78 |
private IDescriptionElementDao descrElementDao; |
78 |
|
|
79 |
@Autowired
|
|
79 |
|
|
80 |
@Autowired |
|
80 | 81 |
private IStatisticsDao statisticsDao; |
81 | 82 |
|
82 | 83 |
/** |
83 | 84 |
* counts all the elements referenced in the configurator from the part of |
84 | 85 |
* the database referenced in the configurator |
85 |
|
|
86 |
* @param configurator |
|
87 |
* @return the Statistics countMap might contain null Numbers |
|
86 |
* |
|
87 |
* @param configurators |
|
88 |
* @return be aware that a Statistics.countMap might contain "null" for {@link Number} value, |
|
89 |
* if the count failed (, if the value is "0" the count succeeded and sum is 0) |
|
88 | 90 |
*/ |
89 | 91 |
@Override |
90 | 92 |
@Transactional |
91 |
|
|
92 |
public Statistics getCountStatistics(StatisticsConfigurator configurator) { |
|
93 |
this.configurator = configurator; |
|
94 |
this.statistics = new Statistics(configurator); |
|
93 |
public List<Statistics> getCountStatistics( |
|
94 |
List<StatisticsConfigurator> configurators) { |
|
95 |
|
|
96 |
statisticsList = new ArrayList<Statistics>(); |
|
97 |
|
|
98 |
for (StatisticsConfigurator statisticsConfigurator : configurators) { |
|
99 |
// create a Statistics element for each configurator |
|
100 |
countStatisticsPart(statisticsConfigurator); |
|
101 |
} |
|
95 | 102 |
// TODO use "about" parameter of Statistics element |
96 |
calculateParts(); |
|
97 |
return this.statistics; |
|
103 |
// calculateParts();
|
|
104 |
return this.statisticsList;
|
|
98 | 105 |
} |
106 |
|
|
99 | 107 |
|
100 |
private void calculateParts() { |
|
101 |
for (StatisticsPartEnum part : configurator.getPart()) { |
|
102 |
switch (part) { |
|
103 |
case ALL: |
|
104 |
countAll(); |
|
105 |
break; |
|
106 |
|
|
107 |
case CLASSIFICATION: |
|
108 |
// TODO |
|
109 |
break; |
|
110 |
} |
|
111 |
} |
|
112 |
|
|
113 |
} |
|
114 | 108 |
|
115 | 109 |
@Transactional |
116 |
private void countAll() { |
|
117 |
|
|
110 |
private void countStatisticsPart(StatisticsConfigurator configurator) { |
|
111 |
//TODO use about |
|
112 |
Statistics statistics = new Statistics(configurator); |
|
113 |
//TODO add about |
|
118 | 114 |
for (StatisticsTypeEnum type : configurator.getType()) { |
119 | 115 |
Long number = null; |
120 | 116 |
switch (type) { |
... | ... | |
129 | 125 |
number = Long.valueOf(taxonDao.count(Taxon.class)); |
130 | 126 |
break; |
131 | 127 |
case ALL_REFERENCES: |
132 |
number = Long.valueOf(referenceDao |
|
133 |
.count(eu.etaxonomy.cdm.model.reference.Reference.class)); |
|
128 |
number = Long |
|
129 |
.valueOf(referenceDao |
|
130 |
.count(eu.etaxonomy.cdm.model.reference.Reference.class)); |
|
134 | 131 |
break; |
135 | 132 |
|
136 | 133 |
case NOMECLATURAL_REFERENCES: |
137 |
// number += (referenceDao.getAllNomenclaturalReferences()).size(); // to slow!!! |
|
134 |
// number += |
|
135 |
// (referenceDao.getAllNomenclaturalReferences()).size(); // to |
|
136 |
// slow!!! |
|
138 | 137 |
number = statisticsDao.countNomenclaturalReferences(); |
139 | 138 |
break; |
140 | 139 |
|
141 | 140 |
case CLASSIFICATION: |
142 |
number = Long.valueOf(classificationDao.count(Classification.class)); |
|
141 |
number = Long.valueOf(classificationDao |
|
142 |
.count(Classification.class)); |
|
143 | 143 |
|
144 | 144 |
break; |
145 | 145 |
|
... | ... | |
148 | 148 |
break; |
149 | 149 |
|
150 | 150 |
case DESCRIPTIVE_SOURCE_REFERENCES: |
151 |
|
|
152 |
number = statisticsDao.countDescriptiveSourceReferences();
|
|
153 |
// number = taxonDao.count |
|
151 |
|
|
152 |
number = statisticsDao.countDescriptiveSourceReferences(); |
|
153 |
|
|
154 | 154 |
break; |
155 | 155 |
} |
156 | 156 |
|
157 | 157 |
statistics.addCount(type, number); |
158 | 158 |
} |
159 |
statisticsList.add(statistics); |
|
160 |
} |
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
//------------------------------------------------- |
|
165 |
|
|
166 |
|
|
167 |
// private void countStatistic(StatisticsConfigurator configurator){ |
|
168 |
// |
|
169 |
// Statistics statistics = new Statistics(configurator); |
|
170 |
// for (StatisticsPartEnum part : configurator.getPart()) { |
|
171 |
// switch (part) { |
|
172 |
// case ALL: |
|
173 |
// countAll(configurator); |
|
174 |
// break; |
|
175 |
// |
|
176 |
// case CLASSIFICATION: |
|
177 |
// // get classifications |
|
178 |
// // foreach classification: |
|
179 |
// countPart(); |
|
180 |
// break; |
|
181 |
// } |
|
182 |
// } |
|
183 |
// } |
|
184 |
|
|
185 |
// private void calculatePart() { |
|
186 |
// //TODO |
|
187 |
// for (StatisticsPartEnum part : configurator.getPart()) { |
|
188 |
// switch (part) { |
|
189 |
// case ALL: |
|
190 |
// countAll(); |
|
191 |
// break; |
|
192 |
// |
|
193 |
// case CLASSIFICATION: |
|
194 |
// // get classifications |
|
195 |
// // foreach classification: |
|
196 |
// countPart(); |
|
197 |
// break; |
|
198 |
// } |
|
199 |
// } |
|
200 |
// |
|
201 |
// } |
|
202 |
|
|
203 |
|
|
204 |
@Transactional |
|
205 |
private void countPart() { |
|
159 | 206 |
|
160 | 207 |
} |
161 | 208 |
|
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/statistics/Statistics.java | ||
---|---|---|
38 | 38 |
|
39 | 39 |
private List<IdentifiableEntity> about; |
40 | 40 |
|
41 |
|
|
41 | 42 |
// it's a pitty, but for JSON Map keys must be Strings |
42 | 43 |
// see also: JSONObject _fromMap( Map map, JsonConfig jsonConfig ) |
43 | 44 |
// --> TODO: modify MapJSONValueProcessor.processArrayValue(Object value, |
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/StatisticsServiceImplTest.java | ||
---|---|---|
58 | 58 |
@Test |
59 | 59 |
public void testGetCountStatistics_partAll() { |
60 | 60 |
|
61 |
createConfigurator(); |
|
62 |
boolean check = true; |
|
63 |
Statistics resultStat = service.getCountStatistics(configurator); |
|
64 |
Map<String, Number> resultCountMap = resultStat.getCountMap(); |
|
65 |
|
|
66 |
for (Map.Entry<StatisticsTypeEnum, Number> protoEntry : prototype |
|
67 |
.entrySet()) { |
|
68 |
|
|
69 |
logger.info(protoEntry.getKey().getLabel()+":\texpected count: " |
|
70 |
+ "\t\t" + protoEntry.getValue() + "\tactual count: " |
|
71 |
+ resultCountMap.get(protoEntry.getKey().getLabel())); |
|
72 |
|
|
73 |
if (!((resultCountMap.get(protoEntry.getKey().getLabel())) |
|
74 |
.equals((Number) 0))) { |
|
75 |
check = false; |
|
76 |
} |
|
77 |
} |
|
78 |
// Assert.assertFalse("everything was counted right!!!", check); |
|
79 |
Assert.assertTrue("some count did not match!!!", check); |
|
80 |
// fail("Not yet implemented"); |
|
61 |
// createConfigurator();
|
|
62 |
// boolean check = true;
|
|
63 |
// Statistics resultStat = service.getCountStatistics(configurator);
|
|
64 |
// Map<String, Number> resultCountMap = resultStat.getCountMap();
|
|
65 |
// |
|
66 |
// for (Map.Entry<StatisticsTypeEnum, Number> protoEntry : prototype
|
|
67 |
// .entrySet()) {
|
|
68 |
// |
|
69 |
// logger.info(protoEntry.getKey().getLabel()+":\texpected count: "
|
|
70 |
// + "\t\t" + protoEntry.getValue() + "\tactual count: "
|
|
71 |
// + resultCountMap.get(protoEntry.getKey().getLabel()));
|
|
72 |
// |
|
73 |
// if (!((resultCountMap.get(protoEntry.getKey().getLabel()))
|
|
74 |
// .equals((Number) 0))) {
|
|
75 |
// check = false;
|
|
76 |
// }
|
|
77 |
// }
|
|
78 |
//// Assert.assertFalse("everything was counted right!!!", check);
|
|
79 |
// Assert.assertTrue("some count did not match!!!", check);
|
|
80 |
//// fail("Not yet implemented");
|
|
81 | 81 |
} |
82 | 82 |
|
83 | 83 |
|
Also available in: Unified diff
first chapter of changing the service, controller and dao to a more generic structure that will be able to provide (amongst others) classification statistics