[1227] | 1 | package gov.va.med.edp.web.controller;
|
---|
| 2 |
|
---|
| 3 | import gov.va.med.edp.vo.BigBoardDebugInfoVO;
|
---|
| 4 | import gov.va.med.edp.web.view.XmlView;
|
---|
| 5 |
|
---|
| 6 | import javax.servlet.http.HttpServletRequest;
|
---|
| 7 | import javax.servlet.http.HttpServletResponse;
|
---|
| 8 |
|
---|
| 9 | import org.apache.log4j.Logger;
|
---|
| 10 | import org.springframework.beans.factory.InitializingBean;
|
---|
| 11 | import org.springframework.util.Assert;
|
---|
| 12 | import org.springframework.util.StringUtils;
|
---|
| 13 | import org.springframework.web.servlet.ModelAndView;
|
---|
| 14 | import org.springframework.web.servlet.support.WebContentGenerator;
|
---|
| 15 |
|
---|
| 16 | public class BigDisplayBoardController extends SiteCodeController implements InitializingBean {
|
---|
| 17 |
|
---|
| 18 | private static final String MACHINE_NAME_PARAM = SiteCodeController.MACHINE_NAME_PARAM;
|
---|
| 19 | public static final String MACHINE_NAME_HEADER = SiteCodeController.MACHINE_NAME_HEADER;
|
---|
| 20 |
|
---|
| 21 | protected static final String XML_VIEW = "xmlView";
|
---|
| 22 |
|
---|
| 23 | private static Logger log = Logger.getLogger(BigDisplayBoardController.class);
|
---|
| 24 |
|
---|
| 25 | public BigDisplayBoardController() {
|
---|
| 26 | setRequireSession(false);
|
---|
| 27 | setSupportedMethods(new String[]{WebContentGenerator.METHOD_POST, WebContentGenerator.METHOD_GET});
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | public void afterPropertiesSet() throws Exception {
|
---|
| 31 | Assert.notNull(getSiteCodeDao(), "siteCodeDao is required");
|
---|
| 32 | Assert.notNull(getTrackingDao(), "trackingDao is required");
|
---|
| 33 | Assert.notNull(getServerPackageVersionDao(), "ServerPackageVersionDao is required");
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
---|
| 37 | String result = "";
|
---|
| 38 | //First attempt is to get the machineName from HTTP Header:EdisClientMachineName as decided
|
---|
| 39 | // this HTTP header is appended by the load balancer and the value of this header (the machine name)
|
---|
| 40 | //is parsed by the load balancer.
|
---|
| 41 | String machineName = parseCNFromHttpHeaders(request.getHeader(MACHINE_NAME_HEADER));
|
---|
| 42 |
|
---|
| 43 | if (StringUtils.hasText(machineName)){
|
---|
| 44 | clearRequestAndSession(request);
|
---|
| 45 | } else {
|
---|
| 46 | machineName = getMachineNameFromUserPrincipalOrSessionOrRequest(request);
|
---|
| 47 | }
|
---|
| 48 | debug("Machine name obtained from certificate/HTTP Header/request/session:" + machineName);
|
---|
| 49 | String siteCode = getSiteCodeDao().getSiteCode(machineName);
|
---|
| 50 |
|
---|
| 51 | if (!StringUtils.hasText(siteCode)){
|
---|
| 52 | String errorMsg = "No site code was found for the machine name: " + machineName;
|
---|
| 53 | return createErrorModelAndView(errorMsg);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | result = getTrackingDao().executeCommand(siteCode, "0", buildParameterMap(request,machineName));
|
---|
| 57 | if (isInitCommand(request))
|
---|
| 58 | result = appendSiteAndVistaLinkConnectionInfo(result, request, siteCode, machineName);
|
---|
| 59 | return createModelAndView(result, siteCode, machineName);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | private void clearRequestAndSession(HttpServletRequest request) {
|
---|
| 64 | request.getSession().setAttribute(MACHINE_NAME_PARAM, null);
|
---|
| 65 | request.setAttribute(MACHINE_NAME_PARAM, null);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | private boolean isInitCommand(HttpServletRequest request) {
|
---|
| 69 | if (request.getParameter("command").equals("initDisplayBoard")) return true;
|
---|
| 70 | return false;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | protected ModelAndView createModelAndView(String result, String siteCode, String machineName) {
|
---|
| 74 | return new ModelAndView(XML_VIEW, XmlView.XML_FRAGMENT, result);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | private String appendSiteAndVistaLinkConnectionInfo(String result,HttpServletRequest request, String siteCode, String machineName) {
|
---|
| 78 | BigBoardDebugInfoVO vistalinkInfo = serverPackageVersionDao.getVistaLinkConnectionInfo(siteCode);
|
---|
| 79 | vistalinkInfo.setSiteId(siteCode);
|
---|
| 80 | vistalinkInfo.setMachineName(machineName);
|
---|
| 81 | result = result.concat(vistalinkInfo.toString());
|
---|
| 82 | return result;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | private void debug(String s) {
|
---|
| 86 | if (log.isDebugEnabled()){
|
---|
| 87 | log.debug(s);
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | }
|
---|