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.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
41
42 @Component
43 public final class PoliticianRoleSummaryPageModContentFactoryImpl extends AbstractPoliticianPageModContentFactoryImpl {
44
45
46 private static final String GOVERNMENT_EXPERIENCE = "Government experience:";
47
48
49 private static final String EU_EXPERIENCE = "EU experience:";
50
51
52 private static final String TOTAL_ASSIGNMENTS = "Total Assignments:";
53
54
55 private static final String SPEAKER_EXPERIENCE = "Speaker experience:";
56
57
58 private static final String PARTY_EXPERIENCE = "Party experience:";
59
60
61 private static final String COMMITTEE_EXPERIENCE = "Committee experience:";
62
63
64 private static final String PARLIAMENT_EXPERIENCE = "Parliament experience:";
65
66
67
68
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
119
120
121
122
123
124
125
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 }