PartyCommitteeBallotDecisionSummaryPageModContentFactoryImpl.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 java.util.List;

  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.ViewRiksdagenCommitteeBallotDecisionPartyEmbeddedId;
  24. import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionPartyEmbeddedId_;
  25. import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionPartySummary;
  26. import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionPartySummary_;
  27. import com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenParty;
  28. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  29. import com.hack23.cia.service.api.DataContainer;
  30. import com.hack23.cia.web.impl.ui.application.action.ViewAction;
  31. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.pagecommands.PageCommandPartyConstants;
  32. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.CardInfoRowUtil;
  33. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
  34. import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
  35. import com.vaadin.ui.Layout;
  36. import com.vaadin.ui.MenuBar;
  37. import com.vaadin.ui.Panel;
  38. import com.vaadin.ui.VerticalLayout;

  39. /**
  40.  * The Class CommitteeBallotDecisionSummaryPageModContentFactoryImpl.
  41.  */
  42. @Component
  43. public final class PartyCommitteeBallotDecisionSummaryPageModContentFactoryImpl
  44.         extends AbstractPartyPageModContentFactoryImpl {

  45.     /** The Constant BALLOT_ID. */
  46.     private static final String BALLOT_ID = "ballotId";

  47.     /** The Constant COLUMN_ORDER. */
  48.     private static final String[] COLUMN_ORDER = { "voteDate", "rm", "org", "embeddedId.id",
  49.             "embeddedId.party", "committeeReport", "title", "subTitle", "winner", "partyApproved",
  50.             "againstProposalParties", "embeddedId.concern", "embeddedId.issue", "endNumber", "createdDate",
  51.             "publicDate", BALLOT_ID, "decisionType", "againstProposalNumber", "ballotType", "label", "avgBornYear",
  52.             "totalVotes", "approved", "noWinner", "percentageYes", "percentageNo", "percentageAbsent",
  53.             "percentageAbstain", "percentageMale", "partyAvgBornYear", "partyTotalVotes", "partyYesVotes",
  54.             "partyNoVotes", "partyAbstainVotes", "partyAbsentVotes", "yesVotes", "noVotes", "abstainVotes",
  55.             "absentVotes", "partyNoWinner", "partyPercentageYes", "partyPercentageNo", "partyPercentageAbsent",
  56.             "partyPercentageAbstain", "partyPercentageMale" };

  57.     /** The Constant COMMITTEE_BALLOT_DECISION_PARTY_SUMMARY. */
  58.     private static final String COMMITTEE_BALLOT_DECISION_PARTY_SUMMARY = PartyViewConstants.GRID_LABEL_COMMITTEE_BALLOT_SUMMARY;

  59.     /** The Constant HIDE_COLUMNS. */
  60.     private static final String[] HIDE_COLUMNS = { "embeddedId", BALLOT_ID, "decisionType", "ballotType",
  61.             "againstProposalNumber", "embeddedId.id", "embeddedId.party", "createdDate", "publicDate", "label",
  62.             "endNumber", "org", "partyPercentageYes", "partyPercentageNo", "partyPercentageAbsent",
  63.             "partyPercentageAbstain", "partyPercentageMale", "partyAvgBornYear", "avgBornYear", "percentageYes",
  64.             "percentageNo", "percentageAbsent", "percentageAbstain", "percentageMale", "approved", "noWinner" };

  65.     /** The Constant LISTENER. */
  66.     private static final PageItemPropertyClickListener LISTENER = new PageItemPropertyClickListener(
  67.             UserViews.BALLOT_VIEW_NAME, BALLOT_ID);

  68.     /** The Constant NESTED_PROPERTIES. */
  69.     private static final String[] NESTED_PROPERTIES = { "embeddedId.id", "embeddedId.concern",
  70.             "embeddedId.issue", "embeddedId.party" };

  71.     /**
  72.      * Instantiates a new party committee ballot decision summary page mod
  73.      * content factory impl.
  74.      */
  75.     public PartyCommitteeBallotDecisionSummaryPageModContentFactoryImpl() {
  76.         super();
  77.     }

  78.     @Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
  79.     @Override
  80.     public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
  81.         final VerticalLayout panelContent = createPanelContent();

  82.         final String pageId = getPageId(parameters);

  83.         final ViewRiksdagenParty viewRiksdagenParty = getItem(parameters);

  84.         getPartyMenuItemFactory().createPartyMenuBar(menuBar, pageId);

  85.         CardInfoRowUtil.createPageHeader(panel, panelContent,
  86.             PartyViewConstants.BALLOT_DECISIONS_HEADER + " " + viewRiksdagenParty.getPartyName(),
  87.             PartyViewConstants.BALLOT_DECISIONS_TITLE,
  88.             PartyViewConstants.BALLOT_DECISIONS_DESC);

  89.         final DataContainer<ViewRiksdagenCommitteeBallotDecisionPartySummary, ViewRiksdagenCommitteeBallotDecisionPartyEmbeddedId> committeeBallotDecisionPartyDataContainer = getApplicationManager()
  90.                 .getDataContainer(ViewRiksdagenCommitteeBallotDecisionPartySummary.class);

  91.         final List<ViewRiksdagenCommitteeBallotDecisionPartySummary> decisionPartySummaryList = committeeBallotDecisionPartyDataContainer
  92.                 .findOrderedByPropertyListByEmbeddedProperty(ViewRiksdagenCommitteeBallotDecisionPartySummary.class,
  93.                         ViewRiksdagenCommitteeBallotDecisionPartySummary_.embeddedId,
  94.                         ViewRiksdagenCommitteeBallotDecisionPartyEmbeddedId.class,
  95.                         ViewRiksdagenCommitteeBallotDecisionPartyEmbeddedId_.party, pageId,
  96.                         ViewRiksdagenCommitteeBallotDecisionPartySummary_.voteDate);

  97.         getGridFactory().createBasicBeanItemNestedPropertiesGrid(panelContent,
  98.                 ViewRiksdagenCommitteeBallotDecisionPartySummary.class, decisionPartySummaryList,
  99.                 COMMITTEE_BALLOT_DECISION_PARTY_SUMMARY, NESTED_PROPERTIES, COLUMN_ORDER, HIDE_COLUMNS, LISTENER,
  100.                 BALLOT_ID, null);

  101.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_PARTY_VIEW, ApplicationEventGroup.USER, NAME, parameters,
  102.         pageId);

  103.         return panelContent;

  104.     }

  105.     @Override
  106.     public boolean matches(final String page, final String parameters) {
  107.         return PageCommandPartyConstants.COMMAND_PARTY_BALLOT_DECISION_SUMMARY.matches(page, parameters);
  108.     }

  109. }