PageActionEventHelperImpl.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.action;

  20. import org.apache.commons.lang3.StringUtils;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.web.context.request.RequestContextHolder;

  24. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  25. import com.hack23.cia.model.internal.application.system.impl.ApplicationOperationType;
  26. import com.hack23.cia.service.api.ApplicationManager;
  27. import com.hack23.cia.service.api.action.application.CreateApplicationEventRequest;
  28. import com.hack23.cia.web.impl.ui.application.util.UserContextUtil;

  29. /**
  30.  * The Class PageActionEventHelperImpl.
  31.  */
  32. @Service
  33. public final class PageActionEventHelperImpl implements PageActionEventHelper {

  34.     /** The application manager. */
  35.     @Autowired
  36.     private ApplicationManager applicationManager;

  37.     /**
  38.      * Instantiates a new page action event helper impl.
  39.      */
  40.     public PageActionEventHelperImpl() {
  41.         super();
  42.     }


  43.     @Override
  44.     public void createPageEvent(final ViewAction viewAction,final ApplicationEventGroup applicationEventGroup,final String page, final String pageMode, final String elementId) {



  45.         String pageModeToUse;

  46.         if (pageMode != null && elementId != null && pageMode.contains(elementId)) {
  47.             pageModeToUse= pageMode.replace(elementId, "").replace("/", "");
  48.         } else {
  49.             pageModeToUse = pageMode;
  50.         }

  51.         if ((pageModeToUse == null || "".equals(pageModeToUse)) && ApplicationEventGroup.USER == applicationEventGroup) {
  52.             pageModeToUse="Overview";
  53.         }

  54.         final CreateApplicationEventRequest serviceRequest = new CreateApplicationEventRequest();
  55.         serviceRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());

  56.         serviceRequest.setEventGroup(applicationEventGroup);
  57.         serviceRequest.setApplicationOperation(ApplicationOperationType.READ);

  58.         serviceRequest.setPage(StringUtils.defaultString(page));
  59.         serviceRequest.setPageMode(StringUtils.defaultString(pageModeToUse));
  60.         serviceRequest.setElementId(StringUtils.defaultString(elementId));

  61.         serviceRequest.setActionName(viewAction.toString());

  62.         serviceRequest.setUserId(UserContextUtil.getUserIdFromSecurityContext());

  63.         serviceRequest.setApplicationMessage(viewAction.toString());

  64.         applicationManager
  65.                 .service(serviceRequest);
  66.     }

  67. }