Skip to content
Snippets Groups Projects
Commit 9a5a7d4e authored by eyan_'s avatar eyan_
Browse files

broken

parent 42b6523a
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_16">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:16" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:win:16" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:16" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:win:16" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:16" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:win:16" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:16" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:win:16" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.7.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.1" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.28" level="project" />
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:3.11.4" level="project" />
</component>
</module>
\ No newline at end of file
package com.example.schedulerapp;
import java.time.LocalDateTime;
import java.lang.reflect.Array;
import java.net.*;
import java.io.*;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
public class Model {
Schedule schedule;
private PrintWriter writer;
private Socket socket;
protected ArrayList<String> shifts;
protected ArrayList<String> employees;
public Model(){
public Model(String hostname, int port) {
this.shifts = new ArrayList<>();
this.employees = new ArrayList<>();
try {
InetAddress ip = InetAddress.getByName(hostname);
this.socket = new Socket(ip, port);
System.out.println("Connected to the scheduling server");
new ReceiveThread(this.socket, this).start();
OutputStream output = this.socket.getOutputStream();
this.writer = new PrintWriter(output, true);
} catch (UnknownHostException error) {
System.out.println("Server not found: " + error.getMessage());
} catch (IOException error) {
System.out.println("I/O Error: " + error.getMessage());
}
}
public ArrayList<Shift> getDailySchedule(){
//sorted alphabetically
//return new ArrayList<>();
//todo
//Return
void getAllEmployees() {
}
void updateAllShifts(){
writer.println("allShifts");
}
void updateAllEmployees(){
writer.println("allEmployees");
}
//test data
ArrayList<Shift> test = new ArrayList<>();
test.add(new Shift(123, LocalDateTime.of(2022, 3, 9, 8, 0),
LocalDateTime.of(2022, 3, 9, 14, 0)));
test.add(new Shift(456, LocalDateTime.of(2022, 3, 9, 8, 30),
LocalDateTime.of(2022, 3, 9, 16, 30)));
test.add(new Shift(789, LocalDateTime.of(2022, 3, 9, 14, 0),
LocalDateTime.of(2022, 3, 9, 22, 0)));
return test;
void addEmployee(String first_name, String last_name) {
writer.println("addEmployee/" + first_name + "/" + last_name);
}
public ArrayList<Shift> getWeeklySchedule(){
//doesn't need to be sorted
//return new ArrayList<>();
ArrayList<Shift> test = new ArrayList<>();
test.add(new Shift(123, LocalDateTime.of(2022, 3, 9, 8, 0),
LocalDateTime.of(2022, 3, 9, 14, 0)));
test.add(new Shift(123, LocalDateTime.of(2022, 3, 6, 8, 30),
LocalDateTime.of(2022, 3, 9, 16, 30)));
test.add(new Shift(123, LocalDateTime.of(2022, 3, 10, 14, 0),
LocalDateTime.of(2022, 3, 9, 22, 0)));
return test;
void removeEmployee(String first_name, String last_name) {
writer.println("removeEmployee/" + first_name + "/" + last_name);
}
void printAllEmployees(){
System.out.println(this.employees);
}
String getEmployeeByID(int id) {
if (!this.employees.isEmpty()) {
for(String e: this.employees){
if(!e.equals("allEmployees")){
String[] eSplit = e.split("\\.");
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";
}
return "No Employees";
}
void addShift(int id, String date, int start, int end, String shiftType){
writer.println("addShift/"+id+"/"+date+"/"+start+"/"+end+"/"+shiftType);
}
void removeShift(int id, String date, int start, int end){
writer.println("removeShift/"+id+"/"+date+"/"+start+"/"+end);
}
void printAllShifts() {
System.out.println(this.shifts);
}
/*
Parameters:
startOfWeek - The first day of the week in "yyyy-mm-dd" format
endOfWeek - The last day of the week in "yyyy-mm-dd" format
Return: ArrayList<String>
*/
ArrayList<String> getShiftsByWeek(String startOfWeek, String endOfWeek){
String[] startSplit = startOfWeek.split("-");
String[] endSplit = endOfWeek.split("-");
ArrayList<String> output = new ArrayList<>();
for(String shift: this.shifts){
if(!shift.equals("allShifts")){
String[] shiftSplit = shift.split("\\.");
String[] dateSplit = shiftSplit[1].split("-");
try {
if(Integer.parseInt(startSplit[0]) >= Integer.parseInt(dateSplit[0]) &&
Integer.parseInt(startSplit[1]) >= Integer.parseInt(dateSplit[1]) &&
Integer.parseInt(startSplit[2]) >= Integer.parseInt(dateSplit[2])){
if(Integer.parseInt(endSplit[0]) >= Integer.parseInt(dateSplit[0]) &&
Integer.parseInt(endSplit[1]) >= Integer.parseInt(dateSplit[1]) &&
Integer.parseInt(endSplit[2]) >= Integer.parseInt(dateSplit[2])){
output.add(shift);
}
}
} catch (Exception e){
System.out.println("Error: Parsing string to int");
}
}
}
return output;
}
ArrayList<String> getEmployeeShifts(String id){
ArrayList<String> output = new ArrayList<>();
for(String shift: this.shifts){
String[] shiftSplit = shift.split("\\.");
if (shiftSplit[0].equals(id)) {
output.add(shift);
}
}
return output;
}
//todo
void getEmployeeShiftsByWeek(){
}
void logOut() {
writer.println("logout");
try {
this.socket.close();
} catch (IOException ex){
System.out.println("Error: Failed to close socket");
}
}
public static void main(String[] args) {
String hostname = "localhost"; //"localhost if connecting to local server, or "172.16.1.99" connecting to Rafi's server
int port = 8989; //Rafi's server port is 8989
Model client = new Model(hostname, port);
System.out.print("Retrieving Data");
while(client.employees.isEmpty() && client.shifts.isEmpty()){
System.out.print(".");
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
System.out.println("Error: ScheduleClient main. Interrupted while retrieving data ");
}
}
System.out.println();
System.out.println("Data retrieved.");
System.out.println("ScheduleClient is ready to use!");
}
public ArrayList<String> returnFormattedEmployeeNames(){
ArrayList<String> result = new ArrayList<>();
ArrayList<String> temp = this.employees;
String tempName = "";
temp.remove(0);
for(int i = 0; i < temp.size(); i++){
String[] templist = temp.get(i).split("\\.");
for(int j =0; j < 3; j++){
if(j == 1 || j == 2){
tempName += templist[j];
}
if(j == 1){
tempName += " ";
}
}
result.add(tempName);
tempName = "";
}
System.out.println(result);
return result;
}
}
package com.example.schedulerapp;
import java.sql.*;
//todo: how does sql work? would that be easier?
public class Schedule {
private final Connection dbConnection;
import java.util.ArrayList;
protected Schedule(Connection c) {
this.dbConnection = c;
}
public class Schedule {
private ArrayList<Shift> shifts;
/*
Name: addShift
Parameters:
int ID: The employees unique ID.
Date: The date as a string in the form of "yyyy-mm-dd".
start: The employees shift start time.
end: The employees shift end time.
Description: Adds a new shift to the database, referencing the employees ID, and assigning a unique shift number.
Return: none
*/
public Schedule(){
shifts = new ArrayList<>();
protected void addShift(int ID, String date, int start, int end){
Date newDate = Date.valueOf(date);
try {
Statement myStatement = dbConnection.createStatement();
myStatement.executeUpdate("INSERT INTO shifts (employee_id, full_date, start_time, end_time) " +
"VALUES ('" + ID +"', '"+ newDate +"', '"+ start +"', '"+ end +"')");
} catch (SQLException e) {
e.printStackTrace();
}
}
// output: all shifts
public ArrayList<Shift> getAllShifts(){
return shifts;
/*
Name: removeShift
Parameters:
int ID: The employees unique ID.
Date: The date as a string in the form of "yyyy-mm-dd".
start: The employees shift start time.
end: The employees shift end time.
Description: Removes the employees shift matching the date, and shift duration.
Return: none
*/
protected void removeShift(String ID, String date, int start, int end){
Date newDate = Date.valueOf(date);
try {
Statement myStatement = dbConnection.createStatement();
myStatement.executeUpdate("DELETE FROM shifts WHERE (employee_id =" + ID + ") " +
"AND WHERE (date = " + newDate +") AND WHERE (start_time = " + start + " ) " +
"AND WHERE (end_time = " + end +")");
} catch (SQLException e) {
e.printStackTrace();
}
}
//todo: java date?
// output: all shifts starting and/or ending on the given date
public ArrayList<Shift> getDateShifts(){
ArrayList<Shift> result = new ArrayList<>();
// get all appropriate shifts, add to result
/*
Name: getShifts
Parameters:
Date: The date as a string in the form of "yyyy-mm-dd".
Description: Returns info for all shifts on a given date.
Return: String
*/
protected String getShifts(String date){
Date newDate = Date.valueOf(date);
String response = "getShifts";
try {
Statement myStatement = dbConnection.createStatement();
ResultSet myRs = myStatement.executeQuery("SELECT FROM shifts WHERE (full_date = " + newDate +")");
while (myRs.next()) {
response = response + "/" + myRs.getString("full_date") + "." +
myRs.getString("employee_id") + "." + myRs.getString("start_time") +
"." + myRs.getString("end_time");
}
return null;
//return result;
} catch (SQLException e) {
e.printStackTrace();
}
return response;
}
//todo
// output: all shifts assigned to given employee
public ArrayList<Shift> getEmpShifts(int empID){
ArrayList<Shift> result = new ArrayList<>();
// get all appropriate shifts, add to result
protected String getShiftsByWeek(String startDate, String endDate){
Date newStart = Date.valueOf(startDate);
Date newEnd = Date.valueOf(endDate);
String response = "getShiftsByWeek";
try {
Statement myStatement = dbConnection.createStatement();
ResultSet myRs = myStatement.executeQuery("SELECT FROM shifts WHERE (full_date >= " + newStart +")" +
"AND WHERE (full_date <= " + newEnd +")");
while (myRs.next()) {
response = response + "/" + myRs.getString("full_date") + "." +
myRs.getString("employee_id") + "." + myRs.getString("start_time") +
"." + myRs.getString("end_time");
}
return null;
//return result;
} catch (SQLException e) {
e.printStackTrace();
}
return response;
}
//todo
// output: all shifts marked as available
public ArrayList<Shift> getAvailableShifts(){
ArrayList<Shift> result = new ArrayList<>();
// get all appropriate shifts, add to result
protected String getEmployeeShiftsByWeek(int ID, String startDate, String endDate){
Date newStart = Date.valueOf(startDate);
Date newEnd = Date.valueOf(endDate);
String response = "getEmployeeShiftsByWeek";
try {
Statement myStatement = dbConnection.createStatement();
ResultSet myRs = myStatement.executeQuery("SELECT FROM shifts WHERE (full_date >= " + newStart +")" +
"AND WHERE (full_date <= " + newEnd +") AND WHERE (employee_id = "+ ID + ")");
while (myRs.next()) {
response = response + "/" + myRs.getString("full_date") + "." +
myRs.getString("employee_id") + "." + myRs.getString("start_time") +
"." + myRs.getString("end_time");
}
return null;
//return result;
} catch (SQLException e) {
e.printStackTrace();
}
return response;
}
protected String allShifts(){
String response = "allShifts";
try {
Statement myStatement = dbConnection.createStatement();
ResultSet myRs = myStatement.executeQuery("SELECT * FROM shifts");
while (myRs.next()) {
response = response + "/" + myRs.getString("employee_id" ) + "." +
myRs.getString("full_date") + "." + myRs.getString("start_time") +
"." + myRs.getString("end_time");
}
} catch (SQLException e) {
e.printStackTrace();
}
return response;
}
}
......@@ -88,7 +88,7 @@ public class ScheduleView extends GridPane implements ModelSubscriber{
dropShift.setAutoHide(true);
}
@Override
public void modelChanged() {
draw();
}
......
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