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.security.access.annotation.Secured;
25  import org.springframework.stereotype.Component;
26  
27  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommittee;
28  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeDecisions;
29  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeDecisionsEmbeddedId;
30  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeDecisions_;
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.labelfactory.LabelFactory;
35  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.CommitteePageMode;
36  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
37  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
38  import com.vaadin.data.util.BeanItemContainer;
39  import com.vaadin.ui.Layout;
40  import com.vaadin.ui.MenuBar;
41  import com.vaadin.ui.Panel;
42  import com.vaadin.ui.VerticalLayout;
43  
44  /**
45   * The Class CommitteeDecisionSummaryPageModContentFactoryImpl.
46   */
47  @Component
48  public final class CommitteeDecisionSummaryPageModContentFactoryImpl
49  		extends AbstractCommitteePageModContentFactoryImpl {
50  
51  	/** The Constant COMMITTEE. */
52  	private static final String COMMITTEE = "Committee:";
53  
54  	/** The Constant DECISION_SUMMARY_NOT_IMPLEMENTED. */
55  	private static final String DECISION_SUMMARY = "Decision Summary";
56  
57  	/**
58  	 * Instantiates a new committee decision summary page mod content factory
59  	 * impl.
60  	 */
61  	public CommitteeDecisionSummaryPageModContentFactoryImpl() {
62  		super();
63  	}
64  
65  	@Override
66  	public boolean matches(final String page, final String parameters) {
67  		return NAME.equals(page) && (!StringUtils.isEmpty(parameters)
68  				&& parameters.contains(CommitteePageMode.DECISIONSUMMARY.toString()));
69  	}
70  
71  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
72  	@Override
73  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
74  		final VerticalLayout panelContent = createPanelContent();
75  
76  		final String pageId = getPageId(parameters);
77  
78  		final DataContainer<ViewRiksdagenCommittee, String> dataContainer = getApplicationManager()
79  				.getDataContainer(ViewRiksdagenCommittee.class);
80  
81  		final ViewRiksdagenCommittee viewRiksdagenCommittee = dataContainer.load(pageId);
82  
83  		if (viewRiksdagenCommittee != null) {
84  
85  			getCommitteeMenuItemFactory().createCommitteeeMenuBar(menuBar, pageId);
86  
87  			LabelFactory.createHeader2Label(panelContent, DECISION_SUMMARY);
88  
89  			final DataContainer<ViewRiksdagenCommitteeDecisions, ViewRiksdagenCommitteeDecisionsEmbeddedId> committeeDecisionDataContainer = getApplicationManager()
90  					.getDataContainer(ViewRiksdagenCommitteeDecisions.class);
91  
92  			final List<ViewRiksdagenCommitteeDecisions> decisionPartySummaryList = committeeDecisionDataContainer
93  					.findOrderedListByProperty(ViewRiksdagenCommitteeDecisions_.org, pageId,
94  							ViewRiksdagenCommitteeDecisions_.createdDate);
95  
96  			final BeanItemContainer<ViewRiksdagenCommitteeDecisions> committeeDecisionDataSource = new BeanItemContainer<>(
97  					ViewRiksdagenCommitteeDecisions.class, decisionPartySummaryList);
98  
99  			getGridFactory().createBasicBeanItemNestedPropertiesGrid(panelContent, committeeDecisionDataSource,
100 					DECISION_SUMMARY, new String[] { "embeddedId.hangarId", "embeddedId.id", "embeddedId.issueNummer" },
101 					new String[] { "createdDate", "publicDate", "committeeReport", "embeddedId.hangarId",
102 							"embeddedId.id", "embeddedId.issueNummer", "rm", "decisionType", "winner", "title",
103 							"header", "endNumber", "org", "committeeProposalUrlXml", "ballotId",
104 							"againstProposalParties", "againstProposalNumber" },
105 					new String[] { "embeddedId", "embeddedId.hangarId", "embeddedId.id", "endNumber", "org",
106 							"committeeProposalUrlXml", "ballotId", "againstProposalParties", "againstProposalNumber",
107 							"createdDate" },
108 					new PageItemPropertyClickListener(UserViews.BALLOT_VIEW_NAME, "ballotId"), "ballotId", null);
109 
110 			panel.setCaption(COMMITTEE + viewRiksdagenCommittee.getEmbeddedId().getDetail());
111 			getPageActionEventHelper().createPageEvent(ViewAction.VISIT_COMMITTEE_VIEW, ApplicationEventGroup.USER,
112 					NAME, parameters, pageId);
113 		}
114 		return panelContent;
115 
116 	}
117 
118 }