Newer
Older
package com.example.schedulerapp;
import java.io.*;
import java.net.*;
public class ReceiveThread extends Thread {
this.client = client;
try {
InputStream input = socket.getInputStream();
reader = new BufferedReader(new InputStreamReader(input));
Rafi Zereselasie (raz070)
committed
} catch (IOException exception) {
System.out.println("Error getting input stream: " + exception.getMessage());
exception.printStackTrace();
}
}
public void run() {
while(true) {
try {
//System.out.println("ReceiveThread.Run.Hello"); why does this run twice.
String[] args = response.split("/");
switch (args[0]) {
case "allEmployees" -> allEmployees(args);
case "allShifts" -> allShifts(args);
case "addEmployee" -> addEmployee(args[1]);
case "removeEmployee" -> removeEmployee(args[1]);
case "addShift" -> addShift(args[1]);
case "removeShift" -> removeShiftByIDL(args[1]);
case "editShift" -> editShiftL(args[1]); // fix
Rafi Zereselasie (raz070)
committed
} catch (IOException exception) {
System.out.println("Dropped connection from server: " + exception.getMessage());
Rafi Zereselasie (raz070)
committed
exception.printStackTrace();
private void allEmployees(String[] allEmployees) {
for (String employee : allEmployees) {
if (!employee.equals("allEmployees")){
addEmployee(employee);
}
}
}
private void addEmployee(String employeeData) {
try {
String[] dataSplit = employeeData.split("\\.");
this.client.employees.put(Integer.parseInt(dataSplit[0]), new Employee(employeeData));
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void removeEmployee(String employeeID) {
int intID = -1;
try {
intID = Integer.parseInt(employeeID);
this.client.employees.remove(intID);
for (Shift shift : this.client.shifts.values()) {
if (shift.getEmployeeID() == intID) {
this.client.shifts.remove(shift.getShiftID());
}
}
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void allShifts(String[] allShifts) {
for (String shift : allShifts) {
if (!shift.equals("allShifts")){
addShift(shift);
}
}
}
private void addShift(String shiftData) {
try {
String[] dataSplit = shiftData.split("\\.");
this.client.shifts.put(Integer.parseInt(dataSplit[4]), new Shift(shiftData));
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void removeShiftByIDL(String id) {
try {
this.client.shifts.remove(Integer.parseInt(id));
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void editShiftL(String editedShift) {
String[] shiftSplit = editedShift.split("\\.");
try {
int shiftID = Integer.parseInt(shiftSplit[4]);
this.client.shifts.remove(shiftID);
this.client.shifts.put(shiftID, new Shift(editedShift));
} catch (Exception exception) {
exception.printStackTrace();
}
}