Skip to content
Snippets Groups Projects
Commit 6c33f835 authored by Michael Kish's avatar Michael Kish
Browse files

Merge branch 'Model' of https://git.cs.usask.ca/esc568/cmpt-370-group-project into main

parents c69deabc c3160200
No related branches found
No related tags found
No related merge requests found
......@@ -7,12 +7,10 @@ import java.util.Arrays;
public class ReceiveThread extends Thread {
private BufferedReader reader;
private Socket socket;
private ScheduleClient client;
private final ScheduleClient client;
public ReceiveThread(Socket socket, ScheduleClient client) {
this.client = client;
this.socket = socket;
try {
InputStream input = socket.getInputStream();
......@@ -29,14 +27,9 @@ public class ReceiveThread extends Thread {
//System.out.println("ReceiveThread.Run.Hello"); why does this run twice.
String response = reader.readLine();
String[] args = response.split("/");
//System.out.println(args[0]); testing
switch (args[0]) {
case "allEmployees":
this.client.employees = new ArrayList<String>(Arrays.asList(args));
break;
case "Shifts":
this.client.shifts = new ArrayList<String>(Arrays.asList(args));
break;
case "allEmployees" -> this.client.employees = new ArrayList<>(Arrays.asList(args));
case "Shifts" -> this.client.shifts = new ArrayList<>(Arrays.asList(args));
}
} catch (IOException error) {
......
......@@ -5,23 +5,20 @@ import java.io.*;
import java.util.ArrayList;
public class ScheduleClient {
private String hostname;
private int port;
private Socket socket;
private PrintWriter writer;
protected ArrayList<String> shifts = new ArrayList<>();
protected ArrayList<String> employees = new ArrayList<>();
protected ArrayList<String> shifts;
protected ArrayList<String> employees;
public ScheduleClient(String hostname, int port) {
this.hostname = hostname;
this.port = port;
this.shifts = new ArrayList<>();
this.employees = new ArrayList<>();
try {
this.socket = new Socket (hostname, port);
Socket socket = new Socket(hostname, port);
System.out.println("Connected to the scheduling server");
new ReceiveThread(socket, this).start();
OutputStream output = this.socket.getOutputStream();
OutputStream output = socket.getOutputStream();
this.writer = new PrintWriter(output, true);
} catch (UnknownHostException error) {
......@@ -56,9 +53,14 @@ public class ScheduleClient {
for(String e: this.employees){
if(!e.equals("allEmployees")){
String[] eSplit = e.split("\\.");
if (eSplit[0].equals(id)){
return eSplit[1] + " " + eSplit[2];
try {
if(Integer.parseInt(eSplit[0]) == id){
return eSplit[1] + " " + eSplit[2];
}
} catch (NumberFormatException exception){
System.out.println("getEmployeeByID: string cannot be integer parsed");
}
}
}
return "No Employee with that ID";
......@@ -72,17 +74,19 @@ public class ScheduleClient {
public static void main(String[] args) {
ScheduleClient client = new ScheduleClient("localhost", 8989);
while(client.employees.isEmpty()){
System.out.println("Retrieving Data...");
}
System.out.println("Data Retrieved!");
/*
//Testing stuff that should be cleaned up for the alpha.
/* Testing stuff that should be cleaned up for the alpha.
System.out.println("1");
client.printAllEmployees();
System.out.println("2");
System.out.println(client.getEmployeeByID(3));
System.out.println("3");
client.addEmployee("John", "Peter");
System.out.println("4");
System.out.println(client.getEmployeeByID(3));
System.out.println(client.getEmployeeByID(7));
client.printAllEmployees();
*/
}
}
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment