Compare commits
8 Commits
0610-Timep
...
947f31f20e
Author | SHA1 | Date | |
---|---|---|---|
947f31f20e | |||
b12de1cd2e | |||
097cce14e8 | |||
646da71e8a | |||
46606a5afc | |||
b205c96f85 | |||
0ef383aa7f | |||
ea6420e234 |
@@ -16,12 +16,7 @@ application {
|
|||||||
mainClassName = "client.MainApplication"
|
mainClassName = "client.MainApplication"
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("com.jfoenix:jfoenix:9.0.10")
|
|
||||||
implementation(project(":data"))
|
implementation(project(":data"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
client/app/src/main/java/customUI/Button.java
Normal file
8
client/app/src/main/java/customUI/Button.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package customUI;
|
||||||
|
|
||||||
|
public class Button extends javafx.scene.control.Button {
|
||||||
|
|
||||||
|
public void setTextValue(String text){
|
||||||
|
super.setText(Converter.CONVERT_STR(text));
|
||||||
|
}
|
||||||
|
}
|
21
client/app/src/main/java/customUI/Converter.java
Normal file
21
client/app/src/main/java/customUI/Converter.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package customUI;
|
||||||
|
|
||||||
|
public class Converter {
|
||||||
|
/*
|
||||||
|
Ä, ä \u00c4, \u00e4
|
||||||
|
Ö, ö \u00d6, \u00f6
|
||||||
|
Ü, ü \u00dc, \u00fc
|
||||||
|
ß \u00df
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public static String CONVERT_STR(String str){
|
||||||
|
return str
|
||||||
|
.replace("ä", "\u00e4")
|
||||||
|
.replace("Ä", "\u00c4")
|
||||||
|
.replace("ö", "\u00f6")
|
||||||
|
.replace("Ö", "\u00d6")
|
||||||
|
.replace("ü", "\u00fc")
|
||||||
|
.replace("Ü", "\u00dc")
|
||||||
|
.replace("ß", "\u00df");
|
||||||
|
}
|
||||||
|
}
|
15
client/app/src/main/java/customUI/Label.java
Normal file
15
client/app/src/main/java/customUI/Label.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package customUI;
|
||||||
|
|
||||||
|
public class Label extends javafx.scene.control.Label {
|
||||||
|
public Label(String content){
|
||||||
|
super(Converter.CONVERT_STR(content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Label(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTextValue(String text){
|
||||||
|
super.setText(Converter.CONVERT_STR(text));
|
||||||
|
}
|
||||||
|
}
|
@@ -1,30 +1,24 @@
|
|||||||
package main;
|
package main;
|
||||||
|
|
||||||
import com.jfoenix.controls.JFXTimePicker;
|
|
||||||
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.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.GridPane;
|
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.util.StringConverter;
|
|
||||||
import javafx.util.converter.LocalTimeStringConverter;
|
|
||||||
import res.DataController;
|
import res.DataController;
|
||||||
import res.Event;
|
import res.Event;
|
||||||
|
|
||||||
import java.time.LocalTime;
|
|
||||||
import java.time.format.FormatStyle;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class CreateEventController {
|
public class CreateEventController {
|
||||||
|
|
||||||
@FXML
|
|
||||||
public GridPane mainGrid;
|
|
||||||
@FXML
|
@FXML
|
||||||
public DatePicker datePickerDate;
|
public DatePicker datePickerDate;
|
||||||
@FXML
|
@FXML
|
||||||
public TextField textName;
|
public TextField textName;
|
||||||
@FXML
|
@FXML
|
||||||
|
public TextField textStart;
|
||||||
|
@FXML
|
||||||
|
public TextField textEnd;
|
||||||
|
@FXML
|
||||||
public ComboBox<String> ComboBoxTyp;
|
public ComboBox<String> ComboBoxTyp;
|
||||||
@FXML
|
@FXML
|
||||||
public ComboBox<String> ComboBoxPriotity;
|
public ComboBox<String> ComboBoxPriotity;
|
||||||
@@ -34,10 +28,6 @@ public class CreateEventController {
|
|||||||
public CheckBox checkBoxIsPrivate;
|
public CheckBox checkBoxIsPrivate;
|
||||||
@FXML
|
@FXML
|
||||||
public Label labelError;
|
public Label labelError;
|
||||||
@FXML
|
|
||||||
public JFXTimePicker timeStart;
|
|
||||||
@FXML
|
|
||||||
public JFXTimePicker timeEnd;
|
|
||||||
|
|
||||||
|
|
||||||
public CreateEventController() {
|
public CreateEventController() {
|
||||||
@@ -45,22 +35,6 @@ public class CreateEventController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
|
||||||
StringConverter<LocalTime> defaultConverter = new LocalTimeStringConverter(FormatStyle.SHORT, Locale.GERMANY);
|
|
||||||
|
|
||||||
JFXTimePicker timePickerStart = new JFXTimePicker();
|
|
||||||
timeStart = timePickerStart;
|
|
||||||
timePickerStart.set24HourView(true);
|
|
||||||
timePickerStart.setConverter(defaultConverter);
|
|
||||||
timePickerStart.getStyleClass().add("timePicker");
|
|
||||||
mainGrid.add(timePickerStart, 1 , 3);
|
|
||||||
|
|
||||||
JFXTimePicker timePickerEnd = new JFXTimePicker();
|
|
||||||
timeEnd = timePickerEnd;
|
|
||||||
timePickerEnd.set24HourView(true);
|
|
||||||
timePickerEnd.setConverter(defaultConverter);
|
|
||||||
timePickerEnd.getStyleClass().add("timePicker");
|
|
||||||
mainGrid.add(timePickerEnd, 1 , 4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -76,8 +50,8 @@ public class CreateEventController {
|
|||||||
ComboBoxPriotity.getSelectionModel().getSelectedIndex(),
|
ComboBoxPriotity.getSelectionModel().getSelectedIndex(),
|
||||||
checkBoxIsFullDay.isSelected(),
|
checkBoxIsFullDay.isSelected(),
|
||||||
checkBoxIsPrivate.isSelected(),
|
checkBoxIsPrivate.isSelected(),
|
||||||
timeStart.getValue().toString(),
|
textStart.getText(),
|
||||||
timeEnd.getValue().toString(),
|
textEnd.getText(),
|
||||||
datePickerDate.getValue().atStartOfDay(),
|
datePickerDate.getValue().atStartOfDay(),
|
||||||
(int) DataController.USER_ID
|
(int) DataController.USER_ID
|
||||||
);
|
);
|
||||||
|
@@ -4,8 +4,8 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Button;
|
import customUI.Button;
|
||||||
import javafx.scene.control.Label;
|
import customUI.Label;
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
@@ -28,7 +28,7 @@ public class MainController {
|
|||||||
private GridPane calendarGrid;
|
private GridPane calendarGrid;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label LabelMonth;
|
private javafx.scene.control.Label LabelMonth;
|
||||||
|
|
||||||
private final String[] dayNames = {"Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"};
|
private final String[] dayNames = {"Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"};
|
||||||
private final Label[] dayLabel = new Label[7];
|
private final Label[] dayLabel = new Label[7];
|
||||||
@@ -108,7 +108,7 @@ public class MainController {
|
|||||||
private void createWeek() {
|
private void createWeek() {
|
||||||
for (int i = 0; i < 7; i++) {
|
for (int i = 0; i < 7; i++) {
|
||||||
Label label = new Label();
|
Label label = new Label();
|
||||||
label.setText(dayNames[i]);
|
label.setTextValue(dayNames[i]);
|
||||||
label.setMaxHeight(Double.MAX_VALUE);
|
label.setMaxHeight(Double.MAX_VALUE);
|
||||||
label.setMaxWidth(Double.MAX_VALUE);
|
label.setMaxWidth(Double.MAX_VALUE);
|
||||||
label.getStyleClass().add("labelDays");
|
label.getStyleClass().add("labelDays");
|
||||||
@@ -140,31 +140,14 @@ public class MainController {
|
|||||||
HBox btnHBox = new HBox();
|
HBox btnHBox = new HBox();
|
||||||
btnHBox.setAlignment(Pos.BOTTOM_RIGHT);
|
btnHBox.setAlignment(Pos.BOTTOM_RIGHT);
|
||||||
Button deleteBtn = new Button();
|
Button deleteBtn = new Button();
|
||||||
deleteBtn.setText(" X ");
|
deleteBtn.setTextValue(" X ");
|
||||||
deleteBtn.setOnAction(e -> {
|
deleteBtn.setOnAction(e -> {
|
||||||
DataController dataController = new DataController();
|
DataController dataController = new DataController();
|
||||||
dataController.deleteEvent(event.getId());
|
dataController.deleteEvent(event.getId());
|
||||||
updateEvents();
|
updateEvents();
|
||||||
});
|
});
|
||||||
Button editBtn = new Button();
|
Button editBtn = new Button();
|
||||||
editBtn.setText("edit");
|
editBtn.setTextValue("edit");
|
||||||
editBtn.setOnAction(event1 -> {
|
|
||||||
try {
|
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(
|
|
||||||
MainApplication.class.getResource("edit-event.fxml"));
|
|
||||||
Scene scene = new Scene(fxmlLoader.load(), 650, 650);
|
|
||||||
scene.getStylesheets().add(Objects.requireNonNull(
|
|
||||||
MainApplication.class.getResource("create-event.css")).toExternalForm());
|
|
||||||
Stage stage = new Stage();
|
|
||||||
stage.setTitle("Termin bearbeiten");
|
|
||||||
stage.setScene(scene);
|
|
||||||
stage.initModality(Modality.APPLICATION_MODAL);
|
|
||||||
stage.setResizable(false);
|
|
||||||
stage.showAndWait();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnHBox.getChildren().add(editBtn);
|
btnHBox.getChildren().add(editBtn);
|
||||||
btnHBox.getChildren().add(deleteBtn);
|
btnHBox.getChildren().add(deleteBtn);
|
||||||
vBox.getChildren().add(btnHBox);
|
vBox.getChildren().add(btnHBox);
|
||||||
@@ -182,12 +165,6 @@ public class MainController {
|
|||||||
Label typeLabel = new Label("Wer: " + event.getOwnerName());
|
Label typeLabel = new Label("Wer: " + event.getOwnerName());
|
||||||
vBox.getChildren().add(typeLabel);
|
vBox.getChildren().add(typeLabel);
|
||||||
|
|
||||||
/*
|
|
||||||
Ä, ä \u00c4, \u00e4
|
|
||||||
Ö, ö \u00d6, \u00f6
|
|
||||||
Ü, ü \u00dc, \u00fc
|
|
||||||
ß \u00df
|
|
||||||
*/
|
|
||||||
Label prioLabel = new Label("Priorit\u00e4t: " + event.getPriority());
|
Label prioLabel = new Label("Priorit\u00e4t: " + event.getPriority());
|
||||||
vBox.getChildren().add(prioLabel);
|
vBox.getChildren().add(prioLabel);
|
||||||
|
|
||||||
@@ -226,7 +203,7 @@ public class MainController {
|
|||||||
weekStartDateTime = now.plusDays(weekOffset * 7L - dayOfWeek + 1);
|
weekStartDateTime = now.plusDays(weekOffset * 7L - dayOfWeek + 1);
|
||||||
|
|
||||||
for (int i = 0; i < 7; i++) {
|
for (int i = 0; i < 7; i++) {
|
||||||
dayLabel[i].setText(dayFormatter.format(weekStartDateTime.plusDays(i)));
|
dayLabel[i].setTextValue(dayFormatter.format(weekStartDateTime.plusDays(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
LabelMonth.setText(dateFormatter.format(weekStartDateTime));
|
LabelMonth.setText(dateFormatter.format(weekStartDateTime));
|
||||||
|
@@ -43,9 +43,4 @@ Label{
|
|||||||
-fx-max-height: 400px;
|
-fx-max-height: 400px;
|
||||||
-fx-wrap-text: true;
|
-fx-wrap-text: true;
|
||||||
-fx-font-size: 16px;
|
-fx-font-size: 16px;
|
||||||
}
|
|
||||||
|
|
||||||
.timePicker{
|
|
||||||
-fx-background-color: white;
|
|
||||||
-fx-max-width: 150px;
|
|
||||||
}
|
}
|
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<?import javafx.collections.FXCollections?>
|
<?import javafx.collections.FXCollections?>
|
||||||
<?import java.lang.String?>
|
<?import java.lang.String?>
|
||||||
<GridPane fx:id="mainGrid" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1"
|
<GridPane xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
fx:controller="main.CreateEventController">
|
fx:controller="main.CreateEventController">
|
||||||
|
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
@@ -39,6 +39,8 @@
|
|||||||
|
|
||||||
<DatePicker fx:id="datePickerDate" GridPane.columnIndex="1" GridPane.rowIndex="1" maxWidth="400" minWidth="400"/>
|
<DatePicker fx:id="datePickerDate" GridPane.columnIndex="1" GridPane.rowIndex="1" maxWidth="400" minWidth="400"/>
|
||||||
<TextField fx:id="textName" GridPane.columnIndex="1" GridPane.rowIndex="2" maxWidth="400" minWidth="400"/>
|
<TextField fx:id="textName" GridPane.columnIndex="1" GridPane.rowIndex="2" maxWidth="400" minWidth="400"/>
|
||||||
|
<TextField fx:id="textStart" GridPane.columnIndex="1" GridPane.rowIndex="3" maxWidth="400" minWidth="400"/>
|
||||||
|
<TextField fx:id="textEnd" GridPane.columnIndex="1" GridPane.rowIndex="4" maxWidth="400" minWidth="400"/>
|
||||||
<ComboBox fx:id="ComboBoxTyp" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="400" minWidth="400"/>
|
<ComboBox fx:id="ComboBoxTyp" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="400" minWidth="400"/>
|
||||||
<ComboBox fx:id="ComboBoxPriotity" GridPane.columnIndex="1" GridPane.rowIndex="6" maxWidth="200" minWidth="200">
|
<ComboBox fx:id="ComboBoxPriotity" GridPane.columnIndex="1" GridPane.rowIndex="6" maxWidth="200" minWidth="200">
|
||||||
<items>
|
<items>
|
||||||
|
46
client/app/src/main/resources/main/edit-event.css
Normal file
46
client/app/src/main/resources/main/edit-event.css
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
GridPane{
|
||||||
|
-fx-background-color: #3E415F;
|
||||||
|
-fx-padding: 20px;
|
||||||
|
-fx-font-size: 20px;
|
||||||
|
-fx-font-family: Segoe UI;
|
||||||
|
|
||||||
|
-fx-border-insets: 1;
|
||||||
|
-fx-border-color: #B0B0B0;
|
||||||
|
-fx-border-style: solid;
|
||||||
|
-fx-border-width: 2;
|
||||||
|
-fx-effect: dropshadow(three-pass-box, rgba(100, 100, 100, 1), 24, 0.5, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Label{
|
||||||
|
-fx-text-fill: white;
|
||||||
|
-fx-max-width: 150px;
|
||||||
|
-fx-min-width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mainLabel{
|
||||||
|
-fx-background-color: #8D99AE;
|
||||||
|
-fx-padding: 10px;
|
||||||
|
-fx-max-width: 200px;
|
||||||
|
-fx-min-width: 200px;
|
||||||
|
-fx-font-weight: bold;
|
||||||
|
-fx-alignment: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inputField{
|
||||||
|
-fx-padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mainButton{
|
||||||
|
-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;
|
||||||
|
}
|
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
<?import javafx.collections.FXCollections?>
|
<?import javafx.collections.FXCollections?>
|
||||||
<?import java.lang.String?>
|
<?import java.lang.String?>
|
||||||
|
<GridPane xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
<GridPane fx:id="mainGrid" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1"
|
|
||||||
fx:controller="main.CreateEventController">
|
fx:controller="main.CreateEventController">
|
||||||
|
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
@@ -39,6 +39,8 @@
|
|||||||
|
|
||||||
<DatePicker fx:id="datePickerDate" GridPane.columnIndex="1" GridPane.rowIndex="1" maxWidth="400" minWidth="400"/>
|
<DatePicker fx:id="datePickerDate" GridPane.columnIndex="1" GridPane.rowIndex="1" maxWidth="400" minWidth="400"/>
|
||||||
<TextField fx:id="textName" GridPane.columnIndex="1" GridPane.rowIndex="2" maxWidth="400" minWidth="400"/>
|
<TextField fx:id="textName" GridPane.columnIndex="1" GridPane.rowIndex="2" maxWidth="400" minWidth="400"/>
|
||||||
|
<TextField fx:id="textStart" GridPane.columnIndex="1" GridPane.rowIndex="3" maxWidth="400" minWidth="400"/>
|
||||||
|
<TextField fx:id="textEnd" GridPane.columnIndex="1" GridPane.rowIndex="4" maxWidth="400" minWidth="400"/>
|
||||||
<ComboBox fx:id="ComboBoxTyp" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="400" minWidth="400"/>
|
<ComboBox fx:id="ComboBoxTyp" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="400" minWidth="400"/>
|
||||||
<ComboBox fx:id="ComboBoxPriotity" GridPane.columnIndex="1" GridPane.rowIndex="6" maxWidth="200" minWidth="200">
|
<ComboBox fx:id="ComboBoxPriotity" GridPane.columnIndex="1" GridPane.rowIndex="6" maxWidth="200" minWidth="200">
|
||||||
<items>
|
<items>
|
||||||
|
27
client/data/src/main/java/helper/Tuple.java
Normal file
27
client/data/src/main/java/helper/Tuple.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package helper;
|
||||||
|
|
||||||
|
public class Tuple<X, Y> {
|
||||||
|
public final X key;
|
||||||
|
public final Y value;
|
||||||
|
|
||||||
|
public Tuple(X key, Y value) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public X getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Y getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Tuple{" +
|
||||||
|
"key=" + key +
|
||||||
|
", value=" + value +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@@ -2,6 +2,7 @@ package res;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import helper.Tuple;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -22,6 +23,7 @@ public class DataController {
|
|||||||
|
|
||||||
private static final String LOGIN_ENDPOINT = "http://localhost:8080/user/login";
|
private static final String LOGIN_ENDPOINT = "http://localhost:8080/user/login";
|
||||||
private static final String ALL_USERS_ENDPOINT = "http://localhost:8080/user/all";
|
private static final String ALL_USERS_ENDPOINT = "http://localhost:8080/user/all";
|
||||||
|
private static final String HEADER_TEST_ENDPOINT = "http://localhost:8080/vpr/header-test";
|
||||||
|
|
||||||
private final HttpRequest httpRequest;
|
private final HttpRequest httpRequest;
|
||||||
|
|
||||||
@@ -31,21 +33,34 @@ public class DataController {
|
|||||||
|
|
||||||
public boolean login(String username, String password) {
|
public boolean login(String username, String password) {
|
||||||
try {
|
try {
|
||||||
USER_ID = Long.parseLong(httpRequest.sendPostRequest(
|
Tuple<Integer, String> response = httpRequest.sendPostRequest(
|
||||||
LOGIN_ENDPOINT,
|
LOGIN_ENDPOINT,
|
||||||
"login=" + username
|
"login=" + username
|
||||||
+ "&password=" + password
|
+ "&password=" + password,
|
||||||
));
|
false
|
||||||
|
);
|
||||||
|
String[] data = response.getValue().split("\\s+");
|
||||||
|
|
||||||
|
USER_ID = Long.parseLong(data[1]);
|
||||||
|
HttpRequest.TOKEN = data[0];
|
||||||
|
|
||||||
|
Tuple<Integer, String> auth = httpRequest.sendPostRequest(
|
||||||
|
HEADER_TEST_ENDPOINT,
|
||||||
|
"",
|
||||||
|
true
|
||||||
|
);
|
||||||
|
System.out.println("auth " + auth);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return USER_ID >= 0;
|
return USER_ID >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createEvent(Event event) {
|
public void createEvent(Event event) {
|
||||||
try {
|
try {
|
||||||
System.out.println(httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam()));
|
System.out.println(httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam(), true));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Es konnte keine Verbindung mit dem Server hergestellt werden.");
|
throw new RuntimeException("Es konnte keine Verbindung mit dem Server hergestellt werden.");
|
||||||
}
|
}
|
||||||
@@ -53,7 +68,7 @@ public class DataController {
|
|||||||
|
|
||||||
public void deleteEvent(int eventId) {
|
public void deleteEvent(int eventId) {
|
||||||
try {
|
try {
|
||||||
System.out.println(httpRequest.sendPostRequest(DELETE_EVENT_ENDPOINT, "eventId=" + eventId));
|
System.out.println(httpRequest.sendPostRequest(DELETE_EVENT_ENDPOINT, "eventId=" + eventId, true));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -63,11 +78,11 @@ public class DataController {
|
|||||||
ArrayList<Event> eventList = new ArrayList<>();
|
ArrayList<Event> eventList = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String jsonResponse = httpRequest.sendPostRequest(ALL_EVENTS_ENDPOINT, "userId=" + USER_ID);
|
Tuple<Integer, String> response = httpRequest.sendPostRequest(ALL_EVENTS_ENDPOINT, "userId=" + USER_ID, true);
|
||||||
|
String jsonResponse = response.getValue();
|
||||||
System.out.println(jsonResponse);
|
System.out.println(jsonResponse);
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
//String json = "{ \"color\" : \"Black\", \"type\" : \"BMW\" }";
|
|
||||||
|
|
||||||
for (Object obj : objectMapper.readValue(jsonResponse, Object[].class)) {
|
for (Object obj : objectMapper.readValue(jsonResponse, Object[].class)) {
|
||||||
ArrayList<Object> list = new ArrayList<>();
|
ArrayList<Object> list = new ArrayList<>();
|
||||||
@@ -107,7 +122,6 @@ public class DataController {
|
|||||||
|
|
||||||
// Parse JSON
|
// Parse JSON
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
//String json = "{ \"color\" : \"Black\", \"type\" : \"BMW\" }";
|
|
||||||
|
|
||||||
return objectMapper.readValue(jsonString, Event[].class);
|
return objectMapper.readValue(jsonString, Event[].class);
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@ package res;
|
|||||||
|
|
||||||
import com.sun.jdi.event.StepEvent;
|
import com.sun.jdi.event.StepEvent;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -70,10 +71,30 @@ public class Event {
|
|||||||
if(name.length() < 3){
|
if(name.length() < 3){
|
||||||
throw new IllegalArgumentException("Der Name muss eine L\u00e4nge von 3 haben.");
|
throw new IllegalArgumentException("Der Name muss eine L\u00e4nge von 3 haben.");
|
||||||
}
|
}
|
||||||
Pattern pattern = Pattern.compile("[A-Za-zÄÖÜäöü0-9 =!?+*/$%€.:,;_<>()-]*");
|
Pattern pattern = Pattern.compile("[A-Za-z\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df0-9 =!?+*/$.:,;_<>()-]*");
|
||||||
Matcher matcher = pattern.matcher(name);
|
Matcher matcher = pattern.matcher(name);
|
||||||
if(!matcher.matches()){
|
if(!matcher.matches()){
|
||||||
throw new IllegalArgumentException("Der Name darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: =!?+*/$%€.:,;_ <>()-");
|
System.out.println(name);
|
||||||
|
|
||||||
|
byte[] bytes = name.getBytes(StandardCharsets.UTF_16);
|
||||||
|
|
||||||
|
String utf8EncodedString = new String(bytes, StandardCharsets.UTF_16);
|
||||||
|
System.out.println(utf8EncodedString);
|
||||||
|
|
||||||
|
for (char c : (name).toCharArray()) {
|
||||||
|
System.out.print(c + " " + (int)c + ", ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
for (char c : (name).toCharArray()) {
|
||||||
|
System.out.print(c + " " + (int)c + ", ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
for (char c : ("TäöüÄÖÜ").toCharArray()) {
|
||||||
|
System.out.print(c + " " + (int)c + ", ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("Der Name darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: \u00e4\u00f6\u00fc \u00c4\u00d6\u00dc \u00df =!?+*/$.:,;_ <>()-");
|
||||||
}
|
}
|
||||||
if(priority < 0){
|
if(priority < 0){
|
||||||
throw new IllegalArgumentException("Bitte eine Priorit\u00e4t w\u00e4hlen.");
|
throw new IllegalArgumentException("Bitte eine Priorit\u00e4t w\u00e4hlen.");
|
||||||
@@ -106,7 +127,7 @@ public class Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = convertToASCII(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPriority() {
|
public int getPriority() {
|
||||||
@@ -192,4 +213,9 @@ public class Event {
|
|||||||
"&isFullDay=" + isFullDay() +
|
"&isFullDay=" + isFullDay() +
|
||||||
"&isPrivate=" + isPrivate();
|
"&isPrivate=" + isPrivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String convertToASCII(String s){
|
||||||
|
byte[] germanBytes = s.getBytes();
|
||||||
|
return new String(germanBytes, StandardCharsets.US_ASCII);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
package res;
|
package res;
|
||||||
|
|
||||||
|
import helper.Tuple;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@@ -9,10 +11,25 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class HttpRequest {
|
public class HttpRequest {
|
||||||
public String sendPostRequest(String urlString, String urlParameters) throws Exception {
|
public static String TOKEN = "";
|
||||||
|
|
||||||
|
public Tuple<Integer, String> sendPostRequest(String urlString, String urlParameters, boolean sendAuth) throws Exception {
|
||||||
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
|
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
|
||||||
int postDataLength = postData.length;
|
int postDataLength = postData.length;
|
||||||
|
|
||||||
|
/*
|
||||||
|
URL url = new URL("http://test.de:8080/event/add");
|
||||||
|
HttpURLConnection http = (HttpURLConnection)url.openConnection();
|
||||||
|
http.setRequestMethod("POST");
|
||||||
|
http.setDoOutput(true);
|
||||||
|
http.setRequestProperty("Accept", "application/json");
|
||||||
|
http.setRequestProperty("Authorization", "Bearer {token}");
|
||||||
|
http.setRequestProperty("Content-Type", "");
|
||||||
|
http.setRequestProperty("Content-Length", "0");
|
||||||
|
|
||||||
|
System.out.println(http.getResponseCode() + " " + http.getResponseMessage());
|
||||||
|
http.disconnect();
|
||||||
|
*/
|
||||||
URL url = new URL(urlString);
|
URL url = new URL(urlString);
|
||||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||||
|
|
||||||
@@ -23,27 +40,35 @@ public class HttpRequest {
|
|||||||
con.setRequestProperty("charset", "utf-8");
|
con.setRequestProperty("charset", "utf-8");
|
||||||
con.setRequestProperty("Content-Length", Integer.toString(postDataLength));
|
con.setRequestProperty("Content-Length", Integer.toString(postDataLength));
|
||||||
con.setUseCaches(false);
|
con.setUseCaches(false);
|
||||||
|
|
||||||
|
if(sendAuth){
|
||||||
|
con.setRequestProperty("Accept", "application/json");
|
||||||
|
con.setRequestProperty("Authorization", "Bearer " + TOKEN);
|
||||||
|
}
|
||||||
|
|
||||||
try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
|
try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
|
||||||
wr.write(postData);
|
wr.write(postData);
|
||||||
}
|
}
|
||||||
|
|
||||||
int status = con.getResponseCode();
|
int status = con.getResponseCode();
|
||||||
if (status == 200) {
|
String inputLine;
|
||||||
BufferedReader in = new BufferedReader(
|
StringBuilder content = new StringBuilder();
|
||||||
new InputStreamReader(con.getInputStream()));
|
BufferedReader in;
|
||||||
String inputLine;
|
|
||||||
StringBuilder content = new StringBuilder();
|
|
||||||
while ((inputLine = in.readLine()) != null) {
|
|
||||||
content.append(inputLine);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
|
|
||||||
con.disconnect();
|
if (status == 200) {
|
||||||
return content.toString();
|
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
} else {
|
} else {
|
||||||
con.disconnect();
|
in = new BufferedReader(new InputStreamReader(con.getErrorStream()));
|
||||||
throw new Exception("Status: " + status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while ((inputLine = in.readLine()) != null) {
|
||||||
|
content.append(inputLine);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
con.disconnect();
|
||||||
|
|
||||||
|
return new Tuple<>(status, content.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sendGetRequest(String urlString) throws Exception {
|
public String sendGetRequest(String urlString) throws Exception {
|
||||||
|
Reference in New Issue
Block a user