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.user.politician.pagemode;
20  
21  import org.springframework.beans.factory.annotation.Autowired;
22  import org.springframework.security.access.annotation.Secured;
23  import org.springframework.stereotype.Component;
24  
25  import com.hack23.cia.model.external.riksdagen.person.impl.PersonData;
26  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummary;
27  import com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician;
28  import com.hack23.cia.service.api.DataContainer;
29  import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.GenericChartDataManager;
30  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
31  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PoliticianPageMode;
32  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
33  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
34  import com.vaadin.data.util.BeanItemContainer;
35  import com.vaadin.ui.Layout;
36  import com.vaadin.ui.MenuBar;
37  import com.vaadin.ui.Panel;
38  import com.vaadin.ui.VerticalLayout;
39  
40  /**
41   * The Class VotesHistoryPageModContentFactoryImpl.
42   */
43  @Component
44  public final class PoliticianVotesHistoryPageModContentFactoryImpl extends AbstractPoliticianPageModContentFactoryImpl {
45  
46  	/**
47  	 * The view riksdagen vote data ballot politician summary chart data
48  	 * manager.
49  	 */
50  	@Autowired
51  	private GenericChartDataManager<ViewRiksdagenVoteDataBallotPoliticianSummary> viewRiksdagenVoteDataBallotPoliticianSummaryChartDataManager;
52  
53  	/**
54  	 * Instantiates a new politician votes history page mod content factory
55  	 * impl.
56  	 */
57  	public PoliticianVotesHistoryPageModContentFactoryImpl() {
58  		super();
59  	}
60  
61  	@Override
62  	public boolean matches(final String page, final String parameters) {
63  		return NAME.equals(page) && parameters.contains(PoliticianPageMode.VOTEHISTORY.toString());
64  	}
65  
66  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
67  	@Override
68  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
69  		final VerticalLayout panelContent = createPanelContent();
70  
71  		final String pageId = getPageId(parameters);
72  
73  		final DataContainer<PersonData, String> dataContainer = getApplicationManager()
74  				.getDataContainer(PersonData.class);
75  
76  		final PersonData personData = dataContainer.load(pageId);
77  		if (personData != null) {
78  
79  			final DataContainer<ViewRiksdagenPolitician, String> politicianDataContainer = getApplicationManager()
80  					.getDataContainer(ViewRiksdagenPolitician.class);
81  
82  			final ViewRiksdagenPolitician viewRiksdagenPolitician = politicianDataContainer.load(personData.getId());
83  
84  			getPoliticianMenuItemFactory().createPoliticianMenuBar(menuBar, pageId);
85  
86  			LabelFactory.createHeader2Label(panelContent,PoliticianPageMode.VOTEHISTORY.toString());
87  
88  
89  			final BeanItemContainer<ViewRiksdagenVoteDataBallotPoliticianSummary> politicianBallotDataSource = new BeanItemContainer<>(
90  					ViewRiksdagenVoteDataBallotPoliticianSummary.class,
91  					viewRiksdagenVoteDataBallotPoliticianSummaryChartDataManager.findByValue(personData.getId()));
92  
93  			getGridFactory().createBasicBeanItemNestedPropertiesGrid(panelContent,
94  					politicianBallotDataSource, "Ballots",
95  					new String[] { "embeddedId.ballotId", "embeddedId.concern", "embeddedId.issue" },
96  					new String[] { "voteDate", "rm", "label", "embeddedId.concern", "embeddedId.issue", "vote",
97  							"won", "partyWon", "rebel", "noWinner", "approved", "partyApproved", "totalVotes",
98  							"partyTotalVotes", "yesVotes", "partyYesVotes", "noVotes", "partyNoVotes",
99  							"partyAbstainVotes", "abstainVotes", "partyAbsentVotes", "absentVotes", "bornYear",
100 							"partyAvgBornYear", "avgBornYear", "gender", "partyPercentageMale",
101 							"percentageMale", "ballotType", "embeddedId.ballotId" },
102 					new String[] { "embeddedId", "partyNoWinner", "partyPercentageYes", "partyPercentageNo",
103 							"partyPercentageAbsent", "partyPercentageAbstain", "percentageYes", "percentageNo",
104 							"percentageAbsent", "percentageAbstain", "firstName", "lastName", "party", "embeddedId.ballotId", "ballotType" },
105 					new PageItemPropertyClickListener(UserViews.BALLOT_VIEW_NAME, "embeddedId.ballotId"), "embeddedId.ballotId", null);
106 
107 			pageCompleted(parameters, panel, pageId, viewRiksdagenPolitician);
108 
109 		}
110 		return panelContent;
111 
112 	}
113 }