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.beans.factory.annotation.Autowired;
24  import org.springframework.security.access.annotation.Secured;
25  import org.springframework.stereotype.Component;
26  
27  import com.hack23.cia.model.external.riksdagen.person.impl.AssignmentData;
28  import com.hack23.cia.model.external.riksdagen.person.impl.PersonData;
29  import com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician;
30  import com.hack23.cia.service.api.DataContainer;
31  import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.PoliticianGhantChartManager;
32  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
33  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PoliticianPageMode;
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 RoleGhantPageModContentFactoryImpl.
41   */
42  @Component
43  public final class PoliticianRoleGhantPageModContentFactoryImpl extends AbstractPoliticianPageModContentFactoryImpl {
44  
45  	@Autowired
46  	private PoliticianGhantChartManager politicianGhantChartManager;
47  
48  	/**
49  	 * Instantiates a new politician role ghant page mod content factory impl.
50  	 */
51  	public PoliticianRoleGhantPageModContentFactoryImpl() {
52  		super();
53  	}
54  
55  	@Override
56  	public boolean matches(final String page, final String parameters) {
57  		return NAME.equals(page) && parameters.contains(PoliticianPageMode.ROLEGHANT.toString());
58  	}
59  
60  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
61  	@Override
62  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
63  		final VerticalLayout panelContent = createPanelContent();
64  
65  		final String pageId = getPageId(parameters);
66  
67  		final DataContainer<PersonData, String> dataContainer = getApplicationManager()
68  				.getDataContainer(PersonData.class);
69  
70  		final PersonData personData = dataContainer.load(pageId);
71  		if (personData != null) {
72  
73  			final DataContainer<ViewRiksdagenPolitician, String> politicianDataContainer = getApplicationManager()
74  					.getDataContainer(ViewRiksdagenPolitician.class);
75  
76  			final ViewRiksdagenPolitician viewRiksdagenPolitician = politicianDataContainer.load(personData.getId());
77  
78  			getPoliticianMenuItemFactory().createPoliticianMenuBar(menuBar, pageId);
79  
80  			LabelFactory.createHeader2Label(panelContent,PoliticianPageMode.ROLEGHANT.toString());
81  
82  			final List<AssignmentData> assignmentList = personData.getPersonAssignmentData()
83  					.getAssignmentList();
84  
85  			politicianGhantChartManager.createRoleGhant(panelContent, assignmentList);
86  
87  			pageCompleted(parameters, panel, pageId, viewRiksdagenPolitician);
88  
89  		}
90  		return panelContent;
91  
92  	}
93  
94  }