LogoutClickListener.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.pageclicklistener;

  20. import org.slf4j.Logger;
  21. import org.slf4j.LoggerFactory;

  22. import com.hack23.cia.service.api.action.application.LogoutRequest;
  23. import com.hack23.cia.service.api.action.common.ServiceResponse;
  24. import com.hack23.cia.service.api.action.common.ServiceResponse.ServiceResult;
  25. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.CommonsViews;
  26. import com.vaadin.server.VaadinService;
  27. import com.vaadin.ui.Button.ClickEvent;
  28. import com.vaadin.ui.Button.ClickListener;
  29. import com.vaadin.ui.Notification;
  30. import com.vaadin.ui.UI;

  31. /**
  32.  * The Class LogoutClickListener.
  33.  *
  34.  * @see LogoutClickEvent
  35.  */
  36. public class LogoutClickListener extends AbstractClickListener implements ClickListener {

  37.     /** The Constant ERROR_MESSAGE. */
  38.     private static final String ERROR_MESSAGE = "Error message";

  39.     /** The Constant LOG_MSG_LOGOUT_FAILURE. */
  40.     private static final String LOG_MSG_LOGOUT_FAILURE = "Logout {} failure";

  41.     /** The Constant LOGGER. */
  42.     private static final Logger LOGGER = LoggerFactory.getLogger(LogoutClickListener.class);

  43.     /** The Constant LOGOUT_FAILED. */
  44.     private static final String LOGOUT_FAILED = "Logout failed";

  45.     /** The Constant serialVersionUID. */
  46.     private static final long serialVersionUID = 1L;

  47.     /** The logout request. */
  48.     private final LogoutRequest logoutRequest;

  49.     /**
  50.      * Instantiates a new logout click listener.
  51.      *
  52.      * @param logoutRequest
  53.      *            the logout request
  54.      */
  55.     public LogoutClickListener(final LogoutRequest logoutRequest) {
  56.         this.logoutRequest = logoutRequest;
  57.     }

  58.     @Override
  59.     public final void buttonClick(final ClickEvent event) {
  60.         final ServiceResponse response = getApplicationManager().service(logoutRequest);


  61.         if (ServiceResult.SUCCESS == response.getResult()) {
  62.             UI.getCurrent().getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
  63.             UI.getCurrent().getSession().close();
  64.             VaadinService.getCurrentRequest().getWrappedSession().invalidate();
  65.         } else {
  66.             showNotification(LOGOUT_FAILED,
  67.                       ERROR_MESSAGE,
  68.                       Notification.Type.WARNING_MESSAGE);
  69.             LOGGER.info(LOG_MSG_LOGOUT_FAILURE,logoutRequest.getSessionId());
  70.         }
  71.     }
  72. }