From 80646e36bfba57e39b0b791882adce24e5577527 Mon Sep 17 00:00:00 2001 From: Ryan Cicchiello Date: Tue, 10 Apr 2018 21:53:41 -0400 Subject: [PATCH] Added ability to edit and delete assignments --- ...assignment.fxml => assignment_dialog.fxml} | 0 client/src/edu/rpi/aris/Main.java | 1 - .../edu/rpi/aris/gui/submit/Assignment.java | 141 ++++++++++++-- ...nmentDialog.java => AssignmentDialog.java} | 52 ++++-- .../rpi/aris/gui/submit/AssignmentWindow.java | 12 +- .../src/edu/rpi/aris/gui/submit/Course.java | 2 +- .../edu/rpi/aris/gui/submit/ProofInfo.java | 13 ++ libaris/res/edu/rpi/aris/VERSION | 2 +- libaris/src/edu/rpi/aris/net/NetUtil.java | 4 + packaging/deb/server/etc/aris.cfg | 3 + .../rpi/aris/net/server/ClientHandler.java | 173 ++++++++++-------- 11 files changed, 291 insertions(+), 112 deletions(-) rename client/res/edu/rpi/aris/gui/submit/{add_assignment.fxml => assignment_dialog.fxml} (100%) rename client/src/edu/rpi/aris/gui/submit/{AddAssignmentDialog.java => AssignmentDialog.java} (65%) diff --git a/client/res/edu/rpi/aris/gui/submit/add_assignment.fxml b/client/res/edu/rpi/aris/gui/submit/assignment_dialog.fxml similarity index 100% rename from client/res/edu/rpi/aris/gui/submit/add_assignment.fxml rename to client/res/edu/rpi/aris/gui/submit/assignment_dialog.fxml diff --git a/client/src/edu/rpi/aris/Main.java b/client/src/edu/rpi/aris/Main.java index 551bda88..4a79bc6e 100644 --- a/client/src/edu/rpi/aris/Main.java +++ b/client/src/edu/rpi/aris/Main.java @@ -2,7 +2,6 @@ import edu.rpi.aris.gui.Aris; import edu.rpi.aris.gui.GuiConfig; -import edu.rpi.aris.gui.submit.AddAssignmentDialog; import edu.rpi.aris.net.client.Client; import javafx.application.Platform; import javafx.scene.control.Alert; diff --git a/client/src/edu/rpi/aris/gui/submit/Assignment.java b/client/src/edu/rpi/aris/gui/submit/Assignment.java index 822e5ce8..a87d9701 100644 --- a/client/src/edu/rpi/aris/gui/submit/Assignment.java +++ b/client/src/edu/rpi/aris/gui/submit/Assignment.java @@ -5,47 +5,57 @@ import edu.rpi.aris.net.NetUtil; import edu.rpi.aris.net.client.Client; import javafx.application.Platform; +import javafx.beans.binding.Bindings; import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleLongProperty; import javafx.beans.property.SimpleObjectProperty; -import javafx.scene.control.TitledPane; -import javafx.scene.control.TreeItem; -import javafx.scene.control.TreeTableColumn; -import javafx.scene.control.TreeTableView; +import javafx.beans.property.SimpleStringProperty; +import javafx.scene.control.*; +import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; +import javafx.stage.Modality; +import org.apache.commons.lang3.tuple.Triple; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.IOException; import java.net.URLDecoder; +import java.net.URLEncoder; import java.text.DateFormat; import java.text.ParseException; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.*; public class Assignment { private static Logger logger = LogManager.getLogger(Assignment.class); - private final String assignedBy; private final int id, classId; - private long dueDate; - private String name; + private final Course course; + private SimpleLongProperty dueDate = new SimpleLongProperty(); + private SimpleStringProperty name = new SimpleStringProperty(); private TitledPane titledPane; - private VBox tableBox = new VBox(); + private VBox tableBox = new VBox(5); private SimpleBooleanProperty loaded = new SimpleBooleanProperty(false); private ArrayList rootNodes = new ArrayList<>(); + private HashSet proofs = new HashSet<>(); - public Assignment(String name, String dueDate, String assignedBy, int id, int classId) { - this.name = name; + public Assignment(String name, String dueDate, String assignedBy, int id, int classId, Course course) { + this.course = course; + this.name.set(name); try { - this.dueDate = NetUtil.DATE_FORMAT.parse(dueDate).getTime(); + this.dueDate.set(NetUtil.DATE_FORMAT.parse(dueDate).getTime()); } catch (ParseException e) { logger.error("Failed to parse due date", e); - this.dueDate = -1; + this.dueDate.set(-1); } - this.assignedBy = assignedBy; this.id = id; this.classId = classId; - String dateStr = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date(this.dueDate)); - titledPane = new TitledPane(name + "\nDue: " + dateStr + "\nAssigned by: " + assignedBy, tableBox); + titledPane = new TitledPane("", tableBox); + titledPane.textProperty().bind(Bindings.createStringBinding(() -> { + String dateStr = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date(Assignment.this.dueDate.get())); + return Assignment.this.name.get() + "\nDue: " + dateStr + "\nAssigned by: " + assignedBy; + }, this.name, this.dueDate)); titledPane.expandedProperty().addListener((observableValue, oldVal, newVal) -> { if (newVal) load(false); @@ -111,9 +121,107 @@ private void buildUI() { view.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY); view.setEditable(false); root.setExpanded(true); + if (AssignmentWindow.instance.getClientInfo().isInstructorProperty().get()) { + Button editAssignment = new Button("Edit Assignment"); + Button deleteAssignment = new Button("Delete Assignment"); + editAssignment.setOnAction(action -> editAssignment()); + deleteAssignment.setOnAction(action -> deleteAssignment()); + HBox box = new HBox(5); + box.getChildren().addAll(editAssignment, deleteAssignment); + tableBox.getChildren().add(box); + } tableBox.getChildren().add(view); } + private void deleteAssignment() { + Alert alert = new Alert(Alert.AlertType.WARNING); + alert.initModality(Modality.WINDOW_MODAL); + alert.initOwner(AssignmentWindow.instance.getStage()); + alert.setTitle("Delete Assignment?"); + alert.setHeaderText("Are you sure you want to delete this assignment?"); + alert.setContentText("This will also delete any student submissions for this assignment"); + alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO); + Optional result = alert.showAndWait(); + result.ifPresent(type -> { + if (type != ButtonType.YES) + return; + new Thread(() -> { + Client client = Main.getClient(); + try { + client.connect(); + client.sendMessage(NetUtil.DELETE_ASSIGNMENT); + client.sendMessage(classId + "|" + id); + String res = client.readMessage(); + if (!NetUtil.OK.equals(Client.checkError(res))) + throw new IOException(res); + AssignmentWindow.instance.loadAssignments(course, true); + } catch (IOException e) { + e.printStackTrace(); + } finally { + client.disconnect(); + } + }).start(); + }); + } + + private void editAssignment() { + ProofList proofList = AssignmentWindow.instance.getProofList(); + proofList.load(false); + try { + AssignmentDialog dialog = new AssignmentDialog(AssignmentWindow.instance.getStage(), proofList, name.get(), new Date(dueDate.get()), proofs); + Optional>> result = dialog.showAndWait(); + if (!result.isPresent()) + return; + Triple> info = result.get(); + String newName = info.getLeft().equals(name.get()) ? null : info.getLeft(); + Date tmpDate = Date.from(info.getMiddle().atZone(ZoneId.systemDefault()).toInstant()); + Date newDate = tmpDate.equals(new Date(dueDate.get())) ? null : tmpDate; + Collection newProofs = info.getRight(); + Set remove = new HashSet<>(); + Set add = new HashSet<>(); + for (ProofInfo p : newProofs) + if (!proofs.contains(p)) + add.add(p); + for (ProofInfo p : proofs) + if (!newProofs.contains(p)) + remove.add(p); + if (newName != null || newDate != null || remove.size() > 0 || add.size() > 0) { + new Thread(() -> { + Client client = Main.getClient(); + try { + client.connect(); + client.sendMessage(NetUtil.UPDATE_ASSIGNMENT); + if (newName != null) + client.sendMessage(NetUtil.RENAME + "|" + classId + "|" + id + "|" + URLEncoder.encode(newName, "UTF-8")); + if (newDate != null) + client.sendMessage(NetUtil.CHANGE_DUE + "|" + classId + "|" + id + "|" + NetUtil.DATE_FORMAT.format(newDate)); + for (ProofInfo p : remove) + client.sendMessage(NetUtil.REMOVE_PROOF + "|" + classId + "|" + id + "|" + p.getProofId()); + for (ProofInfo p : add) + client.sendMessage(NetUtil.ADD_PROOF + "|" + classId + "|" + id + "|" + p.getProofId()); + client.sendMessage(NetUtil.DONE); + String res = client.readMessage(); + if (!NetUtil.OK.equals(Client.checkError(res))) + throw new IOException(res); + Platform.runLater(() -> { + if (newName != null) + name.set(newName); + if (newDate != null) + dueDate.set(newDate.getTime()); + load(true); + }); + } catch (IOException e) { + e.printStackTrace(); + } finally { + client.disconnect(); + } + }).start(); + } + } catch (IOException e) { + logger.error("Failed to show assignment dialog", e); + } + } + private void addChildren(AssignmentInfo rootInfo, TreeItem rootItem) { if (rootInfo.getChildren() != null) { rootInfo.getChildren().sort(Comparator.naturalOrder()); @@ -195,6 +303,7 @@ private void loadInstructor(Client client) throws IOException { String name = URLDecoder.decode(split[1], "UTF-8"); String createdBy = URLDecoder.decode(split[2], "UTF-8"); long timestamp = NetUtil.DATE_FORMAT.parse(URLDecoder.decode(split[3], "UTF-8")).getTime(); + proofs.add(new ProofInfo(pid, name, createdBy, timestamp, true)); for (UserInfo info : users.values()) { ProofInfo proofInfo = new ProofInfo(pid, name, createdBy, timestamp, true); proofMap.computeIfAbsent(info.getUserId(), uid -> new HashMap<>()).put(pid, proofInfo); @@ -230,7 +339,7 @@ private void loadInstructor(Client client) throws IOException { } public String getName() { - return name; + return name.get(); } public TitledPane getPane() { diff --git a/client/src/edu/rpi/aris/gui/submit/AddAssignmentDialog.java b/client/src/edu/rpi/aris/gui/submit/AssignmentDialog.java similarity index 65% rename from client/src/edu/rpi/aris/gui/submit/AddAssignmentDialog.java rename to client/src/edu/rpi/aris/gui/submit/AssignmentDialog.java index d690633d..a1d36fa9 100644 --- a/client/src/edu/rpi/aris/gui/submit/AddAssignmentDialog.java +++ b/client/src/edu/rpi/aris/gui/submit/AssignmentDialog.java @@ -15,17 +15,18 @@ import org.apache.commons.lang3.tuple.Triple; import java.io.IOException; +import java.text.SimpleDateFormat; import java.time.LocalDateTime; -import java.util.Collection; -import java.util.List; -import java.util.Objects; +import java.time.ZoneId; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; -public class AddAssignmentDialog extends Dialog>> { +public class AssignmentDialog extends Dialog>> { private static final Pattern timePattern = Pattern.compile("(?i)(?1[0-2]|0?[1-9]):(?[0-5][0-9]) *?(?AM|PM)"); + private static final SimpleDateFormat timeFormat = new SimpleDateFormat("h:mm a"); private final ProofList availableProofs; @FXML private TextField nameField; @@ -36,12 +37,13 @@ public class AddAssignmentDialog extends Dialog list = proofBox.getChildren().stream().map(node -> (ProofInfo) ((ComboBox) ((HBox) node).getChildren().get(0)).getSelectionModel().getSelectedItem()).filter(Objects::nonNull).collect(Collectors.toList()); return new ImmutableTriple<>(name, date, list); }); } - private void addSelector() { + public AssignmentDialog(Window parent, ProofList availableProofs, String name, Date dueDate, Set proofs) throws IOException { + this(parent, availableProofs); + proofBox.getChildren().clear(); + for (ProofInfo info : proofs) + addSelector().getSelectionModel().select(info); + nameField.setText(name); + timeInput.setText(timeFormat.format(dueDate)); + this.dueDate.setValue(dueDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()); + edit = true; + } + + private ComboBox addSelector() { HBox box = new HBox(5); ComboBox combo = new ComboBox<>(); combo.setPromptText("Select Proof"); @@ -89,6 +106,19 @@ public void changed(ObservableValue observable, ProofInfo o Button delete = new Button("-"); delete.disableProperty().bind(Bindings.createBooleanBinding(() -> combo.getSelectionModel().getSelectedItem() == null, combo.getSelectionModel().selectedItemProperty())); delete.setOnAction(action -> { + if (edit) { + Alert alert = new Alert(Alert.AlertType.WARNING); + alert.initModality(Modality.WINDOW_MODAL); + alert.initOwner(getDialogPane().getScene().getWindow()); + alert.setTitle("Remove Proof?"); + alert.setHeaderText("Are you sure you want to remove this proof"); + alert.setContentText("This will also delete any student submissions\nfor this proof on this assignment"); + alert.getButtonTypes().setAll(ButtonType.NO, ButtonType.YES); + alert.getDialogPane().getScene().getWindow().sizeToScene(); + Optional result = alert.showAndWait(); + if (!result.isPresent() || result.get() != ButtonType.YES) + return; + } proofBox.getChildren().remove(box); getDialogPane().getScene().getWindow().sizeToScene(); }); @@ -96,6 +126,7 @@ public void changed(ObservableValue observable, ProofInfo o box.getChildren().addAll(combo, delete); proofBox.getChildren().add(box); getDialogPane().getScene().getWindow().sizeToScene(); + return combo; } @FXML @@ -103,5 +134,4 @@ private void initialize() { okBtn.disableProperty().bind(Bindings.createBooleanBinding(() -> !timePattern.matcher(timeInput.getText()).matches() || nameField.getText().length() == 0 || dueDate.getValue() == null || proofBox.getChildren().size() < 2, timeInput.textProperty(), nameField.textProperty(), dueDate.valueProperty(), proofBox.getChildren())); addSelector(); } - } diff --git a/client/src/edu/rpi/aris/gui/submit/AssignmentWindow.java b/client/src/edu/rpi/aris/gui/submit/AssignmentWindow.java index e974cf29..b03f7b32 100644 --- a/client/src/edu/rpi/aris/gui/submit/AssignmentWindow.java +++ b/client/src/edu/rpi/aris/gui/submit/AssignmentWindow.java @@ -178,7 +178,7 @@ private void initialize() { Bindings.bindContent(proofTable.getItems(), proofList.getProofs()); } - private void loadAssignments(Course newCourse, boolean reload) { + public void loadAssignments(Course newCourse, boolean reload) { Platform.runLater(() -> { assignments.getPanes().clear(); if (newCourse == null) @@ -458,7 +458,7 @@ private void refresh() { @FXML private void createAssignment() throws IOException { proofList.load(false); - AddAssignmentDialog dialog = new AddAssignmentDialog(stage, proofList); + AssignmentDialog dialog = new AssignmentDialog(stage, proofList); Optional>> result = dialog.showAndWait(); if (result.isPresent()) { Triple> r = result.get(); @@ -489,4 +489,12 @@ public void integrityCheckFailed(String filename) { alert.getDialogPane().setPrefWidth(500); alert.showAndWait(); } + + public Stage getStage() { + return stage; + } + + public ProofList getProofList() { + return proofList; + } } diff --git a/client/src/edu/rpi/aris/gui/submit/Course.java b/client/src/edu/rpi/aris/gui/submit/Course.java index e780eecf..ec640bdc 100644 --- a/client/src/edu/rpi/aris/gui/submit/Course.java +++ b/client/src/edu/rpi/aris/gui/submit/Course.java @@ -43,7 +43,7 @@ public void load(Runnable runnable, boolean reload) { try { Platform.runLater(() -> { try { - assignments.add(new Assignment(URLDecoder.decode(split[0], "UTF-8"), URLDecoder.decode(split[1], "UTF-8"), URLDecoder.decode(split[2], "UTF-8"), Integer.parseInt(split[3]), id)); + assignments.add(new Assignment(URLDecoder.decode(split[0], "UTF-8"), URLDecoder.decode(split[1], "UTF-8"), URLDecoder.decode(split[2], "UTF-8"), Integer.parseInt(split[3]), id, this)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } diff --git a/client/src/edu/rpi/aris/gui/submit/ProofInfo.java b/client/src/edu/rpi/aris/gui/submit/ProofInfo.java index dc061698..e033a3b5 100644 --- a/client/src/edu/rpi/aris/gui/submit/ProofInfo.java +++ b/client/src/edu/rpi/aris/gui/submit/ProofInfo.java @@ -77,6 +77,19 @@ public String toString() { return name; } + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ProofInfo)) + return false; + ProofInfo info = (ProofInfo) obj; + return info.proofId == proofId; + } + + @Override + public int hashCode() { + return proofId; + } + public GradingStatus getGradingStatus() { return gradingStatus; } diff --git a/libaris/res/edu/rpi/aris/VERSION b/libaris/res/edu/rpi/aris/VERSION index e4a35e8b..12a74d75 100644 --- a/libaris/res/edu/rpi/aris/VERSION +++ b/libaris/res/edu/rpi/aris/VERSION @@ -1 +1 @@ -0.0.38 +0.0.39 diff --git a/libaris/src/edu/rpi/aris/net/NetUtil.java b/libaris/src/edu/rpi/aris/net/NetUtil.java index b17cbbf2..491aca2e 100644 --- a/libaris/src/edu/rpi/aris/net/NetUtil.java +++ b/libaris/src/edu/rpi/aris/net/NetUtil.java @@ -60,6 +60,10 @@ public class NetUtil { public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static final String TOO_LARGE = "TOO_LARGE"; public static final String NO_DATA = "NO_DATA"; + public static final String RENAME = "RENAME"; + public static final String ADD_PROOF = "ADD_PROOF"; + public static final String REMOVE_PROOF = "REMOVE_PROOF"; + public static final String CHANGE_DUE = "CHANGE_DUE"; /** * Compares two version strings. diff --git a/packaging/deb/server/etc/aris.cfg b/packaging/deb/server/etc/aris.cfg index 545c36f1..faccd135 100644 --- a/packaging/deb/server/etc/aris.cfg +++ b/packaging/deb/server/etc/aris.cfg @@ -15,6 +15,9 @@ db-pass arispass # The private key for the above certificate. If this is not specified here of on the command line the server will run in self signing mode # key +# The domain name of the server. Note this is only required when the server is running in self signing mode +# domain + # The name of the postgres database for Aris to use # db-name aris diff --git a/server/src/edu/rpi/aris/net/server/ClientHandler.java b/server/src/edu/rpi/aris/net/server/ClientHandler.java index b4a4ad17..a9dd361c 100644 --- a/server/src/edu/rpi/aris/net/server/ClientHandler.java +++ b/server/src/edu/rpi/aris/net/server/ClientHandler.java @@ -630,93 +630,106 @@ private void deleteAssignment() throws IOException, SQLException { } private void updateAssignment() throws IOException, SQLException { - String[] str = in.readUTF().split("\\|"); if (!userType.equals(NetUtil.USER_INSTRUCTOR)) { sendMessage(NetUtil.UNAUTHORIZED); return; } - if (str.length != 4) { - sendMessage(NetUtil.INVALID); - return; - } - int aid, cid; - try { - cid = Integer.parseInt(str[1]); - aid = Integer.parseInt(str[2]); - } catch (NumberFormatException e) { - sendMessage(NetUtil.ERROR); - return; - } - try (Connection connection = dbManager.getConnection()) { - switch (str[0]) { - case "RENAME": - String name = URLDecoder.decode(str[3], "UTF-8"); - try (PreparedStatement statement = connection.prepareStatement("UPDATE assignment SET name = ? WHERE id = ? AND class_id = ?;")) { - statement.setString(1, name); - statement.setInt(2, aid); - statement.setInt(3, cid); - statement.executeUpdate(); - } - break; - case "ADD_PROOF": - int pid; - try { - pid = Integer.parseInt(str[3]); - } catch (NumberFormatException e) { - sendMessage(NetUtil.ERROR); - return; - } - try (PreparedStatement select = connection.prepareStatement("SELECT name, due_date, assigned_by FROM assignment WHERE id = ? AND class_id = ?;"); - PreparedStatement addProof = connection.prepareStatement("INSERT INTO assignment VALUES(?, ?, ?, ?, ?, ?);")) { - select.setInt(1, aid); - select.setInt(2, cid); - try (ResultSet rs = select.executeQuery()) { - if (!rs.next()) { - sendMessage(NetUtil.ERROR); - return; + boolean done = false; + while (!done) { + String[] str = in.readUTF().split("\\|"); + if (str.length == 1 && str[0].equals(NetUtil.DONE)) { + done = true; + continue; + } + if (str.length != 4) { + sendMessage(NetUtil.INVALID); + return; + } + int aid, cid; + try { + cid = Integer.parseInt(str[1]); + aid = Integer.parseInt(str[2]); + } catch (NumberFormatException e) { + sendMessage(NetUtil.ERROR); + return; + } + try (Connection connection = dbManager.getConnection()) { + switch (str[0]) { + case NetUtil.RENAME: + String name = URLDecoder.decode(str[3], "UTF-8"); + try (PreparedStatement statement = connection.prepareStatement("UPDATE assignment SET name = ? WHERE id = ? AND class_id = ?;")) { + statement.setString(1, name); + statement.setInt(2, aid); + statement.setInt(3, cid); + statement.executeUpdate(); + } + break; + case NetUtil.ADD_PROOF: + int pid; + try { + pid = Integer.parseInt(str[3]); + } catch (NumberFormatException e) { + sendMessage(NetUtil.ERROR); + return; + } + try (PreparedStatement select = connection.prepareStatement("SELECT name, due_date, assigned_by FROM assignment WHERE id = ? AND class_id = ?;"); + PreparedStatement addProof = connection.prepareStatement("INSERT INTO assignment VALUES(?, ?, ?, ?, ?, ?);")) { + select.setInt(1, aid); + select.setInt(2, cid); + try (ResultSet rs = select.executeQuery()) { + if (!rs.next()) { + sendMessage(NetUtil.ERROR); + return; + } + String n = rs.getString(1); + String due_date = rs.getString(2); + String assigned = rs.getString(3); + addProof.setInt(1, aid); + addProof.setInt(2, cid); + addProof.setInt(3, pid); + addProof.setString(4, n); + addProof.setString(5, due_date); + addProof.setString(6, assigned); + addProof.executeUpdate(); } - String n = rs.getString(1); - String due_date = rs.getString(2); - String assigned = rs.getString(3); - addProof.setInt(1, aid); - addProof.setInt(2, cid); - addProof.setInt(3, pid); - addProof.setString(4, n); - addProof.setString(5, due_date); - addProof.setString(6, assigned); - addProof.executeUpdate(); } - } - break; - case "REMOVE_PROOF": - try { - pid = Integer.parseInt(str[3]); - } catch (NumberFormatException e) { - sendMessage(NetUtil.ERROR); - return; - } - try (PreparedStatement removeAssignment = connection.prepareStatement("DELETE FROM assignment WHERE id = ? AND class_id = ? AND proof_id = ?;")) { - removeAssignment.setInt(1, aid); - removeAssignment.setInt(2, cid); - removeAssignment.setInt(3, pid); - removeAssignment.executeUpdate(); - } - break; - case "CHANGE_DUE": - long time; - try { - time = Long.parseLong(str[3]); - } catch (NumberFormatException e) { - sendMessage(NetUtil.ERROR); + break; + case NetUtil.REMOVE_PROOF: + try { + pid = Integer.parseInt(str[3]); + } catch (NumberFormatException e) { + sendMessage(NetUtil.ERROR); + return; + } + try (PreparedStatement removeAssignment = connection.prepareStatement("DELETE FROM assignment WHERE id = ? AND class_id = ? AND proof_id = ?;")) { + removeAssignment.setInt(1, aid); + removeAssignment.setInt(2, cid); + removeAssignment.setInt(3, pid); + removeAssignment.executeUpdate(); + } + break; + case NetUtil.CHANGE_DUE: + Date time; + try { + time = NetUtil.DATE_FORMAT.parse(str[3]); + } catch (ParseException e) { + sendMessage(NetUtil.ERROR); + return; + } + try (PreparedStatement statement = connection.prepareStatement("UPDATE assignment SET due_date = ? WHERE id = ? AND class_id = ?;")) { + statement.setTimestamp(1, new Timestamp(time.getTime())); + statement.setInt(2, aid); + statement.setInt(3, cid); + statement.executeUpdate(); + } + break; + case NetUtil.DONE: + done = true; + break; + default: + sendMessage(NetUtil.INVALID); return; - } - try (PreparedStatement statement = connection.prepareStatement("UPDATE assignment SET due_date = ? WHERE id = ? AND class_id = ?;")) { - statement.setString(1, NetUtil.DATE_FORMAT.format(new Date(time))); - statement.setInt(2, aid); - statement.setInt(3, cid); - statement.executeUpdate(); - } - break; + } } } sendMessage("OK");