Skip to content

Commit 4229704

Browse files
committed
Refactor to allow alternate implementations of LoginPanel, make client command line testable
Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent 7ecf54b commit 4229704

File tree

8 files changed

+393
-238
lines changed

8 files changed

+393
-238
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.mirth.connect.client.ui;
2+
3+
/**
4+
* Public interface for the login panel so alternative implementations can be provided.
5+
*/
6+
public abstract class AbstractLoginPanel extends javax.swing.JFrame {
7+
8+
/**
9+
* Initialize and show the login UI.
10+
*/
11+
public abstract void initialize(String mirthServer, String version, String user, String pass);
12+
13+
/**
14+
* Update the status text shown on the login UI.
15+
*/
16+
public abstract void setStatus(String status);
17+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.mirth.connect.client.ui;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
5+
/**
6+
* Immutable holder for command line options used by the Mirth client.
7+
*/
8+
public class CommandLineOptions {
9+
private final String server;
10+
private final String version;
11+
private final String username;
12+
private final String password;
13+
private final String protocols;
14+
private final String cipherSuites;
15+
16+
/**
17+
* Parse command line arguments for Mirth client.
18+
*/
19+
public CommandLineOptions(String[] args) {
20+
String server = "https://localhost:8443";
21+
String version = "";
22+
String username = "";
23+
String password = "";
24+
String protocols = "";
25+
String cipherSuites = "";
26+
27+
if (args == null) {
28+
args = new String[0];
29+
}
30+
31+
if (args.length > 0) {
32+
server = args[0];
33+
}
34+
if (args.length > 1) {
35+
version = args[1];
36+
}
37+
if (args.length > 2) {
38+
if (StringUtils.equalsIgnoreCase(args[2], "-ssl")) {
39+
// <server> <version> -ssl [<protocols> [<ciphersuites> [<username> [<password>]]]]
40+
if (args.length > 3) {
41+
protocols = args[3];
42+
}
43+
if (args.length > 4) {
44+
cipherSuites = args[4];
45+
}
46+
if (args.length > 5) {
47+
username = args[5];
48+
}
49+
if (args.length > 6) {
50+
password = args[6];
51+
}
52+
} else {
53+
// <server> <version> <username> [<password> [-ssl [<protocols> [<ciphersuites>]]]]
54+
username = args[2];
55+
if (args.length > 3) {
56+
password = args[3];
57+
}
58+
if (args.length > 4 && StringUtils.equalsIgnoreCase(args[4], "-ssl")) {
59+
if (args.length > 5) {
60+
protocols = args[5];
61+
}
62+
if (args.length > 6) {
63+
cipherSuites = args[6];
64+
}
65+
}
66+
}
67+
}
68+
69+
this.server = server;
70+
this.version = version;
71+
this.username = username;
72+
this.password = password;
73+
this.protocols = protocols;
74+
this.cipherSuites = cipherSuites;
75+
}
76+
77+
public String getServer() {
78+
return server;
79+
}
80+
81+
public String getVersion() {
82+
return version;
83+
}
84+
85+
public String getUsername() {
86+
return username;
87+
}
88+
89+
public String getPassword() {
90+
return password;
91+
}
92+
93+
public String getProtocols() {
94+
return protocols;
95+
}
96+
97+
public String getCipherSuites() {
98+
return cipherSuites;
99+
}
100+
}

client/src/com/mirth/connect/client/ui/Frame.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ public void eventDispatched(AWTEvent e)
543543
*/
544544
public void setupFrame(Client mirthClient) throws ClientException {
545545

546-
LoginPanel login = LoginPanel.getInstance();
546+
AbstractLoginPanel login = LoginPanelFactory.getInstance();
547547

548548
// Initialize the send message dialog
549549
editMessageDialog = new EditMessageDialog();
@@ -1524,7 +1524,7 @@ public void alertThrowable(Component parentComponent, Throwable t, String custom
15241524
}
15251525
mirthClient.close();
15261526
this.dispose();
1527-
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
1527+
LoginPanelFactory.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
15281528
return;
15291529
} else if (t.getCause() != null && t.getCause() instanceof HttpHostConnectException && (StringUtils.contains(t.getCause().getMessage(), "Connection refused") || StringUtils.contains(t.getCause().getMessage(), "Host is down"))) {
15301530
connectionError = true;
@@ -1542,7 +1542,7 @@ public void alertThrowable(Component parentComponent, Throwable t, String custom
15421542
}
15431543
mirthClient.close();
15441544
this.dispose();
1545-
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
1545+
LoginPanelFactory.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
15461546
return;
15471547
}
15481548
}
@@ -2292,7 +2292,7 @@ public boolean logout(boolean quit, boolean confirmFirst) {
22922292
this.dispose();
22932293

22942294
if (!quit) {
2295-
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
2295+
LoginPanelFactory.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
22962296
}
22972297

22982298
return true;

0 commit comments

Comments
 (0)