source: EDIS/trunk/java/tracking-server-core/src/main/java/gov/va/med/edp/dao/rpc/VistaLinkServerPackageVersionDao.java@ 1257

Last change on this file since 1257 was 1257, checked in by Solomon Blaz, 13 years ago

deleted duplicate classes from gov.va.med.edp.rpc package in favor of ones in gov.va.med.edp.vistalink and configured rest of application accordingly

File size: 2.9 KB
Line 
1package gov.va.med.edp.dao.rpc;
2
3import gov.va.med.edp.vistalink.VistaLinkTemplate;
4import gov.va.med.edp.vo.BigBoardDebugInfoVO;
5import gov.va.med.edp.dao.ServerPackageVersionDao;
6
7import java.util.Map;
8import java.util.HashMap;
9import java.io.StringReader;
10import java.io.IOException;
11
12import gov.va.med.vistalink.adapter.spi.VistaLinkServerInfo;
13import org.w3c.dom.Document;
14import org.w3c.dom.Element;
15import org.xml.sax.InputSource;
16import org.xml.sax.SAXException;
17import org.springframework.dao.DataAccessException;
18import org.springframework.dao.DataRetrievalFailureException;
19
20import javax.xml.parsers.DocumentBuilder;
21import javax.xml.parsers.DocumentBuilderFactory;
22import javax.xml.parsers.ParserConfigurationException;
23
24/**
25 * TODO: document VistaLinkServerPackageVersionDao
26 */
27public 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}
Note: See TracBrowser for help on using the repository browser.