PartyGovernmentRolesPageModContentFactoryImpl.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.party.pagemode;

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

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

  36. /**
  37.  * The Class GovernmentRolesPageModContentFactoryImpl.
  38.  */
  39. @Component
  40. public final class PartyGovernmentRolesPageModContentFactoryImpl extends AbstractPartyPageModContentFactoryImpl {

  41.     /** The Constant PERSON_ID. */
  42.     private static final String PERSON_ID = "personId";

  43.     /** The Constant COLUMN_ORDER. */
  44.     private static final String[] COLUMN_ORDER = { "roleId", PERSON_ID, "firstName", "lastName", "active",
  45.             "detail", "roleCode", "fromDate", "toDate", "totalDaysServed" };
  46.     /** The Constant GOVERNMENT_ROLES. */
  47.     private static final String GOVERNMENT_ROLES = "Government Roles";

  48.     /** The Constant HIDE_COLUMNS. */
  49.     private static final String[] HIDE_COLUMNS = { "roleId", PERSON_ID, "party" };

  50.     /**
  51.      * Instantiates a new party government roles page mod content factory impl.
  52.      */
  53.     public PartyGovernmentRolesPageModContentFactoryImpl() {
  54.         super();
  55.     }

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

  61.         final String pageId = getPageId(parameters);

  62.         final ViewRiksdagenParty viewRiksdagenParty = getItem(parameters);
  63.         getPartyMenuItemFactory().createPartyMenuBar(menuBar, pageId);

  64.         CardInfoRowUtil.createPageHeader(panel, panelContent, PartyViewConstants.GOVERNMENT_ROLES_HEADER + viewRiksdagenParty.getPartyName(), PartyViewConstants.GOVERNMENT_ROLES_TITLE, PartyViewConstants.GOVERNMENT_ROLES_DESC);

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

  67.         getGridFactory().createBasicBeanItemGrid(panelContent, ViewRiksdagenGovermentRoleMember.class,
  68.                 govermentRoleMemberDataContainer.findListByProperty(
  69.                         new Object[] { viewRiksdagenParty.getPartyId(), Boolean.TRUE },
  70.                         ViewRiksdagenGovermentRoleMember_.party, ViewRiksdagenGovermentRoleMember_.active),
  71.                 GOVERNMENT_ROLES, COLUMN_ORDER, HIDE_COLUMNS,
  72.                 new PageItemPropertyClickListener(UserViews.POLITICIAN_VIEW_NAME, PERSON_ID), null, null);

  73.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_PARTY_VIEW, ApplicationEventGroup.USER, NAME, parameters,
  74.         pageId);
  75.         return panelContent;

  76.     }

  77.     @Override
  78.     public boolean matches(final String page, final String parameters) {
  79.         return PageCommandPartyConstants.COMMAND_PARTY_GOVERNMENT_ROLES.matches(page, parameters);
  80.     }

  81. }