GovernmentBodyRankingDataGridPageModContentFactoryImpl.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.govermentbodyranking.pagemode;

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

  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.security.access.annotation.Secured;
  24. import org.springframework.stereotype.Service;

  25. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  26. import com.hack23.cia.service.external.esv.api.EsvApi;
  27. import com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary;
  28. import com.hack23.cia.web.impl.ui.application.action.ViewAction;
  29. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.pagecommands.PageCommandGovernmentBodyRankingConstants;
  30. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.CardInfoRowUtil;
  31. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
  32. import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
  33. import com.hack23.cia.web.impl.ui.application.views.user.govermentbody.pagemode.GovernmentBodyDescriptionConstants;
  34. import com.hack23.cia.web.impl.ui.application.views.user.govermentbody.pagemode.GovernmentBodyViewConstants;
  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 GovernmentBodyRankingDataGridPageModContentFactoryImpl.
  41.  */
  42. @Service
  43. public final class GovernmentBodyRankingDataGridPageModContentFactoryImpl
  44.         extends AbstractGovernmentBodyRankingPageModContentFactoryImpl {

  45.     /** The Constant LISTENER. */
  46.     private static final PageItemPropertyClickListener LISTENER = new PageItemPropertyClickListener(
  47.             UserViews.GOVERNMENT_BODY_VIEW_NAME, GovernmentBodyViewConstants.ORG_NUMBER_PROPERTY);

  48.     /** The esv api. */
  49.     @Autowired
  50.     private EsvApi esvApi;

  51.     /**
  52.      * Instantiates a new government body ranking data grid page mod content factory
  53.      * impl.
  54.      */
  55.     public GovernmentBodyRankingDataGridPageModContentFactoryImpl() {
  56.         super();
  57.     }

  58.     @Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
  59.     @Override
  60.     public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
  61.         final VerticalLayout panelContent = createPanelContent();

  62.         getGovernmentBodyRankingMenuItemFactory().createGovernmentBodyRankingMenuBar(menuBar);
  63.         CardInfoRowUtil.createPageHeader(panel, panelContent,
  64.                 GovernmentBodyDescriptionConstants.RANKING_HEADER,
  65.                 GovernmentBodyDescriptionConstants.RANKING_SUBTITLE,
  66.                 GovernmentBodyDescriptionConstants.RANKING_DESC);

  67.         final String pageId = getPageId(parameters);

  68.         final Map<Integer, List<GovernmentBodyAnnualSummary>> dataMap = esvApi.getData();

  69.         final List<GovernmentBodyAnnualSummary> list = dataMap.get(GovernmentBodyViewConstants.DEFAULT_YEAR);

  70.         getGridFactory().createBasicBeanItemGrid(panelContent,
  71.             GovernmentBodyAnnualSummary.class,
  72.             list,
  73.             GovernmentBodyViewConstants.GOVERNMENT_BODIES,
  74.             GovernmentBodyViewConstants.COLUMN_ORDER,
  75.             GovernmentBodyViewConstants.HIDE_COLUMNS,
  76.             LISTENER, null, null);

  77.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_GOVERNMENT_BODY_RANKING_VIEW,
  78.                 ApplicationEventGroup.USER, NAME, parameters, pageId);

  79.         return panelContent;

  80.     }

  81.     @Override
  82.     public boolean matches(final String page, final String parameters) {
  83.         return PageCommandGovernmentBodyRankingConstants.COMMAND_GOVERNMENT_BODY_RANKING_DATAGRID.matches(page, parameters);
  84.     }

  85. }