TableFactoryImpl.java

  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. import java.util.List;

  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;

  23. import com.hack23.cia.service.api.ApplicationManager;
  24. import com.hack23.cia.service.api.DataContainer;
  25. import com.hack23.cia.service.api.DataSummary;
  26. import com.vaadin.ui.Table;

  27. /**
  28.  * The Class TableFactoryImpl.
  29.  */
  30. @Service
  31. public final class TableFactoryImpl implements TableFactory {

  32.     /** The Constant VOTES. */
  33.     private static final String VOTES = "Votes";

  34.     /** The Constant COMMITTEE_PROPOSAL_SIZE. */
  35.     private static final String COMMITTEE_PROPOSAL_SIZE = "committeeProposalSize";

  36.     /** The Constant DOCUMENT_STATUS. */
  37.     private static final String DOCUMENT_STATUS = "documentStatus";

  38.     /** The Constant DOCUMENT_CONTENT. */
  39.     private static final String DOCUMENT_CONTENT = "documentContent";

  40.     /** The Constant DOCUMENT_ELEMENT. */
  41.     private static final String DOCUMENT_ELEMENT = "DocumentElement";

  42.     /** The Constant PARLIAMENT_MEMBER. */
  43.     private static final String PARLIAMENT_MEMBER = "Parliament member";

  44.     /** The Constant COLUMN_MISSING. */
  45.     private static final String COLUMN_MISSING = "Missing";

  46.     /** The Constant COLUMN_SIZE. */
  47.     private static final String COLUMN_SIZE = "Size";

  48.     /** The Constant COLUMN_NAME. */
  49.     private static final String COLUMN_NAME = "Name";

  50.     /** The Constant FIRST_AND_ONLY. */
  51.     private static final int FIRST_AND_ONLY = 0;

  52.     /** The Constant ZERO_MISSING. */
  53.     private static final String ZERO_MISSING = Long.toString(0);

  54.     /** The application manager. */
  55.     @Autowired
  56.     private ApplicationManager applicationManager;

  57.     /**
  58.      * Instantiates a new table factory impl.
  59.      */
  60.     public TableFactoryImpl() {
  61.         super();
  62.     }

  63.     @Override
  64.     public Table createDataSummaryTable() {
  65.         final Table summaryTable = new Table();
  66.         summaryTable.addContainerProperty(COLUMN_NAME, String.class, null);
  67.         summaryTable.addContainerProperty(COLUMN_SIZE, String.class, null);
  68.         summaryTable.addContainerProperty(COLUMN_MISSING, String.class, null);

  69.         final DataContainer<DataSummary, String> dataContainer = applicationManager.getDataContainer(DataSummary.class);

  70.         final List<DataSummary> all = dataContainer.getAll();

  71.         if (!all.isEmpty()) {
  72.             final DataSummary dataSummary = all.get(FIRST_AND_ONLY);

  73.             int indexNr = 1;

  74.             summaryTable.addItem(new Object[] { PARLIAMENT_MEMBER, Long.toString(dataSummary.personSize), ZERO_MISSING },indexNr);
  75.             indexNr = indexNr + 1;


  76.             summaryTable.addItem(new Object[] { DOCUMENT_ELEMENT, Long.toString(dataSummary.documentElementSize), ZERO_MISSING },indexNr);
  77.             indexNr = indexNr + 1;


  78.             summaryTable.addItem(new Object[] { DOCUMENT_CONTENT, Long.toString(dataSummary.documentContentSize),Long.toString(dataSummary.documentElementSize - dataSummary.documentContentSize) },indexNr);
  79.             indexNr = indexNr + 1;


  80.             summaryTable.addItem(new Object[] { DOCUMENT_STATUS, Long.toString(dataSummary.documentStatusSize),Long.toString(dataSummary.documentElementSize - dataSummary.documentStatusSize) },indexNr);
  81.             indexNr = indexNr + 1;


  82.             summaryTable.addItem(new Object[] { COMMITTEE_PROPOSAL_SIZE,Long.toString(dataSummary.committeeProposalSize), ZERO_MISSING }, indexNr);
  83.             indexNr = indexNr + 1;


  84.             summaryTable.addItem(new Object[] { VOTES, Long.toString(dataSummary.voteSize),Long.toString(dataSummary.totalBallotVotes - dataSummary.voteSize) },indexNr);
  85.             summaryTable.setSizeFull();

  86.         }

  87.         return summaryTable;
  88.     }

  89. }