Compare commits
3 Commits
Update_cre
...
947f31f20e
Author | SHA1 | Date | |
---|---|---|---|
947f31f20e | |||
b12de1cd2e | |||
097cce14e8 |
@@ -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"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,30 +1,26 @@
|
|||||||
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;
|
||||||
|
@FXML
|
||||||
public ComboBox<String> ComboBoxPriotity;
|
public ComboBox<String> ComboBoxPriotity;
|
||||||
@FXML
|
@FXML
|
||||||
public CheckBox checkBoxIsFullDay;
|
public CheckBox checkBoxIsFullDay;
|
||||||
@@ -32,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() {
|
||||||
@@ -43,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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -74,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
|
||||||
);
|
);
|
||||||
|
@@ -148,23 +148,6 @@ public class MainController {
|
|||||||
});
|
});
|
||||||
Button editBtn = new Button();
|
Button editBtn = new Button();
|
||||||
editBtn.setTextValue("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);
|
||||||
|
@@ -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: 200px;
|
|
||||||
}
|
}
|
@@ -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>
|
||||||
@@ -23,23 +23,26 @@
|
|||||||
<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>
|
||||||
|
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="1">Titel:</Label>
|
<Label styleClass="inputLabel" GridPane.rowIndex="1">Datum:</Label>
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="2">Datum:</Label>
|
<Label styleClass="inputLabel" GridPane.rowIndex="2">Titel:</Label>
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="3">Von:</Label>
|
<Label styleClass="inputLabel" GridPane.rowIndex="3">Von:</Label>
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="4">Bis:</Label>
|
<Label styleClass="inputLabel" GridPane.rowIndex="4">Bis:</Label>
|
||||||
|
<Label styleClass="inputLabel" GridPane.rowIndex="5">Typ:</Label>
|
||||||
|
<Label styleClass="inputLabel" GridPane.rowIndex="6">Priorität:</Label>
|
||||||
|
<Label styleClass="inputLabel" GridPane.rowIndex="7">Ganztägig:</Label>
|
||||||
|
<Label styleClass="inputLabel" GridPane.rowIndex="8">Privat:</Label>
|
||||||
|
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="5">Priorität:</Label>
|
<DatePicker fx:id="datePickerDate" GridPane.columnIndex="1" GridPane.rowIndex="1" maxWidth="400" minWidth="400"/>
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="6">Ganztägig:</Label>
|
<TextField fx:id="textName" GridPane.columnIndex="1" GridPane.rowIndex="2" maxWidth="400" minWidth="400"/>
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="7">Privat:</Label>
|
<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"/>
|
||||||
<TextField fx:id="textName" GridPane.columnIndex="1" GridPane.rowIndex="1" maxWidth="400" minWidth="400"/>
|
<ComboBox fx:id="ComboBoxTyp" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="400" minWidth="400"/>
|
||||||
<DatePicker fx:id="datePickerDate" GridPane.columnIndex="1" GridPane.rowIndex="2" maxWidth="200" minWidth="200"/>
|
<ComboBox fx:id="ComboBoxPriotity" GridPane.columnIndex="1" GridPane.rowIndex="6" maxWidth="200" minWidth="200">
|
||||||
|
|
||||||
<ComboBox fx:id="ComboBoxPriotity" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="200" minWidth="200">
|
|
||||||
<items>
|
<items>
|
||||||
<FXCollections fx:factory="observableArrayList">
|
<FXCollections fx:factory="observableArrayList">
|
||||||
<String fx:value="gering"/>
|
<String fx:value="gering"/>
|
||||||
@@ -48,11 +51,11 @@
|
|||||||
</FXCollections>
|
</FXCollections>
|
||||||
</items>
|
</items>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
<CheckBox fx:id="checkBoxIsFullDay" GridPane.columnIndex="1" GridPane.rowIndex="6"/>
|
<CheckBox fx:id="checkBoxIsFullDay" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
|
||||||
<CheckBox fx:id="checkBoxIsPrivate" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
|
<CheckBox fx:id="checkBoxIsPrivate" GridPane.columnIndex="1" GridPane.rowIndex="8"/>
|
||||||
<Label fx:id="labelError" 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>
|
||||||
|
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>
|
||||||
@@ -23,23 +23,26 @@
|
|||||||
<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 bearbeiten</Label>
|
<Label styleClass="mainLabel">Termin bearbeiten</Label>
|
||||||
|
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="1">Titel:</Label>
|
<Label styleClass="inputLabel" GridPane.rowIndex="1">Datum:</Label>
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="2">Datum:</Label>
|
<Label styleClass="inputLabel" GridPane.rowIndex="2">Titel:</Label>
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="3">Von:</Label>
|
<Label styleClass="inputLabel" GridPane.rowIndex="3">Von:</Label>
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="4">Bis:</Label>
|
<Label styleClass="inputLabel" GridPane.rowIndex="4">Bis:</Label>
|
||||||
|
<Label styleClass="inputLabel" GridPane.rowIndex="5">Typ:</Label>
|
||||||
|
<Label styleClass="inputLabel" GridPane.rowIndex="6">Priorität:</Label>
|
||||||
|
<Label styleClass="inputLabel" GridPane.rowIndex="7">Ganztägig:</Label>
|
||||||
|
<Label styleClass="inputLabel" GridPane.rowIndex="8">Privat:</Label>
|
||||||
|
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="5">Priorität:</Label>
|
<DatePicker fx:id="datePickerDate" GridPane.columnIndex="1" GridPane.rowIndex="1" maxWidth="400" minWidth="400"/>
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="6">Ganztägig:</Label>
|
<TextField fx:id="textName" GridPane.columnIndex="1" GridPane.rowIndex="2" maxWidth="400" minWidth="400"/>
|
||||||
<Label styleClass="inputLabel" GridPane.rowIndex="7">Privat:</Label>
|
<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"/>
|
||||||
<TextField fx:id="textName" GridPane.columnIndex="1" GridPane.rowIndex="1" maxWidth="400" minWidth="400"/>
|
<ComboBox fx:id="ComboBoxTyp" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="400" minWidth="400"/>
|
||||||
<DatePicker fx:id="datePickerDate" GridPane.columnIndex="1" GridPane.rowIndex="2" maxWidth="200" minWidth="200"/>
|
<ComboBox fx:id="ComboBoxPriotity" GridPane.columnIndex="1" GridPane.rowIndex="6" maxWidth="200" minWidth="200">
|
||||||
|
|
||||||
<ComboBox fx:id="ComboBoxPriotity" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="200" minWidth="200">
|
|
||||||
<items>
|
<items>
|
||||||
<FXCollections fx:factory="observableArrayList">
|
<FXCollections fx:factory="observableArrayList">
|
||||||
<String fx:value="gering"/>
|
<String fx:value="gering"/>
|
||||||
@@ -48,11 +51,11 @@
|
|||||||
</FXCollections>
|
</FXCollections>
|
||||||
</items>
|
</items>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
<CheckBox fx:id="checkBoxIsFullDay" GridPane.columnIndex="1" GridPane.rowIndex="6"/>
|
<CheckBox fx:id="checkBoxIsFullDay" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
|
||||||
<CheckBox fx:id="checkBoxIsPrivate" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
|
<CheckBox fx:id="checkBoxIsPrivate" GridPane.columnIndex="1" GridPane.rowIndex="8"/>
|
||||||
<Label fx:id="labelError" 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">Speichern</Button>
|
<Button styleClass="mainButton" onAction="#createBtnClick" maxWidth="150" minWidth="150">Speichern</Button>
|
||||||
</HBox>
|
</HBox>
|
||||||
|
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,16 +33,28 @@ 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
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,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, true);
|
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<>();
|
||||||
@@ -108,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);
|
||||||
}
|
}
|
||||||
|
@@ -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,7 +11,9 @@ 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, boolean sendAuth) 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;
|
||||||
|
|
||||||
@@ -39,7 +43,7 @@ public class HttpRequest {
|
|||||||
|
|
||||||
if(sendAuth){
|
if(sendAuth){
|
||||||
con.setRequestProperty("Accept", "application/json");
|
con.setRequestProperty("Accept", "application/json");
|
||||||
con.setRequestProperty("Authorization", "Bearer {token}");
|
con.setRequestProperty("Authorization", "Bearer " + TOKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
|
try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
|
||||||
@@ -47,22 +51,24 @@ public class HttpRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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