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;
20
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.web.context.request.RequestContextHolder;
25
26 import com.hack23.cia.model.internal.application.system.impl.ApplicationSessionType;
27 import com.hack23.cia.service.api.ApplicationManager;
28 import com.hack23.cia.service.api.ConfigurationManager;
29 import com.hack23.cia.service.api.UserConfiguration;
30 import com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest;
31 import com.hack23.cia.service.api.action.common.ServiceResponse;
32 import com.hack23.cia.web.impl.ui.application.util.WebBrowserUtil;
33 import com.hack23.cia.web.impl.ui.application.views.common.MainView;
34 import com.vaadin.annotations.Push;
35 import com.vaadin.annotations.StyleSheet;
36 import com.vaadin.annotations.Theme;
37 import com.vaadin.server.Page;
38 import com.vaadin.server.VaadinRequest;
39 import com.vaadin.server.VaadinSession;
40 import com.vaadin.server.WebBrowser;
41 import com.vaadin.shared.ui.ui.Transport;
42 import com.vaadin.spring.annotation.SpringUI;
43 import com.vaadin.spring.annotation.SpringViewDisplay;
44 import com.vaadin.spring.navigator.SpringNavigator;
45 import com.vaadin.ui.UI;
46
47
48
49
50
51 @SpringUI
52 @SpringViewDisplay
53 @Theme("cia")
54 @Push(transport = Transport.WEBSOCKET_XHR)
55 @StyleSheet({"https://fonts.googleapis.com/css?family=Inconsolata"})
56 public final class CitizenIntelligenceAgencyUI extends UI {
57
58
59 private static final long serialVersionUID = 1L;
60
61
62 private static final String LOG_INFO_BROWSER_ADDRESS_APPLICATION_SESSION_ID_RESULT = "Browser url: {} , lang: {} , address: {} , application:{}, sessionId:{}, result:{}";
63
64
65 private static final Logger LOGGER = LoggerFactory
66 .getLogger(CitizenIntelligenceAgencyUI.class);
67
68
69 @Autowired
70 private MainView mainView;
71
72
73 @Autowired
74 private transient ApplicationManager applicationManager;
75
76 @Autowired
77 private transient ConfigurationManager configurationManager;
78
79 @Autowired
80 private SpringNavigator springNavigator;
81
82
83
84
85 public CitizenIntelligenceAgencyUI() {
86 super();
87 }
88
89
90 @Override
91 protected void init(final VaadinRequest request) {
92 VaadinSession.getCurrent().setErrorHandler(new UiInstanceErrorHandler(this));
93 setSizeFull();
94
95 springNavigator.addView("", mainView);
96 setNavigator(springNavigator);
97
98
99 final Page currentPage = Page.getCurrent();
100 final String requestUrl = currentPage.getLocation().toString();
101 final String language = request.getLocale().getLanguage();
102 final UserConfiguration userConfiguration = configurationManager.getUserConfiguration(requestUrl, language);
103
104 currentPage.setTitle(userConfiguration.getAgency().getAgencyName() + ":" + userConfiguration.getPortal().getPortalName() + ":" + userConfiguration.getLanguage().getLanguageName());
105
106 if (getSession().getUIs().isEmpty()) {
107 final WebBrowser webBrowser = currentPage.getWebBrowser();
108
109 final CreateApplicationSessionRequest serviceRequest = new CreateApplicationSessionRequest();
110 serviceRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
111
112 final String ipInformation = WebBrowserUtil.getIpInformation(webBrowser);
113 serviceRequest.setIpInformation(ipInformation);
114 serviceRequest.setUserAgentInformation(webBrowser.getBrowserApplication());
115 serviceRequest.setLocale(webBrowser.getLocale().toString());
116 serviceRequest.setOperatingSystem(WebBrowserUtil.getOperatingSystem(webBrowser));
117 serviceRequest.setSessionType(ApplicationSessionType.ANONYMOUS);
118
119 final ServiceResponse serviceResponse = applicationManager.service(serviceRequest);
120 LOGGER.info(LOG_INFO_BROWSER_ADDRESS_APPLICATION_SESSION_ID_RESULT,requestUrl,language,ipInformation,webBrowser.getBrowserApplication(),serviceRequest.getSessionId(),serviceResponse.getResult().toString());
121 }
122 }
123
124
125 }