Little refactor and reorganize project
This commit is contained in:
parent
76a81fe0f1
commit
b9f43a39d3
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
.idea
|
||||
out
|
||||
target
|
62
pom.xml
Normal file
62
pom.xml
Normal file
@ -0,0 +1,62 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>ftp.sar</groupId>
|
||||
<artifactId>ftp-sar</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>FTP-SAR</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<junit.jupiter.version>5.5.2</junit.jupiter.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx</artifactId>
|
||||
<version>11</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-controls</artifactId>
|
||||
<version>11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-fxml</artifactId>
|
||||
<version>11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-maven-plugin</artifactId>
|
||||
<version>0.0.3</version>
|
||||
<configuration>
|
||||
<mainClass>ftp.sar.Main</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -1,108 +0,0 @@
|
||||
package application.client.server;
|
||||
|
||||
import application.PropertiesLoader;
|
||||
import application.client.exception.CannotConnectException;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
|
||||
public class ServerConnector {
|
||||
private PropertiesLoader propertiesLoader = PropertiesLoader.getInstance();
|
||||
|
||||
public ServerConnector() {
|
||||
}
|
||||
|
||||
public boolean readFileList(Server server) {
|
||||
try {
|
||||
Socket socket = new Socket(server.getIp(), server.getPort());
|
||||
DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
|
||||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(dataOutputStream);
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
|
||||
|
||||
String command = "GET_ALL_FILES";
|
||||
|
||||
bufferedWriter.write(command, 0, command.length());
|
||||
bufferedWriter.flush();
|
||||
bufferedWriter.close();
|
||||
socket.close();
|
||||
|
||||
|
||||
|
||||
socket = new Socket(server.getIp(), server.getPort());
|
||||
DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(dataInputStream);
|
||||
BufferedReader reader = new BufferedReader(inputStreamReader);
|
||||
|
||||
while (true) {
|
||||
String file = reader.readLine();
|
||||
System.out.println(file);
|
||||
|
||||
if (file == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
server.addToFileList(file);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// public static Connector getInstance() {
|
||||
// return instance;
|
||||
// }
|
||||
//
|
||||
// public void connect(String ip) throws CannotConnectException {
|
||||
// this.isConnect = false;
|
||||
// try {
|
||||
// this.client = new Socket(ip, Integer.parseInt(this.propertiesLoader.get("port")));
|
||||
// this.checkIfConnect();
|
||||
// } catch (IOException e) {
|
||||
// throw new CannotConnectException();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void checkIfConnect() {
|
||||
// String pattern = this.propertiesLoader.get("serverStatusConnect");
|
||||
//
|
||||
// this.isConnect = pattern.equals(this.getMessage());
|
||||
// }
|
||||
//
|
||||
// public String getMessage() {
|
||||
// String message = null;
|
||||
// try {
|
||||
// System.out.println("Trying to get input stream");
|
||||
// DataInputStream inputStream = new DataInputStream(this.client.getInputStream());
|
||||
// InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
|
||||
// BufferedReader br = new BufferedReader(inputStreamReader);
|
||||
// message = br.readLine();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// System.out.println("Message received: "+ message);
|
||||
// return message;
|
||||
// }
|
||||
//
|
||||
// public void getFileList() {
|
||||
// try {
|
||||
// DataOutputStream outputStream = new DataOutputStream(this.client.getOutputStream());
|
||||
// OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
|
||||
// BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
|
||||
//
|
||||
// bufferedWriter.write("GET_ALL_FILES");
|
||||
// bufferedWriter.flush();
|
||||
//
|
||||
// this.getMessage();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public boolean isConnect() {
|
||||
// return this.isConnect;
|
||||
// }
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package application.client.validator;
|
||||
|
||||
public interface Validator {
|
||||
public boolean validate(Object value);
|
||||
}
|
@ -1,18 +1,23 @@
|
||||
package application;
|
||||
package ftp.sar;
|
||||
|
||||
import application.client.view.ResourceLoader;
|
||||
import ftp.sar.view.ResourceLoader;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
|
||||
public class Main extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception{
|
||||
|
||||
Object o = getClass();
|
||||
|
||||
ResourceLoader loader = ResourceLoader.getInstance();
|
||||
Object c = loader.getResource("main_page.fxml");
|
||||
Object a = getClass().getClassLoader().getResource("resources/main_page.fxml");
|
||||
Object b = getClass().getClassLoader().getResource("main_page.fxml");
|
||||
|
||||
Parent root = FXMLLoader.load(loader.getResource("main_page.fxml"));
|
||||
primaryStage.setTitle("FTP SAR");
|
@ -1,7 +1,7 @@
|
||||
package application;
|
||||
package ftp.sar;
|
||||
|
||||
|
||||
import application.client.view.ResourceLoader;
|
||||
import ftp.sar.view.ResourceLoader;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
@ -1,4 +1,4 @@
|
||||
package application.client.exception;
|
||||
package ftp.sar.exception;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -1,12 +1,11 @@
|
||||
package application.client.server;
|
||||
package ftp.sar.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Server {
|
||||
private String ip;
|
||||
private int port;
|
||||
private ArrayList<String> fileList = new ArrayList<String>();
|
||||
private ArrayList<String> fileList = new ArrayList<>();
|
||||
|
||||
public Server (String ip, int port) {
|
||||
this.ip = ip;
|
64
src/main/java/ftp/sar/server/ServerConnector.java
Normal file
64
src/main/java/ftp/sar/server/ServerConnector.java
Normal file
@ -0,0 +1,64 @@
|
||||
package ftp.sar.server;
|
||||
|
||||
import ftp.sar.PropertiesLoader;
|
||||
import ftp.sar.exception.CannotConnectException;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
|
||||
public class ServerConnector {
|
||||
private PropertiesLoader propertiesLoader = PropertiesLoader.getInstance();
|
||||
|
||||
public ServerConnector() {
|
||||
}
|
||||
|
||||
public boolean readFileList(Server server) throws CannotConnectException {
|
||||
|
||||
this.sendRequest("GET_ALL_FILES", server);
|
||||
|
||||
try {
|
||||
Socket socket = new Socket(server.getIp(), server.getPort());
|
||||
DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(dataInputStream);
|
||||
BufferedReader reader = new BufferedReader(inputStreamReader);
|
||||
|
||||
while (true) {
|
||||
String file = reader.readLine();
|
||||
System.out.println(file);
|
||||
|
||||
if (file == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
server.addToFileList(file);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void sendRequest(
|
||||
String request,
|
||||
Server server
|
||||
) throws CannotConnectException {
|
||||
Socket socket;
|
||||
try {
|
||||
socket = new Socket(server.getIp(), server.getPort());
|
||||
DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
|
||||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(dataOutputStream);
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
|
||||
|
||||
bufferedWriter.write(request, 0, request.length());
|
||||
bufferedWriter.flush();
|
||||
bufferedWriter.close();
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
throw new CannotConnectException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,20 +1,23 @@
|
||||
package application.client.server;
|
||||
package ftp.sar.server;
|
||||
|
||||
import application.client.validator.IpValidator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import ftp.sar.exception.CannotConnectException;
|
||||
import ftp.sar.validator.IpValidator;
|
||||
|
||||
public class ServerFactory {
|
||||
|
||||
public Server create(String ip, int port) {
|
||||
if (!this.validate(ip)) {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
Server server = this.createServer(ip, port);
|
||||
|
||||
ServerConnector connector = new ServerConnector();
|
||||
connector.readFileList(server);
|
||||
try {
|
||||
connector.readFileList(server);
|
||||
} catch (CannotConnectException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return server;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package application.client.validator;
|
||||
package ftp.sar.validator;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
5
src/main/java/ftp/sar/validator/Validator.java
Normal file
5
src/main/java/ftp/sar/validator/Validator.java
Normal file
@ -0,0 +1,5 @@
|
||||
package ftp.sar.validator;
|
||||
|
||||
public interface Validator {
|
||||
boolean validate(Object value);
|
||||
}
|
@ -1,18 +1,17 @@
|
||||
package application.client.view;
|
||||
package ftp.sar.view;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
public class ResourceLoader {
|
||||
private static final ResourceLoader instance = new ResourceLoader();
|
||||
public static final String RESOURCE_FOLDER = "resource/";
|
||||
|
||||
public URL getResource(String name) {
|
||||
return getClass().getClassLoader().getResource(RESOURCE_FOLDER + name);
|
||||
return getClass().getClassLoader().getResource(name);
|
||||
}
|
||||
|
||||
public InputStream getResourceAsStream(String name) {
|
||||
return getClass().getClassLoader().getResourceAsStream(RESOURCE_FOLDER + name);
|
||||
return getClass().getClassLoader().getResourceAsStream( name);
|
||||
}
|
||||
|
||||
public String getPath(String name) {
|
@ -1,7 +1,6 @@
|
||||
package application.client.view.mainPage;
|
||||
package ftp.sar.view.mainPage;
|
||||
|
||||
import application.client.server.ServerConnector;
|
||||
import application.client.server.ServerFactory;
|
||||
import ftp.sar.server.ServerFactory;
|
||||
import javafx.event.Event;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.TextField;
|
@ -6,7 +6,7 @@
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.client.view.mainPage.MainPageController">
|
||||
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ftp.sar.view.mainPage.MainPageController">
|
||||
<children>
|
||||
<Pane prefHeight="70.0" prefWidth="640.0">
|
||||
<children>
|
17
src/test/java/ftp/sar/server/TestServer.java
Normal file
17
src/test/java/ftp/sar/server/TestServer.java
Normal file
@ -0,0 +1,17 @@
|
||||
package ftp.sar.server;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TestServer {
|
||||
public static final String IP = "192.168.0.1";
|
||||
public static final int PORT = 6666;
|
||||
|
||||
@Test
|
||||
public void testCreateServer() {
|
||||
Server server = new Server(IP, PORT);
|
||||
|
||||
assertEquals(IP, server.getIp());
|
||||
}
|
||||
}
|
2
target/classes/config.properties
Normal file
2
target/classes/config.properties
Normal file
@ -0,0 +1,2 @@
|
||||
port=7332
|
||||
serverStatusConnect=CONNECT
|
BIN
target/classes/ftp/sar/Main.class
Normal file
BIN
target/classes/ftp/sar/Main.class
Normal file
Binary file not shown.
BIN
target/classes/ftp/sar/PropertiesLoader.class
Normal file
BIN
target/classes/ftp/sar/PropertiesLoader.class
Normal file
Binary file not shown.
BIN
target/classes/ftp/sar/exception/CannotConnectException.class
Normal file
BIN
target/classes/ftp/sar/exception/CannotConnectException.class
Normal file
Binary file not shown.
BIN
target/classes/ftp/sar/server/Server.class
Normal file
BIN
target/classes/ftp/sar/server/Server.class
Normal file
Binary file not shown.
BIN
target/classes/ftp/sar/server/ServerConnector.class
Normal file
BIN
target/classes/ftp/sar/server/ServerConnector.class
Normal file
Binary file not shown.
BIN
target/classes/ftp/sar/server/ServerFactory.class
Normal file
BIN
target/classes/ftp/sar/server/ServerFactory.class
Normal file
Binary file not shown.
BIN
target/classes/ftp/sar/validator/IpValidator.class
Normal file
BIN
target/classes/ftp/sar/validator/IpValidator.class
Normal file
Binary file not shown.
BIN
target/classes/ftp/sar/validator/Validator.class
Normal file
BIN
target/classes/ftp/sar/validator/Validator.class
Normal file
Binary file not shown.
BIN
target/classes/ftp/sar/view/ResourceLoader.class
Normal file
BIN
target/classes/ftp/sar/view/ResourceLoader.class
Normal file
Binary file not shown.
BIN
target/classes/ftp/sar/view/mainPage/MainPageController.class
Normal file
BIN
target/classes/ftp/sar/view/mainPage/MainPageController.class
Normal file
Binary file not shown.
20
target/classes/main_page.fxml
Normal file
20
target/classes/main_page.fxml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ftp.sar.view.mainPage.MainPageController">
|
||||
<children>
|
||||
<Pane prefHeight="70.0" prefWidth="640.0">
|
||||
<children>
|
||||
<Button layoutX="529.0" layoutY="22.0" mnemonicParsing="false" onAction="#tryAddServer" text="Add server" />
|
||||
<TextField fx:id="ipField" layoutX="344.0" layoutY="22.0" />
|
||||
<Label layoutX="65.0" layoutY="27.0" text="SAR - Send and Revice" />
|
||||
<Label alignment="CENTER" layoutX="345.0" layoutY="48.0" prefHeight="16.0" prefWidth="170.0" textAlignment="JUSTIFY" textFill="RED" />
|
||||
</children>
|
||||
</Pane>
|
||||
</children>
|
||||
</VBox>
|
@ -0,0 +1,10 @@
|
||||
ftp/sar/validator/Validator.class
|
||||
ftp/sar/PropertiesLoader.class
|
||||
ftp/sar/server/ServerFactory.class
|
||||
ftp/sar/view/mainPage/MainPageController.class
|
||||
ftp/sar/view/ResourceLoader.class
|
||||
ftp/sar/validator/IpValidator.class
|
||||
ftp/sar/exception/CannotConnectException.class
|
||||
ftp/sar/server/ServerConnector.class
|
||||
ftp/sar/server/Server.class
|
||||
ftp/sar/Main.class
|
@ -0,0 +1,10 @@
|
||||
/home/mkdrwal/project/ZSIK_Projekt/src/main/java/ftp/sar/view/ResourceLoader.java
|
||||
/home/mkdrwal/project/ZSIK_Projekt/src/main/java/ftp/sar/server/ServerFactory.java
|
||||
/home/mkdrwal/project/ZSIK_Projekt/src/main/java/ftp/sar/Main.java
|
||||
/home/mkdrwal/project/ZSIK_Projekt/src/main/java/ftp/sar/PropertiesLoader.java
|
||||
/home/mkdrwal/project/ZSIK_Projekt/src/main/java/ftp/sar/server/Server.java
|
||||
/home/mkdrwal/project/ZSIK_Projekt/src/main/java/ftp/sar/validator/Validator.java
|
||||
/home/mkdrwal/project/ZSIK_Projekt/src/main/java/ftp/sar/view/mainPage/MainPageController.java
|
||||
/home/mkdrwal/project/ZSIK_Projekt/src/main/java/ftp/sar/validator/IpValidator.java
|
||||
/home/mkdrwal/project/ZSIK_Projekt/src/main/java/ftp/sar/server/ServerConnector.java
|
||||
/home/mkdrwal/project/ZSIK_Projekt/src/main/java/ftp/sar/exception/CannotConnectException.java
|
Loading…
Reference in New Issue
Block a user