1 | package gov.va.med.edp.dao.rpc;
|
---|
2 |
|
---|
3 | import gov.va.med.edp.rpc.VistaLinkDaoSupport;
|
---|
4 | import gov.va.med.edp.vo.BigBoardDebugInfoVO;
|
---|
5 | import gov.va.med.edp.dao.ServerPackageVersionDao;
|
---|
6 |
|
---|
7 | import java.util.Map;
|
---|
8 | import java.util.HashMap;
|
---|
9 | import java.io.StringReader;
|
---|
10 | import java.io.IOException;
|
---|
11 |
|
---|
12 | import org.w3c.dom.Document;
|
---|
13 | import org.w3c.dom.Element;
|
---|
14 | import org.xml.sax.InputSource;
|
---|
15 | import org.xml.sax.SAXException;
|
---|
16 | import org.springframework.dao.DataAccessException;
|
---|
17 | import org.springframework.dao.DataRetrievalFailureException;
|
---|
18 |
|
---|
19 | import javax.xml.parsers.DocumentBuilder;
|
---|
20 | import javax.xml.parsers.DocumentBuilderFactory;
|
---|
21 | import javax.xml.parsers.ParserConfigurationException;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * TODO: document VistaLinkServerPackageVersionDao
|
---|
25 | */
|
---|
26 | public class VistaLinkServerPackageVersionDao extends VistaLinkBigBoardDao implements ServerPackageVersionDao {
|
---|
27 | private static final String UNABLE_TO_GET_VERSION_INFO = "unable to get version info";
|
---|
28 |
|
---|
29 | public String getServerPackageVersion(String stationNumber) {
|
---|
30 | Map params = new HashMap();
|
---|
31 | params.put("command", "initTracking");
|
---|
32 | String result = executeCommand(stationNumber, null, params);
|
---|
33 | return getVersion(result);
|
---|
34 | }
|
---|
35 |
|
---|
36 | public BigBoardDebugInfoVO getVistaLinkConnectionInfo(String stationNumber) throws DataAccessException {
|
---|
37 | return getRpcTemplate().getVistaLinkConnectionInfo(stationNumber, EDPTRACKING_APPLICATION_USER);
|
---|
38 | }
|
---|
39 |
|
---|
40 | private String getVersion(String result) {
|
---|
41 | Document doc = buildDocument(result);
|
---|
42 | return getVersion(doc);
|
---|
43 | }
|
---|
44 |
|
---|
45 | private Element getUserElement(Document doc) {
|
---|
46 | return (Element) doc.getDocumentElement().getElementsByTagName("user").item(0);
|
---|
47 | }
|
---|
48 |
|
---|
49 | private String getVersion(Document doc) {
|
---|
50 | Element user = getUserElement(doc);
|
---|
51 | if (user == null) return null;
|
---|
52 | return user.getAttribute("version");
|
---|
53 | }
|
---|
54 |
|
---|
55 | private Document buildDocument(String result) {
|
---|
56 | try {
|
---|
57 | DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
---|
58 | return builder.parse(new InputSource(new StringReader("<results>" + result + "</results>")));
|
---|
59 | } catch (ParserConfigurationException e) {
|
---|
60 | throw new DataRetrievalFailureException(UNABLE_TO_GET_VERSION_INFO, e);
|
---|
61 | } catch (IOException e) {
|
---|
62 | throw new DataRetrievalFailureException(UNABLE_TO_GET_VERSION_INFO, e);
|
---|
63 | } catch (SAXException e) {
|
---|
64 | throw new DataRetrievalFailureException(UNABLE_TO_GET_VERSION_INFO, e);
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | }
|
---|