1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.common.ServiceResponse.ServiceResult;
25 import com.hack23.cia.service.api.action.user.SearchDocumentRequest;
26 import com.hack23.cia.service.api.action.user.SearchDocumentResponse;
27 import com.vaadin.ui.Button.ClickEvent;
28 import com.vaadin.ui.Button.ClickListener;
29 import com.vaadin.ui.Notification;
30
31
32
33
34 public final class SearchDocumentClickListener implements ClickListener {
35
36
37 private static final String ERROR_MESSAGE = "Error message";
38
39
40 private static final String SEARCH_FAILED = "Search failed";
41
42
43 private static final String LOG_MSG_SEARCH_DOCUMENT_FAILURE = "SearchDocument {} failure";
44
45
46 private static final String LOG_MSG_SEARCH_DOCUMENT = "SearchDocument {}";
47
48
49 private static final String SEARCH_SUCCESS = "Search success";
50
51
52 private static final long serialVersionUID = 1L;
53
54
55 private static final Logger LOGGER = LoggerFactory.getLogger(SearchDocumentClickListener.class);
56
57
58 private final SearchDocumentRequest reqisterRequest;
59
60
61 private final SearchDocumentResponseHandler responseHandler;
62
63
64
65
66
67
68
69
70
71 public SearchDocumentClickListener(final SearchDocumentRequest reqisterRequest, final SearchDocumentResponseHandler responseHandler) {
72 this.reqisterRequest = reqisterRequest;
73 this.responseHandler = responseHandler;
74 }
75
76 @Override
77 public void buttonClick(final ClickEvent event) {
78 final SearchDocumentResponse response = (SearchDocumentResponse) ApplicationMangerAccess.getApplicationManager().service(reqisterRequest);
79 if (ServiceResult.SUCCESS == response.getResult()) {
80 LOGGER.info(LOG_MSG_SEARCH_DOCUMENT,reqisterRequest.getSearchExpression());
81 Notification.show(SEARCH_SUCCESS,
82 "Found :" + response.getResultElement().size(),
83 Notification.Type.HUMANIZED_MESSAGE);
84 responseHandler.handle(response);
85
86 } else {
87 Notification.show(SEARCH_FAILED,
88 ERROR_MESSAGE,
89 Notification.Type.WARNING_MESSAGE);
90 LOGGER.info(LOG_MSG_SEARCH_DOCUMENT_FAILURE,reqisterRequest.getSearchExpression());
91 }
92 }
93 }