fleshed out VistALink Tester program
This commit is contained in:
parent
3c75ac927e
commit
c105f56b8b
|
@ -3,14 +3,17 @@ package gov.va.med.edp;
|
||||||
import gov.va.med.edp.vistalink.VistaLinkTemplate;
|
import gov.va.med.edp.vistalink.VistaLinkTemplate;
|
||||||
import gov.va.med.edp.vistalink.locator.VistaLinkConnectorConfig;
|
import gov.va.med.edp.vistalink.locator.VistaLinkConnectorConfig;
|
||||||
import gov.va.med.edp.vistalink.locator.VistaLinkConnectorConfigConnectionFactoryLocator;
|
import gov.va.med.edp.vistalink.locator.VistaLinkConnectorConfigConnectionFactoryLocator;
|
||||||
|
import gov.va.med.vistalink.adapter.cci.VistaLinkResourceException;
|
||||||
import joptsimple.OptionException;
|
import joptsimple.OptionException;
|
||||||
import joptsimple.OptionParser;
|
import joptsimple.OptionParser;
|
||||||
import joptsimple.OptionSet;
|
import joptsimple.OptionSet;
|
||||||
import joptsimple.OptionSpec;
|
import joptsimple.OptionSpec;
|
||||||
|
import org.springframework.dao.DataAccessResourceFailureException;
|
||||||
|
|
||||||
import java.io.Console;
|
import java.io.Console;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -19,31 +22,42 @@ import static java.util.Arrays.asList;
|
||||||
public class VistaLinkTester {
|
public class VistaLinkTester {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
OptionParser parser = new OptionParser();
|
OptionParser parser = new OptionParser();
|
||||||
OptionSpec<String> hostOption = parser.acceptsAll(asList("S", "server", "host")).withRequiredArg().ofType(String.class);
|
parser.acceptsAll(asList("?", "help"), "Print usage information");
|
||||||
OptionSpec<Integer> portOption = parser.acceptsAll(asList("P", "port")).withRequiredArg().ofType(Integer.class);
|
OptionSpec<String> hostOption = parser.acceptsAll(asList("S", "server", "host"), "Hostname or IP where VistALink is listening").withRequiredArg().ofType(String.class);
|
||||||
OptionSpec<String> divisionOption = parser.acceptsAll(asList("D", "division", "station-num")).withRequiredArg().ofType(String.class);
|
OptionSpec<Integer> portOption = parser.acceptsAll(asList("P", "port"), "Port where VistALink is listening").withRequiredArg().ofType(Integer.class);
|
||||||
OptionSpec<String> rpcContextOption = parser.acceptsAll(asList("C", "context", "rpc-context")).withRequiredArg().ofType(String.class);
|
OptionSpec<String> divisionOption = parser.acceptsAll(asList("D", "division", "station-num"), "Station Number").withRequiredArg().ofType(String.class);
|
||||||
OptionSpec<String> rpcNameOption = parser.acceptsAll(asList("N", "name", "rpc-name")).withRequiredArg().ofType(String.class);
|
OptionSpec<String> duzOption = parser.acceptsAll(asList("U", "DUZ")).withRequiredArg().ofType(String.class);
|
||||||
|
OptionSpec<String> rpcContextOption = parser.acceptsAll(asList("C", "context", "rpc-context"), "RPC Context").withRequiredArg().ofType(String.class);
|
||||||
|
OptionSpec<String> rpcNameOption = parser.acceptsAll(asList("N", "name", "rpc-name"), "RPC Name").withRequiredArg().ofType(String.class);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OptionSet options = parser.parse(args);
|
OptionSet options = parser.parse(args);
|
||||||
|
|
||||||
|
if (options.has("?") || options.has("help")) {
|
||||||
|
System.out.println("Usage:");
|
||||||
|
parser.printHelpOn(System.out);
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
Console console = System.console();
|
Console console = System.console();
|
||||||
|
|
||||||
String host = options.has(hostOption) ? hostOption.value(options) : console.readLine("Host: ");
|
String host = options.has(hostOption) ? hostOption.value(options) : console.readLine("Host: ");
|
||||||
int port = options.has(portOption) ? portOption.value(options) : Integer.parseInt(console.readLine("Port: "));
|
int port = options.has(portOption) ? portOption.value(options) : Integer.parseInt(console.readLine("Port: "));
|
||||||
String division = options.has(divisionOption) ? divisionOption.value(options) : console.readLine("Division: ");
|
String division = options.has(divisionOption) ? divisionOption.value(options) : console.readLine("Station Number: ");
|
||||||
|
|
||||||
char[] accessCode = console.readPassword("Access: ");
|
char[] accessCodeChars = console.readPassword("Access: ");
|
||||||
char[] verifyCode = console.readPassword("Verify: ");
|
char[] verifyCodeChars = console.readPassword("Verify: ");
|
||||||
|
|
||||||
|
String accessCode = new String(accessCodeChars);
|
||||||
|
String verifyCode = new String(verifyCodeChars);
|
||||||
|
|
||||||
|
String duz = options.has(duzOption) ? duzOption.value(options) : console.readLine("DUZ: ");
|
||||||
String rpcContext = options.has(rpcContextOption) ? rpcContextOption.value(options) : console.readLine("RPC Context: ");
|
String rpcContext = options.has(rpcContextOption) ? rpcContextOption.value(options) : console.readLine("RPC Context: ");
|
||||||
String rpcName = options.has(rpcNameOption) ? rpcNameOption.value(options) : console.readLine("RPC Name: ");
|
String rpcName = options.has(rpcNameOption) ? rpcNameOption.value(options) : console.readLine("RPC Name: ");
|
||||||
;
|
|
||||||
|
|
||||||
if (rpcContext == null) rpcContext = "";
|
if (rpcContext == null) rpcContext = "";
|
||||||
|
|
||||||
VistaLinkTester tester = new VistaLinkTester(host, port, division, accessCode.toString(), verifyCode.toString());
|
VistaLinkTester tester = new VistaLinkTester(host, port, division, accessCode, verifyCode);
|
||||||
|
|
||||||
System.out.println("Enter RPC Parameters (^ when finished)");
|
System.out.println("Enter RPC Parameters (^ when finished)");
|
||||||
|
|
||||||
|
@ -60,19 +74,34 @@ public class VistaLinkTester {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Executing vlink://" + division + "@" + host + ":" + port + "/" + rpcContext + "/" + rpcName);
|
System.out.println("Executing vlink://" + division + "@" + host + ":" + port + "/" + rpcContext + "/" + rpcName + formatRpcParams(params));
|
||||||
|
|
||||||
System.out.println(tester.execute(rpcContext, rpcName, params));
|
System.out.println(tester.execute(duz, rpcContext, rpcName, params));
|
||||||
} catch (OptionException e) {
|
} catch (OptionException e) {
|
||||||
System.out.println(e.getLocalizedMessage());
|
System.out.println(e.getLocalizedMessage());
|
||||||
System.out.println("Usage:");
|
System.out.println("Usage:");
|
||||||
parser.printHelpOn(System.out);
|
parser.printHelpOn(System.out);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
} catch (gov.va.med.edp.vistalink.VistaLinkDataRetrievalFailureException e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
// HashSet connectors = new HashSet();
|
}
|
||||||
// connectors.add(new VistaLinkConnectorConfig("500", "WORLDVISTA DEMO CLINIC", "66.206.177.84", 9310, "EDISUSER1", "VISTAIS#1"));
|
|
||||||
|
private static String formatRpcParams(List params) {
|
||||||
|
StringBuilder b = new StringBuilder();
|
||||||
|
if (!params.isEmpty()) b.append("?");
|
||||||
|
for (int i = 0; i < params.size(); i++) {
|
||||||
|
b.append("[");
|
||||||
|
b.append(i + 1);
|
||||||
|
b.append("]=");
|
||||||
|
b.append(params.get(i).toString());
|
||||||
|
if (i < params.size() - 1) {
|
||||||
|
b.append("&");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return b.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String division;
|
private String division;
|
||||||
|
@ -91,10 +120,10 @@ public class VistaLinkTester {
|
||||||
t = new VistaLinkTemplate(l);
|
t = new VistaLinkTemplate(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String execute(String rpcContext, String rpcName, List params) {
|
public String execute(String duz, String rpcContext, String rpcName, List params) {
|
||||||
if (params.size() > 0)
|
if (params.size() > 0)
|
||||||
return t.rpcAsApplication(this.division, "VISTALINK TESTER", rpcContext, rpcName, params);
|
return t.rpcAsUser(this.division, duz, rpcContext, rpcName, params);
|
||||||
else
|
else
|
||||||
return t.rpcAsApplication(this.division, "VISTALINK TESTER", rpcContext, rpcName);
|
return t.rpcAsUser(this.division, duz, rpcContext, rpcName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue