PartyRankingDataGridPageModContentFactoryImpl.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.partyranking.pagemode;

  20. import org.springframework.security.access.annotation.Secured;
  21. import org.springframework.stereotype.Service;

  22. import com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenPartySummary;
  23. import com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenPartySummary_;
  24. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  25. import com.hack23.cia.service.api.DataContainer;
  26. import com.hack23.cia.web.impl.ui.application.action.ViewAction;
  27. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.pagecommands.PageCommandPartyRankingConstants;
  28. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.CardInfoRowUtil;
  29. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
  30. import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
  31. import com.vaadin.ui.Layout;
  32. import com.vaadin.ui.MenuBar;
  33. import com.vaadin.ui.Panel;
  34. import com.vaadin.ui.VerticalLayout;


  35. /**
  36.  * The Class PartyRankingDataGridPageModContentFactoryImpl.
  37.  */
  38. @Service
  39. public final class PartyRankingDataGridPageModContentFactoryImpl extends AbstractPartyRankingPageModContentFactoryImpl {

  40.     /** The Constant COLUMN_ORDER. */
  41.     /** The Constant COLUMN_ORDER. */
  42.     private static final String[] COLUMN_ORDER = {
  43.         "party",                          // Party name
  44.         "currentlyActiveMembers",         // Current active members
  45.         "totalDocumentsLastYear",         // Recent activity
  46.         "avgDocumentsLastYear",           // Recent productivity per member
  47.         "totalDocuments",                 // Historical volume
  48.         "avgDocumentsPerMember",         // Overall productivity
  49.         "veryHighActivityMembers",       // Member activity distribution
  50.         "highActivityMembers",
  51.         "mediumActivityMembers",
  52.         "lowActivityMembers",
  53.         "totalPartyMotions",             // Motion types distribution
  54.         "totalCommitteeMotions",
  55.         "totalIndividualMotions",
  56.         "totalCollaborativeMotions",
  57.         "partyFocusedMembers",          // Member focus distribution
  58.         "committeeFocusedMembers",
  59.         "individualFocusedMembers",
  60.         "currentAssignments",            // Current positions
  61.         "currentMinistryAssignments",
  62.         "currentCommitteeAssignments",
  63.         "currentCommitteeLeadershipAssignments"
  64.     };

  65.     /** The Constant HIDE_COLUMNS. */
  66.     private static final String[] HIDE_COLUMNS = {
  67.         "active",
  68.         "activeParliament",
  69.         "activeGovernment",
  70.         "activeCommittee",
  71.         "activeEu",
  72.         "activeParty",
  73.         "activeSpeaker",
  74.         "totalDaysServedParliament",
  75.         "totalDaysServedCommittee",
  76.         "totalDaysServedGovernment",
  77.         "totalDaysServedEu",
  78.         "totalDaysServedParty",
  79.         "totalDaysServedSpeaker",
  80.         "totalDaysServedCommitteeLeadership",
  81.         "totalDaysServedCommitteeSubstitute",
  82.         "totalActiveEu",
  83.         "currentCommitteeSubstituteAssignments",
  84.         "totalCommitteeSubstituteAssignments",
  85.         "currentSpeakerAssignments",
  86.         "totalSpeakerAssignments",
  87.         "totalFollowUpMotions",          // Can be accessed in detailed view
  88.         "firstAssignmentDate",           // Less relevant for activity focus
  89.         "lastAssignmentDate",
  90.         "totalPartyAssignments",
  91.         "totalMinistryAssignments",
  92.         "totalCommitteeAssignments",
  93.         "totalCommitteeLeadershipAssignments"
  94.     };
  95.     /** The Constant LISTENER. */
  96.     private static final PageItemPropertyClickListener LISTENER = new PageItemPropertyClickListener(UserViews.PARTY_VIEW_NAME, "party");

  97.     /** The Constant NAME. */
  98.     public static final String NAME = UserViews.PARTY_RANKING_VIEW_NAME;

  99.     /** The Constant PARTIES. */
  100.     private static final String PARTIES = "Parties";

  101.     /**
  102.      * Instantiates a new party ranking data grid page mod content factory impl.
  103.      */
  104.     public PartyRankingDataGridPageModContentFactoryImpl() {
  105.         super();
  106.     }

  107.     /**
  108.      * Creates the content.
  109.      *
  110.      * @param parameters the parameters
  111.      * @param menuBar the menu bar
  112.      * @param panel the panel
  113.      * @return the layout
  114.      */
  115.     @SuppressWarnings("unchecked")
  116.     @Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
  117.     @Override
  118.     public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
  119.         final VerticalLayout panelContent = createPanelContent();

  120.         getPartyRankingMenuItemFactory().createPartyRankingMenuBar(menuBar);

  121.         CardInfoRowUtil.createPageHeader(panel, panelContent,
  122.             PartyRankingViewConstants.DATAGRID_TITLE,
  123.             PartyRankingViewConstants.TITLE_PARTY_RANKINGS,
  124.             PartyRankingViewConstants.DATAGRID_DESC);

  125.         final String pageId = getPageId(parameters);


  126.         final DataContainer<ViewRiksdagenPartySummary, String> dataContainer = getApplicationManager()
  127.                 .getDataContainer(ViewRiksdagenPartySummary.class);

  128.         getGridFactory().createBasicBeanItemGrid(panelContent, ViewRiksdagenPartySummary.class, dataContainer.findListByProperty(
  129.                 new Object[] { Boolean.TRUE }, ViewRiksdagenPartySummary_.active),
  130.                 PARTIES,
  131.                 COLUMN_ORDER, HIDE_COLUMNS, LISTENER, null, null);



  132.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_PARTY_RANKING_VIEW, ApplicationEventGroup.USER,
  133.                 NAME, parameters, pageId);

  134.         return panelContent;

  135.     }

  136.     /**
  137.      * Matches.
  138.      *
  139.      * @param page the page
  140.      * @param parameters the parameters
  141.      * @return true, if successful
  142.      */
  143.     @Override
  144.     public boolean matches(final String page, final String parameters) {
  145.         return PageCommandPartyRankingConstants.COMMAND_PARTY_RANKING_DATAGRID.matches(page, parameters);
  146.     }

  147. }