PartyVoteHistoryPageModContentFactoryImpl.java

  1. /*
  2.  * Copyright 2010-2025 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.party.pagemode;

  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.security.access.annotation.Secured;
  22. import org.springframework.stereotype.Component;

  23. import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPartySummary;
  24. import com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenParty;
  25. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  26. import com.hack23.cia.web.impl.ui.application.action.ViewAction;
  27. import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.GenericChartDataManager;
  28. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.pagecommands.PageCommandPartyConstants;
  29. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.CardInfoRowUtil;
  30. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
  31. import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
  32. import com.vaadin.ui.Layout;
  33. import com.vaadin.ui.MenuBar;
  34. import com.vaadin.ui.Panel;
  35. import com.vaadin.ui.VerticalLayout;

  36. /**
  37.  * The Class VoteHistoryPageModContentFactoryImpl.
  38.  */
  39. @Component
  40. public final class PartyVoteHistoryPageModContentFactoryImpl extends AbstractPartyPageModContentFactoryImpl {

  41.     /** The Constant BALLOTS. */
  42.     private static final String BALLOTS = "Ballots";

  43.     /** The Constant EMBEDDED_ID_BALLOT_ID. */
  44.     private static final String EMBEDDED_ID_BALLOT_ID = "embeddedId.ballotId";

  45.     /** The Constant COLUMN_ORDER. */
  46.     private static final String[] COLUMN_ORDER = { "embeddedId.party", "voteDate", "rm", "label",
  47.             "embeddedId.concern", "embeddedId.issue", "approved", "partyApproved", "totalVotes", "partyTotalVotes",
  48.             "yesVotes", "partyYesVotes", "noVotes", "partyNoVotes", "partyAbstainVotes", "abstainVotes",
  49.             "partyAbsentVotes", "absentVotes", "partyAvgBornYear", "avgBornYear", "partyPercentageMale",
  50.             "percentageMale", "ballotType", EMBEDDED_ID_BALLOT_ID };

  51.     /** The Constant HIDE_COLUMNS. */
  52.     private static final String[] HIDE_COLUMNS = { "embeddedId", "partyNoWinner", "partyPercentageYes",
  53.             "partyPercentageNo", "partyPercentageAbsent", "partyPercentageAbstain", "percentageYes", "percentageNo",
  54.             "percentageAbsent", "percentageAbstain", "ballotType", "embeddedId.party", EMBEDDED_ID_BALLOT_ID,
  55.             "partyAvgBornYear", "avgBornYear", "partyPercentageMale", "percentageMale", "noWinner" };

  56.     /** The Constant LISTENER. */
  57.     private static final PageItemPropertyClickListener LISTENER = new PageItemPropertyClickListener(
  58.             UserViews.BALLOT_VIEW_NAME, EMBEDDED_ID_BALLOT_ID);

  59.     /** The Constant NESTED_PROPERTIES. */
  60.     private static final String[] NESTED_PROPERTIES = { EMBEDDED_ID_BALLOT_ID, "embeddedId.concern",
  61.             "embeddedId.issue", "embeddedId.party" };

  62.     /** The view riksdagen vote data ballot party summary chart data manager. */
  63.     @Autowired
  64.     private GenericChartDataManager<ViewRiksdagenVoteDataBallotPartySummary> viewRiksdagenVoteDataBallotPartySummaryChartDataManager;

  65.     /**
  66.      * Instantiates a new party vote history page mod content factory impl.
  67.      */
  68.     public PartyVoteHistoryPageModContentFactoryImpl() {
  69.         super();
  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.         final String pageId = getPageId(parameters);

  76.         final ViewRiksdagenParty viewRiksdagenParty = getItem(parameters);
  77.         getPartyMenuItemFactory().createPartyMenuBar(menuBar, pageId);

  78.         CardInfoRowUtil.createPageHeader(panel, panelContent,
  79.             PartyViewConstants.VOTE_HISTORY_HEADER + " " + viewRiksdagenParty.getPartyName(),
  80.             PartyViewConstants.VOTE_HISTORY_TITLE,
  81.             PartyViewConstants.VOTE_HISTORY_DESC);

  82.         getGridFactory().createBasicBeanItemNestedPropertiesGrid(panelContent,
  83.                 ViewRiksdagenVoteDataBallotPartySummary.class,
  84.                 viewRiksdagenVoteDataBallotPartySummaryChartDataManager.findByValue(pageId), BALLOTS, NESTED_PROPERTIES,
  85.                 COLUMN_ORDER, HIDE_COLUMNS, LISTENER, EMBEDDED_ID_BALLOT_ID, null);

  86.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_PARTY_VIEW, ApplicationEventGroup.USER, NAME, parameters,
  87.         pageId);
  88.         return panelContent;

  89.     }

  90.     @Override
  91.     public boolean matches(final String page, final String parameters) {
  92.         return PageCommandPartyConstants.COMMAND_PARTY_VOTE_HISTORY.matches(page, parameters);
  93.     }

  94. }