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