View Javadoc
1   /*
2    * Copyright 2014 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id$
17   *  $HeadURL$
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   * The Class TableFactoryImpl.
33   */
34  @Service
35  public final class TableFactoryImpl implements TableFactory {
36  
37  	/** The Constant VOTES. */
38  	private static final String VOTES = "Votes";
39  
40  	/** The Constant COMMITTEE_PROPOSAL_SIZE. */
41  	private static final String COMMITTEE_PROPOSAL_SIZE = "committeeProposalSize";
42  
43  	/** The Constant DOCUMENT_STATUS. */
44  	private static final String DOCUMENT_STATUS = "documentStatus";
45  
46  	/** The Constant DOCUMENT_CONTENT. */
47  	private static final String DOCUMENT_CONTENT = "documentContent";
48  
49  	/** The Constant DOCUMENT_ELEMENT. */
50  	private static final String DOCUMENT_ELEMENT = "DocumentElement";
51  
52  	/** The Constant PARLIAMENT_MEMBER. */
53  	private static final String PARLIAMENT_MEMBER = "Parliament member";
54  
55  	/** The Constant COLUMN_MISSING. */
56  	private static final String COLUMN_MISSING = "Missing";
57  
58  	/** The Constant COLUMN_SIZE. */
59  	private static final String COLUMN_SIZE = "Size";
60  
61  	/** The Constant COLUMN_NAME. */
62  	private static final String COLUMN_NAME = "Name";
63  
64  	/** The Constant FIRST_AND_ONLY. */
65  	private static final int FIRST_AND_ONLY = 0;
66  
67  	/** The Constant ZERO_MISSING. */
68  	private static final String ZERO_MISSING = Long.toString(0);
69  
70  	/** The application manager. */
71  	@Autowired
72  	private ApplicationManager applicationManager;
73  
74  	/**
75  	 * Instantiates a new table factory impl.
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 }