source: EDIS/tags/ed/tracking-server-core/src/main/java/gov/va/med/edp/dao/rpc/VistaLinkServerPackageVersionDao.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.rpc.VistaLinkDaoSupport;
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 org.w3c.dom.Document;
13import org.w3c.dom.Element;
14import org.xml.sax.InputSource;
15import org.xml.sax.SAXException;
16import org.springframework.dao.DataAccessException;
17import org.springframework.dao.DataRetrievalFailureException;
18
19import javax.xml.parsers.DocumentBuilder;
20import javax.xml.parsers.DocumentBuilderFactory;
21import javax.xml.parsers.ParserConfigurationException;
22
23/**
24 * TODO: document VistaLinkServerPackageVersionDao
25 */
26public 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}
Note: See TracBrowser for help on using the repository browser.