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.admin.SendEmailRequest;
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.UserViews;
28  import com.vaadin.ui.Button.ClickEvent;
29  import com.vaadin.ui.Button.ClickListener;
30  import com.vaadin.ui.Notification;
31  import com.vaadin.ui.UI;
32  
33  /**
34   * The Class SendEmailClickListener.
35   */
36  public final class SendEmailClickListener implements ClickListener {
37  
38  	/** The Constant SEND_EMAIL_FAILURE. */
39  	private static final String SEND_EMAIL_FAILURE = "SendEmail {} failure";
40  
41  	/** The Constant ERROR_MESSAGE. */
42  	private static final String ERROR_MESSAGE = "Error message";
43  
44  	/** The Constant SEND_EMAIL_FAILEDFAILED. */
45  	private static final String SEND_EMAIL_FAILEDFAILED = "Send email failed";
46  
47  	/** The Constant LOG_MSG_SEND_EMAIL. */
48  	private static final String LOG_MSG_SEND_EMAIL = "SendEmail {}";
49  
50  	/** The Constant serialVersionUID. */
51  	private static final long serialVersionUID = 1L;
52  
53  	/** The Constant LOGGER. */
54  	private static final Logger LOGGER = LoggerFactory.getLogger(SendEmailClickListener.class);
55  
56  	/** The reqister request. */
57  	private final SendEmailRequest sendEmailRequest;
58  
59  	/**
60  	 * Instantiates a new register user click listener.
61  	 *
62  	 * @param sendEmailRequest
63  	 *            the reqister request
64  	 */
65  	public SendEmailClickListener(final SendEmailRequest sendEmailRequest) {
66  		this.sendEmailRequest = sendEmailRequest;
67  	}
68  
69  	@Override
70  	public void buttonClick(final ClickEvent event) {
71  		final ServiceResponse response = ApplicationMangerAccess.getApplicationManager().service(sendEmailRequest);
72  		if (ServiceResult.SUCCESS == response.getResult()) {
73  			LOGGER.info(LOG_MSG_SEND_EMAIL,sendEmailRequest.getEmail());
74  			UI.getCurrent().getNavigator().navigateTo(UserViews.USERHOME_VIEW_NAME);
75  		} else {
76  			Notification.show(SEND_EMAIL_FAILEDFAILED,
77  	                  ERROR_MESSAGE,
78  	                  Notification.Type.WARNING_MESSAGE);
79  			LOGGER.info(SEND_EMAIL_FAILURE,sendEmailRequest.getEmail());
80  		}
81  	}
82  }