1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl;
20
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Map.Entry;
24 import java.util.stream.Collectors;
25
26 import org.dussan.vaadin.dcharts.DCharts;
27 import org.dussan.vaadin.dcharts.base.elements.XYseries;
28 import org.dussan.vaadin.dcharts.data.DataSeries;
29 import org.dussan.vaadin.dcharts.options.Series;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Service;
32
33 import com.hack23.cia.model.internal.application.data.document.impl.RiksdagenDocumentTypeSummaryEmbeddedId;
34 import com.hack23.cia.model.internal.application.data.document.impl.ViewRiksdagenDocumentTypeDailySummary;
35 import com.hack23.cia.service.api.ApplicationManager;
36 import com.hack23.cia.service.api.DataContainer;
37 import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.ChartOptions;
38 import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.DocumentChartDataManager;
39 import com.vaadin.ui.AbstractOrderedLayout;
40
41
42
43
44 @Service
45 public final class DocumentChartDataManagerImpl extends AbstractChartDataManagerImpl implements DocumentChartDataManager {
46
47
48 private static final String MOT_PROP_BET = "mot:prop:bet";
49
50
51 private static final String YEAR_PREFIX = "19";
52
53
54 private static final String EMPTY_STRING = "";
55
56
57 @Autowired
58 private ApplicationManager applicationManager;
59
60
61 @Autowired
62 private ChartOptions chartOptions;
63
64
65
66
67
68 public DocumentChartDataManagerImpl() {
69 super();
70 }
71
72
73
74
75
76
77
78 private Map<String, List<ViewRiksdagenDocumentTypeDailySummary>> getDocumentTypeMap() {
79 final DataContainer<ViewRiksdagenDocumentTypeDailySummary, RiksdagenDocumentTypeSummaryEmbeddedId> documentTypeSummaryDailyDataContainer = applicationManager
80 .getDataContainer(ViewRiksdagenDocumentTypeDailySummary.class);
81
82 return documentTypeSummaryDailyDataContainer.getAll().parallelStream()
83 .filter(t -> t != null && !t.getEmbeddedId().getPublicDate().startsWith(YEAR_PREFIX)
84 && MOT_PROP_BET.contains(t.getEmbeddedId().getDocumentType()))
85 .collect(Collectors.groupingBy(t -> t.getEmbeddedId().getDocumentType()));
86 }
87
88
89
90 @Override
91 public void createDocumentTypeChart(final AbstractOrderedLayout content) {
92
93 final Map<String, List<ViewRiksdagenDocumentTypeDailySummary>> map = getDocumentTypeMap();
94
95 final DataSeries dataSeries = new DataSeries();
96
97 final Series series = new Series();
98
99 for (final Entry<String, List<ViewRiksdagenDocumentTypeDailySummary>> entry : map.entrySet()) {
100
101 if (entry.getKey() != null && !EMPTY_STRING.equals(entry.getKey())) {
102
103 series.addSeries(new XYseries().setLabel(entry.getKey()));
104
105 dataSeries.newSeries();
106 final List<ViewRiksdagenDocumentTypeDailySummary> list = entry.getValue();
107 for (final ViewRiksdagenDocumentTypeDailySummary viewRiksdagenVoteDataBallotPartySummaryDaily : list) {
108 if (viewRiksdagenVoteDataBallotPartySummaryDaily != null) {
109 dataSeries.add(viewRiksdagenVoteDataBallotPartySummaryDaily.getEmbeddedId().getPublicDate(),
110 viewRiksdagenVoteDataBallotPartySummaryDaily.getTotal());
111 }
112 }
113 }
114
115 }
116
117 addChart(content,"Document type", new DCharts().setDataSeries(dataSeries).setOptions(chartOptions.createOptionsXYDateFloatLegendOutside(series)).show());
118 }
119
120 }