From a41384a1165ef1022366e492fbe9178e4ef42222 Mon Sep 17 00:00:00 2001 From: Daniel Zdravkovic <3012893@stud.hs-mannheim.de> Date: Mon, 10 Jun 2024 11:59:35 +0200 Subject: [PATCH 1/3] get_all_users method (complete but without encoding method) --- .../java/de/hs_mannheim/domain/System.java | 35 ++++++++++++++++--- src/main/java/de/hs_mannheim/domain/User.java | 14 ++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index cf8c246..b91c89e 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -1,14 +1,13 @@ package de.hs_mannheim.domain; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.TreeSet; @@ -39,9 +38,35 @@ public class System { public void set_current_user_bike_avg_kmh(double bike_avg_kmh){ this.current_user.setBike_avg_kmh(bike_avg_kmh); } + + public void encoding(String string){ + + } - public HashSet get_all_user(){ - return new HashSet(); + public HashSet get_all_user() throws FileNotFoundException, IOException{ + HashSet all_users = new HashSet<>(); + File file = new File("user_information.csv"); + String[] fileString = new String[8]; + + if(file.exists() && file.isFile()){ + FileReader fileReader = new FileReader(file); + BufferedReader bufferedReader = new BufferedReader(fileReader); + String path; + + while((path = bufferedReader.readLine()) != null){ + fileString = path.split(";"); + fileString = (String[]) Arrays.stream(fileString) + .map(string -> string.substring(0, string.length()-1)) + .toArray(); + encoding(fileString[1]); + all_users.add(new User(fileString[0], fileString[1], fileString[2], + Integer.parseInt(fileString[3]), fileString[4], + Double.parseDouble(fileString[5]), + Double.parseDouble(fileString[6]), + Double.parseDouble(fileString[7]))); + } + } + return all_users; } public boolean sign_in_user(String username, String password){ diff --git a/src/main/java/de/hs_mannheim/domain/User.java b/src/main/java/de/hs_mannheim/domain/User.java index 54eacac..cd9b6f9 100644 --- a/src/main/java/de/hs_mannheim/domain/User.java +++ b/src/main/java/de/hs_mannheim/domain/User.java @@ -11,6 +11,20 @@ public class User { private double car_avg_kmh; private double bike_avg_kmh; + public User(){} + + public User(String username, String password, String hometown, int zip + , String car_name, double car_l_100km, double car_avg_kmh, double bike_avg_kmh){ + this.username = username; + this.password = password; + this.hometown = hometown; + this.zip = zip; + this.car_name = car_name; + this.car_l_100km = car_l_100km; + this.car_avg_kmh = car_avg_kmh; + this.bike_avg_kmh = bike_avg_kmh; + } + public String getUsername() { return username; } From 5120dd94be3b7229c9e7ac51081f8d6c98d5d2c5 Mon Sep 17 00:00:00 2001 From: Daniel Zdravkovic <3012893@stud.hs-mannheim.de> Date: Mon, 10 Jun 2024 13:34:52 +0200 Subject: [PATCH 2/3] encoding und decoding methods mit Base64 implementiert --- src/main/java/de/hs_mannheim/domain/System.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index b91c89e..0b4ea1d 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -11,6 +11,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.TreeSet; +import org.apache.commons.codec.binary.Base64; import org.json.JSONObject; public class System { @@ -39,8 +40,17 @@ public class System { this.current_user.setBike_avg_kmh(bike_avg_kmh); } - public void encoding(String string){ + public void decoding(String string){ + byte[] binary_data = Base64.decodeBase64(string); + string = new String(binary_data); + } + public void encoding(String string){ + byte[] binary_data = new byte[string.length()]; + for(int i = 0; i < string.length(); i++){ + binary_data[i] = (byte) string.charAt(i); + } + string = Base64.encodeBase64String(binary_data); } public HashSet get_all_user() throws FileNotFoundException, IOException{ From 41676607adca78f2b563bd37a9f7ece3054cdb06 Mon Sep 17 00:00:00 2001 From: Daniel Zdravkovic <3012893@stud.hs-mannheim.de> Date: Mon, 10 Jun 2024 14:17:14 +0200 Subject: [PATCH 3/3] createSheet Methode welche eine Tabelle erstellt mit User Informationen --- .../java/de/hs_mannheim/domain/System.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 0b4ea1d..c5513e7 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -12,16 +12,20 @@ import java.util.HashSet; import java.util.TreeSet; import org.apache.commons.codec.binary.Base64; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.json.JSONObject; public class System { - + private User current_user = new User(); private String api_key; private ArrayList distances = new ArrayList<>(); + private XSSFWorkbook workbook = new XSSFWorkbook(); public System(String api_key) { this.api_key = api_key; + createSheet(); } public void set_current_user_zip(String zip){ @@ -52,10 +56,21 @@ public class System { } string = Base64.encodeBase64String(binary_data); } - + + public void createSheet(){ + try + { + XSSFSheet sheet1 = workbook.createSheet("user_information"); + FileOutputStream fileOut = new FileOutputStream("workbook.xlsx"); + workbook.write(fileOut); + fileOut.close(); + } + catch(Exception ex) {} + } + public HashSet get_all_user() throws FileNotFoundException, IOException{ HashSet all_users = new HashSet<>(); - File file = new File("user_information.csv"); + File file = new File("workbook.xlsx"); String[] fileString = new String[8]; if(file.exists() && file.isFile()){