1 | package gov.va.med.edp.web.controller;
|
---|
2 |
|
---|
3 | import gov.va.med.edp.dao.ServerPackageVersionDao;
|
---|
4 | import gov.va.med.edp.dao.TrackingDao;
|
---|
5 | import gov.va.med.edp.springframework.security.userdetails.VistaUserDetails;
|
---|
6 | import gov.va.med.edp.vo.BigBoardDebugInfoVO;
|
---|
7 | import gov.va.med.edp.web.view.XmlView;
|
---|
8 | import org.springframework.beans.factory.InitializingBean;
|
---|
9 | import org.springframework.security.context.SecurityContextHolder;
|
---|
10 | import org.springframework.util.Assert;
|
---|
11 | import org.springframework.util.StringUtils;
|
---|
12 | import org.springframework.web.servlet.ModelAndView;
|
---|
13 | import org.springframework.web.servlet.mvc.AbstractController;
|
---|
14 | import org.springframework.web.servlet.support.WebContentGenerator;
|
---|
15 |
|
---|
16 | import javax.servlet.http.HttpServletRequest;
|
---|
17 | import javax.servlet.http.HttpServletResponse;
|
---|
18 | import java.util.Map;
|
---|
19 | import java.util.HashMap;
|
---|
20 | import java.util.Enumeration;
|
---|
21 | import java.util.Set;
|
---|
22 |
|
---|
23 | public class TrackingController extends AbstractController implements InitializingBean {
|
---|
24 |
|
---|
25 | private TrackingDao trackingDao;
|
---|
26 | private ServerPackageVersionDao serverPackageVersionDao;
|
---|
27 | protected static final String XML_VIEW = "xmlView";
|
---|
28 |
|
---|
29 | public TrackingController() {
|
---|
30 | setRequireSession(true);
|
---|
31 | setSupportedMethods(new String[]{WebContentGenerator.METHOD_POST});
|
---|
32 | }
|
---|
33 |
|
---|
34 | public void afterPropertiesSet() throws Exception {
|
---|
35 | Assert.notNull(trackingDao, "trackingDao is required");
|
---|
36 | }
|
---|
37 |
|
---|
38 | protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
---|
39 | validateSwfID(request);
|
---|
40 | VistaUserDetails userInfo = getUserInfo(request);
|
---|
41 | String result = trackingDao.executeCommand(userInfo.getLoginStationNumber(), userInfo.getDuz(), buildParameterMap(request));
|
---|
42 | if (isInitDisplayBoardCommand(request))
|
---|
43 | result = appendSiteAndVistaLinkConnectionInfo(result, request);
|
---|
44 | return createModelAndView(result);
|
---|
45 | }
|
---|
46 |
|
---|
47 | private void validateSwfID(HttpServletRequest request) throws UnrecognizedClientException {
|
---|
48 | String swfID = request.getParameter("swfID");
|
---|
49 | if (!StringUtils.hasLength(swfID)) return;
|
---|
50 |
|
---|
51 | String ids = (String) request.getSession().getAttribute(SessionConstants.RECOGNIZED_SWF_IDS_KEY);
|
---|
52 | Set idSet = StringUtils.commaDelimitedListToSet(ids);
|
---|
53 | if (idSet.isEmpty()) throw new UnrecognizedClientException(UnrecognizedClientException.UNRECOGNIZED_CLIENT_MESSAGE, swfID);
|
---|
54 | if (!idSet.contains(swfID)) throw new UnrecognizedClientException(UnrecognizedClientException.UNRECOGNIZED_CLIENT_MESSAGE, swfID);
|
---|
55 | }
|
---|
56 |
|
---|
57 | public void setTrackingDao(TrackingDao trackingDao) {
|
---|
58 | this.trackingDao = trackingDao;
|
---|
59 | }
|
---|
60 |
|
---|
61 | public void setServerPackageVersionDao(ServerPackageVersionDao serverPackageVersionDao) {
|
---|
62 | this.serverPackageVersionDao = serverPackageVersionDao;
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected VistaUserDetails getUserInfo(HttpServletRequest request) throws NoUserInfoInSessionException {
|
---|
66 | VistaUserDetails userInfo = (VistaUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
---|
67 | if (userInfo == null) throw new NoUserInfoInSessionException();
|
---|
68 | return userInfo;
|
---|
69 | }
|
---|
70 |
|
---|
71 | protected ModelAndView createModelAndView(String result) {
|
---|
72 | return new ModelAndView(XML_VIEW, XmlView.XML_FRAGMENT, result);
|
---|
73 | }
|
---|
74 |
|
---|
75 | private boolean isInitDisplayBoardCommand(HttpServletRequest request) {
|
---|
76 | if (request.getParameter("command").equals("initDisplayBoard")) return true;
|
---|
77 | return false;
|
---|
78 | }
|
---|
79 |
|
---|
80 | private String appendSiteAndVistaLinkConnectionInfo(String result,HttpServletRequest request) throws Exception{
|
---|
81 | String stnNumber = getUserInfo(request).getLoginStationNumber();
|
---|
82 | BigBoardDebugInfoVO vistalinkInfo = serverPackageVersionDao.getVistaLinkConnectionInfo(stnNumber);
|
---|
83 | vistalinkInfo.setSiteId(stnNumber);
|
---|
84 | result = result.concat(vistalinkInfo.toString());
|
---|
85 | return result;
|
---|
86 | }
|
---|
87 |
|
---|
88 | protected Map buildParameterMap(HttpServletRequest request) {
|
---|
89 | Map params = new HashMap();
|
---|
90 | Enumeration e = request.getParameterNames();
|
---|
91 | while (e.hasMoreElements()) {
|
---|
92 | String paramName = (String) e.nextElement();
|
---|
93 | params.put(paramName, request.getParameter(paramName));
|
---|
94 | }
|
---|
95 | return params;
|
---|
96 | }
|
---|
97 | }
|
---|