AbstractPoliticianPageModContentFactoryImpl.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.politician.pagemode;

  20. import java.util.Locale;

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

  22. import com.hack23.cia.model.external.riksdagen.person.impl.PersonData;
  23. import com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician;
  24. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.PoliticianMenuItemFactory;
  25. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.AbstractItemPageModContentFactoryImpl;
  26. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;

  27. /**
  28.  * The Class AbstractPoliticianPageModContentFactoryImpl.
  29.  */
  30. abstract class AbstractPoliticianPageModContentFactoryImpl extends AbstractItemPageModContentFactoryImpl<ViewRiksdagenPolitician> {

  31.     /** The Constant DAYS_PER_STANDARD_YEAR. */
  32.     private static final long DAYS_PER_STANDARD_YEAR = 365L;

  33.     /** The Constant NAME. */
  34.     public static final String NAME = UserViews.POLITICIAN_VIEW_NAME;

  35.     /** The politician ranking menu item factory. */
  36.     @Autowired
  37.     private PoliticianMenuItemFactory politicianMenuItemFactory;


  38.     /**
  39.      * Instantiates a new abstract politician page mod content factory impl.
  40.      */
  41.     AbstractPoliticianPageModContentFactoryImpl() {
  42.         super();
  43.     }

  44.     /**
  45.      * Convert to years string.
  46.      *
  47.      * @param totalDays
  48.      *            the total days
  49.      * @return the string
  50.      */
  51.     protected static final String convertToYearsString(final long totalDays) {
  52.         final long years = totalDays / DAYS_PER_STANDARD_YEAR;
  53.         final long days = totalDays - years * DAYS_PER_STANDARD_YEAR;

  54.         return years + " Years " + days + " days";
  55.     }

  56.     @Override
  57.     protected ViewRiksdagenPolitician getItem(final String parameters) {
  58.         final String pageId = getPageId(parameters);
  59.         final PersonData personData = getApplicationManager().getDataContainer(PersonData.class).load(pageId);
  60.         if (personData != null) {
  61.             return getApplicationManager().getDataContainer(ViewRiksdagenPolitician.class).load(personData.getId());
  62.         } else {
  63.             return null;
  64.         }
  65.     }

  66.     /**
  67.      * Format title.
  68.      *
  69.      * @param politician the politician
  70.      * @param pageTitle the page title
  71.      * @return the string
  72.      */
  73.     public static String formatTitle(final ViewRiksdagenPolitician politician, final String pageTitle) {
  74.         return String.format(Locale.ENGLISH, PoliticianPageTitleConstants.PAGE_TITLE_FORMAT,
  75.             politician.getFirstName(),
  76.             politician.getLastName(),
  77.             politician.getParty()) + " " + pageTitle;
  78.     }

  79.     /**
  80.      * Format title.
  81.      *
  82.      * @param politician the politician
  83.      * @return the string
  84.      */
  85.     public static String formatTitle(final ViewRiksdagenPolitician politician) {
  86.         return politician.getFirstName() + ' ' +
  87.                politician.getLastName() + '(' +
  88.                politician.getParty() + ')';
  89.     }


  90.     /**
  91.      * Gets the politician ranking menu item factory.
  92.      *
  93.      * @return the politician ranking menu item factory
  94.      */
  95.     protected final PoliticianMenuItemFactory getPoliticianMenuItemFactory() {
  96.         return politicianMenuItemFactory;
  97.     }

  98. }