source: EDIS/tags/ed/tracking-server-core/src/main/java/gov/va/med/edp/dao/rpc/VistaLinkSessionDao.java@ 1240

Last change on this file since 1240 was 1240, checked in by George Lilly, 13 years ago

new version from the VA

File size: 2.6 KB
Line 
1package gov.va.med.edp.dao.rpc;
2
3import gov.va.med.edp.dao.SessionDao;
4import gov.va.med.edp.vo.SessionVO;
5import org.springframework.dao.DataAccessException;
6import org.springframework.dao.DataRetrievalFailureException;
7import org.w3c.dom.Document;
8import org.w3c.dom.Element;
9import org.xml.sax.InputSource;
10import org.xml.sax.SAXException;
11
12import javax.xml.parsers.DocumentBuilder;
13import javax.xml.parsers.DocumentBuilderFactory;
14import javax.xml.parsers.ParserConfigurationException;
15import java.io.IOException;
16import java.io.StringReader;
17import java.util.HashMap;
18import java.util.Map;
19
20public class VistaLinkSessionDao extends VistaLinkTrackingDao implements SessionDao {
21 private static final String UNABLE_TO_GET_USER_INFO = "unable to get user info";
22
23 public SessionVO getSessionInfo(String stationNumber, String duz) throws DataAccessException {
24 Map params = new HashMap();
25 params.put("command", "initUser");
26 String result = executeCommand(stationNumber, duz, params);
27 return createSessionInfo(result);
28 }
29
30 private SessionVO createSessionInfo(String result) {
31 Document doc = buildDocument(result);
32
33 SessionVO session = new SessionVO();
34 session.setServerPackageVersion(getServerPackageVersion(doc));
35 session.setTimeOutMillis(Integer.parseInt(getTimeout(doc)));
36 session.setCountDownMillis(Integer.parseInt(getCountdown(doc)));
37 return session;
38 }
39
40 private String getServerPackageVersion(Document doc) {
41 return getUserElement(doc).getAttribute("version");
42 }
43
44 private String getTimeout(Document doc) {
45 return getUserElement(doc).getAttribute("timeOut");
46 }
47
48 private Element getUserElement(Document doc) {
49 return ((Element) doc.getDocumentElement().getElementsByTagName("user").item(0));
50 }
51
52 private String getCountdown(Document doc) {
53 return getUserElement(doc).getAttribute("countDown");
54 }
55
56 private Document buildDocument(String result) {
57 try {
58 DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
59 return builder.parse(new InputSource(new StringReader("<results>" + result + "</results>")));
60 } catch (ParserConfigurationException e) {
61 throw new DataRetrievalFailureException(UNABLE_TO_GET_USER_INFO, e);
62 } catch (IOException e) {
63 throw new DataRetrievalFailureException(UNABLE_TO_GET_USER_INFO, e);
64 } catch (SAXException e) {
65 throw new DataRetrievalFailureException(UNABLE_TO_GET_USER_INFO, e);
66 }
67 }
68
69
70}
Note: See TracBrowser for help on using the repository browser.