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.tablefactory;
20
21 import java.util.List;
22
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.stereotype.Service;
25
26 import com.hack23.cia.service.api.ApplicationManager;
27 import com.hack23.cia.service.api.DataContainer;
28 import com.hack23.cia.service.api.DataSummary;
29 import com.vaadin.ui.Table;
30
31
32
33
34 @Service
35 public final class TableFactoryImpl implements TableFactory {
36
37
38 private static final String VOTES = "Votes";
39
40
41 private static final String COMMITTEE_PROPOSAL_SIZE = "committeeProposalSize";
42
43
44 private static final String DOCUMENT_STATUS = "documentStatus";
45
46
47 private static final String DOCUMENT_CONTENT = "documentContent";
48
49
50 private static final String DOCUMENT_ELEMENT = "DocumentElement";
51
52
53 private static final String PARLIAMENT_MEMBER = "Parliament member";
54
55
56 private static final String COLUMN_MISSING = "Missing";
57
58
59 private static final String COLUMN_SIZE = "Size";
60
61
62 private static final String COLUMN_NAME = "Name";
63
64
65 private static final int FIRST_AND_ONLY = 0;
66
67
68 private static final String ZERO_MISSING = Long.toString(0);
69
70
71 @Autowired
72 private ApplicationManager applicationManager;
73
74
75
76
77 public TableFactoryImpl() {
78 super();
79 }
80
81 @Override
82 public Table createDataSummaryTable() {
83 final Table summaryTable = new Table();
84 summaryTable.addContainerProperty(COLUMN_NAME, String.class, null);
85 summaryTable.addContainerProperty(COLUMN_SIZE, String.class, null);
86 summaryTable.addContainerProperty(COLUMN_MISSING, String.class, null);
87
88 final DataContainer<DataSummary, String> dataContainer = applicationManager.getDataContainer(DataSummary.class);
89
90 final List<DataSummary> all = dataContainer.getAll();
91
92 if (!all.isEmpty()) {
93 final DataSummary dataSummary = all.get(FIRST_AND_ONLY);
94
95 int indexNr = 1;
96
97 summaryTable.addItem(new Object[] { PARLIAMENT_MEMBER, Long.toString(dataSummary.personSize), ZERO_MISSING },indexNr);
98 indexNr = indexNr + 1;
99
100
101 summaryTable.addItem(new Object[] { DOCUMENT_ELEMENT, Long.toString(dataSummary.documentElementSize), ZERO_MISSING },indexNr);
102 indexNr = indexNr + 1;
103
104
105 summaryTable.addItem(new Object[] { DOCUMENT_CONTENT, Long.toString(dataSummary.documentContentSize),Long.toString(dataSummary.documentElementSize - dataSummary.documentContentSize) },indexNr);
106 indexNr = indexNr + 1;
107
108
109 summaryTable.addItem(new Object[] { DOCUMENT_STATUS, Long.toString(dataSummary.documentStatusSize),Long.toString(dataSummary.documentElementSize - dataSummary.documentStatusSize) },indexNr);
110 indexNr = indexNr + 1;
111
112
113 summaryTable.addItem(new Object[] { COMMITTEE_PROPOSAL_SIZE,Long.toString(dataSummary.committeeProposalSize), ZERO_MISSING }, indexNr);
114 indexNr = indexNr + 1;
115
116
117 summaryTable.addItem(new Object[] { VOTES, Long.toString(dataSummary.voteSize),Long.toString(dataSummary.totalBallotVotes - dataSummary.voteSize) },indexNr);
118 summaryTable.setSizeFull();
119
120 }
121
122 return summaryTable;
123 }
124
125 }