UserHomeApplicationEventsPageModContentFactoryImpl.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.home.pagemode;

  20. import java.util.Optional;

  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.system.impl.ApplicationActionEvent;
  25. import com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent_;
  26. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  27. import com.hack23.cia.model.internal.application.user.impl.UserAccount;
  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.menufactory.api.UserHomeMenuItemFactory;
  31. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.pagecommands.PageCommandUserHomeConstants;
  32. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.CardInfoRowUtil;
  33. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.AdminViews;
  34. import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
  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 UserHomeApplicationEventsPageModContentFactoryImpl.
  41.  */
  42. @Component
  43. public final class UserHomeApplicationEventsPageModContentFactoryImpl
  44.         extends AbstractUserHomePageModContentFactoryImpl {

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

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

  51.     /** The Constant HIDE_COLUMNS. */
  52.     private static final String[] HIDE_COLUMNS = { "hjid", "userId", "sessionId", "modelObjectId",
  53.             "modelObjectVersion" };

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

  57.     /** The user home menu item factory. */
  58.     @Autowired
  59.     private UserHomeMenuItemFactory userHomeMenuItemFactory;

  60.     /**
  61.      * Instantiates a new user home security settings page mod content factory
  62.      * impl.
  63.      */
  64.     public UserHomeApplicationEventsPageModContentFactoryImpl() {
  65.         super();
  66.     }

  67.     @Secured({ "ROLE_USER", "ROLE_ADMIN" })
  68.     @Override
  69.     public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
  70.         final VerticalLayout panelContent = createPanelContent();
  71.         final String pageId = getPageId(parameters);
  72.         final Optional<UserAccount> userAccount = getActiveUserAccount();

  73.         if (userAccount.isPresent()) {

  74.             userHomeMenuItemFactory.createUserHomeMenuBar(menuBar, pageId);
  75.             CardInfoRowUtil.createPageHeader(panel, panelContent,
  76.                 UserHomeViewConstants.TITLE_PREFIX + UserHomeViewConstants.USER_EVENTS_TITLE,
  77.                 UserHomeViewConstants.USER_EVENTS_TITLE,
  78.                 UserHomeViewConstants.USER_EVENTS_DESC);

  79.             final DataContainer<ApplicationActionEvent, Long> eventDataContainer = getApplicationManager()
  80.                     .getDataContainer(ApplicationActionEvent.class);

  81.             getGridFactory().createBasicBeanItemGrid(panelContent, ApplicationActionEvent.class,
  82.                     eventDataContainer.findOrderedListByProperty(ApplicationActionEvent_.userId,
  83.                             userAccount.get().getUserId(), ApplicationActionEvent_.createdDate),
  84.                     APPLICATION_ACTION_EVENT, COLUMN_ORDER, HIDE_COLUMNS, LISTENER, null, null);
  85.         }

  86.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_USER_HOME_VIEW, ApplicationEventGroup.USER, NAME,
  87.                 parameters, pageId);

  88.         return panelContent;

  89.     }

  90.     @Override
  91.     public boolean matches(final String page, final String parameters) {
  92.         return PageCommandUserHomeConstants.COMMAND_USERHOME_USER_EVENTS.matches(page, parameters);
  93.     }

  94. }