AbstractGovernmentBodyPageModContentFactoryImpl.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.govermentbody.pagemode;

  20. import java.util.List;
  21. import java.util.Locale;
  22. import java.util.Map;
  23. import java.util.stream.Collectors;

  24. import org.springframework.beans.factory.annotation.Autowired;

  25. import com.hack23.cia.service.external.esv.api.EsvApi;
  26. import com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary;
  27. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.GovernmentBodyMenuItemFactory;
  28. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.AbstractItemPageModContentFactoryImpl;
  29. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;

  30. /**
  31.  * The Class AbstractGovernmentBodyPageModContentFactoryImpl.
  32.  */
  33. abstract class AbstractGovernmentBodyPageModContentFactoryImpl extends AbstractItemPageModContentFactoryImpl<List<GovernmentBodyAnnualSummary>> {

  34.     /** The Constant NAME. */
  35.     public static final String NAME = UserViews.GOVERNMENT_BODY_VIEW_NAME;

  36.     /** The esv api. */
  37.     @Autowired
  38.     private EsvApi esvApi;

  39.     /** The government body menu item factory. */
  40.     @Autowired
  41.     private GovernmentBodyMenuItemFactory governmentBodyMenuItemFactory;

  42.     /**
  43.      * Instantiates a new abstract government body page mod content factory impl.
  44.      */
  45.     AbstractGovernmentBodyPageModContentFactoryImpl() {
  46.         super();
  47.     }

  48.     /**
  49.      * Gets the government body menu item factory.
  50.      *
  51.      * @return the government body menu item factory
  52.      */
  53.     protected final GovernmentBodyMenuItemFactory getGovernmentBodyMenuItemFactory() {
  54.         return governmentBodyMenuItemFactory;
  55.     }

  56.     @Override
  57.     protected List<GovernmentBodyAnnualSummary> getItem(final String parameters) {
  58.         final Map<String, List<GovernmentBodyAnnualSummary>> map = esvApi.getData().get(2024).stream().collect(Collectors.groupingBy(GovernmentBodyAnnualSummary::getOrgNumber));
  59.         return map.get(getPageId(parameters));
  60.     }

  61.     /**
  62.      * Format year.
  63.      *
  64.      * @param year the year
  65.      * @return the string
  66.      */
  67.     public static String formatYear(final int year) {
  68.         return String.format(Locale.ENGLISH, "%d", year);
  69.     }

  70.     /**
  71.      * Format count.
  72.      *
  73.      * @param count the count
  74.      * @return the string
  75.      */
  76.     public static String formatCount(final int count) {
  77.         return String.format(Locale.ENGLISH, "%d", count);
  78.     }

  79.     /**
  80.      * Format title.
  81.      *
  82.      * @param govBody the gov body
  83.      * @param pageTitle the page title
  84.      * @return the string
  85.      */
  86.     public static String formatTitle(final GovernmentBodyAnnualSummary govBody, final String pageTitle) {
  87.         if (govBody == null) {
  88.             return pageTitle;
  89.         }
  90.         return String.format(Locale.ENGLISH, "%s %s", pageTitle, govBody.getName());
  91.     }

  92. }