SendEmailClickListener.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.admin.SendEmailRequest;
  23. import com.hack23.cia.service.api.action.common.ServiceResponse;
  24. import com.hack23.cia.service.api.action.common.ServiceResponse.ServiceResult;
  25. import com.vaadin.ui.Button.ClickEvent;
  26. import com.vaadin.ui.Button.ClickListener;
  27. import com.vaadin.ui.Notification;

  28. /**
  29.  * The Class SendEmailClickListener.
  30.  *
  31.  * @see SendEmailClickEvent
  32.  */
  33. public class SendEmailClickListener extends AbstractClickListener implements ClickListener {

  34.     public static final String EMAIL_DESC = "email desc";

  35.     /** The Constant EMAIL_SENT. */
  36.     public static final String EMAIL_SENT = "Email Sent";

  37.     /** The Constant LOG_MSG_SEND_EMAIL. */
  38.     public static final String LOG_MSG_SEND_EMAIL = "SendEmail {}";

  39.     /** The Constant LOGGER. */
  40.     private static final Logger LOGGER = LoggerFactory.getLogger(SendEmailClickListener.class);

  41.     /** The Constant SEND_EMAIL_FAILEDFAILED. */
  42.     public static final String SEND_EMAIL_FAILEDFAILED = "Send email failed";

  43.     /** The Constant SEND_EMAIL_FAILURE. */
  44.     public static final String SEND_EMAIL_FAILURE = "SendEmail {} failure";

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

  47.     /** The reqister request. */
  48.     private final SendEmailRequest sendEmailRequest;

  49.     /**
  50.      * Instantiates a new register user click listener.
  51.      *
  52.      * @param sendEmailRequest
  53.      *            the reqister request
  54.      */
  55.     public SendEmailClickListener(final SendEmailRequest sendEmailRequest) {
  56.         this.sendEmailRequest = sendEmailRequest;
  57.     }

  58.     @Override
  59.     public final void buttonClick(final ClickEvent event) {
  60.         final ServiceResponse response = getApplicationManager().service(sendEmailRequest);
  61.         if (ServiceResult.SUCCESS == response.getResult()) {
  62.             LOGGER.info(LOG_MSG_SEND_EMAIL,sendEmailRequest.getEmail());
  63.             showNotification(EMAIL_SENT, EMAIL_DESC, Notification.Type.HUMANIZED_MESSAGE);
  64.         } else {
  65.             showNotification(SEND_EMAIL_FAILEDFAILED,
  66.                       response.getErrorMessage(),
  67.                       Notification.Type.WARNING_MESSAGE);
  68.             LOGGER.info(SEND_EMAIL_FAILURE,sendEmailRequest.getEmail());
  69.         }
  70.     }
  71. }