1 | package gov.va.med.edp.web.controller;
|
---|
2 |
|
---|
3 |
|
---|
4 | import javax.servlet.http.HttpServletRequest;
|
---|
5 | import javax.servlet.http.HttpServletResponse;
|
---|
6 | import javax.servlet.http.HttpSession;
|
---|
7 |
|
---|
8 | import org.apache.log4j.Logger;
|
---|
9 | import org.springframework.util.Assert;
|
---|
10 | import org.springframework.util.StringUtils;
|
---|
11 | import org.springframework.web.servlet.ModelAndView;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * TODO: document BigBoardClientVersionSynchronizationController
|
---|
15 | */
|
---|
16 | public class BigBoardClientVersionSynchronizationController extends ClientVersionSynchronizationController {
|
---|
17 |
|
---|
18 |
|
---|
19 | private String errorMsg;
|
---|
20 |
|
---|
21 | private static Logger logger = Logger.getLogger(BigBoardClientVersionSynchronizationController.class);
|
---|
22 |
|
---|
23 |
|
---|
24 | public void afterPropertiesSet() throws Exception {
|
---|
25 | setRequireSession(false);
|
---|
26 | super.afterPropertiesSet();
|
---|
27 | Assert.notNull(serverPackageVersionDao, "serverPackageVersionDao must not be null");
|
---|
28 | Assert.notNull(getSiteCodeDao(), "siteCodeDao is required");
|
---|
29 | Assert.notNull(getTrackingDao(), "trackingDao is required");
|
---|
30 |
|
---|
31 | }
|
---|
32 |
|
---|
33 | protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
---|
34 | //First attempt is to get the machineName from HTTP Header:EdisClientMachineName as decided
|
---|
35 | // this HTTP header is appended by the load balancer and the value of this header (the machine name)
|
---|
36 | //is parsed by the load balancer.
|
---|
37 | String machineName = parseCNFromHttpHeaders(request.getHeader(MACHINE_NAME_HEADER));
|
---|
38 |
|
---|
39 | if (StringUtils.hasText(machineName)){
|
---|
40 | debug("Machine name obtained from HTTP Header:" + MACHINE_NAME_HEADER + " was: " + machineName);
|
---|
41 | } else {
|
---|
42 | debug("No Machine name was found in HTTP Header:" + MACHINE_NAME_HEADER );
|
---|
43 | machineName = getMachineNameFromUserPrincipalOrSessionOrRequest(request);
|
---|
44 | }
|
---|
45 | //set the machine name in an existing session for refreshes/restored sessions
|
---|
46 | HttpSession session = request.getSession(false);
|
---|
47 | if (session != null){
|
---|
48 | session.setAttribute(MACHINE_NAME_PARAM, machineName);
|
---|
49 | } else {
|
---|
50 | return createErrorModelAndView("Invalid Session was detected. Please try re-launching the EDIS Big Board");
|
---|
51 | }
|
---|
52 |
|
---|
53 | String siteCode = getSiteCodeDao().getSiteCode(machineName);
|
---|
54 | debug("Site Code Obtained for Machine: " + machineName + " was: " + siteCode);
|
---|
55 |
|
---|
56 | if (!StringUtils.hasText(siteCode)){
|
---|
57 | errorMsg = "A matching site code for the machine: " + machineName + " was not found in the EDP.SiteMapper table.\n" +
|
---|
58 | "Please contact the EDIS national help desk with this message for remedy.";
|
---|
59 | return createErrorModelAndView(errorMsg);
|
---|
60 | }
|
---|
61 |
|
---|
62 | String serverPackageVersion = (String) request.getSession().getAttribute(SessionConstants.SERVER_PACKAGE_VERSION_KEY);
|
---|
63 | if (serverPackageVersion == null) {
|
---|
64 | serverPackageVersion = serverPackageVersionDao.getServerPackageVersion(siteCode);
|
---|
65 | request.getSession().setAttribute(SessionConstants.SERVER_PACKAGE_VERSION_KEY, serverPackageVersion);
|
---|
66 | }
|
---|
67 | debug("serverPackageVersion is: " + serverPackageVersion);
|
---|
68 |
|
---|
69 | if (isBoardNameAvailableForMachine(siteCode, machineName, request)) return super.handleRequestInternal(request, response);
|
---|
70 |
|
---|
71 | return createErrorModelAndView(errorMsg);
|
---|
72 | }
|
---|
73 |
|
---|
74 | private boolean isBoardNameAvailableForMachine(String siteCode, String machineName, HttpServletRequest request) {
|
---|
75 | String result = getTrackingDao().executeCommand(siteCode, "0", buildParameterMap(request,machineName));
|
---|
76 | if (result.startsWith("<error>")){
|
---|
77 | int start = result.indexOf("<error>");
|
---|
78 | int end = result.indexOf("</error>");
|
---|
79 | errorMsg = result.substring(start + 7, end);
|
---|
80 | debug("isBoardNameAvailableForMachine: false");
|
---|
81 | return false;
|
---|
82 | }
|
---|
83 | debug("isBoardNameAvailableForMachine: true");
|
---|
84 | return true;
|
---|
85 | }
|
---|
86 |
|
---|
87 | private void debug(String s) {
|
---|
88 | if (logger.isDebugEnabled()){
|
---|
89 | logger.debug(s);
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | }
|
---|