Skip to content

Commit 50d2d07

Browse files
committed
Add 'serverOS' field in JschServerConnectionInfo model
1 parent 513470a commit 50d2d07

File tree

6 files changed

+57
-28
lines changed

6 files changed

+57
-28
lines changed

src/main/java/root/core/domain/JschConnectionInfo.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package root.core.domain;
22

33
import lombok.Data;
4+
import root.core.domain.enums.ServerOS;
45

56
@Data
67
public class JschConnectionInfo {
78
private String serverName;
9+
private ServerOS serverOS;
810
private String host;
911
private int port;
1012
private String userName;
@@ -15,29 +17,37 @@ public JschConnectionInfo() {
1517
this.alc = new AlertLogCommand();
1618
}
1719

18-
public JschConnectionInfo(String serverName, String host, int port, String userName, String password) {
20+
public JschConnectionInfo(String serverName, ServerOS serverOS, String host, int port, String userName,
21+
String password) {
1922
this.serverName = serverName;
23+
this.serverOS = serverOS;
2024
this.host = host;
2125
this.port = port;
2226
this.userName = userName;
2327
this.password = password;
2428
this.alc = new AlertLogCommand();
2529
}
2630

27-
public JschConnectionInfo(String serverName, String host, String port, String userName, String password) {
28-
this(serverName, host, 22, userName, password);
31+
public JschConnectionInfo(String serverName, ServerOS serverOS, String host, String port, String userName,
32+
String password) {
33+
this(serverName, serverOS, host, 22, userName, password);
2934
this.setPort(port);
3035
}
3136

32-
public JschConnectionInfo(String serverName, String host, int port, String userName, String password,
33-
AlertLogCommand alc) {
34-
this(serverName, host, port, userName, password);
37+
public JschConnectionInfo(String serverName, ServerOS serverOS, String host, int port, String userName,
38+
String password, AlertLogCommand alc) {
39+
this(serverName, serverOS, host, port, userName, password);
3540
this.alc = alc;
3641
}
3742

38-
public JschConnectionInfo(String serverName, String host, String port, String userName, String password,
39-
AlertLogCommand alc) {
40-
this(serverName, host, 22, userName, password, alc);
43+
public JschConnectionInfo(String serverName, ServerOS serverOS, String host, String port, String userName,
44+
String password, AlertLogCommand alc) {
45+
this(serverName, serverOS, host, 22, userName, password, alc);
46+
this.setPort(port);
47+
}
48+
49+
public JschConnectionInfo(String host, String port, String userName, String password) {
50+
this("", null, host, 22, userName, password);
4151
this.setPort(port);
4252
}
4353

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package root.core.domain.enums;
2+
3+
public enum ServerOS {
4+
WINDOW, LINUX
5+
}

src/main/java/root/core/repository/implement/PropertyRepositoryImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import root.core.domain.AlertLogCommand;
3434
import root.core.domain.JdbcConnectionInfo;
3535
import root.core.domain.JschConnectionInfo;
36+
import root.core.domain.enums.ServerOS;
3637
import root.core.repository.constracts.PropertyRepository;
3738

3839
@Slf4j
@@ -529,11 +530,16 @@ public JdbcConnectionInfo getJdbcConnectionInfo(String dbName) {
529530
@Override
530531
public JschConnectionInfo getJschConnectionInfo(String serverName) {
531532
String serverHost = connInfoConfig.getString(serverName + ".server.host");
533+
ServerOS serverOS = null;
534+
try {
535+
serverOS = ServerOS.valueOf(connInfoConfig.getString(serverName + ".server.os"));
536+
} catch (Exception e) {
537+
}
532538
String serverPort = connInfoConfig.getString(serverName + ".server.port");
533539
String serverUserName = connInfoConfig.getString(serverName + ".server.username");
534540
String serverPassword = connInfoConfig.getString(serverName + ".server.password");
535541
AlertLogCommand alc = getAlertLogCommand(serverName);
536-
return new JschConnectionInfo(serverName.toUpperCase(), serverHost, serverPort, serverUserName, serverPassword,
542+
return new JschConnectionInfo(serverName, serverOS, serverHost, serverPort, serverUserName, serverPassword,
537543
alc);
538544
}
539545

src/main/java/root/javafx/CustomView/ServerConnInfoControl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public ConnectionTestService getConnectionTestService(ConnectionInfoAP curAP) {
5151
String id = ((TextField) curAP.lookup("#userTF")).getText();
5252
String pw = ((PasswordField) curAP.lookup("#passwordPF")).getText();
5353

54-
return new ServerConnectService(new JschConnectionInfo("", host, port, id, pw));
54+
return new ServerConnectService(new JschConnectionInfo(host, port, id, pw));
5555
}
5656

5757
@Override

src/main/java/root/javafx/CustomView/ServerConnectionInfoAnchorPane.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import lombok.EqualsAndHashCode;
1515
import root.core.domain.AlertLogCommand;
1616
import root.core.domain.JschConnectionInfo;
17+
import root.core.domain.enums.ServerOS;
1718
import root.core.repository.constracts.PropertyRepository;
1819
import root.core.repository.implement.PropertyRepositoryImpl;
1920
import root.javafx.DI.DependencyInjection;
@@ -28,6 +29,9 @@ public class ServerConnectionInfoAnchorPane extends ConnectionInfoAP {
2829
@FXML
2930
TextField serverNameTF;
3031

32+
@FXML
33+
JFXComboBox<ServerOS> serverOSCB;
34+
3135
@FXML
3236
TextField hostTF;
3337

@@ -62,18 +66,19 @@ public ServerConnectionInfoAnchorPane() {
6266
boolean isAnyEmptyInputForConnectionTest() {
6367
return StringUtils.isAnyEmpty(hostTF.getText(), portTF.getText(), userTF.getText(), passwordPF.getText());
6468
}
65-
69+
6670
public void init() {
6771
// Set textFormatter
6872
portTF.setTextFormatter(new NumberTextFormatter());
69-
73+
7074
// Set AlertLogDateFormat ComboBox values
7175
alertLogDateFormatCB.getItems()
72-
.addAll(propertyRepository.getCommonResources("server.setting.dateformat.combo"));
76+
.addAll(propertyRepository.getCommonResources("server.setting.dateformat.combo"));
7377
}
7478

7579
public void setInitialValue(JschConnectionInfo jsch) {
7680
serverNameTF.setText(jsch.getServerName());
81+
serverOSCB.getSelectionModel().select(jsch.getServerOS());
7782
hostTF.setText(jsch.getHost());
7883
portTF.setText(String.valueOf(jsch.getPort()));
7984
userTF.setText(jsch.getUserName());
@@ -84,21 +89,22 @@ public void setInitialValue(JschConnectionInfo jsch) {
8489

8590
public JschConnectionInfo getInputValues() {
8691
JschConnectionInfo jsch = new JschConnectionInfo();
87-
jsch.setServerName(this.serverNameTF.getText());
88-
jsch.setHost(this.hostTF.getText());
89-
jsch.setPort(this.portTF.getText());
90-
jsch.setUserName(this.userTF.getText());
91-
jsch.setPassword(this.passwordPF.getText());
92+
jsch.setServerName(serverNameTF.getText());
93+
jsch.setServerOS(serverOSCB.getValue());
94+
jsch.setHost(hostTF.getText());
95+
jsch.setPort(portTF.getText());
96+
jsch.setUserName(userTF.getText());
97+
jsch.setPassword(passwordPF.getText());
9298
AlertLogCommand alc = new AlertLogCommand();
93-
alc.setReadFilePath(this.alertLogFilePathTF.getText());
94-
alc.setDateFormat(this.alertLogDateFormatCB.getSelectionModel().getSelectedItem());
99+
alc.setReadFilePath(alertLogFilePathTF.getText());
100+
alc.setDateFormat(alertLogDateFormatCB.getSelectionModel().getSelectedItem());
95101
jsch.setAlc(alc);
96102
return jsch;
97103
}
98104

99105
public boolean isAnyEmptyInput() {
100-
return StringUtils.isAnyEmpty(hostTF.getText(), portTF.getText(), userTF.getText(), serverNameTF.getText(),
101-
passwordPF.getText(), alertLogFilePathTF.getText(),
102-
alertLogDateFormatCB.getSelectionModel().getSelectedItem());
106+
return StringUtils.isAnyEmpty(serverOSCB.getSelectionModel().getSelectedItem().name(), hostTF.getText(),
107+
portTF.getText(), userTF.getText(), serverNameTF.getText(), passwordPF.getText(),
108+
alertLogFilePathTF.getText(), alertLogDateFormatCB.getSelectionModel().getSelectedItem());
103109
}
104110
}

src/test/java/root/common/server/implement/JschServerTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.jcraft.jsch.Session;
2121

2222
import root.core.domain.JschConnectionInfo;
23+
import root.core.domain.enums.ServerOS;
2324

2425
public class JschServerTest {
2526

@@ -28,11 +29,12 @@ public class JschServerTest {
2829
@BeforeAll
2930
public static void setup() {
3031
String serverName = "DKY SERVER";
32+
ServerOS serverOS = ServerOS.WINDOW;
3133
String host = "192.168.154.1";
3234
String userName = "dky";
3335
String port = "22";
3436
String password = "ehruddbs1!";
35-
jsch = new JschServer(new JschConnectionInfo(serverName, host, port, userName, password));
37+
jsch = new JschServer(new JschConnectionInfo(serverName, serverOS, host, port, userName, password));
3638
}
3739

3840
@Test
@@ -128,23 +130,23 @@ public void testGetServerName() {
128130
String serverName = jsch.getServerName();
129131
assertEquals(serverName, "DKY SERVER");
130132
}
131-
133+
132134
@Test
133135
public void testExecuteCommand_EchoCommand() throws Exception {
134136
jsch.init();
135137
Session session = jsch.getSession();
136138
String result = jsch.executeCommand(session, "echo 1");
137139
assertEquals("1", result.trim());
138140
}
139-
141+
140142
@Test
141143
public void testExecuteCommand_TailCommand() throws Exception {
142144
jsch.init();
143145
Session session = jsch.getSession();
144146
String result = jsch.executeCommand(session, "tail -500 C://Users/aserv/Desktop/alert_DB.log");
145147
assertNotEquals(result, "");
146148
}
147-
149+
148150
@Test
149151
public void testValidateConn_Valid() throws Exception {
150152
jsch.init();

0 commit comments

Comments
 (0)