Compare commits

..

No commits in common. "2269f05f5231260f241186f8afade83ec816eec2" and "22e7d306781be8229a261e8e6028c5df13572512" have entirely different histories.

8 changed files with 62 additions and 156 deletions

View File

@ -12,7 +12,6 @@ import javafx.util.converter.LocalTimeStringConverter;
import res.DataController; import res.DataController;
import res.Event; import res.Event;
import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.format.FormatStyle; import java.time.format.FormatStyle;
import java.util.Locale; import java.util.Locale;
@ -66,8 +65,8 @@ public class CreateEventController {
ComboBoxPriotity.getSelectionModel().getSelectedIndex(), ComboBoxPriotity.getSelectionModel().getSelectedIndex(),
toggleBtnIsFullDay.isSelected(), toggleBtnIsFullDay.isSelected(),
toggleBtnIsPrivate.isSelected(), toggleBtnIsPrivate.isSelected(),
timeStart.getValue(), timeStart.getValue().toString(),
timeEnd.getValue(), timeEnd.getValue().toString(),
datePickerDate.getValue().atStartOfDay(), datePickerDate.getValue().atStartOfDay(),
(int) DataController.USER_ID (int) DataController.USER_ID
); );

View File

@ -13,32 +13,26 @@ public class MainApplication extends Application {
@Override @Override
public void start(Stage stage) throws IOException { public void start(Stage stage) throws IOException {
System.out.println("Ignore 'Illegal reflective access operation'-Warning. See https://github.com/sshahine/JFoenix/issues/1170"); FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 1200, 700);
scene.getStylesheets().add(Objects.requireNonNull(
MainApplication.class.getResource("main-view.css")).toExternalForm());
stage.setTitle("SharePlaner");
stage.setScene(scene);
// Load login-scene
FXMLLoader fxmlLoaderLogin = new FXMLLoader(MainApplication.class.getResource("../users/login.fxml")); FXMLLoader fxmlLoaderLogin = new FXMLLoader(MainApplication.class.getResource("../users/login.fxml"));
Scene sceneLogin = new Scene(fxmlLoaderLogin.load(), 650, 500); Scene sceneLogin = new Scene(fxmlLoaderLogin.load(), 650, 500);
sceneLogin.getStylesheets().add(Objects.requireNonNull( sceneLogin.getStylesheets().add(Objects.requireNonNull(
MainApplication.class.getResource("../users/login.css")).toExternalForm() MainApplication.class.getResource("../users/login.css")).toExternalForm());
);
Stage stageLogin = new Stage(); Stage stageLogin = new Stage();
stageLogin.setTitle("Anmelden"); stageLogin.setTitle("Anmelden");
stageLogin.setScene(sceneLogin); stageLogin.setScene(sceneLogin);
stageLogin.showAndWait(); stageLogin.showAndWait();
if (DataController.USER_ID >= 0) { if (DataController.USER_ID >= 0) {
// Load main-scene
FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 1200, 700);
scene.getStylesheets().add(Objects.requireNonNull(
MainApplication.class.getResource("main-view.css")).toExternalForm()
);
stage.setTitle("SharePlaner");
stage.setScene(scene);
stage.show(); stage.show();
System.out.println("Logged in...");
} }
} }

View File

@ -56,7 +56,7 @@ public class MainController {
} }
DataController dataController = new DataController(); DataController dataController = new DataController();
ArrayList<Event> eventList = dataController.getAllVisibleEvents(weekStartDateTime, weekStartDateTime.plusDays(7)); ArrayList<Event> eventList = dataController.getAllVisibleEvents();
for (Event event : eventList) { for (Event event : eventList) {
addEvent(event); addEvent(event);
@ -143,7 +143,7 @@ public class MainController {
deleteBtn.setTextValue(" X "); deleteBtn.setTextValue(" X ");
deleteBtn.setOnAction(e -> { deleteBtn.setOnAction(e -> {
DataController dataController = new DataController(); DataController dataController = new DataController();
dataController.deleteEvent(event.getOwnerId(), event.getId(), event.getDate()); dataController.deleteEvent(event.getId());
updateEvents(); updateEvents();
}); });
Button editBtn = new Button(); Button editBtn = new Button();

View File

@ -7,5 +7,4 @@ dependencies {
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion") implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion") implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion") implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
} }

View File

@ -1,27 +0,0 @@
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 +
'}';
}
}

