Complete rewrite/restructure of the project
This commit is contained in:
10
hellofx/data/build.gradle.kts
Normal file
10
hellofx/data/build.gradle.kts
Normal file
@@ -0,0 +1,10 @@
|
||||
plugins {
|
||||
java
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.0")
|
||||
implementation("com.fasterxml.jackson.core:jackson-core:2.13.0")
|
||||
implementation("com.fasterxml.jackson.core:jackson-annotations:2.13.0")
|
||||
}
|
2
hellofx/data/build/tmp/jar/MANIFEST.MF
Normal file
2
hellofx/data/build/tmp/jar/MANIFEST.MF
Normal file
@@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
|
8
hellofx/data/src/main/java/kaka/Dings.java
Normal file
8
hellofx/data/src/main/java/kaka/Dings.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package kaka;
|
||||
|
||||
public class Dings {
|
||||
|
||||
public static int a() {
|
||||
return 5;
|
||||
}
|
||||
}
|
68
hellofx/data/src/main/java/res/Event.java
Normal file
68
hellofx/data/src/main/java/res/Event.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package res;
|
||||
|
||||
public class Event {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private int priority;
|
||||
private boolean isFullDay;
|
||||
private String start;
|
||||
private String end;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public void setPriority(int priority) {
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public boolean isFullDay() {
|
||||
return isFullDay;
|
||||
}
|
||||
|
||||
public void setFullDay(boolean fullDay) {
|
||||
isFullDay = fullDay;
|
||||
}
|
||||
|
||||
public String getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(String start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public String getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(String end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name +
|
||||
"\nVon: " + start +
|
||||
"\nBis: " + start +
|
||||
"\nisFullDay = " + isFullDay;
|
||||
|
||||
}
|
||||
}
|
63
hellofx/data/src/main/java/res/RestController.java
Normal file
63
hellofx/data/src/main/java/res/RestController.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package res;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RestController {
|
||||
|
||||
private static final String ALL_EVENTS_ENDPOINT = "http://localhost:8080/vpr/all-events";
|
||||
private static final String ALL_USERS_ENDPOINT = "http://localhost:8080/vpr/all-users";
|
||||
|
||||
public Event[] getAllEvents(){
|
||||
Event[] eventList = null;
|
||||
|
||||
try {
|
||||
URL url = new URL(ALL_EVENTS_ENDPOINT);
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
|
||||
con.setConnectTimeout(5000);
|
||||
con.setReadTimeout(5000);
|
||||
|
||||
int status = con.getResponseCode();
|
||||
if(status == 200){
|
||||
BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(con.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuilder content = new StringBuilder();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
content.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
eventList = parseJsonToEventList(content.toString());
|
||||
for (Event e : eventList){
|
||||
System.out.println(e);
|
||||
}
|
||||
}else{
|
||||
System.out.println("Status: " + status);
|
||||
}
|
||||
con.disconnect();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return eventList;
|
||||
}
|
||||
|
||||
private Event[] parseJsonToEventList(String jsonString) throws JsonProcessingException {
|
||||
ArrayList<Event> eventList;
|
||||
|
||||
// Parse JSON
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
//String json = "{ \"color\" : \"Black\", \"type\" : \"BMW\" }";
|
||||
|
||||
return objectMapper.readValue(jsonString, Event[].class);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user