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 java.util.List;
22  
23  import org.springframework.security.access.annotation.Secured;
24  import org.springframework.stereotype.Component;
25  
26  import com.hack23.cia.model.external.riksdagen.person.impl.AssignmentData;
27  import com.hack23.cia.model.external.riksdagen.person.impl.PersonData;
28  import com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician;
29  import com.hack23.cia.service.api.DataContainer;
30  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
31  import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
32  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PoliticianPageMode;
33  import com.vaadin.ui.Label;
34  import com.vaadin.ui.Layout;
35  import com.vaadin.ui.MenuBar;
36  import com.vaadin.ui.Panel;
37  import com.vaadin.ui.VerticalLayout;
38  
39  /**
40   * The Class RoleSummaryPageModContentFactoryImpl.
41   */
42  @Component
43  public final class PoliticianRoleSummaryPageModContentFactoryImpl extends AbstractPoliticianPageModContentFactoryImpl {
44  
45  	/** The Constant GOVERNMENT_EXPERIENCE. */
46  	private static final String GOVERNMENT_EXPERIENCE = "Government experience:";
47  
48  	/** The Constant EU_EXPERIENCE. */
49  	private static final String EU_EXPERIENCE = "EU experience:";
50  
51  	/** The Constant TOTAL_ASSIGNMENTS. */
52  	private static final String TOTAL_ASSIGNMENTS = "Total Assignments:";
53  
54  	/** The Constant SPEAKER_EXPERIENCE. */
55  	private static final String SPEAKER_EXPERIENCE = "Speaker experience:";
56  
57  	/** The Constant PARTY_EXPERIENCE. */
58  	private static final String PARTY_EXPERIENCE = "Party experience:";
59  
60  	/** The Constant COMMITTEE_EXPERIENCE. */
61  	private static final String COMMITTEE_EXPERIENCE = "Committee experience:";
62  
63  	/** The Constant PARLIAMENT_EXPERIENCE. */
64  	private static final String PARLIAMENT_EXPERIENCE = "Parliament experience:";
65  
66  
67  	/**
68  	 * Instantiates a new politician role summary page mod content factory impl.
69  	 */
70  	public PoliticianRoleSummaryPageModContentFactoryImpl() {
71  		super();
72  	}
73  
74  	@Override
75  	public boolean matches(final String page, final String parameters) {
76  		return NAME.equals(page) && parameters.contains(PoliticianPageMode.ROLESUMMARY.toString());
77  	}
78  
79  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
80  	@Override
81  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
82  		final VerticalLayout panelContent = createPanelContent();
83  
84  		final String pageId = getPageId(parameters);
85  
86  		final DataContainer<PersonData, String> dataContainer = getApplicationManager()
87  				.getDataContainer(PersonData.class);
88  
89  		final PersonData personData = dataContainer.load(pageId);
90  		if (personData != null) {
91  
92  			final DataContainer<ViewRiksdagenPolitician, String> politicianDataContainer = getApplicationManager()
93  					.getDataContainer(ViewRiksdagenPolitician.class);
94  
95  			final ViewRiksdagenPolitician viewRiksdagenPolitician = politicianDataContainer.load(personData.getId());
96  
97  			getPoliticianMenuItemFactory().createPoliticianMenuBar(menuBar, pageId);
98  
99  			LabelFactory.createHeader2Label(panelContent,PoliticianPageMode.ROLESUMMARY.toString());
100 
101 
102 
103 
104 
105 			final List<AssignmentData> assignmentList = personData.getPersonAssignmentData()
106 					.getAssignmentList();
107 
108 			createRoleSummary(panelContent, assignmentList, viewRiksdagenPolitician);
109 
110 			pageCompleted(parameters, panel, pageId, viewRiksdagenPolitician);
111 
112 		}
113 		return panelContent;
114 
115 	}
116 
117 	/**
118 	 * Creates the role summary.
119 	 *
120 	 * @param roleSummaryLayoutTabsheet
121 	 *            the role summary layout tabsheet
122 	 * @param assignmentList
123 	 *            the assignment list
124 	 * @param viewRiksdagenPolitician
125 	 *            the view riksdagen politician
126 	 */
127 	private void createRoleSummary(final VerticalLayout roleSummaryLayoutTabsheet, final List<AssignmentData> assignmentList,
128 			final ViewRiksdagenPolitician viewRiksdagenPolitician) {
129 
130 		final VerticalLayout layout = new VerticalLayout();
131 		layout.setSizeFull();
132 
133 		layout.addComponent(new Label(TOTAL_ASSIGNMENTS + assignmentList.size()));
134 
135 		if (viewRiksdagenPolitician != null) {
136 
137 			layout.addComponent(new Label(GOVERNMENT_EXPERIENCE
138 					+ convertToYearsString(viewRiksdagenPolitician.getTotalDaysServedGovernment())));
139 			layout.addComponent(new Label(
140 					SPEAKER_EXPERIENCE + convertToYearsString(viewRiksdagenPolitician.getTotalDaysServedSpeaker())));
141 			layout.addComponent(new Label(COMMITTEE_EXPERIENCE
142 					+ convertToYearsString(viewRiksdagenPolitician.getTotalDaysServedCommittee())));
143 			layout.addComponent(
144 					new Label(EU_EXPERIENCE + convertToYearsString(viewRiksdagenPolitician.getTotalDaysServedEu())));
145 			layout.addComponent(new Label(PARLIAMENT_EXPERIENCE
146 					+ convertToYearsString(viewRiksdagenPolitician.getTotalDaysServedParliament())));
147 			layout.addComponent(new Label(
148 					PARTY_EXPERIENCE + convertToYearsString(viewRiksdagenPolitician.getTotalDaysServedParty())));
149 		}
150 
151 		roleSummaryLayoutTabsheet.addComponent(layout);
152 		roleSummaryLayoutTabsheet.setExpandRatio(layout, ContentRatio.GRID);
153 
154 	}
155 
156 
157 }