MinistryRoleGhantPageModContentFactoryImpl.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.goverment.pagemode;

  20. import java.util.List;

  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.security.access.annotation.Secured;
  23. import org.springframework.stereotype.Component;

  24. import com.hack23.cia.model.internal.application.data.ministry.impl.ViewRiksdagenGovermentRoleMember;
  25. import com.hack23.cia.model.internal.application.data.ministry.impl.ViewRiksdagenGovermentRoleMember_;
  26. import com.hack23.cia.model.internal.application.data.ministry.impl.ViewRiksdagenMinistry;
  27. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  28. import com.hack23.cia.service.api.DataContainer;
  29. import com.hack23.cia.web.impl.ui.application.action.ViewAction;
  30. import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.MinistryGhantChartManager;
  31. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.pagecommands.PageCommandMinistryConstants;
  32. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.CardInfoRowUtil;
  33. import com.vaadin.ui.Layout;
  34. import com.vaadin.ui.MenuBar;
  35. import com.vaadin.ui.Panel;
  36. import com.vaadin.ui.VerticalLayout;

  37. /**
  38.  * The Class MinistryRoleGhantPageModContentFactoryImpl.
  39.  */
  40. @Component
  41. public final class MinistryRoleGhantPageModContentFactoryImpl extends AbstractMinistryPageModContentFactoryImpl {

  42.     /** The ministry ghant chart manager. */
  43.     @Autowired
  44.     private MinistryGhantChartManager ministryGhantChartManager;

  45.     /**
  46.      * Instantiates a new ministry role ghant page mod content factory impl.
  47.      */
  48.     public MinistryRoleGhantPageModContentFactoryImpl() {
  49.         super();
  50.     }

  51.     @Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
  52.     @Override
  53.     public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
  54.         final VerticalLayout panelContent = createPanelContent();

  55.         final String pageId = getPageId(parameters);

  56.         final ViewRiksdagenMinistry viewRiksdagenMinistry = getItem(parameters);
  57.         getMinistryMenuItemFactory().createMinistryMenuBar(menuBar, pageId);

  58.         CardInfoRowUtil.createPageHeader(panel, panelContent,
  59.             MinistryViewConstants.ROLE_GHANT_TITLE + " " + viewRiksdagenMinistry.getNameId(),
  60.             MinistryViewConstants.ROLE_GHANT_SUBTITLE,
  61.             MinistryViewConstants.ROLE_GHANT_DESC);

  62.         final DataContainer<ViewRiksdagenGovermentRoleMember, String> govermentRoleMemberDataContainer = getApplicationManager()
  63.                 .getDataContainer(ViewRiksdagenGovermentRoleMember.class);

  64.         final List<ViewRiksdagenGovermentRoleMember> allMembers = govermentRoleMemberDataContainer
  65.                 .getAllBy(ViewRiksdagenGovermentRoleMember_.detail, viewRiksdagenMinistry.getNameId());

  66.         ministryGhantChartManager.createRoleGhant(panelContent, allMembers);

  67.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_MINISTRY_VIEW, ApplicationEventGroup.USER, NAME,
  68.                 parameters, pageId);
  69.         return panelContent;

  70.     }

  71.     @Override
  72.     public boolean matches(final String page, final String parameters) {
  73.         return PageCommandMinistryConstants.COMMAND_MINISTRY_ROLE_GHANT.matches(page, parameters);
  74.     }

  75. }