SearchDocumentClickListener.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.common.ServiceResponse.ServiceResult;
  23. import com.hack23.cia.service.api.action.user.SearchDocumentRequest;
  24. import com.hack23.cia.service.api.action.user.SearchDocumentResponse;
  25. import com.hack23.cia.web.impl.ui.application.views.pageclicklisteners.handlers.api.SearchDocumentResponseHandler;
  26. import com.vaadin.ui.Button.ClickEvent;
  27. import com.vaadin.ui.Button.ClickListener;
  28. import com.vaadin.ui.Notification;

  29. /**
  30.  * The Class SearchDocumentClickListener.
  31.  *
  32.  * @see SearchDocumentClickEvent
  33.  */
  34. public class SearchDocumentClickListener extends AbstractClickListener implements ClickListener {

  35.     /** The Constant ERROR_MESSAGE. */
  36.     private static final String ERROR_MESSAGE = "Error message";

  37.     /** The Constant LOG_MSG_SEARCH_DOCUMENT. */
  38.     private static final String LOG_MSG_SEARCH_DOCUMENT = "SearchDocument {}";

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

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

  43.     /** The Constant SEARCH_FAILED. */
  44.     private static final String SEARCH_FAILED = "Search failed";

  45.     /** The Constant SEARCH_SUCCESS. */
  46.     private static final String SEARCH_SUCCESS = "Search success";

  47.     /** The Constant serialVersionUID. */
  48.     private static final long serialVersionUID = 1L;

  49.     /** The reqister request. */
  50.     private final SearchDocumentRequest reqisterRequest;

  51.     /** The response handler. */
  52.     private final SearchDocumentResponseHandler responseHandler;

  53.     /**
  54.      * Instantiates a new search document click listener.
  55.      *
  56.      * @param reqisterRequest
  57.      *            the reqister request
  58.      * @param responseHandler
  59.      *            the response handler
  60.      */
  61.     public SearchDocumentClickListener(final SearchDocumentRequest reqisterRequest, final SearchDocumentResponseHandler responseHandler) {
  62.         this.reqisterRequest = reqisterRequest;
  63.         this.responseHandler = responseHandler;
  64.     }

  65.     @Override
  66.     public final void buttonClick(final ClickEvent event) {
  67.         final SearchDocumentResponse response = (SearchDocumentResponse) getApplicationManager().service(reqisterRequest);
  68.         if (ServiceResult.SUCCESS == response.getResult()) {
  69.             LOGGER.info(LOG_MSG_SEARCH_DOCUMENT,reqisterRequest.getSearchExpression());
  70.             showNotification(SEARCH_SUCCESS,
  71.                       "Found :" + response.getResultElement().size(),
  72.                       Notification.Type.HUMANIZED_MESSAGE);
  73.             responseHandler.handle(response);

  74.         } else {
  75.             showNotification(SEARCH_FAILED,
  76.                       ERROR_MESSAGE,
  77.                       Notification.Type.WARNING_MESSAGE);
  78.             LOGGER.info(LOG_MSG_SEARCH_DOCUMENT_FAILURE,reqisterRequest.getSearchExpression());
  79.         }
  80.     }
  81. }