UserHomeApplicationSessionsPageModContentFactoryImpl.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.ApplicationEventGroup;
  25. import com.hack23.cia.model.internal.application.system.impl.ApplicationSession;
  26. import com.hack23.cia.model.internal.application.system.impl.ApplicationSession_;
  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.converters.ListPropertyConverter;
  31. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.UserHomeMenuItemFactory;
  32. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.pagecommands.PageCommandUserHomeConstants;
  33. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.CardInfoRowUtil;
  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.vaadin.ui.Layout;
  37. import com.vaadin.ui.MenuBar;
  38. import com.vaadin.ui.Panel;
  39. import com.vaadin.ui.VerticalLayout;

  40. /**
  41.  * The Class UserHomeApplicationSessionsPageModContentFactoryImpl.
  42.  */
  43. @Component
  44. public final class UserHomeApplicationSessionsPageModContentFactoryImpl
  45.         extends AbstractUserHomePageModContentFactoryImpl {

  46.     /** The Constant APPLICATION_SESSION. */
  47.     private static final String APPLICATION_SESSION = "ApplicationSession";

  48.     /** The Constant COLLECTION_PROPERTY_CONVERTERS. */
  49.     private static final ListPropertyConverter[] COLLECTION_PROPERTY_CONVERTERS = {
  50.             new ListPropertyConverter("page", "events", "actionName") };

  51.     /** The Constant COLUMN_ORDER. */
  52.     private static final String[] COLUMN_ORDER = { "hjid", "createdDate", "operatingSystem",
  53.             "ipInformation", "events", "userAgentInformation" };

  54.     /** The Constant HIDE_COLUMNS. */
  55.     private static final String[] HIDE_COLUMNS = { "hjid", "modelObjectId", "modelObjectVersion",
  56.             "sessionId", "sessionType", "userId", "locale" };

  57.     /** The Constant LISTENER. */
  58.     private static final PageItemPropertyClickListener LISTENER = new PageItemPropertyClickListener(
  59.             AdminViews.ADMIN_APPLICATIONS_SESSION_VIEW_NAME, "hjid");

  60.     /** The user home menu item factory. */
  61.     @Autowired
  62.     private UserHomeMenuItemFactory userHomeMenuItemFactory;

  63.     /**
  64.      * Instantiates a new user home security settings page mod content factory
  65.      * impl.
  66.      */
  67.     public UserHomeApplicationSessionsPageModContentFactoryImpl() {
  68.         super();
  69.     }

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

  76.         if (userAccount.isPresent()) {
  77.             userHomeMenuItemFactory.createUserHomeMenuBar(menuBar, pageId);
  78.             CardInfoRowUtil.createPageHeader(panel, panelContent,
  79.                 UserHomeViewConstants.TITLE_PREFIX + UserHomeViewConstants.USER_VISITS_TITLE,
  80.                 UserHomeViewConstants.USER_VISITS_TITLE,
  81.                 UserHomeViewConstants.USER_VISITS_DESC);

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

  84.             getGridFactory().createBasicBeanItemGrid(panelContent, ApplicationSession.class,
  85.                     sessionDataContainer.findOrderedListByProperty(ApplicationSession_.userId,
  86.                             userAccount.get().getUserId(), ApplicationSession_.createdDate),
  87.                     APPLICATION_SESSION, COLUMN_ORDER, HIDE_COLUMNS, LISTENER, null, COLLECTION_PROPERTY_CONVERTERS);
  88.         }

  89.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_USER_HOME_VIEW, ApplicationEventGroup.USER, NAME,
  90.                 parameters, pageId);

  91.         return panelContent;

  92.     }

  93.     @Override
  94.     public boolean matches(final String page, final String parameters) {
  95.         return PageCommandUserHomeConstants.COMMAND_USERHOME_USER_VISITS.matches(page, parameters);
  96.     }

  97. }