AdminApplicationEventsPageModContentFactoryImpl.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.List;

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

  23. import com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent;
  24. import com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent_;
  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.admin.AdminViewConstants;
  29. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.pagecommands.PageCommandAdminConstants;
  30. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.CardInfoRowUtil;
  31. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.AdminViews;
  32. import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
  33. import com.vaadin.icons.VaadinIcons;
  34. import com.vaadin.server.Responsive;
  35. import com.vaadin.ui.Layout;
  36. import com.vaadin.ui.MenuBar;
  37. import com.vaadin.ui.Panel;
  38. import com.vaadin.ui.VerticalLayout;

  39. /**
  40.  * The Class AdminApplicationEventsPageModContentFactoryImpl.
  41.  */
  42. @Component
  43. public final class AdminApplicationEventsPageModContentFactoryImpl extends AbstractAdminSystemPageModContentFactoryImpl {

  44.     /** The Constant APPLICATION_ACTION_EVENT. */
  45.     private static final String APPLICATION_ACTION_EVENT = "ApplicationActionEvent";

  46.     /** The Constant COLUMN_ORDER. */
  47.     private static final String[] COLUMN_ORDER = { "hjid", "createdDate", "userId", "actionName", "errorMessage",
  48.             "applicationMessage", "page", "pageMode", "elementId", "modelObjectVersion" };

  49.     /** The Constant HIDE_COLUMNS. */
  50.     private static final String[] HIDE_COLUMNS = { "hjid", "modelObjectId", "modelObjectVersion", "sessionId",
  51.             "eventGroup", "applicationOperation" };

  52.     /** The Constant LISTENER. */
  53.     private static final PageItemPropertyClickListener LISTENER = new PageItemPropertyClickListener(
  54.             AdminViews.ADMIN_APPLICATIONS_EVENTS_VIEW_NAME, "hjid");

  55.     /** The Constant NAME. */
  56.     public static final String NAME = AdminViews.ADMIN_APPLICATIONS_EVENTS_VIEW_NAME;

  57.     /**
  58.      * Instantiates a new admin application events page mod content factory impl.
  59.      */
  60.     public AdminApplicationEventsPageModContentFactoryImpl() {
  61.         super(NAME);
  62.     }

  63.     @Secured({ "ROLE_ADMIN" })
  64.     @Override
  65.     public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
  66.         final VerticalLayout content = createPanelContent();

  67.         final String pageId = getPageId(parameters);
  68.         final int pageNr = getPageNr(parameters);

  69.         getMenuItemFactory().createMainPageMenuBar(menuBar);

  70.         CardInfoRowUtil.createPageHeader(panel, content, AdminViewConstants.ADMIN_APPLICATION_EVENTS, AdminViewConstants.EVENT_DETAILS,
  71.                 AdminViewConstants.EVENT_REVIEW);

  72.         final DataContainer<ApplicationActionEvent, Long> dataContainer = getApplicationManager()
  73.                 .getDataContainer(ApplicationActionEvent.class);

  74.         final List<ApplicationActionEvent> pageOrderBy = dataContainer.getPageOrderBy(pageNr, DEFAULT_RESULTS_PER_PAGE,
  75.                 ApplicationActionEvent_.createdDate);

  76.         getPagingUtil().createPagingControls(content, NAME, pageId, dataContainer.getSize(), pageNr,
  77.                 DEFAULT_RESULTS_PER_PAGE);

  78.         getGridFactory().createBasicBeanItemGrid(content, ApplicationActionEvent.class, pageOrderBy,
  79.                 APPLICATION_ACTION_EVENT, COLUMN_ORDER, HIDE_COLUMNS, LISTENER, null, null);

  80.         if (pageId != null && !pageId.isEmpty()) {
  81.             final ApplicationActionEvent applicationActionEvent = dataContainer.load(Long.valueOf(pageId));
  82.             if (applicationActionEvent != null) {
  83.                 // Instead of form fields, use a card layout similar to the party overview.
  84.                 final Panel cardPanel = new Panel();
  85.                 cardPanel.addStyleName("politician-overview-card"); // Reuse existing style
  86.                 cardPanel.setWidth("100%");
  87.                 cardPanel.setHeightUndefined();
  88.                 Responsive.makeResponsive(cardPanel);

  89.                 final VerticalLayout cardContent = new VerticalLayout();
  90.                 cardContent.setMargin(true);
  91.                 cardContent.setSpacing(true);
  92.                 cardContent.setWidth("100%");
  93.                 cardPanel.setContent(cardContent);

  94.                 content.addComponent(cardPanel);

  95.                 CardInfoRowUtil.createCardHeader(cardContent, AdminViewConstants.EVENT_DETAILS);

  96.                 // Attributes layout
  97.                 final VerticalLayout attributesLayout = new VerticalLayout();
  98.                 attributesLayout.setSpacing(true);
  99.                 attributesLayout.setWidth("100%");
  100.                 cardContent.addComponent(attributesLayout);

  101.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, AdminViewConstants.CREATED_DATE,
  102.                         String.valueOf(applicationActionEvent.getCreatedDate()), VaadinIcons.CALENDAR);
  103.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, AdminViewConstants.EVENT_GROUP,
  104.                         String.valueOf(applicationActionEvent.getEventGroup()), VaadinIcons.INFO);
  105.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, AdminViewConstants.APPLICATION_OPERATION,
  106.                         String.valueOf(applicationActionEvent.getApplicationOperation()), VaadinIcons.TOOLS);
  107.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, AdminViewConstants.PAGE,
  108.                         String.valueOf(applicationActionEvent.getPage()), VaadinIcons.FILE_TEXT);
  109.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, AdminViewConstants.PAGE_MODE,
  110.                         String.valueOf(applicationActionEvent.getPageMode()), VaadinIcons.LIST);
  111.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, AdminViewConstants.ELEMENT_ID,
  112.                         String.valueOf(applicationActionEvent.getElementId()), VaadinIcons.POINTER);
  113.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, AdminViewConstants.ACTION_NAME,
  114.                         String.valueOf(applicationActionEvent.getActionName()), VaadinIcons.PLAY_CIRCLE);
  115.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, AdminViewConstants.USER_ID,
  116.                         String.valueOf(applicationActionEvent.getUserId()), VaadinIcons.USER);
  117.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, AdminViewConstants.SESSION_ID,
  118.                         String.valueOf(applicationActionEvent.getSessionId()), VaadinIcons.KEY);
  119.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, AdminViewConstants.ERROR_MESSAGE,
  120.                         String.valueOf(applicationActionEvent.getErrorMessage()), VaadinIcons.WARNING);
  121.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, AdminViewConstants.APPLICATION_MESSAGE,
  122.                         String.valueOf(applicationActionEvent.getApplicationMessage()), VaadinIcons.INFO_CIRCLE);
  123.             }
  124.         }

  125.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_APPLICATION_EVENTS_VIEW,
  126.                 ApplicationEventGroup.ADMIN, NAME, null, pageId);

  127.         return content;
  128.     }

  129.     @Override
  130.     public boolean matches(final String page, final String parameters) {
  131.         return PageCommandAdminConstants.COMMAND_APPLICATION_EVENTS.matches(page, parameters);
  132.     }

  133. }