From 071bc85d8a3593a2de8b1e16091428a77bbe6c68 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Sun, 17 Jun 2018 12:07:00 +0200 Subject: Separate validation errors from exceptions w.r.t logging, alert [#25963] --- .../controller/CreateOperationController.java | 50 ++++++++++++---------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'src/main/java/at/ac') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateOperationController.java index 81437f5..8cebeab 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateOperationController.java @@ -164,14 +164,12 @@ public class CreateOperationController { fpVehicles.getChildren().add(controller.getRootElement()); } - } catch (ServiceException | IOException | InvalidOperationException e) { + } catch (ServiceException | IOException e) { LOG.error("Exception in updateList(). ", e); - - Alert alert = new Alert(Alert.AlertType.ERROR); - alert.setTitle("Fehler"); - alert.setHeaderText("Fehler!"); - alert.setContentText(e.getMessage()); - alert.showAndWait(); + showAlert(AlertType.ERROR, "Fehler", e.getMessage()); + } catch (InvalidOperationException e) { + LOG.debug("Validation error in updateList(). ", e); + showAlert(AlertType.ERROR, "Validierungsfehler", e.getMessage()); } try { lvActiveOperations.setItems( @@ -179,11 +177,10 @@ public class CreateOperationController { operationService.list(EnumSet.of(Status.ACTIVE)))); } catch (ServiceException e) { LOG.error("ServiceException in updateList(). ", e); - Alert alert = new Alert(Alert.AlertType.ERROR); - alert.setTitle("Fehler - Einsätze"); - alert.setHeaderText("Beim Holen der aktiven Einsätze ist ein Fehler aufgetreten."); - alert.setContentText(e.getMessage()); - alert.showAndWait(); + showAlert( + AlertType.ERROR, + "Fehler", + "Beim Holen der aktiven Einsätze ist ein Fehler aufgetreten"); } } @@ -276,20 +273,19 @@ public class CreateOperationController { .build(); try { operationService.add(operation); - } catch (ServiceException | InvalidOperationException e) { + } catch (ServiceException e) { LOG.error("Exception in createOperationClicked(). ", e); - Alert alert = new Alert(Alert.AlertType.ERROR); - alert.setTitle("Fehler"); - alert.setHeaderText("Fehler!"); - alert.setContentText(e.getMessage()); - alert.showAndWait(); + showAlert(AlertType.ERROR, "Fehler", e.getMessage()); + return; + } catch (InvalidOperationException e) { + LOG.debug("Validation error in createOperationClicked(). ", e); + showAlert(AlertType.ERROR, "Validierungsfehler", e.getMessage()); return; } - Alert alert = new Alert(AlertType.CONFIRMATION); - alert.setTitle("Erfolg"); - alert.setHeaderText("Erfolgreich gespeichert"); - alert.setContentText("Der Einsatz wurde erfolgreich gespeichert."); - alert.showAndWait(); + showAlert( + AlertType.CONFIRMATION, + "Erfolgreich gespeichert", + "Der Einsatz wurde erfolgreich gespeichert."); updateList(); lblChosenVehicles.setText("keine ausgewählt"); txtAddress.setText(""); @@ -298,6 +294,14 @@ public class CreateOperationController { chosenVehicles = new LinkedList<>(); } + private void showAlert(AlertType alertType, String title, String content) { + Alert alert = new Alert(alertType); + alert.setTitle(title); + alert.setHeaderText(title); + alert.setContentText(content); + alert.showAndWait(); + } + public void onRegistrationLinkClicked(ActionEvent actionEvent) { LOG.debug("Hyperlink \"Anmeldungen\" clicked."); openRegistrationWindow(); -- cgit v1.2.3-70-g09d2