Added input validation for creating events
This commit is contained in:
parent
0296333733
commit
d081a88dcd
@ -3,10 +3,7 @@ package main;
|
|||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.CheckBox;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.ComboBox;
|
|
||||||
import javafx.scene.control.DatePicker;
|
|
||||||
import javafx.scene.control.TextField;
|
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import res.DataController;
|
import res.DataController;
|
||||||
import res.Event;
|
import res.Event;
|
||||||
@ -29,16 +26,25 @@ public class CreateEventController {
|
|||||||
public CheckBox checkBoxIsFullDay;
|
public CheckBox checkBoxIsFullDay;
|
||||||
@FXML
|
@FXML
|
||||||
public CheckBox checkBoxIsPrivate;
|
public CheckBox checkBoxIsPrivate;
|
||||||
|
@FXML
|
||||||
|
public Label labelError;
|
||||||
|
|
||||||
|
|
||||||
public CreateEventController(){}
|
|
||||||
|
public CreateEventController() {
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize(){}
|
public void initialize() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void createBtnClick(ActionEvent actionEvent){
|
protected void createBtnClick(ActionEvent actionEvent) {
|
||||||
|
try {
|
||||||
|
if(datePickerDate.getValue() == null){
|
||||||
|
throw new IllegalArgumentException("Bitte w\u00e4hle ein Datum aus");
|
||||||
|
}
|
||||||
|
|
||||||
Event event = new Event(
|
Event event = new Event(
|
||||||
textName.getText(),
|
textName.getText(),
|
||||||
@ -58,10 +64,13 @@ public class CreateEventController {
|
|||||||
|
|
||||||
Stage stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
|
Stage stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
|
||||||
stage.close();
|
stage.close();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
labelError.setText(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void abortBtnClick(ActionEvent event){
|
protected void abortBtnClick(ActionEvent event) {
|
||||||
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
|
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
|
||||||
stage.close();
|
stage.close();
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ public class MainController {
|
|||||||
protected void onAddBtnClick() {
|
protected void onAddBtnClick() {
|
||||||
try {
|
try {
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("create-event.fxml"));
|
FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("create-event.fxml"));
|
||||||
Scene scene = new Scene(fxmlLoader.load(), 650, 500);
|
Scene scene = new Scene(fxmlLoader.load(), 650, 650);
|
||||||
scene.getStylesheets().add(Objects.requireNonNull(MainApplication.class.getResource("create-event.css")).toExternalForm());
|
scene.getStylesheets().add(Objects.requireNonNull(MainApplication.class.getResource("create-event.css")).toExternalForm());
|
||||||
Stage stage = new Stage();
|
Stage stage = new Stage();
|
||||||
stage.setTitle("Termin erstellen");
|
stage.setTitle("Termin erstellen");
|
||||||
|
@ -33,3 +33,14 @@ Label{
|
|||||||
.mainButton{
|
.mainButton{
|
||||||
-fx-font-weight: bold;
|
-fx-font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#labelError{
|
||||||
|
-fx-font-weight: bold;
|
||||||
|
-fx-max-width: 1000px;
|
||||||
|
-fx-text-fill: #ff5555;
|
||||||
|
-fx-padding: 16px;
|
||||||
|
-fx-min-height: 140px;
|
||||||
|
-fx-max-height: 400px;
|
||||||
|
-fx-wrap-text: true;
|
||||||
|
-fx-font-size: 16px;
|
||||||
|
}
|
@ -22,6 +22,7 @@
|
|||||||
<RowConstraints vgrow="ALWAYS" />
|
<RowConstraints vgrow="ALWAYS" />
|
||||||
<RowConstraints vgrow="ALWAYS" />
|
<RowConstraints vgrow="ALWAYS" />
|
||||||
<RowConstraints vgrow="ALWAYS" />
|
<RowConstraints vgrow="ALWAYS" />
|
||||||
|
<RowConstraints vgrow="ALWAYS" />
|
||||||
</rowConstraints>
|
</rowConstraints>
|
||||||
|
|
||||||
<Label styleClass="mainLabel">Termin anlegen</Label>
|
<Label styleClass="mainLabel">Termin anlegen</Label>
|
||||||
@ -51,8 +52,9 @@
|
|||||||
</ComboBox>
|
</ComboBox>
|
||||||
<CheckBox fx:id="checkBoxIsFullDay" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
|
<CheckBox fx:id="checkBoxIsFullDay" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
|
||||||
<CheckBox fx:id="checkBoxIsPrivate" GridPane.columnIndex="1" GridPane.rowIndex="8"/>
|
<CheckBox fx:id="checkBoxIsPrivate" GridPane.columnIndex="1" GridPane.rowIndex="8"/>
|
||||||
|
<Label fx:id="labelError" GridPane.columnIndex="1" GridPane.rowIndex="9"/>
|
||||||
|
|
||||||
<HBox GridPane.columnIndex="1" GridPane.rowIndex="9" GridPane.columnSpan="2" alignment="CENTER_RIGHT">
|
<HBox GridPane.columnIndex="1" GridPane.rowIndex="10" GridPane.columnSpan="2" alignment="CENTER_RIGHT">
|
||||||
<Button onAction="#abortBtnClick" maxWidth="150" minWidth="150" >Abbrechen</Button>
|
<Button onAction="#abortBtnClick" maxWidth="150" minWidth="150" >Abbrechen</Button>
|
||||||
<Button styleClass="mainButton" onAction="#createBtnClick" maxWidth="150" minWidth="150">Anlegen</Button>
|
<Button styleClass="mainButton" onAction="#createBtnClick" maxWidth="150" minWidth="150">Anlegen</Button>
|
||||||
</HBox>
|
</HBox>
|
||||||
|
@ -29,7 +29,7 @@ public class DataController {
|
|||||||
try {
|
try {
|
||||||
System.out.println(httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam()));
|
System.out.println(httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException("Es konnte keine Verbindung mit dem Server hergestellt werden.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,9 +2,14 @@ package res;
|
|||||||
|
|
||||||
import com.sun.jdi.event.StepEvent;
|
import com.sun.jdi.event.StepEvent;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.regex.PatternSyntaxException;
|
||||||
|
|
||||||
public class Event {
|
public class Event {
|
||||||
|
|
||||||
@ -61,7 +66,23 @@ public class Event {
|
|||||||
String end,
|
String end,
|
||||||
LocalDateTime date,
|
LocalDateTime date,
|
||||||
int ownerId
|
int ownerId
|
||||||
) {
|
) throws IllegalArgumentException{
|
||||||
|
if(name.length() < 3){
|
||||||
|
throw new IllegalArgumentException("Der Name muss eine L\u00e4nge von 3 haben.");
|
||||||
|
}
|
||||||
|
Pattern pattern = Pattern.compile("[A-Za-zÄÖÜäöü0-9 =!?+*/$%€.:,;_<>()-]*");
|
||||||
|
Matcher matcher = pattern.matcher(name);
|
||||||
|
if(!matcher.matches()){
|
||||||
|
throw new IllegalArgumentException("Der Name Darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: =!?+*/$%€.:,;_ <>()-");
|
||||||
|
}
|
||||||
|
if(priority < 0){
|
||||||
|
throw new IllegalArgumentException("Bitte eine Priorit\u00e4t w\u00e4hlen.");
|
||||||
|
}
|
||||||
|
LocalDateTime today = LocalDateTime.now().toLocalDate().atStartOfDay();
|
||||||
|
if(Duration.between(today, date).isNegative()){
|
||||||
|
throw new IllegalArgumentException("Das Datum muss in der Zukunft liegen.");
|
||||||
|
}
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
this.isFullDay = isFullDay;
|
this.isFullDay = isFullDay;
|
||||||
|
Loading…
Reference in New Issue
Block a user