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.goverment.pagemode;
20  
21  import java.util.List;
22  
23  import org.apache.commons.lang3.StringUtils;
24  import org.springframework.beans.factory.annotation.Autowired;
25  import org.springframework.security.access.annotation.Secured;
26  import org.springframework.stereotype.Component;
27  
28  import com.hack23.cia.model.internal.application.data.ministry.impl.ViewRiksdagenGovermentRoleMember;
29  import com.hack23.cia.model.internal.application.data.ministry.impl.ViewRiksdagenGovermentRoleMember_;
30  import com.hack23.cia.model.internal.application.data.ministry.impl.ViewRiksdagenMinistry;
31  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
32  import com.hack23.cia.service.api.DataContainer;
33  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
34  import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.MinistryGhantChartManager;
35  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
36  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.MinistryPageMode;
37  import com.vaadin.ui.Layout;
38  import com.vaadin.ui.MenuBar;
39  import com.vaadin.ui.Panel;
40  import com.vaadin.ui.VerticalLayout;
41  
42  /**
43   * The Class MinistryRoleGhantPageModContentFactoryImpl.
44   */
45  @Component
46  public final class MinistryRoleGhantPageModContentFactoryImpl extends AbstractMinistryPageModContentFactoryImpl {
47  
48  	/** The Constant ROLE_GHANT. */
49  	private static final String ROLE_GHANT = "Role Ghant";
50  
51  	/** The Constant MINISTRY. */
52  	private static final String MINISTRY = "Ministry:";
53  
54  	@Autowired
55  	private MinistryGhantChartManager ministryGhantChartManager;
56  
57  	/**
58  	 * Instantiates a new ministry role ghant page mod content factory impl.
59  	 */
60  	public MinistryRoleGhantPageModContentFactoryImpl() {
61  		super();
62  	}
63  
64  	@Override
65  	public boolean matches(final String page, final String parameters) {
66  		return NAME.equals(page) && (!StringUtils.isEmpty(parameters) && parameters.contains(MinistryPageMode.ROLEGHANT.toString()));
67  	}
68  
69  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
70  	@Override
71  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
72  		final VerticalLayout panelContent = createPanelContent();
73  
74  		final String pageId = getPageId(parameters);
75  
76  		final DataContainer<ViewRiksdagenMinistry, String> dataContainer = getApplicationManager()
77  				.getDataContainer(ViewRiksdagenMinistry.class);
78  
79  		final ViewRiksdagenMinistry viewRiksdagenMinistry = dataContainer.load(pageId);
80  
81  		if (viewRiksdagenMinistry != null) {
82  
83  			getMinistryMenuItemFactory().createMinistryMenuBar(menuBar, pageId);
84  
85  			LabelFactory.createHeader2Label(panelContent,ROLE_GHANT);
86  
87  
88  			final DataContainer<ViewRiksdagenGovermentRoleMember, String> govermentRoleMemberDataContainer = getApplicationManager()
89  					.getDataContainer(ViewRiksdagenGovermentRoleMember.class);
90  
91  			final List<ViewRiksdagenGovermentRoleMember> allMembers = govermentRoleMemberDataContainer.getAllBy(ViewRiksdagenGovermentRoleMember_.detail, viewRiksdagenMinistry.getNameId());
92  
93  			ministryGhantChartManager.createRoleGhant(panelContent, allMembers);
94  
95  			panel.setCaption(MINISTRY + viewRiksdagenMinistry.getNameId());
96  			getPageActionEventHelper().createPageEvent(ViewAction.VISIT_MINISTRY_VIEW, ApplicationEventGroup.USER, NAME,
97  					parameters, pageId);
98  
99  		}
100 
101 		return panelContent;
102 
103 	}
104 
105 }