View Javadoc
1   /*
2    * Copyright 2014 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  
21  import org.slf4j.Logger;
22  import org.slf4j.LoggerFactory;
23  
24  import com.hack23.cia.service.api.action.application.LogoutRequest;
25  import com.hack23.cia.service.api.action.common.ServiceResponse;
26  import com.hack23.cia.service.api.action.common.ServiceResponse.ServiceResult;
27  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.CommonsViews;
28  import com.vaadin.server.VaadinService;
29  import com.vaadin.ui.Button.ClickEvent;
30  import com.vaadin.ui.Button.ClickListener;
31  import com.vaadin.ui.Notification;
32  import com.vaadin.ui.UI;
33  
34  /**
35   * The Class LogoutClickListener.
36   */
37  public final class LogoutClickListener implements ClickListener {
38  
39  	/** The Constant LOG_MSG_LOGOUT_FAILURE. */
40  	private static final String LOG_MSG_LOGOUT_FAILURE = "Logout {} failure";
41  
42  	/** The Constant ERROR_MESSAGE. */
43  	private static final String ERROR_MESSAGE = "Error message";
44  
45  	/** The Constant LOGOUT_FAILED. */
46  	private static final String LOGOUT_FAILED = "Logout failed";
47  
48  	/** The Constant serialVersionUID. */
49  	private static final long serialVersionUID = 1L;
50  
51  	/** The Constant LOGGER. */
52  	private static final Logger LOGGER = LoggerFactory.getLogger(LogoutClickListener.class);
53  
54  	/** The logout request. */
55  	private final LogoutRequest logoutRequest;
56  
57  	/**
58  	 * Instantiates a new logout click listener.
59  	 *
60  	 * @param logoutRequest
61  	 *            the logout request
62  	 */
63  	public LogoutClickListener(final LogoutRequest logoutRequest) {
64  		this.logoutRequest = logoutRequest;
65  	}
66  
67  	@Override
68  	public void buttonClick(final ClickEvent event) {
69  		final ServiceResponse response = ApplicationMangerAccess.getApplicationManager().service(logoutRequest);
70  
71  
72  		if (ServiceResult.SUCCESS == response.getResult()) {
73  			UI.getCurrent().getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
74  			UI.getCurrent().getSession().close();
75  			VaadinService.getCurrentRequest().getWrappedSession().invalidate();
76  		} else {
77  			Notification.show(LOGOUT_FAILED,
78  	                  ERROR_MESSAGE,
79  	                  Notification.Type.WARNING_MESSAGE);
80  			LOGGER.info(LOG_MSG_LOGOUT_FAILURE,logoutRequest.getSessionId());
81  		}
82  	}
83  }