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  import java.util.Locale;
23  
24  import org.apache.commons.lang3.StringUtils;
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.ViewRiksdagenCommitteeBallotDecisionPartyEmbeddedId;
30  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionSummary;
31  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionSummary_;
32  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
33  import com.hack23.cia.service.api.DataContainer;
34  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
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.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
38  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
39  import com.vaadin.data.util.BeanItemContainer;
40  import com.vaadin.ui.Layout;
41  import com.vaadin.ui.MenuBar;
42  import com.vaadin.ui.Panel;
43  import com.vaadin.ui.VerticalLayout;
44  
45  /**
46   * The Class CommitteeBallotDecisionSummaryPageModContentFactoryImpl.
47   */
48  @Component
49  public final class CommitteeBallotDecisionSummaryPageModContentFactoryImpl
50  		extends AbstractCommitteePageModContentFactoryImpl {
51  
52  	/** The Constant COMMITTEE. */
53  	private static final String COMMITTEE = "Committee:";
54  
55  	/** The Constant BALLOT_DECISION_SUMMARY. */
56  	private static final String BALLOT_DECISION_SUMMARY = "Ballot Decision Summary";
57  
58  	/**
59  	 * Instantiates a new committee ballot decision summary page mod content
60  	 * factory impl.
61  	 */
62  	public CommitteeBallotDecisionSummaryPageModContentFactoryImpl() {
63  		super();
64  	}
65  
66  	@Override
67  	public boolean matches(final String page, final String parameters) {
68  		return NAME.equals(page) && (!StringUtils.isEmpty(parameters)
69  				&& parameters.contains(CommitteePageMode.BALLOTDECISIONSUMMARY.toString()));
70  	}
71  
72  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
73  	@Override
74  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
75  		final VerticalLayout panelContent = createPanelContent();
76  
77  		final String pageId = getPageId(parameters);
78  
79  		final DataContainer<ViewRiksdagenCommittee, String> dataContainer = getApplicationManager()
80  				.getDataContainer(ViewRiksdagenCommittee.class);
81  
82  		final ViewRiksdagenCommittee viewRiksdagenCommittee = dataContainer.load(pageId);
83  
84  		if (viewRiksdagenCommittee != null) {
85  
86  			getCommitteeMenuItemFactory().createCommitteeeMenuBar(menuBar, pageId);
87  
88  			LabelFactory.createHeader2Label(panelContent, BALLOT_DECISION_SUMMARY);
89  
90  			final DataContainer<ViewRiksdagenCommitteeBallotDecisionSummary, ViewRiksdagenCommitteeBallotDecisionPartyEmbeddedId> committeeBallotDecisionPartyDataContainer = getApplicationManager()
91  					.getDataContainer(ViewRiksdagenCommitteeBallotDecisionSummary.class);
92  
93  			final List<ViewRiksdagenCommitteeBallotDecisionSummary> decisionPartySummaryList = committeeBallotDecisionPartyDataContainer
94  					.findOrderedListByProperty(ViewRiksdagenCommitteeBallotDecisionSummary_.org,
95  							pageId.toUpperCase(Locale.ENGLISH),
96  							ViewRiksdagenCommitteeBallotDecisionSummary_.createdDate);
97  
98  			final BeanItemContainer<ViewRiksdagenCommitteeBallotDecisionSummary> committeeBallotDecisionPartyDataSource = new BeanItemContainer<>(
99  					ViewRiksdagenCommitteeBallotDecisionSummary.class, decisionPartySummaryList);
100 
101 			getGridFactory().createBasicBeanItemNestedPropertiesGrid(panelContent,
102 					committeeBallotDecisionPartyDataSource, "Committee Ballot Decision Summary",
103 					new String[] { "embeddedId.concern", "embeddedId.issue", "embeddedId.id" },
104 					new String[] { "voteDate", "embeddedId.concern", "embeddedId.id", "committeeReport",
105 							"embeddedId.issue", "rm", "title", "subTitle", "endNumber", "org", "createdDate",
106 							"publicDate", "ballotId", "decisionType", "againstProposalParties", "againstProposalNumber",
107 							"winner", "ballotType", "label", "avgBornYear", "totalVotes", "yesVotes", "noVotes",
108 							"abstainVotes", "absentVotes", "approved", "noWinner", "percentageYes", "percentageNo",
109 							"percentageAbsent", "percentageAbstain", "percentageMale" },
110 					new String[] { "embeddedId", "embeddedId.id", "endNumber", "org", "createdDate", "publicDate",
111 							"ballotId", "decisionType", "label", "againstProposalNumber", "avgBornYear",
112 							"percentageMale", "approved", "noWinner", "ballotType", "percentageYes", "percentageNo",
113 							"percentageAbsent", "percentageAbstain" },
114 					new PageItemPropertyClickListener(UserViews.BALLOT_VIEW_NAME, "ballotId"), "ballotId", null);
115 
116 			panel.setCaption(COMMITTEE + viewRiksdagenCommittee.getEmbeddedId().getDetail());
117 			getPageActionEventHelper().createPageEvent(ViewAction.VISIT_COMMITTEE_VIEW, ApplicationEventGroup.USER,
118 					NAME, parameters, pageId);
119 		}
120 		return panelContent;
121 
122 	}
123 
124 }