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.committee.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.committee.impl.ViewRiksdagenCommittee;
29  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeRoleMember;
30  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeRoleMember_;
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.CommitteeGhantChartManager;
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.CommitteePageMode;
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 CommitteeRoleGhantPageModContentFactoryImpl.
44   */
45  @Component
46  public final class CommitteeRoleGhantPageModContentFactoryImpl extends AbstractCommitteePageModContentFactoryImpl {
47  
48  	/** The Constant COMMITTEE. */
49  	private static final String COMMITTEE = "Committee:";
50  
51  	/** The Constant ROLE_GHANT_NOT_IMPLEMENTED. */
52  	private static final String ROLE_GHANT = "Role chart";
53  
54  	@Autowired
55  	private CommitteeGhantChartManager committeeGhantChartManager;
56  
57  	/**
58  	 * Instantiates a new committee role ghant page mod content factory impl.
59  	 */
60  	public CommitteeRoleGhantPageModContentFactoryImpl() {
61  		super();
62  	}
63  
64  	@Override
65  	public boolean matches(final String page, final String parameters) {
66  		return NAME.equals(page)
67  				&& (!StringUtils.isEmpty(parameters) && parameters.contains(CommitteePageMode.ROLEGHANT.toString()));
68  	}
69  
70  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
71  	@Override
72  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
73  		final VerticalLayout panelContent = createPanelContent();
74  
75  		final String pageId = getPageId(parameters);
76  
77  		final DataContainer<ViewRiksdagenCommittee, String> dataContainer = getApplicationManager()
78  				.getDataContainer(ViewRiksdagenCommittee.class);
79  
80  		final ViewRiksdagenCommittee viewRiksdagenCommittee = dataContainer.load(pageId);
81  
82  		if (viewRiksdagenCommittee != null) {
83  
84  			getCommitteeMenuItemFactory().createCommitteeeMenuBar(menuBar, pageId);
85  
86  			LabelFactory.createHeader2Label(panelContent,ROLE_GHANT);
87  
88  
89  			final DataContainer<ViewRiksdagenCommitteeRoleMember, String> committeeRoleMemberDataContainer = getApplicationManager()
90  					.getDataContainer(ViewRiksdagenCommitteeRoleMember.class);
91  
92  			final List<ViewRiksdagenCommitteeRoleMember> allMembers = committeeRoleMemberDataContainer.getAllBy(ViewRiksdagenCommitteeRoleMember_.detail,
93  							viewRiksdagenCommittee.getEmbeddedId().getDetail());
94  
95  			committeeGhantChartManager.createRoleGhant(panelContent, allMembers);
96  
97  			panel.setCaption(COMMITTEE + viewRiksdagenCommittee.getEmbeddedId().getDetail());
98  			getPageActionEventHelper().createPageEvent(ViewAction.VISIT_COMMITTEE_VIEW, ApplicationEventGroup.USER,
99  					NAME, parameters, pageId);
100 		}
101 		return panelContent;
102 
103 	}
104 
105 }