Changeset 1262 for EDIS/trunk


Ignore:
Timestamp:
Oct 16, 2011, 4:47:09 PM (13 years ago)
Author:
Solomon Blaz
Message:

fleshed out VistALink Tester program

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EDIS/trunk/java/vistalink-tester/src/main/java/gov/va/med/edp/VistaLinkTester.java

    r1260 r1262  
    44import gov.va.med.edp.vistalink.locator.VistaLinkConnectorConfig;
    55import gov.va.med.edp.vistalink.locator.VistaLinkConnectorConfigConnectionFactoryLocator;
     6import gov.va.med.vistalink.adapter.cci.VistaLinkResourceException;
    67import joptsimple.OptionException;
    78import joptsimple.OptionParser;
    89import joptsimple.OptionSet;
    910import joptsimple.OptionSpec;
     11import org.springframework.dao.DataAccessResourceFailureException;
    1012
    1113import java.io.Console;
    1214import java.io.IOException;
    1315import java.util.ArrayList;
     16import java.util.Arrays;
    1417import java.util.HashSet;
    1518import java.util.List;
     
    2023    public static void main(String[] args) throws IOException {
    2124        OptionParser parser = new OptionParser();
    22         OptionSpec<String> hostOption = parser.acceptsAll(asList("S", "server", "host")).withRequiredArg().ofType(String.class);
    23         OptionSpec<Integer> portOption = parser.acceptsAll(asList("P", "port")).withRequiredArg().ofType(Integer.class);
    24         OptionSpec<String> divisionOption = parser.acceptsAll(asList("D", "division", "station-num")).withRequiredArg().ofType(String.class);
    25         OptionSpec<String> rpcContextOption = parser.acceptsAll(asList("C", "context", "rpc-context")).withRequiredArg().ofType(String.class);
    26         OptionSpec<String> rpcNameOption = parser.acceptsAll(asList("N", "name", "rpc-name")).withRequiredArg().ofType(String.class);
     25        parser.acceptsAll(asList("?", "help"), "Print usage information");
     26        OptionSpec<String> hostOption = parser.acceptsAll(asList("S", "server", "host"), "Hostname or IP where VistALink is listening").withRequiredArg().ofType(String.class);
     27        OptionSpec<Integer> portOption = parser.acceptsAll(asList("P", "port"), "Port where VistALink is listening").withRequiredArg().ofType(Integer.class);
     28        OptionSpec<String> divisionOption = parser.acceptsAll(asList("D", "division", "station-num"), "Station Number").withRequiredArg().ofType(String.class);
     29        OptionSpec<String> duzOption = parser.acceptsAll(asList("U", "DUZ")).withRequiredArg().ofType(String.class);
     30        OptionSpec<String> rpcContextOption = parser.acceptsAll(asList("C", "context", "rpc-context"), "RPC Context").withRequiredArg().ofType(String.class);
     31        OptionSpec<String> rpcNameOption = parser.acceptsAll(asList("N", "name", "rpc-name"), "RPC Name").withRequiredArg().ofType(String.class);
    2732
    2833        try {
    2934            OptionSet options = parser.parse(args);
     35
     36            if (options.has("?") || options.has("help")) {
     37                System.out.println("Usage:");
     38                parser.printHelpOn(System.out);
     39                System.exit(0);
     40            }
    3041
    3142            Console console = System.console();
     
    3344            String host = options.has(hostOption) ? hostOption.value(options) : console.readLine("Host: ");
    3445            int port = options.has(portOption) ? portOption.value(options) : Integer.parseInt(console.readLine("Port: "));
    35             String division = options.has(divisionOption) ? divisionOption.value(options) : console.readLine("Division: ");
     46            String division = options.has(divisionOption) ? divisionOption.value(options) : console.readLine("Station Number: ");
    3647
    37             char[] accessCode = console.readPassword("Access: ");
    38             char[] verifyCode = console.readPassword("Verify: ");
     48            char[] accessCodeChars = console.readPassword("Access: ");
     49            char[] verifyCodeChars = console.readPassword("Verify: ");
    3950
     51            String accessCode = new String(accessCodeChars);
     52            String verifyCode = new String(verifyCodeChars);
     53
     54            String duz = options.has(duzOption) ? duzOption.value(options) : console.readLine("DUZ: ");
    4055            String rpcContext = options.has(rpcContextOption) ? rpcContextOption.value(options) : console.readLine("RPC Context: ");
    4156            String rpcName = options.has(rpcNameOption) ? rpcNameOption.value(options) : console.readLine("RPC Name: ");
    42             ;
    4357
    4458            if (rpcContext == null) rpcContext = "";
    4559
    46             VistaLinkTester tester = new VistaLinkTester(host, port, division, accessCode.toString(), verifyCode.toString());
     60            VistaLinkTester tester = new VistaLinkTester(host, port, division, accessCode, verifyCode);
    4761
    4862            System.out.println("Enter RPC Parameters (^ when finished)");
     
    6175            }
    6276
    63             System.out.println("Executing vlink://" + division + "@" + host + ":" + port + "/" + rpcContext + "/" + rpcName);
     77            System.out.println("Executing vlink://" + division + "@" + host + ":" + port + "/" + rpcContext + "/" + rpcName + formatRpcParams(params));
    6478
    65             System.out.println(tester.execute(rpcContext, rpcName, params));
     79            System.out.println(tester.execute(duz, rpcContext, rpcName, params));
    6680        } catch (OptionException e) {
    6781            System.out.println(e.getLocalizedMessage());
     
    6983            parser.printHelpOn(System.out);
    7084            System.exit(1);
     85        } catch (gov.va.med.edp.vistalink.VistaLinkDataRetrievalFailureException e) {
     86            System.out.println(e.getMessage());
    7187        } catch (Throwable t) {
    7288            t.printStackTrace();
    7389        }
    74 //        HashSet connectors = new HashSet();
    75 //        connectors.add(new VistaLinkConnectorConfig("500", "WORLDVISTA DEMO CLINIC", "66.206.177.84", 9310, "EDISUSER1", "VISTAIS#1"));
     90    }
     91
     92    private static String formatRpcParams(List params) {
     93        StringBuilder b = new StringBuilder();
     94        if (!params.isEmpty()) b.append("?");
     95        for (int i = 0; i < params.size(); i++) {
     96            b.append("[");
     97            b.append(i + 1);
     98            b.append("]=");
     99            b.append(params.get(i).toString());
     100            if (i < params.size() - 1) {
     101                b.append("&");
     102            }
     103        }
     104        return b.toString();
    76105    }
    77106
     
    92121    }
    93122
    94     public String execute(String rpcContext, String rpcName, List params) {
     123    public String execute(String duz, String rpcContext, String rpcName, List params) {
    95124        if (params.size() > 0)
    96             return t.rpcAsApplication(this.division, "VISTALINK TESTER", rpcContext, rpcName, params);
     125            return t.rpcAsUser(this.division, duz, rpcContext, rpcName, params);
    97126        else
    98             return t.rpcAsApplication(this.division, "VISTALINK TESTER", rpcContext, rpcName);
     127            return t.rpcAsUser(this.division, duz, rpcContext, rpcName);
    99128    }
    100129}
Note: See TracChangeset for help on using the changeset viewer.