ManageUserAccountClickListener.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.ManageUserAccountRequest;
  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 ManageUserAccountClickListener.
  30.  *
  31.  * @see ManageUserAccountClickEvent
  32.  */
  33. public class ManageUserAccountClickListener extends AbstractClickListener implements ClickListener {

  34.     public static final String MANAGE_USER_ACCOUNT_DESC = "manage user account desc";

  35.     /** The Constant LOG_MSG_SEND_EMAIL. */
  36.     public static final String LOG_MSG = "Operation {}";

  37.     /** The Constant LOGGER. */
  38.     private static final Logger LOGGER = LoggerFactory.getLogger(ManageUserAccountClickListener.class);

  39.     /** The Constant EMAIL_SENT. */
  40.     public static final String OPERATION_COMPLETED = "Operation completed";

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

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

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

  47.     /** The reqister request. */
  48.     private final ManageUserAccountRequest manageUserAccountRequest;

  49.     /**
  50.      * Instantiates a new manage user account click listener.
  51.      *
  52.      * @param manageUserAccountRequest
  53.      *            the manage user account request
  54.      */
  55.     public ManageUserAccountClickListener(final ManageUserAccountRequest manageUserAccountRequest) {
  56.         this.manageUserAccountRequest = manageUserAccountRequest;
  57.     }

  58.     @Override
  59.     public final void buttonClick(final ClickEvent event) {
  60.         final ServiceResponse response = getApplicationManager().service(manageUserAccountRequest);
  61.         if (ServiceResult.SUCCESS == response.getResult()) {
  62.             LOGGER.info(LOG_MSG,manageUserAccountRequest.getUserAcountId());
  63.             showNotification(OPERATION_COMPLETED, MANAGE_USER_ACCOUNT_DESC, Notification.Type.HUMANIZED_MESSAGE);
  64.         } else {
  65.             showNotification(OPERATION_FAILED,
  66.                       response.getErrorMessage(),
  67.                       Notification.Type.WARNING_MESSAGE);
  68.             LOGGER.info(OPERATION_FAILURE,manageUserAccountRequest.getUserAcountId());
  69.         }
  70.     }
  71. }