View File

@ -1,9 +1,7 @@
package res; package res;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
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;
@ -12,7 +10,6 @@ import java.io.OutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
public class DataController { public class DataController {
@ -25,7 +22,6 @@ 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;
@ -35,28 +31,16 @@ public class DataController {
public boolean login(String username, String password) { public boolean login(String username, String password) {
try { try {
Tuple<Integer, String> response = httpRequest.sendPostRequest( USER_ID = Long.parseLong(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;
} }
@ -68,35 +52,34 @@ public class DataController {
} }
} }
public void deleteEvent(int userId, int eventId, LocalDateTime date) { public void deleteEvent(int eventId) {
try { try {
System.out.println("DELETE: userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate()); System.out.println(httpRequest.sendPostRequest(DELETE_EVENT_ENDPOINT, "eventId=" + eventId, true));
System.out.println(httpRequest.sendPostRequest(
DELETE_EVENT_ENDPOINT,
"userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate(),
true
));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public ArrayList<Event> getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) { public ArrayList<Event> getAllVisibleEvents() {
ArrayList<Event> eventList = new ArrayList<>(); ArrayList<Event> eventList = new ArrayList<>();
try { try {
Tuple<Integer, String> response = httpRequest.sendPostRequest( String jsonResponse = httpRequest.sendPostRequest(ALL_EVENTS_ENDPOINT, "userId=" + USER_ID, true);
ALL_EVENTS_ENDPOINT,
"userId=" + USER_ID + "&startDate=" + startDate.toLocalDate() + "&endDate=" + endDate.toLocalDate(),
true
);
String jsonResponse = response.getValue();
System.out.println(jsonResponse); System.out.println(jsonResponse);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
objectMapper.findAndRegisterModules(); //String json = "{ \"color\" : \"Black\", \"type\" : \"BMW\" }";
eventList = (ArrayList<Event>) objectMapper.readValue(jsonResponse, new TypeReference<List<Event>>(){});
for (Object obj : objectMapper.readValue(jsonResponse, Object[].class)) {
ArrayList<Object> list = new ArrayList<>();
if (obj.getClass().isArray()) {
list = (ArrayList<Object>) Arrays.asList((Object[]) obj);
} else if (obj instanceof Collection) {
list = new ArrayList<>((Collection<?>) obj);
}
eventList.add(new Event(list));
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -125,6 +108,7 @@ 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);
} }

View File

@ -2,13 +2,10 @@ package res;
import com.sun.jdi.event.StepEvent; import com.sun.jdi.event.StepEvent;
import java.io.Serializable;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.sql.SQLOutput;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime;
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.Matcher;
@ -46,10 +43,6 @@ public class Event {
u.name AS uname u.name AS uname
*/ */
public Event() {
}
public Event(ArrayList<Object> arr) { public Event(ArrayList<Object> arr) {
id = (int) arr.get(0); id = (int) arr.get(0);
name = (String) arr.get(1); name = (String) arr.get(1);
@ -66,50 +59,21 @@ public class Event {
ownerName = arr.get(8) + " " + arr.get(9); ownerName = arr.get(8) + " " + arr.get(9);
} }
public Event(
int id,
String name,
int priority,
boolean isFullDay,
boolean isPrivate,
String start,
String end,
String date,
int ownerId,
String ownerName
) {
this.ownerId = ownerId;
this.ownerName = ownerName;
this.id = id;
this.name = name;
this.start = start;
this.end = end;
this.priority = priority;
this.isFullDay = isFullDay;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
this.date = LocalDateTime.parse(date + " 00:00", formatter);
}
public Event(String name, public Event(String name,
int priority, int priority,
boolean isFullDay, boolean isFullDay,
boolean isPrivate, boolean isPrivate,
LocalTime start, String start,
LocalTime end, String end,
LocalDateTime date, LocalDateTime date,
int ownerId int ownerId
) throws IllegalArgumentException { ) throws IllegalArgumentException{
if(name.length() < 3){
System.out.println("Create Event");
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\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df0-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()){
System.out.println(name); System.out.println(name);
byte[] bytes = name.getBytes(StandardCharsets.UTF_16); byte[] bytes = name.getBytes(StandardCharsets.UTF_16);
@ -118,25 +82,25 @@ public class Event {
System.out.println(utf8EncodedString); System.out.println(utf8EncodedString);
for (char c : (name).toCharArray()) { for (char c : (name).toCharArray()) {
System.out.print(c + " " + (int) c + ", "); System.out.print(c + " " + (int)c + ", ");
} }
System.out.println(); System.out.println();
for (char c : (name).toCharArray()) { for (char c : (name).toCharArray()) {
System.out.print(c + " " + (int) c + ", "); System.out.print(c + " " + (int)c + ", ");
} }
System.out.println(); System.out.println();
for (char c : ("TäöüÄÖÜ").toCharArray()) { for (char c : ("TäöüÄÖÜ").toCharArray()) {
System.out.print(c + " " + (int) c + ", "); System.out.print(c + " " + (int)c + ", ");
} }
System.out.println(); System.out.println();
throw new IllegalArgumentException("Der Name darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: \u00e4\u00f6\u00fc \u00c4\u00d6\u00dc \u00df =!?+*/$.:,;_ <>()-"); 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.");
} }
LocalDateTime today = LocalDateTime.now().toLocalDate().atStartOfDay(); LocalDateTime today = LocalDateTime.now().toLocalDate().atStartOfDay();
if (Duration.between(today, date).isNegative()) { if(Duration.between(today, date).isNegative()){
throw new IllegalArgumentException("Das Datum muss in der Zukunft liegen."); throw new IllegalArgumentException("Das Datum muss in der Zukunft liegen.");
} }
@ -144,8 +108,8 @@ public class Event {
this.priority = priority; this.priority = priority;
this.isFullDay = isFullDay; this.isFullDay = isFullDay;
this.isPrivate = isPrivate; this.isPrivate = isPrivate;
if (start != null) this.start = start.toString(); this.start = start;
if (start != null) this.end = end.toString(); this.end = end;
this.date = date; this.date = date;
this.ownerId = ownerId; this.ownerId = ownerId;
} }
@ -210,9 +174,8 @@ public class Event {
return date; return date;
} }
public void setDate(String date) { public void setDate(LocalDateTime date) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); this.date = date;
this.date = LocalDateTime.parse(date + " 00:00", formatter);
} }
public int getOwnerId() { public int getOwnerId() {
@ -246,12 +209,12 @@ public class Event {
"&name=" + getName() + "&name=" + getName() +
"&start=" + getStart() + "&start=" + getStart() +
"&end=" + getEnd() + "&end=" + getEnd() +
"&priority=" + getPriority() + "&prority=" + getPriority() +
"&isFullDay=" + isFullDay() + "&isFullDay=" + isFullDay() +
"&isPrivate=" + isPrivate(); "&isPrivate=" + isPrivate();
} }
private String convertToASCII(String s) { private String convertToASCII(String s){
byte[] germanBytes = s.getBytes(); byte[] germanBytes = s.getBytes();
return new String(germanBytes, StandardCharsets.US_ASCII); return new String(germanBytes, StandardCharsets.US_ASCII);
} }

View File

@ -1,7 +1,5 @@
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;
@ -11,9 +9,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
public class HttpRequest { public class HttpRequest {
public static String TOKEN = ""; public String sendPostRequest(String urlString, String urlParameters, boolean sendAuth) throws Exception {
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;
@ -43,7 +39,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())) {
@ -51,24 +47,22 @@ public class HttpRequest {
} }
int status = con.getResponseCode(); int status = con.getResponseCode();
String inputLine;
StringBuilder content = new StringBuilder();
BufferedReader in;
if (status == 200) { if (status == 200) {
in = new BufferedReader(new InputStreamReader(con.getInputStream())); BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
con.disconnect();
return content.toString();
} else { } else {
in = new BufferedReader(new InputStreamReader(con.getErrorStream())); con.disconnect();
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 {