DocumentOverviewPageModContentFactoryImpl.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.document.pagemode;

  20. import org.apache.commons.lang3.StringUtils;
  21. import org.springframework.security.access.annotation.Secured;
  22. import org.springframework.stereotype.Component;

  23. import com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement;
  24. import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentData;
  25. import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentData_;
  26. import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentStatusContainer;
  27. import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentStatusContainer_;
  28. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  29. import com.hack23.cia.service.api.DataContainer;
  30. import com.hack23.cia.web.impl.ui.application.action.ViewAction;
  31. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.pagecommands.PageCommandDocumentConstants;
  32. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.CardInfoRowUtil;
  33. import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
  34. import com.vaadin.icons.VaadinIcons;
  35. import com.vaadin.server.Responsive;
  36. import com.vaadin.ui.HorizontalLayout;
  37. import com.vaadin.ui.Layout;
  38. import com.vaadin.ui.MenuBar;
  39. import com.vaadin.ui.Panel;
  40. import com.vaadin.ui.VerticalLayout;

  41. /**
  42.  * The Class DocumentOverviewPageModContentFactoryImpl.
  43.  */
  44. @Component
  45. public final class DocumentOverviewPageModContentFactoryImpl extends AbstractDocumentPageModContentFactoryImpl {

  46.     /**
  47.      * Instantiates a new document overview page mod content factory impl.
  48.      */
  49.     public DocumentOverviewPageModContentFactoryImpl() {
  50.         super();
  51.     }

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

  56.         final String pageId = getPageId(parameters);

  57.         final DocumentElement documentElement = getItem(parameters);
  58.         getDocumentMenuItemFactory().createDocumentMenuBar(menuBar, pageId);

  59.         final DataContainer<DocumentStatusContainer, String> documentStatusContainerDataContainer = getApplicationManager()
  60.                 .getDataContainer(DocumentStatusContainer.class);

  61.         final DocumentStatusContainer documentStatusContainer = documentStatusContainerDataContainer
  62.                 .findByQueryProperty(DocumentStatusContainer.class, DocumentStatusContainer_.document,
  63.                         DocumentData.class, DocumentData_.id, pageId);

  64.         CardInfoRowUtil.createPageHeader(panel, panelContent,
  65.             DocumentViewConstants.OVERVIEW_TITLE + " " + documentElement.getTitle() + " " + documentElement.getSubTitle(),
  66.             DocumentViewConstants.OVERVIEW_SUBTITLE,
  67.             DocumentViewConstants.OVERVIEW_DESC);

  68.         // Create a card panel for document info
  69.         final Panel cardPanel = new Panel();
  70.         cardPanel.addStyleName("politician-overview-card");
  71.         cardPanel.setWidth("100%");
  72.         cardPanel.setHeightUndefined();
  73.         Responsive.makeResponsive(cardPanel);

  74.         final VerticalLayout cardContent = new VerticalLayout();
  75.         cardContent.setMargin(true);
  76.         cardContent.setSpacing(true);
  77.         cardContent.setWidth("100%");
  78.         cardPanel.setContent(cardContent);

  79.         panelContent.addComponent(cardPanel);
  80.         panelContent.setExpandRatio(cardPanel, ContentRatio.SMALL_GRID);

  81.         CardInfoRowUtil.createCardHeader(cardContent, DocumentViewConstants.OVERVIEW_SECTION_DOC_INFO);

  82.         // Two-column layout
  83.         final HorizontalLayout attributesLayout = new HorizontalLayout();
  84.         attributesLayout.setSpacing(true);
  85.         attributesLayout.setWidth("100%");
  86.         cardContent.addComponent(attributesLayout);

  87.         // Left column: Document Profile (from DocumentElement)
  88.         final VerticalLayout profileLayout = CardInfoRowUtil.createSectionLayout(
  89.             DocumentViewConstants.OVERVIEW_SECTION_DOC_PROFILE);

  90.         // Display a selection of DocumentElement fields
  91.         profileLayout.addComponent(CardInfoRowUtil.createInfoRow(
  92.             DocumentViewConstants.FIELD_TITLE,
  93.             documentElement.getTitle(),
  94.             VaadinIcons.FILE_TEXT_O,
  95.             DocumentViewConstants.TOOLTIP_TITLE));

  96.         if (!StringUtils.isEmpty(documentElement.getSubTitle())) {
  97.             profileLayout.addComponent(CardInfoRowUtil.createInfoRow(
  98.                 DocumentViewConstants.FIELD_SUBTITLE,
  99.                 documentElement.getSubTitle(),
  100.                 VaadinIcons.FILE_TEXT,
  101.                 DocumentViewConstants.TOOLTIP_SUBTITLE));
  102.         }

  103.         profileLayout.addComponent(CardInfoRowUtil.createInfoRow(
  104.             DocumentViewConstants.FIELD_ORGANIZATION,
  105.             documentElement.getOrg(),
  106.             VaadinIcons.INSTITUTION,
  107.             DocumentViewConstants.TOOLTIP_ORGANIZATION));

  108.         profileLayout.addComponent(CardInfoRowUtil.createInfoRow(
  109.             DocumentViewConstants.FIELD_DOC_TYPE,
  110.             documentElement.getDocumentType(),
  111.             VaadinIcons.FILE_CODE,
  112.             DocumentViewConstants.TOOLTIP_DOC_TYPE));

  113.         profileLayout.addComponent(CardInfoRowUtil.createInfoRow(
  114.             DocumentViewConstants.FIELD_STATUS,
  115.             documentElement.getStatus(),
  116.             VaadinIcons.QUESTION_CIRCLE,
  117.             DocumentViewConstants.TOOLTIP_STATUS));

  118.         profileLayout.addComponent(CardInfoRowUtil.createInfoRow(
  119.             DocumentViewConstants.FIELD_MADE_PUBLIC,
  120.             String.valueOf(documentElement.getMadePublicDate()),
  121.             VaadinIcons.CALENDAR_USER,
  122.             DocumentViewConstants.TOOLTIP_MADE_PUBLIC));

  123.         // Right column: Metadata & Status (from DocumentStatusContainer and
  124.         // DocumentData)
  125.         final VerticalLayout metadataLayout = CardInfoRowUtil.createSectionLayout(
  126.             DocumentViewConstants.OVERVIEW_SECTION_METADATA);

  127.         if (documentStatusContainer != null) {
  128.             // DocumentCategory (from DocumentStatusContainer)
  129.             if (!StringUtils.isEmpty(documentStatusContainer.getDocumentCategory())) {
  130.                 metadataLayout.addComponent(CardInfoRowUtil.createInfoRow(
  131.                     DocumentViewConstants.FIELD_CATEGORY,
  132.                     documentStatusContainer.getDocumentCategory(),
  133.                     VaadinIcons.BOOK,
  134.                     DocumentViewConstants.TOOLTIP_CATEGORY));
  135.             }

  136.             // DocumentData fields (AS_LIST2)
  137.             final DocumentData documentData = documentStatusContainer.getDocument();
  138.             if (documentData != null) {
  139.                 // Choose a few key fields from DocumentData
  140.                 if (!StringUtils.isEmpty(documentData.getLabel())) {
  141.                     metadataLayout.addComponent(CardInfoRowUtil.createInfoRow(
  142.                         DocumentViewConstants.FIELD_LABEL,
  143.                         documentData.getLabel(),
  144.                         VaadinIcons.TAG,
  145.                         DocumentViewConstants.TOOLTIP_LABEL));
  146.                 }
  147.                 if (!StringUtils.isEmpty(documentData.getTempLabel())) {
  148.                     metadataLayout.addComponent(CardInfoRowUtil.createInfoRow(
  149.                         DocumentViewConstants.FIELD_TEMP_LABEL,
  150.                         documentData.getTempLabel(),
  151.                         VaadinIcons.EDIT,
  152.                         DocumentViewConstants.TOOLTIP_TEMP_LABEL));
  153.                 }
  154.                 if (!StringUtils.isEmpty(documentData.getHangarId())) {
  155.                     metadataLayout.addComponent(CardInfoRowUtil.createInfoRow(
  156.                         DocumentViewConstants.FIELD_HANGAR_ID,
  157.                         documentData.getHangarId(),
  158.                         VaadinIcons.CLIPBOARD,
  159.                         DocumentViewConstants.TOOLTIP_HANGAR_ID));
  160.                 }
  161.                 if (documentData.getNumberValue() != null) {
  162.                     metadataLayout.addComponent(CardInfoRowUtil.createInfoRow(
  163.                         DocumentViewConstants.FIELD_NUMBER_VALUE,
  164.                         String.valueOf(documentData.getNumberValue()),
  165.                         VaadinIcons.BAR_CHART,
  166.                         DocumentViewConstants.TOOLTIP_NUMBER_VALUE));
  167.                 }
  168.             }
  169.         }

  170.         attributesLayout.addComponents(profileLayout, metadataLayout);

  171.         // After the card, add the overview layout
  172.         final VerticalLayout overviewLayout = new VerticalLayout();
  173.         overviewLayout.setSizeFull();
  174.         panelContent.addComponent(overviewLayout);
  175.         panelContent.setExpandRatio(overviewLayout, ContentRatio.LARGE_FORM);

  176.         getDocumentMenuItemFactory().createOverviewPage(overviewLayout, pageId);

  177.         panel.setContent(panelContent);
  178.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_DOCUMENT_VIEW, ApplicationEventGroup.USER, NAME,
  179.                 parameters, pageId);

  180.         return panelContent;

  181.     }


  182.     @Override
  183.     public boolean matches(final String page, final String parameters) {
  184.         return PageCommandDocumentConstants.COMMAND_DOCUMENT_OVERVIEW.matches(page, parameters);
  185.     }

  186. }