From 776068940db7388c064267e16034bbb1f348caab Mon Sep 17 00:00:00 2001 From: f43nd1r Date: Fri, 15 Jun 2018 10:29:59 +0200 Subject: [PATCH] fix group by. Closes #8 --- .../java/com/faendir/acra/service/DataService.java | 4 ++-- .../acra/ui/view/base/statistics/Property.java | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/faendir/acra/service/DataService.java b/src/main/java/com/faendir/acra/service/DataService.java index 55c851f..3377617 100644 --- a/src/main/java/com/faendir/acra/service/DataService.java +++ b/src/main/java/com/faendir/acra/service/DataService.java @@ -323,8 +323,8 @@ public class DataService implements Serializable { } } - public Map countReports(@NonNull Predicate where, Expression groupBy, @NonNull Expression select) { - List result = ((JPAQuery) new JPAQuery<>(entityManager)).from(report).where(where).groupBy(groupBy).select(select, report.id.count()).fetch(); + public Map countReports(@NonNull Predicate where, @NonNull Expression select) { + List result = ((JPAQuery) new JPAQuery<>(entityManager)).from(report).where(where).groupBy(select).select(select, report.id.count()).fetch(); return result.stream().collect(Collectors.toMap(tuple -> tuple.get(select), tuple -> tuple.get(report.id.count()))); } diff --git a/src/main/java/com/faendir/acra/ui/view/base/statistics/Property.java b/src/main/java/com/faendir/acra/ui/view/base/statistics/Property.java index a921042..b01299f 100644 --- a/src/main/java/com/faendir/acra/ui/view/base/statistics/Property.java +++ b/src/main/java/com/faendir/acra/ui/view/base/statistics/Property.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.faendir.acra.ui.view.base.statistics; import com.faendir.acra.service.DataService; @@ -44,17 +43,14 @@ class Property, T> { private final C filterComponent; private final Function filter; private final Chart chart; - private final Expression groupBy; private final Expression select; - private Property(String filterText, C filterComponent, Function filter, Chart chart, DataService dataService, Expression groupBy, - Expression select) { + private Property(String filterText, C filterComponent, Function filter, Chart chart, DataService dataService, Expression select) { this.dataService = dataService; this.checkBox = new CheckBox(filterText); this.filterComponent = filterComponent; this.filter = filter; this.chart = chart; - this.groupBy = groupBy; this.select = select; filterComponent.setEnabled(false); filterComponent.setWidth(100, Sizeable.Unit.PERCENTAGE); @@ -76,7 +72,7 @@ class Property, T> { } void update(BooleanExpression expression) { - chart.setContent(dataService.countReports(expression, groupBy, select)); + chart.setContent(dataService.countReports(expression, select)); } static class Factory { @@ -91,7 +87,7 @@ class Property, T> { Property createStringProperty(String filterText, String chartTitle, ComparableExpressionBase stringExpression) { ComboBox comboBox = new ComboBox<>(null, dataService.getFromReports(expression, stringExpression)); comboBox.setEmptySelectionAllowed(false); - return new Property<>(filterText, comboBox, stringExpression::eq, new PieChart(chartTitle), dataService, stringExpression, stringExpression); + return new Property<>(filterText, comboBox, stringExpression::eq, new PieChart(chartTitle), dataService, stringExpression); } Property createAgeProperty(String filterText, String chartTitle, DateTimeExpression dateTimeExpression) { @@ -103,8 +99,7 @@ class Property, T> { days -> dateTimeExpression.after(LocalDateTime.now().minus(days, ChronoUnit.DAYS)), new TimeChart(chartTitle), dataService, - SQLExpressions.date(dateTimeExpression), - dateTimeExpression); + SQLExpressions.date(dateTimeExpression)); } } }