AdminApplicationConfigurationPageModContentFactoryImpl.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.admin.system.pagemode;

  20. import java.util.Arrays;
  21. import java.util.List;

  22. import org.springframework.security.access.annotation.Secured;
  23. import org.springframework.stereotype.Component;
  24. import org.springframework.web.context.request.RequestContextHolder;

  25. import com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration;
  26. import com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration_;
  27. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  28. import com.hack23.cia.service.api.DataContainer;
  29. import com.hack23.cia.service.api.action.admin.UpdateApplicationConfigurationRequest;
  30. import com.hack23.cia.web.impl.ui.application.action.ViewAction;
  31. import com.hack23.cia.web.impl.ui.application.views.admin.AdminViewConstants;
  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.ContentSize;
  34. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.AdminViews;
  35. import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
  36. import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.UpdateApplicationConfigurationClickListener;
  37. import com.vaadin.icons.VaadinIcons;
  38. import com.vaadin.server.Responsive;
  39. import com.vaadin.ui.Button.ClickListener;
  40. import com.vaadin.ui.FormLayout;
  41. import com.vaadin.ui.HorizontalLayout;
  42. import com.vaadin.ui.Layout;
  43. import com.vaadin.ui.MenuBar;
  44. import com.vaadin.ui.Panel;
  45. import com.vaadin.ui.VerticalLayout;

  46. /**
  47.  * The Class AdminApplicationConfigurationPageModContentFactoryImpl.
  48.  */
  49. @Component
  50. public final class AdminApplicationConfigurationPageModContentFactoryImpl
  51.         extends AbstractAdminSystemPageModContentFactoryImpl {

  52.     /** The Constant APPLICATION_CONFIGURATION. */
  53.     private static final String APPLICATION_CONFIGURATION = "ApplicationConfiguration";

  54.     /** The Constant AS_LIST2. */
  55.     private static final List<String> AS_LIST2 = Arrays.asList("configTitle", "configDescription", "componentTitle",
  56.             "componentDescription", "propertyValue");

  57.     /** The Constant COLUMN_ORDER. */
  58.     private static final String[] COLUMN_ORDER = { "hjid", "configurationGroup", "component", "componentTitle",
  59.             "configTitle", "configDescription", "componentDescription", "propertyId", "propertyValue" };

  60.     /** The Constant HIDE_COLUMNS. */
  61.     private static final String[] HIDE_COLUMNS = { "hjid", "modelObjectId", "modelObjectVersion", "createdDate",
  62.             "updatedDate", "propertyId", "componentDescription", "componentTitle" };

  63.     /** The Constant NAME. */
  64.     public static final String NAME = AdminViews.ADMIN_APPLICATIONS_CONFIGURATION_VIEW_NAME;

  65.     /** The Constant UPDATE_CONFIGURATION. */
  66.     private static final String UPDATE_CONFIGURATION = "Update Configuration";

  67.     /**
  68.      * Instantiates a new admin application configuration page mod content factory impl.
  69.      */
  70.     public AdminApplicationConfigurationPageModContentFactoryImpl() {
  71.         super(NAME);
  72.     }

  73.     @Secured({ "ROLE_ADMIN" })
  74.     @Override
  75.     public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
  76.         final VerticalLayout content = createPanelContent();

  77.         final String pageId = getPageId(parameters);
  78.         final int pageNr = getPageNr(parameters);

  79.         getMenuItemFactory().createMainPageMenuBar(menuBar);

  80.         CardInfoRowUtil.createPageHeader(panel, content, AdminViewConstants.ADMIN_APPLICATION_CONFIGURATION, AdminViewConstants.APPLICATION_CONFIGURATION_OVERVIEW,
  81.                 AdminViewConstants.APPLICATION_CONFIGURATION_OVERVIEW);

  82.         final DataContainer<ApplicationConfiguration, Long> dataContainer = getApplicationManager()
  83.                 .getDataContainer(ApplicationConfiguration.class);

  84.         final List<ApplicationConfiguration> pageOrderBy = dataContainer
  85.                 .getPageOrderBy(pageNr, DEFAULT_RESULTS_PER_PAGE, ApplicationConfiguration_.configurationGroup);

  86.         getPagingUtil().createPagingControls(content, NAME, pageId, dataContainer.getSize(), pageNr,
  87.                 DEFAULT_RESULTS_PER_PAGE);

  88.         getGridFactory().createBasicBeanItemGrid(
  89.                 content,
  90.                 ApplicationConfiguration.class,
  91.                 pageOrderBy,
  92.                 APPLICATION_CONFIGURATION,
  93.                 COLUMN_ORDER,
  94.                 HIDE_COLUMNS,
  95.                 new PageItemPropertyClickListener(AdminViews.ADMIN_APPLICATIONS_CONFIGURATION_VIEW_NAME, "hjid"),
  96.                 null,
  97.                 null
  98.         );

  99.         if (pageId != null && !pageId.isEmpty()) {
  100.             final ApplicationConfiguration applicationConfiguration = dataContainer.load(Long.valueOf(pageId));
  101.             if (applicationConfiguration != null) {

  102.                 final HorizontalLayout horizontalLayout = new HorizontalLayout();
  103.                 horizontalLayout.setWidth(ContentSize.FULL_SIZE);
  104.                 content.addComponent(horizontalLayout);

  105.                 final VerticalLayout leftLayout = new VerticalLayout();
  106.                 leftLayout.setSizeFull();
  107.                 leftLayout.addStyleName("v-layout-content-overview-panel-level1");

  108.                 final VerticalLayout rightLayout = new VerticalLayout();
  109.                 rightLayout.setSizeFull();
  110.                 rightLayout.addStyleName("v-layout-content-overview-panel-level2");

  111.                 horizontalLayout.addComponents(leftLayout, rightLayout);

  112.                 // Left side: Card layout for ApplicationConfiguration details
  113.                 final Panel cardPanel = new Panel();
  114.                 cardPanel.addStyleName("politician-overview-card"); // Reuse existing card style
  115.                 cardPanel.setWidth("100%");
  116.                 cardPanel.setHeightUndefined();
  117.                 Responsive.makeResponsive(cardPanel);

  118.                 final VerticalLayout cardContent = new VerticalLayout();
  119.                 cardContent.setMargin(true);
  120.                 cardContent.setSpacing(true);
  121.                 cardContent.setWidth("100%");
  122.                 cardPanel.setContent(cardContent);

  123.                 leftLayout.addComponent(cardPanel);

  124.                 CardInfoRowUtil.createCardHeader(cardContent,"Application Configuration Details");

  125.                 // Attributes layout
  126.                 final VerticalLayout attributesLayout = new VerticalLayout();
  127.                 attributesLayout.setSpacing(true);
  128.                 attributesLayout.setWidth("100%");
  129.                 cardContent.addComponent(attributesLayout);

  130.                 // Display relevant fields using info rows, skipping null or empty
  131.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, "Configuration Group:",
  132.                         applicationConfiguration.getConfigurationGroup().toString(), VaadinIcons.GROUP);
  133.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, "Component:",
  134.                         applicationConfiguration.getComponent(), VaadinIcons.TOOLS);
  135.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, "Config Title:",
  136.                         applicationConfiguration.getConfigTitle(), VaadinIcons.FILE_TEXT);
  137.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, "Config Description:",
  138.                         applicationConfiguration.getConfigDescription(), VaadinIcons.FILE_O);
  139.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, "Property Value:",
  140.                         applicationConfiguration.getPropertyValue(), VaadinIcons.PASTE);
  141.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, "Created Date:",
  142.                         String.valueOf(applicationConfiguration.getCreatedDate()), VaadinIcons.CALENDAR);
  143.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, "Updated Date:",
  144.                         String.valueOf(applicationConfiguration.getUpdatedDate()), VaadinIcons.CALENDAR_CLOCK);

  145.                 // Right side: Form for updating the application configuration
  146.                 final UpdateApplicationConfigurationRequest request = new UpdateApplicationConfigurationRequest();
  147.                 request.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
  148.                 request.setApplicationConfigurationId(applicationConfiguration.getHjid());
  149.                 request.setConfigTitle(applicationConfiguration.getConfigTitle());
  150.                 request.setConfigDescription(applicationConfiguration.getConfigDescription());
  151.                 request.setComponentTitle(applicationConfiguration.getConfigTitle());
  152.                 request.setComponentDescription(applicationConfiguration.getComponentDescription());
  153.                 request.setPropertyValue(applicationConfiguration.getPropertyValue());

  154.                 final ClickListener buttonListener = new UpdateApplicationConfigurationClickListener(request);

  155.                 final Panel updateFormPanel = new Panel();
  156.                 updateFormPanel.setSizeFull();
  157.                 rightLayout.addComponent(updateFormPanel);

  158.                 final FormLayout updateFormContent = new FormLayout();
  159.                 updateFormPanel.setContent(updateFormContent);

  160.                 getFormFactory().addRequestInputFormFields(updateFormContent, request,
  161.                         UpdateApplicationConfigurationRequest.class, AS_LIST2,
  162.                         UPDATE_CONFIGURATION, buttonListener);
  163.             }
  164.         }

  165.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_APPLICATION_CONFIGURATION_VIEW,
  166.                 ApplicationEventGroup.ADMIN, NAME, null, pageId);

  167.         return content;
  168.     }

  169. }