CommitteeBallotDecisionSummaryPageModContentFactoryImpl.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.committee.pagemode;

  20. import java.util.List;
  21. import java.util.Locale;

  22. import org.springframework.security.access.annotation.Secured;
  23. import org.springframework.stereotype.Component;

  24. import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommittee;
  25. import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionPartyEmbeddedId;
  26. import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionSummary;
  27. import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionSummary_;
  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.PageCommandCommitteeConstants;
  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 CommitteeBallotDecisionSummaryPageModContentFactoryImpl
  44. extends AbstractCommitteePageModContentFactoryImpl {

  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", "embeddedId.concern", "embeddedId.id",
  49.             "committeeReport", "embeddedId.issue", "rm", "title", "subTitle", "endNumber", "org", "createdDate",
  50.             "publicDate", BALLOT_ID, "decisionType", "againstProposalParties", "againstProposalNumber", "winner",
  51.             "ballotType", "label", "avgBornYear", "totalVotes", "yesVotes", "noVotes", "abstainVotes", "absentVotes",
  52.             "approved", "noWinner", "percentageYes", "percentageNo", "percentageAbsent", "percentageAbstain",
  53.             "percentageMale" };

  54.     /** The Constant COMMITTEE_BALLOT_DECISION_SUMMARY. */
  55.     private static final String COMMITTEE_BALLOT_DECISION_SUMMARY = "Committee Ballot Decision Summary";

  56.     /** The Constant HIDE_COLUMNS. */
  57.     private static final String[] HIDE_COLUMNS = { "embeddedId", "embeddedId.id", "endNumber", "org",
  58.             "createdDate", "publicDate", BALLOT_ID, "decisionType", "label", "againstProposalNumber", "avgBornYear",
  59.             "percentageMale", "approved", "noWinner", "ballotType", "percentageYes", "percentageNo", "percentageAbsent",
  60.             "percentageAbstain" };

  61.     /** The Constant LISTENER. */
  62.     private static final PageItemPropertyClickListener LISTENER = new PageItemPropertyClickListener(
  63.             UserViews.BALLOT_VIEW_NAME, BALLOT_ID);

  64.     /** The Constant NESTED_PROPERTIES. */
  65.     private static final String[] NESTED_PROPERTIES = { "embeddedId.concern", "embeddedId.issue",
  66.             "embeddedId.id" };

  67.     /**
  68.      * Instantiates a new committee ballot decision summary page mod content
  69.      * factory impl.
  70.      */
  71.     public CommitteeBallotDecisionSummaryPageModContentFactoryImpl() {
  72.         super();
  73.     }

  74.     @Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
  75.     @Override
  76.     public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
  77.         final VerticalLayout panelContent = createPanelContent();

  78.         final String pageId = getPageId(parameters);

  79.         final ViewRiksdagenCommittee viewRiksdagenCommittee = getItem(parameters);
  80.         getCommitteeMenuItemFactory().createCommitteeeMenuBar(menuBar, pageId);

  81.         CardInfoRowUtil.createPageHeader(panel, panelContent,
  82.             CommitteeViewConstants.BD_TITLE_HEADER + viewRiksdagenCommittee.getEmbeddedId().getDetail(),
  83.             CommitteeViewConstants.BD_TITLE,
  84.             CommitteeViewConstants.BD_DESCRIPTION);

  85.         final DataContainer<ViewRiksdagenCommitteeBallotDecisionSummary, ViewRiksdagenCommitteeBallotDecisionPartyEmbeddedId> committeeBallotDecisionPartyDataContainer = getApplicationManager()
  86.                         .getDataContainer(ViewRiksdagenCommitteeBallotDecisionSummary.class);

  87.         final List<ViewRiksdagenCommitteeBallotDecisionSummary> decisionPartySummaryList = committeeBallotDecisionPartyDataContainer
  88.                 .findOrderedListByProperty(ViewRiksdagenCommitteeBallotDecisionSummary_.org,
  89.                         pageId.toUpperCase(Locale.ENGLISH), ViewRiksdagenCommitteeBallotDecisionSummary_.createdDate);

  90.         getGridFactory().createBasicBeanItemNestedPropertiesGrid(panelContent,
  91.                 ViewRiksdagenCommitteeBallotDecisionSummary.class, decisionPartySummaryList,
  92.                 COMMITTEE_BALLOT_DECISION_SUMMARY, NESTED_PROPERTIES, COLUMN_ORDER, HIDE_COLUMNS, LISTENER, BALLOT_ID,
  93.                 null);

  94.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_COMMITTEE_VIEW, ApplicationEventGroup.USER, NAME,
  95.                 parameters, pageId);
  96.         return panelContent;

  97.     }

  98.     @Override
  99.     public boolean matches(final String page, final String parameters) {
  100.         return PageCommandCommitteeConstants.COMMAND_COMMITTEE_BALLOT_DECISION_SUMMARY.matches(page, parameters);
  101.     }

  102. }