PreparedStatements -> Anti SQL Injection

Doxygen Generieren
Javadoc Generieren
UML Generieren
This commit is contained in:
2021-05-18 19:13:48 +02:00
parent c37342d6ee
commit f9a9a60e6f
244 changed files with 3835 additions and 4274 deletions

View File

@ -66,7 +66,7 @@ public class ConfigHelper {
* @param value Wert der eingetragen werden soll
*/
public static void setIniString(String filename, String sectionName, String optionName, String value) {
Wini ini = null;
Wini ini;
try {
ini = new Wini(new File(filename));
ini.put(sectionName, optionName, value);
@ -85,7 +85,7 @@ public class ConfigHelper {
* @param value Wert der eingetragen werden soll
*/
public static void setIniInt(String filename, String sectionName, String optionName, int value){
Wini ini = null;
Wini ini;
try {
ini = new Wini(new File(filename));
ini.put(sectionName, optionName, value);
@ -99,6 +99,7 @@ public class ConfigHelper {
* Gibt den namen des standard Config file zurück
* @return Name des standard config files
*/
@SuppressWarnings("SameReturnValue")
public static String getStandartConfig() {
return standartConfig;
}

View File

@ -50,8 +50,6 @@ public class DirectionMap {
/**
* Downloadet die Map von Mapquest
* @param start Startpunkt
* @param ende Endpunkt
* @return Image von der Map
* @throws IOException Fehler beim Get der Map
*/

View File

@ -6,6 +6,7 @@ import tourplaner.object.Tour;
import tourplaner.ui.ProgressBar;
import java.io.*;
import java.sql.SQLException;
import java.util.ArrayList;
/**
@ -50,12 +51,19 @@ public class Exporter {
ArrayList<Tour> touren = JsonHelper.getTourenFromJson(new FileReader(EinheitenAdder.addJson(this.path)));
DbConnect dbConnect = new DbConnect();
ArrayList<Tour> allTours = dbConnect.getAllTouren(progressBar, 15);
int size = progressBar.getProgressSize(allTours.size(), 35);
allTours.forEach(t -> {
TourPlaner.delTour(t.getName());
progressBar.addProgress(size);
});
if(allTours != null && allTours.size() != 0) {
int size = progressBar.getProgressSize(allTours.size(), 35);
allTours.forEach(t -> {
try {
TourPlaner.delTour(t.getName());
} catch (SQLException throwables) {
LogHelper.error(throwables);
}
progressBar.addProgress(size);
});
}else {
progressBar.setProgress(35);
}
int finalSize = progressBar.getProgressSize(touren.size() * 3, progressMax);
for (Tour tour: touren) {
new DirectionMap(tour.getStart(), tour.getZiel(), tour.getName());
@ -68,7 +76,7 @@ public class Exporter {
}
progressBar.addProgress(finalSize);
}
} catch (IOException e) {
} catch (IOException | SQLException e) {
LogHelper.error(e);
progressBar.setProgress(progressMax);
}

View File

@ -3,7 +3,6 @@ package tourplaner.business;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@ -26,7 +25,7 @@ public class FileHelper {
// to open the file.
desktop.open(file);
} catch (IOException e) {
e.printStackTrace();
LogHelper.error(e);
}
}
@ -41,22 +40,12 @@ public class FileHelper {
ImageIO.write(ImgHelper.toBufferedImage(img), type, file);
}
/**
* Holt ein image von einem File
* @param file File mit dem image
* @return Das buffered image
* @throws IOException Fehler beim öffnen des bildes
*/
public static BufferedImage getImage(File file) throws IOException {
return ImageIO.read(file);
}
/**
* Löscht ein File
* @param file File das zu löschen ist
* @return false bei error
*/
public static boolean delFile(File file){
return file.delete();
public static void delFile(File file){
//noinspection ResultOfMethodCallIgnored
file.delete();
}
}

View File

@ -6,14 +6,6 @@ import org.apache.log4j.*;
* Hilft beim Logging mit log4j
*/
public class LogHelper{
/**
* Log info in file und Console
* @param msg Nachricht in dem Log
* @param name Name des Log Eintrags
*/
public static void info(String msg, String name){
getLog(name).info(msg);
}
/**
* Log info in file und Console
@ -30,7 +22,8 @@ public class LogHelper{
* @param e Exception
*/
public static void error(Exception e){
getLog(e.getClass().getName()).error(e.getMessage());
e.printStackTrace();
getLog(e.getClass().getPackage().getName() + e.getClass().getName()).error(e.getMessage());
}
/**

View File

@ -1,15 +1,12 @@
package tourplaner.business;
import com.itextpdf.text.*;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import tourplaner.object.Log;
import tourplaner.object.Tour;
import com.itextpdf.text.pdf.PdfWriter;
import tourplaner.ui.ProgressBar;
import java.awt.*;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
@ -145,12 +142,12 @@ public class Reporter {
subCatPart.add(new Paragraph(EinheitenAdder.addMinuten(ConfigHelper.getLangIniString("reportdauercal") + " " + tour.getDauer())));
subCatPart.add(new Paragraph(EinheitenAdder.addKm(ConfigHelper.getLangIniString("reportstreckecal") + " " + tour.getStrecke())));
Paragraph emptyLine = new Paragraph();
addEmptyLine(emptyLine, 5);
addEmptyLine(emptyLine);
subCatPart.add(emptyLine);
// now add all this to the document
document.add(catPart);
Image image1 = null;
Image image1;
try {
image1 = Image.getInstance(TourPlaner.getImagePdfPath(tour.getName()));
image1.setAlignment(Element.ALIGN_CENTER);
@ -186,10 +183,10 @@ public class Reporter {
/**
* Fügt eine leere zeile an den Paragraph an
* @param paragraph Hier wird hinzugefügt
* @param number Um wie viele Leere Zeilen hinzugefügt werden soll
*
*/
private static void addEmptyLine(Paragraph paragraph, int number) {
for (int i = 0; i < number; i++) {
private static void addEmptyLine(Paragraph paragraph) {
for (int i = 0; i < 5; i++) {
paragraph.add(new Paragraph(" "));
}
}

View File

@ -1,15 +1,14 @@
package tourplaner.business;
import javafx.collections.ObservableList;
import org.apache.log4j.Logger;
import tourplaner.data.DbConnect;
import tourplaner.object.Log;
import tourplaner.object.Tour;
import tourplaner.ui.ProgressBar;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Locale;
import java.util.UUID;
@ -42,7 +41,7 @@ public class TourPlaner{
* @return false bei error
* @throws IOException Fehler beim editieren der Tour
*/
public static boolean editTour(String oldname, Tour tour) throws IOException {
public static void editTour(String oldname, Tour tour) throws IOException, SQLException {
ProgressBar progressBar = new ProgressBar("Edit...");
int step = progressBar.getProgressSize(3, 100);
FileHelper.delFile(new File(getImagePath(oldname)));
@ -52,50 +51,44 @@ public class TourPlaner{
progressBar.addProgress(step);
tour.setDauer(directionMap.getDauer()+"");
tour.setStrecke(directionMap.getStrecke());
boolean ret = new DbConnect().editTour(oldname, tour);
new DbConnect().editTour(oldname, tour);
progressBar.setProgress(100);
return ret;
}
/**
* Löscht eine Tour
* @param tourname Tourname
* @return false bei error
*/
public static boolean delTour(String tourname){
public static void delTour(String tourname) throws SQLException {
FileHelper.delFile(new File(getImagePath(tourname)));
FileHelper.delFile(new File(getImagePdfPath(tourname)));
boolean ret = new DbConnect().delTour(tourname);
return ret;
new DbConnect().delTour(tourname);
}
/**
* Fügt eine Tour hinzu
* @param newTour Neue Tour
* @param progressBar Aktuelle Progressbar
* @param progressMax Maximale anzeige der Progress bar
* @return false bei error
* @throws IOException Fehler beim hinzufügen der Tour
*/
public static boolean addTourMax(Tour newTour, ProgressBar progressBar, int progressMax) throws IOException {
public static void addTourMax(Tour newTour, ProgressBar progressBar, int progressMax) throws IOException, SQLException {
int step = progressBar.getProgressSize(2, progressMax);
DirectionMap directionMap = new DirectionMap(newTour.getStart(), newTour.getZiel(), newTour.getName());
progressBar.addProgress(step);
newTour.setDauer(directionMap.getDauer()+"");
newTour.setStrecke(directionMap.getStrecke());
boolean ret = new DbConnect().addTour(newTour);
new DbConnect().addTour(newTour);
progressBar.setProgress(progressMax);
return ret;
}
/**
* Fügt eine Tour hinzu
* @param newTour Neue Tour
* @param progressBar Aktuelle Progressbar
* @return false bei error
* @throws IOException Fehler beim hinzufügen der Tour
*/
public static boolean addTour(Tour newTour, ProgressBar progressBar) throws IOException {
return addTourMax(newTour, progressBar, 100);
public static void addTour(Tour newTour, ProgressBar progressBar) throws IOException, SQLException {
addTourMax(newTour, progressBar, 100);
}
/**
@ -147,32 +140,29 @@ public class TourPlaner{
* Fügt ein Log hinzu
* @param tourname Name der Tour
* @param log Neues Log
* @return false bei error
*/
public static boolean addLog(String tourname, Log log){
public static void addLog(String tourname, Log log) throws SQLException {
if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
return new DbConnect().addLog(tourname, log);
new DbConnect().addLog(tourname, log);
}
/**
* Löscht ein Log
* @param tourname Name der Tour
* @param id Id des Logs
* @return false bei error
*/
public static boolean delLog(String tourname, String id){
return new DbConnect().delLog(tourname, id);
public static void delLog(String tourname, String id) throws SQLException {
new DbConnect().delLog(tourname, id);
}
/**
* Editiert ein Log
* @param tourname Name der Tour
* @param log Neues Log
* @return false bei error
*/
public static boolean editLog(String tourname, Log log){
public static void editLog(String tourname, Log log) throws SQLException {
if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
return new DbConnect().editLog(tourname, log);
new DbConnect().editLog(tourname, log);
}
/**

View File

@ -13,7 +13,7 @@ import java.util.ArrayList;
*/
public class DbConnect {
private Connection c;
private Statement stmt;
private PreparedStatement preparedStatement;
/**
@ -40,68 +40,54 @@ public class DbConnect {
* Bearbeitet eine Tour
* @param oldname Alter Tour name
* @param tour Neues Tour Object
* @return false bei error
*/
public boolean editTour(String oldname, Tour tour) {
public void editTour(String oldname, Tour tour) throws SQLException {
String tourname = tour.getName();
ArrayList<Boolean> result = new ArrayList<>();
ArrayList<Log> logs = getLogs(oldname);
result.add(delLogs(oldname));
result.add(PostgresHelper.executeUpdate("UPDATE public.tour SET tourname = '"+tour.getName()+"', dauer = 1, mapjson = '"+tour.getMapJson()+"', start = '"+tour.getStart()+"', ziel = '"+tour.getZiel()+"', strecke = "+tour.getStrecke()+" WHERE tourname ='" + oldname + "';"));
logs.forEach(log -> result.add(addLog(tourname, log)));
return !result.contains(false);
delLogs(oldname);
PostgresHelper.executeUpdateEditTour("UPDATE public.tour SET tourname = ?, dauer = 1, mapjson = ?, start = ?, ziel = ?, strecke = ? WHERE tourname =?;", tour.getName(), tour.getMapJson(), tour.getStart(), tour.getZiel(), tour.getStrecke(), oldname);
logs.forEach(log -> {
try {
addLog(tourname, log);
} catch (SQLException throwables) {
LogHelper.error(throwables);
}
});
}
private boolean delLogs(String tourname){
return PostgresHelper.executeUpdate("DELETE FROM public.log WHERE tourname = '"+tourname+"'");
private void delLogs(String tourname) throws SQLException {
PostgresHelper.executeUpdateString("DELETE FROM public.log WHERE tourname = ?", tourname);
}
/**
* Fügt eine Tour hinzu
* @param tour Neue Tour
* @return false bei error
*/
public boolean addTour(Tour tour){
return PostgresHelper.executeUpdate("INSERT INTO public.tour (tourname, dauer, mapjson, start, ziel, strecke) VALUES ('"+tour.getName()+"', "+tour.getDauer()+", '"+tour.getMapJson()+"', '"+tour.getStart()+"', '"+tour.getZiel()+"', "+tour.getStrecke()+")");
public void addTour(Tour tour) throws SQLException {
PostgresHelper.executeUpdateAddTour("INSERT INTO public.tour (tourname, dauer, mapjson, start, ziel, strecke) VALUES (?, ?, ?, ?, ?, ?)", tour.getName(), tour.getDauer(), tour.getMapJson(), tour.getStart(), tour.getZiel(), tour.getStrecke());
}
/**
* Löscht eine Tour anhand des Tournamens
* @param tourname Tourname der zu löschen ist
* @return false bei error
*/
public boolean delTour(String tourname){
ArrayList<Boolean> result = new ArrayList<>();
result.add(delLogs(tourname));
result.add(PostgresHelper.executeUpdate("DELETE FROM public.tour WHERE tourname = '"+tourname+"'"));
return !result.contains(false);
}
public boolean delAllData(){
ArrayList<Boolean> result = new ArrayList<>();
result.add(delAllLog());
result.add(delAllTour());
return !result.contains(false);
}
private boolean delAllTour(){
return PostgresHelper.executeUpdate("DELETE FROM public.tour");
}
private boolean delAllLog(){
return PostgresHelper.executeUpdate("DELETE FROM public.log");
public void delTour(String tourname) throws SQLException {
delLogs(tourname);
PostgresHelper.executeUpdateString("DELETE FROM public.tour WHERE tourname = ?",tourname);
}
public ArrayList<Log> getLogs(String tourname){
this.c = PostgresHelper.con();
String id, bemerkung, rating;
double dauer, strecke, pause, gegangen, avg, hightmeter;
double dauer, strecke, pause, hightmeter;
Date datum;
ArrayList<Log> logs = new ArrayList<>();
try {
stmt = this.c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM public.log where tourname = '"+ tourname +"'");
this.preparedStatement = this.c.prepareStatement("SELECT * FROM public.log where tourname = ?");
this.preparedStatement.setString(1, tourname);
ResultSet rs = this.preparedStatement.executeQuery();
while (rs.next()) {
id = rs.getString("id");
bemerkung = rs.getString("bemerkung");
@ -118,7 +104,7 @@ public class DbConnect {
}
}
rs.close();
stmt.close();
this.preparedStatement.close();
this.c.close();
return logs;
} catch (Exception e) {
@ -134,26 +120,24 @@ public class DbConnect {
* @param log Der Logeintrag
* @return false bei error
*/
public boolean addLog(String tourname, Log log){
public void addLog(String tourname, Log log) throws SQLException {
if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
return PostgresHelper.executeUpdate("INSERT INTO public.log (tourname, id, bemerkung, datum, strecke, avg, hightmeter, pause, gegangen, dauer, rating) VALUES ('"+tourname+"', '"+log.getId()+"', '"+log.getBemerkung()+"', '"+log.getDatum()+"', "
+log.getStrecke()+", "+log.getAvgspeed()+", "+log.getHightmeter()+", "+log.getPause()+", "+log.getGegangen()+", "+log.getDauer()+",'"+log.getRating()+"')");
PostgresHelper.executeUpdateAddLog("INSERT INTO public.log (tourname, id, bemerkung, datum, strecke, avg, hightmeter, pause, gegangen, dauer, rating) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?)", tourname, log.getId(),log.getBemerkung(),log.getDatum(),log.getStrecke(),log.getAvgspeed(),log.getHightmeter(),log.getPause(),log.getGegangen(),log.getDauer(),log.getRating());
}
public boolean editLog(String tourname, Log log){
return PostgresHelper.executeUpdate("UPDATE public.log SET bemerkung = '"+log.getBemerkung()+"', datum = '"+log.getDatum()+"', strecke = "+log.getStrecke()+", avg = "+log.getAvgspeed()+", hightmeter = "+
log.getHightmeter()+", pause = "+log.getPause()+", gegangen = "+log.getGegangen()+", dauer = "+log.getDauer()+", rating = '"+log.getRating()+"' WHERE tourname = '"+tourname+"' and id = '"+log.getId()+"'");
public void editLog(String tourname, Log log) throws SQLException {
PostgresHelper.executeUpdateEditLog("UPDATE public.log SET bemerkung = ?, datum = ?, strecke = ?, avg = ?, hightmeter = ?, pause = ?, gegangen = ?, dauer = ?, rating = ? WHERE tourname = ? and id = ?", log.getBemerkung(),log.getDatum(),log.getStrecke(),log.getAvgspeed(),log.getHightmeter(),log.getPause(),log.getGegangen(),log.getDauer(),log.getRating(),tourname ,log.getId());
}
public boolean delLog(String tourname, String id){
return PostgresHelper.executeUpdate("DELETE FROM public.log WHERE tourname = '"+tourname+"' and id = '"+id+"'");
public void delLog(String tourname, String id) throws SQLException {
PostgresHelper.executeUpdateDelLog("DELETE FROM public.log WHERE tourname = ? and id = ?", tourname, id);
}
private int getTourSize() throws SQLException {
Connection con = PostgresHelper.con();
Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM tour;");
int size =0;
int size;
if (rs != null)
{
rs.last(); // moves cursor to the last row
@ -178,29 +162,33 @@ public class DbConnect {
ArrayList<Tour> touren = new ArrayList<>();
try {
int tourSize = getTourSize();
int step = progressBar.getProgressSize(tourSize, maxLevel);
stmt = this.c.createStatement();
ResultSet rs = stmt.executeQuery("select * from tour;");
while (rs.next()) {
tourname = rs.getString("tourname");
mapjson = rs.getString("mapjson");
start = rs.getString("start");
ziel = rs.getString("ziel");
dauer = rs.getDouble("dauer");
strecke = rs.getDouble("strecke");
if (!tourname.isEmpty()) {
touren.add(new Tour(tourname, dauer + "", mapjson, strecke, start, ziel, getLogs(tourname)));
progressBar.addProgress(step);
}else {
progressBar.setProgress(maxLevel);
return null;
if (tourSize > 0) {
int step = progressBar.getProgressSize(tourSize, maxLevel);
this.preparedStatement = this.c.prepareStatement("select * from tour;");
ResultSet rs = this.preparedStatement.executeQuery();
while (rs.next()) {
tourname = rs.getString("tourname");
mapjson = rs.getString("mapjson");
start = rs.getString("start");
ziel = rs.getString("ziel");
dauer = rs.getDouble("dauer");
strecke = rs.getDouble("strecke");
if (!tourname.isEmpty()) {
touren.add(new Tour(tourname, dauer + "", mapjson, strecke, start, ziel, getLogs(tourname)));
progressBar.addProgress(step);
} else {
progressBar.setProgress(maxLevel);
return null;
}
}
progressBar.setProgress(maxLevel);
rs.close();
this.c.close();
return touren;
}else {
progressBar.setProgress(maxLevel);
return null;
}
progressBar.setProgress(maxLevel);
rs.close();
stmt.close();
this.c.close();
return touren;
} catch (Exception e) {
LogHelper.error(e);
progressBar.setProgress(maxLevel);
@ -220,8 +208,9 @@ public class DbConnect {
Tour touren = null;
try {
stmt = this.c.createStatement();
ResultSet rs = stmt.executeQuery("select * from tour where tourname = '"+tn+"';");
this.preparedStatement = this.c.prepareStatement("select * from tour where tourname = ?;");
this.preparedStatement.setString(1, tn);
ResultSet rs = this.preparedStatement.executeQuery();
while (rs.next()) {
tourname = rs.getString("tourname");
mapjson = rs.getString("mapjson");
@ -236,7 +225,7 @@ public class DbConnect {
}
}
rs.close();
stmt.close();
this.preparedStatement.close();
this.c.close();
return touren;
} catch (Exception e) {
@ -244,5 +233,4 @@ public class DbConnect {
return null;
}
}
}
}

View File

@ -4,10 +4,8 @@ package tourplaner.data;
import tourplaner.business.ConfigHelper;
import tourplaner.business.LogHelper;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import java.time.LocalDate;
/**
* Hilfsfunktionen für die verwendung der Postgres DB
@ -30,55 +28,180 @@ public class PostgresHelper {
return c;
}
/**
* Führt ein Sql statement ohne rückgabe aus, mit message nachricht
* @param sql Sql command
* @param message Mesasage die vor dem Durchführen angezeigt wird
* @return True bei erfolg, sonst false
*/
public static boolean executeUpdateMessage(String sql, String message){
LogHelper.info(message, "PostgresHelper");
return executeUpdate(sql);
}
/**
* Führt ein Sql statement ohne rückgabe aus
* @param sql Sql command
* @return True bei erfolg, sonst false
*/
public static boolean executeUpdate(String sql){
try {
exUpdate(sql);
} catch (SQLException e) {
LogHelper.error(e.getMessage(), e.getClass().getName());
return false;
}
return true;
}
/**
* Führt ein Sql statement ohne rückgabe aus
* @param sql Sql command
* @return True bei erfolg, sonst false
* @param preparedStatement Das prepared statement
* @param c Die connection zur db
* @throws SQLException Fehler beim ausführen
*/
private static boolean exUpdate(String sql) throws SQLException {
Connection c = con();
Statement stmt;
stmt = c.createStatement();
stmt.executeUpdate(sql);
stmt.close();
private static void exUpdate(PreparedStatement preparedStatement, Connection c) throws SQLException {
preparedStatement.executeUpdate();
c.close();
return true;
}
public static boolean executeUpdateNoLog(String sql){
/**
* @param sql SQL aus dem das prepared statement gebildet wird
*/
public static void executeUpdateNoLog(String sql){
try {
exUpdate(sql);
return true;
}catch (Exception e){
return false;
Connection c = con();
PreparedStatement preparedStatement = c.prepareStatement(sql);
exUpdate(preparedStatement, c);
} catch (SQLException ignored) {
}
}
/**
* Erstellt ein log
* @param content sql statement
* @param tourname Name des Logs
* @param id Id des Logs
* @param bemerkung Bemerkung des Logs
* @param datum Datum des Logs
* @param strecke Strecke des Logs
* @param avgspeed Durchschnittsgeschwindigkeit des Logs
* @param hightmeter Höhenmeter des Logs
* @param pause Pause des Logs
* @param gegangen Gegangene Zeit des Logs
* @param dauer Dauer des Logs
* @param rating Rating des Logs
* @return false bei error
* @throws SQLException Sql error
*/
public static void executeUpdateAddLog(String content, String tourname, String id, String bemerkung, LocalDate datum, double strecke, double avgspeed, double hightmeter, double pause, double gegangen, double dauer, String rating) throws SQLException {
Connection c = con();
PreparedStatement preparedStatement = c.prepareStatement(content);
preparedStatement.setString(1, tourname);
preparedStatement.setString(2, id);
preparedStatement.setString(3, bemerkung);
preparedStatement.setDate(4, Date.valueOf(datum));
preparedStatement.setDouble(5, strecke);
preparedStatement.setDouble(6, avgspeed);
preparedStatement.setDouble(7, hightmeter);
preparedStatement.setDouble(8, pause);
preparedStatement.setDouble(9, gegangen);
preparedStatement.setDouble(10, dauer);
preparedStatement.setString(11, rating);
exUpdate(preparedStatement, c);
}
/**
* Bearbeitet ein log
* @param content Sql statement
* @param bemerkung Bemerkung des Logs
* @param datum Datum des Logs
* @param strecke Strecke des Logs
* @param avgspeed Durchschnittsgeschwindigkeit des Logs
* @param hightmeter Höhenmeter des Logs
* @param pause Pause des Logs
* @param gegangen Gegangene Zeit des Logs
* @param dauer Dauer des Logs
* @param rating Rating des Logs
* @param tourname Name der Tour des Logs
* @param id ID des Logs
* @return false bei error
* @throws SQLException Sql error
*/
public static void executeUpdateEditLog(String content, String bemerkung, LocalDate datum, double strecke, double avgspeed, double hightmeter, double pause, double gegangen, double dauer, String rating, String tourname, String id) throws SQLException {
Connection c = con();
PreparedStatement preparedStatement = c.prepareStatement(content);
preparedStatement.setString(1, bemerkung);
preparedStatement.setDate(2, Date.valueOf(datum));
preparedStatement.setDouble(3, strecke);
preparedStatement.setDouble(4, avgspeed);
preparedStatement.setDouble(5, hightmeter);
preparedStatement.setDouble(6, pause);
preparedStatement.setDouble(7, gegangen);
preparedStatement.setDouble(8, dauer);
preparedStatement.setString(9, rating);
preparedStatement.setString(10, tourname);
preparedStatement.setString(11, id);
exUpdate(preparedStatement, c);
}
/**
* Löscht ein log
* @param content Sql statement
* @param tourname Name der Tour
* @param id Id des logs
* @return false bei error
* @throws SQLException SQL error
*/
public static void executeUpdateDelLog(String content, String tourname, String id) throws SQLException {
Connection c = con();
PreparedStatement preparedStatement = c.prepareStatement(content);
preparedStatement.setString(1, tourname);
preparedStatement.setString(2, id);
exUpdate(preparedStatement, c);
}
/**
* Führt sql statement aus, mit einem String
* @param content Sql Statement
* @param string String im statement
* @return false bei error
* @throws SQLException Sql error
*/
public static void executeUpdateString(String content, String string) throws SQLException {
Connection c = con();
PreparedStatement preparedStatement = c.prepareStatement(content);
preparedStatement.setString(1, string);
exUpdate(preparedStatement, c);
}
/**
* Fügt eine Tour hinzu
* @param content Sql Statement
* @param name Name der Tour
* @param dauer Dauer der Tour
* @param mapJson MapJson der Tour
* @param start Start der Tour
* @param ziel Ziel der Tour
* @param strecke Strecke der Tour
* @return false bei error
* @throws SQLException Sql error
*/
public static void executeUpdateAddTour(String content, String name, String dauer, String mapJson, String start, String ziel, double strecke) throws SQLException {
Connection c = con();
PreparedStatement preparedStatement = c.prepareStatement(content);
preparedStatement.setString(1, name);
preparedStatement.setDouble(2, Double.parseDouble(dauer));
preparedStatement.setString(3, mapJson);
preparedStatement.setString(4, start);
preparedStatement.setString(5, ziel);
preparedStatement.setDouble(6, strecke);
exUpdate(preparedStatement, c);
}
/**
* Bearbeitet eine Tour
* @param content Sql Statement
* @param name Name der Tour
* @param mapJson MapJson der Tour
* @param start Start der Tour1
* @param ziel Ziel der Tour
* @param strecke Strecke der Tour
* @param oldname Alter Name der Tour
* @return false bei error
* @throws SQLException Sql error
*/
public static void executeUpdateEditTour(String content, String name, String mapJson, String start, String ziel, double strecke, String oldname) throws SQLException {
Connection c = con();
PreparedStatement preparedStatement = c.prepareStatement(content);
preparedStatement.setString(1, name);
preparedStatement.setString(2, mapJson);
preparedStatement.setString(3, start);
preparedStatement.setString(4, ziel);
preparedStatement.setDouble(5, strecke);
preparedStatement.setString(6, oldname);
exUpdate(preparedStatement, c);
}
}

View File

@ -3,9 +3,16 @@ package tourplaner.object;
import java.time.LocalDate;
public class Log {
private String id, bemerkung, rating;
private LocalDate datum;
private double strecke, avgspeed, hightmeter, pause, dauer, gegangen;
private String id;
private final String bemerkung;
private final String rating;
private final LocalDate datum;
private final double strecke;
private double avgspeed;
private final double hightmeter;
private final double pause;
private final double dauer;
private final double gegangen;
public Log(String id, double dauer, LocalDate datum, double strecke, String bemerkung, double hightmeter, double pause, String rating) {
this.id = id;

View File

@ -8,10 +8,10 @@ import java.util.concurrent.atomic.AtomicReference;
*/
public class Tour {
private String dauer;
private String mapJson;
private String name;
private String start;
private String ziel;
private final String mapJson;
private final String name;
private final String start;
private final String ziel;
private double strecke;
private ArrayList<Log> log;

View File

@ -1,6 +1,5 @@
package tourplaner.tests;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tourplaner.business.ConfigHelper;
import tourplaner.business.EinheitenAdder;

View File

@ -3,17 +3,22 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="tourplaner.ui.TourDetailsTabController">
<children>
<TableView fx:id="beschreibungTableView" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<columns>
<TableColumn fx:id="nameCol" minWidth="100.0" prefWidth="-1.0" text="Tourname" />
<TableColumn fx:id="dauerCol" maxWidth="1.7976931348623157E308" minWidth="100.0" prefWidth="-1.0" text="Dauer" />
<TableColumn fx:id="streckeCol" maxWidth="1.7976931348623157E308" minWidth="100.0" prefWidth="-1.0" text="Strecke" />
<TableColumn fx:id="startCol" maxWidth="1.7976931348623157E308" minWidth="100.0" prefWidth="-1.0" text="Startpunk" />
<TableColumn fx:id="zielCol" maxWidth="1.7976931348623157E308" minWidth="100.0" prefWidth="-1.0" text="Zielpunkt" />
</columns>
</TableView>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="tourplaner.ui.TourDetailsTabController">
<TableView fx:id="beschreibungTableView" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<columns>
<TableColumn fx:id="nameCol" minWidth="100.0" prefWidth="-1.0" text="Tourname"/>
<TableColumn fx:id="dauerCol" maxWidth="1.7976931348623157E308" minWidth="100.0" prefWidth="-1.0"
text="Dauer"/>
<TableColumn fx:id="streckeCol" maxWidth="1.7976931348623157E308" minWidth="100.0" prefWidth="-1.0"
text="Strecke"/>
<TableColumn fx:id="startCol" maxWidth="1.7976931348623157E308" minWidth="100.0" prefWidth="-1.0"
text="Startpunk"/>
<TableColumn fx:id="zielCol" maxWidth="1.7976931348623157E308" minWidth="100.0" prefWidth="-1.0"
text="Zielpunkt"/>
</columns>
</TableView>
</children>
</AnchorPane>

View File

@ -68,35 +68,33 @@
<padding>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</padding>
<HBox>
<children>
<Label text="Tours:">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="6.0" top="10.0" />
</HBox.margin>
</Label>
<Button fx:id="tourAdd" mnemonicParsing="false" onAction="#addTour" text="+">
<HBox.margin>
<Insets bottom="6.0" right="6.0" top="6.0" />
</HBox.margin>
</Button>
<Button fx:id="tourDel" mnemonicParsing="false" onAction="#delTour" text="-">
<HBox.margin>
<Insets bottom="6.0" right="6.0" top="6.0" />
</HBox.margin>
</Button>
<Button fx:id="editTourBtn" mnemonicParsing="false" onAction="#editTourBtn" text="Edit">
<HBox.margin>
<Insets bottom="6.0" right="6.0" top="6.0" />
</HBox.margin>
</Button>
<HBox>
<Label text="Tours:">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="6.0" top="10.0"/>
</HBox.margin>
</Label>
<Button fx:id="tourAdd" mnemonicParsing="false" onAction="#addTour" text="+">
<HBox.margin>
<Insets bottom="6.0" right="6.0" top="6.0"/>
</HBox.margin>
</Button>
<Button fx:id="tourDel" mnemonicParsing="false" onAction="#delTour" text="-">
<HBox.margin>
<Insets bottom="6.0" right="6.0" top="6.0"/>
</HBox.margin>
</Button>
<Button fx:id="editTourBtn" mnemonicParsing="false" onAction="#editTourBtn" text="Edit">
<HBox.margin>
<Insets bottom="6.0" right="6.0" top="6.0"/>
</HBox.margin>
</Button>
<Button fx:id="copyTourBtn" mnemonicParsing="false" onAction="#copyTour" text="Copy">
<HBox.margin>
<Insets bottom="6.0" right="6.0" top="6.0" />
</HBox.margin>
<HBox.margin>
<Insets bottom="6.0" right="6.0" top="6.0"/>
</HBox.margin>
</Button>
</children>
</HBox>
</HBox>
<AnchorPane HBox.hgrow="ALWAYS" />
<TextField fx:id="sucheInput" onKeyPressed="#sucheEnter" promptText="Suche..." />
<Button fx:id="sucheButton" mnemonicParsing="false" onAction="#suche" text="Suchen" />

View File

@ -2,8 +2,6 @@ package tourplaner.ui;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.stage.Stage;
@ -28,16 +26,6 @@ public class AlertHelper {
alertType(Alert.AlertType.WARNING, title, header, msg);
}
/**
* Info Dialog
* @param title Title des Dialogs
* @param header Header des Dialogs
* @param msg Nachricht des Dialogs
*/
public static void inform(String title, String header, String msg){
alertType(Alert.AlertType.INFORMATION, title, header, msg);
}
/**
* Error Dialog
* @param title Title des Dialogs

View File

@ -12,8 +12,8 @@ import java.io.IOException;
public class ProgressBar {
private int status;
private JFrame frame;
private JProgressBar progressBar;
private final JFrame frame;
private final JProgressBar progressBar;
public ProgressBar(String title){
this.frame = new JFrame(title);

View File

@ -18,6 +18,7 @@ import tourplaner.viewmodels.ViewModel;
import java.io.IOException;
import java.net.URL;
import java.sql.SQLException;
import java.util.ResourceBundle;
import java.util.concurrent.atomic.AtomicInteger;
@ -25,6 +26,7 @@ public class TourplanerController implements Initializable {
//VM
private final ViewModel viewModel = new ViewModel();
//Tour list -> links
@SuppressWarnings("CanBeFinal")
public ListView<String> TourListView = new ListView<>();
//Tabs zu Tour -> rechts oben
public TabPane viewTabPane;
@ -48,33 +50,29 @@ public class TourplanerController implements Initializable {
ProgressBar progressBar = new ProgressBar("Copy");
this.viewModel.copyTour(progressBar, 80);
syncTourNamen(progressBar, 90);
tourFocusOnSelected(progressBar, 100);
tourFocusOnSelected(progressBar);
}
@FXML
private void copyLogBtn(){
this.viewModel.copyLog();
syncLogs();
try {
this.viewModel.copyLog();
syncLogs();
} catch (SQLException throwables) {
LogHelper.error(throwables);
}
}
@FXML
private void onlangenglisch(){
ConfigHelper.setIniString(ConfigHelper.getStandartConfig(), "lang", "lang", "langen");
try {
langToFxml();
} catch (IOException e) {
LogHelper.error(e);
}
langToFxml();
}
@FXML
private void onlangdeutsch(){
ConfigHelper.setIniString(ConfigHelper.getStandartConfig(), "lang", "lang", "langde");
try {
langToFxml();
} catch (IOException e) {
LogHelper.error(e);
}
langToFxml();
}
@FXML
@ -87,16 +85,24 @@ public class TourplanerController implements Initializable {
private void editTourBtn(){
try {
this.viewModel.editTour();
} catch (IOException e) {
} catch (IOException | SQLException e) {
LogHelper.error(e);
}
syncTour(this.viewModel.getSelectedTour().getName());
String name = this.viewModel.getSelectedTour().getName();
titleTextView.setText(name);
tourFocusOnSelected(new ProgressBar("Focus"));
syncTour(name);
syncLogs();
}
@FXML
private void editLogBtn(){
this.viewModel.editLog();
syncLogs();
try {
this.viewModel.editLog();
syncLogs();
} catch (SQLException throwables) {
LogHelper.error(throwables);
}
}
/**
* Öffnet github im standart browser
@ -148,50 +154,53 @@ public class TourplanerController implements Initializable {
@FXML
private void tourListSelectedItem(MouseEvent mouseEvent){
//Beschreibung
ProgressBar progressBar = new ProgressBar("Tour auswählen...");
int steps = progressBar.getProgressSize(7, 100);
String selectedItem = TourListView.getSelectionModel().getSelectedItem();
this.viewModel.selectTour(selectedItem);
titleTextView.setText(selectedItem);
progressBar.addProgress(steps);
syncTour(selectedItem);
progressBar.addProgress(steps);
this.tourDetailsTabController.tourListSelectItem();
//Log anzeigen
logTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinelogsvorhanden")));
logTableView.getItems().clear();
progressBar.addProgress(steps);
logTableView.setItems(this.viewModel.getLogData());
progressBar.addProgress(steps);
logDauerCol.setCellValueFactory(new PropertyValueFactory<>("dauer"));
logStreckeCol.setCellValueFactory(new PropertyValueFactory<>("strecke"));
logDatumCol.setCellValueFactory(new PropertyValueFactory<>("datum"));
logAvgCol.setCellValueFactory(new PropertyValueFactory<>("avgspeed"));
logHightCol.setCellValueFactory(new PropertyValueFactory<>("hightmeter"));
logPauseCol.setCellValueFactory(new PropertyValueFactory<>("pause"));
logGegangenCol.setCellValueFactory(new PropertyValueFactory<>("gegangen"));
logBemerkungCol.setCellValueFactory(new PropertyValueFactory<>("bemerkung"));
logRatingCol1.setCellValueFactory(new PropertyValueFactory<>("rating"));
progressBar.addProgress(steps);
mapImageView.setImage(this.viewModel.getImage(this.viewModel.getSelectedTour().getName()));
if(this.viewModel.isSucheAktiv()){
this.viewModel.setSucheAktiv(false);
syncTourNamen(progressBar, 100 - steps);
this.sucheInput.setText("");
tourFocusOnSelected(progressBar, 100);
if(!selectedItem.isEmpty()) {
ProgressBar progressBar = new ProgressBar("Tour auswählen...");
int steps = progressBar.getProgressSize(7, 100);
this.viewModel.selectTour(selectedItem);
titleTextView.setText(selectedItem);
progressBar.addProgress(steps);
syncTour(selectedItem);
progressBar.addProgress(steps);
this.tourDetailsTabController.tourListSelectItem();
//Log anzeigen
logTableView.setPlaceholder(new Label(ConfigHelper.getLangIniString("keinelogsvorhanden")));
logTableView.getItems().clear();
progressBar.addProgress(steps);
logTableView.setItems(this.viewModel.getLogData());
progressBar.addProgress(steps);
logDauerCol.setCellValueFactory(new PropertyValueFactory<>("dauer"));
logStreckeCol.setCellValueFactory(new PropertyValueFactory<>("strecke"));
logDatumCol.setCellValueFactory(new PropertyValueFactory<>("datum"));
logAvgCol.setCellValueFactory(new PropertyValueFactory<>("avgspeed"));
logHightCol.setCellValueFactory(new PropertyValueFactory<>("hightmeter"));
logPauseCol.setCellValueFactory(new PropertyValueFactory<>("pause"));
logGegangenCol.setCellValueFactory(new PropertyValueFactory<>("gegangen"));
logBemerkungCol.setCellValueFactory(new PropertyValueFactory<>("bemerkung"));
logRatingCol1.setCellValueFactory(new PropertyValueFactory<>("rating"));
progressBar.addProgress(steps);
mapImageView.setImage(this.viewModel.getImage(this.viewModel.getSelectedTour().getName()));
if (this.viewModel.isSucheAktiv()) {
this.viewModel.setSucheAktiv(false);
syncTourNamen(progressBar, 100 - steps);
this.sucheInput.setText("");
tourFocusOnSelected(progressBar);
}
progressBar.setProgress(100);
}
progressBar.setProgress(100);
}
/**
* Setzt den Focus auf die ausgewählte Tour
*/
private void tourFocusOnSelected(ProgressBar progressBar, int maxLevel){
private void tourFocusOnSelected(ProgressBar progressBar){
//Tour namen select focus
AtomicInteger index = new AtomicInteger();
AtomicInteger indexF = new AtomicInteger();
this.viewModel.getTourNamen(progressBar, maxLevel).forEach(tn -> {
this.viewModel.getTourNamen(progressBar, 100).forEach(tn -> {
index.getAndIncrement();
if(tn.equals(this.viewModel.getSelectedTour().getName())){
indexF.set(index.get());
@ -261,8 +270,12 @@ public class TourplanerController implements Initializable {
@FXML
private void delLog(){
this.viewModel.delLog();
syncLogs();
try {
this.viewModel.delLog();
syncLogs();
} catch (SQLException throwables) {
LogHelper.error(throwables);
}
}
/**
@ -285,16 +298,8 @@ public class TourplanerController implements Initializable {
TourListView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
TourListView.setOrientation(Orientation.VERTICAL);
syncTourNamen(new ProgressBar("Start"), 100);
if(ConfigHelper.getIniInt(ConfigHelper.getStandartConfig(), "settings", "openpdf") == 1){
this.openpdf.setSelected(true);
}else {
this.openpdf.setSelected(false);
}
if(ConfigHelper.getIniInt(ConfigHelper.getStandartConfig(), "settings", "openmap") == 1){
this.openmap.setSelected(true);
}else {
this.openmap.setSelected(false);
}
this.openpdf.setSelected(ConfigHelper.getIniInt(ConfigHelper.getStandartConfig(), "settings", "openpdf") == 1);
this.openmap.setSelected(ConfigHelper.getIniInt(ConfigHelper.getStandartConfig(), "settings", "openmap") == 1);
ToggleGroup langgroup = new ToggleGroup();
this.langdeutsch.setToggleGroup(langgroup);
this.langenglisch.setToggleGroup(langgroup);
@ -306,24 +311,24 @@ public class TourplanerController implements Initializable {
this.langenglisch.setSelected(true);
}
// Child fxml load
FXMLLoader loader = new FXMLLoader(Main.class.getResource("tourDetails.fxml"));
try {
// Child fxml load
FXMLLoader loader = new FXMLLoader(Main.class.getResource("tourDetails.fxml"));
this.beschreibungTab.setContent(loader.load());
this.tourDetailsTabController = loader.getController();
langToFxml();
deselectAll();
} catch (IOException e) {
LogHelper.error(e);
}
this.tourDetailsTabController = loader.getController();
langToFxml();
deselectAll();
}
/**
* Setzt jedem Element den Text der gewählten Sprache
*/
private void langToFxml() throws IOException {
private void langToFxml() {
this.kartenTab.setText(ConfigHelper.getLangIniString("fkarte"));
this.beschreibungTab.setText(ConfigHelper.getLangIniString("fbeschreibung"));
this.editBtn.setText(ConfigHelper.getLangIniString("fedit"));
@ -387,9 +392,8 @@ public class TourplanerController implements Initializable {
@FXML
private void importBtn(){
ProgressBar progressBar = new ProgressBar("Import");
deselectAll();
this.viewModel.importData(progressBar, 90);
ProgressBar progressBar = this.viewModel.importData(90);
syncTourNamen(progressBar, 100);
}

View File

@ -13,9 +13,9 @@ import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@ -41,7 +41,7 @@ public class ViewModel {
* prüft ob eine tour ausgewählt ist
* @throws IOException Fehler beim editieren der Tour
*/
public void editTour() throws IOException {
public void editTour() throws IOException, SQLException {
if (this.selectedTour == null){
AlertHelper.warn(ConfigHelper.getLangIniString("achtung"),
ConfigHelper.getLangIniString("keinetourselected"),
@ -66,7 +66,7 @@ public class ViewModel {
Tour newTour = new Tour(this.neueTourName, "TBD", "TBD", 0, this.neueTourStart, this.neueTourZiel);
this.tourData.add(newTour);
this.tourNamen.add(this.neueTourName);
LogHelper.info("Edit Tour: " + this.neueTourName + " upload zu Postgres war: " + TourPlaner.editTour(this.selectedTour.getName(), newTour), "ViewModel - EditTour");
TourPlaner.editTour(this.selectedTour.getName(), newTour);
selectTour(this.neueTourName);
}
}
@ -167,7 +167,7 @@ public class ViewModel {
progressBar.addProgress(10);
try {
TourPlaner.addTour(newTour, progressBar);
} catch (IOException e) {
} catch (IOException | SQLException e) {
LogHelper.error(e);
return false;
}
@ -195,7 +195,8 @@ public class ViewModel {
/**
* Bearbeitet einen gewählten Log eintrag
*/
public void editLog(){
@SuppressWarnings("UnusedAssignment")
public void editLog() throws SQLException {
if(this.selectedTour != null) {
if(this.selectedLog != null) {
AtomicReference<Tour> tourAkt = new AtomicReference<>();
@ -310,7 +311,7 @@ public class ViewModel {
* @return Das eingegebene korekte Datum
*/
private LocalDate dateInput(LocalDate date){
LocalDate neuesDatum = null;
LocalDate neuesDatum;
neuesDatum = AlertHelper.datePicker(date);
return neuesDatum;
}
@ -351,6 +352,7 @@ public class ViewModel {
* Fügt einen Log eintrag zu einer Tour hinzu.
* Ist keine Tour ausgewählt, dann kommt eine Warnung an den User!
*/
@SuppressWarnings("UnusedAssignment")
public void addLog(){
if (!keineTourSelected()){
this.tourData.forEach(s -> {
@ -377,7 +379,11 @@ public class ViewModel {
if(rating >= 0.0) {
Log newLog = new Log(newId.get(), dauer, date, strecke, this.neueBemerkung, hightmeter, pause, rating + "");
this.logData.add(newLog);
TourPlaner.addLog(this.selectedTour.getName(), newLog);
try {
TourPlaner.addLog(this.selectedTour.getName(), newLog);
} catch (SQLException throwables) {
LogHelper.error(throwables);
}
s.addLog(newLog);
}
}
@ -398,7 +404,7 @@ public class ViewModel {
/**
* Entfernt ein Log anhand des selectierten Logs
*/
public void delLog(){
public void delLog() throws SQLException {
if(this.selectedLog != null) {
TourPlaner.delLog(this.selectedTour.getName(), this.selectedLog.getId());
this.selectedLog = null;
@ -502,7 +508,7 @@ public class ViewModel {
TourPlaner.delTour(tourname);
setSelectedTour(null);
progressBar.setProgress(100);
} catch (NullPointerException e) {
} catch (NullPointerException | SQLException e) {
LogHelper.error(e);
}
}else {
@ -567,8 +573,8 @@ public class ViewModel {
/**
* Öffnet einen link im Standart Browser
* @param uriString
* @param appname
* @param uriString Uri String zum öffnen
* @param appname App Name
*/
private void openBrowser(String uriString, String appname){
Desktop desktop = java.awt.Desktop.getDesktop();
@ -584,15 +590,6 @@ public class ViewModel {
}
}
/**
* Funktion für noch nicht implementierte sachen wie im Menu der 'Bearbeiten' und 'Optionen' Knopf
*/
public void nimpButton(){
AlertHelper.inform(ConfigHelper.getLangIniString("achtung"),
ConfigHelper.getLangIniString("fktnichtimplementiert"),
ConfigHelper.getLangIniString("vergessenodernochnichtsoweit"));
}
/**
* Startet den Tour Report
*/
@ -623,13 +620,16 @@ public class ViewModel {
/**
* Importiert alle daten von einem File das hier gewählt wird
* @return Die aktuelle Progressbar
*/
public void importData(ProgressBar progressBar, int maxProgress) {
public ProgressBar importData(int maxProgress) {
String file = AlertHelper.fileChooser("Importiere");
ProgressBar progressBar = new ProgressBar("Import");
if (file != null){
this.tourNamen = FXCollections.observableArrayList();
new Exporter(file).doImport(progressBar, maxProgress);
}
return progressBar;
}
/**
@ -650,12 +650,18 @@ public class ViewModel {
/**
* Kopiert einen Log eintrag und erstellt dafür eine neue Id für das kopierte log
*/
public void copyLog() {
public void copyLog() throws SQLException {
Log selectedLog = getSelectedLog();
Tour selectedTour = getSelectedTour();
if(selectedLog == null && selectedTour == null){
//TODO kein log & keine tour selected error alert
}else {
if(selectedTour == null){
AlertHelper.warn(ConfigHelper.getLangIniString("achtung"),
ConfigHelper.getLangIniString("keinetourselected"),
ConfigHelper.getLangIniString("keinetourselected"));
}else if(selectedLog == null) {
AlertHelper.warn(ConfigHelper.getLangIniString("achtung"),
ConfigHelper.getLangIniString("keinlogselected"),
ConfigHelper.getLangIniString("keinlogselected"));
}else{
selectedLog.setId(TourPlaner.newLogId(this.logData));
TourPlaner.addLog(selectedTour.getName(), selectedLog);
}
@ -663,14 +669,15 @@ public class ViewModel {
/**
* Kopiert eie Tour und hängt dafür am ende des namens ein _copy an
* @return Der neue Tour name, bei error ""
*/
public String copyTour(ProgressBar progressBar, int maxLevel) {
public void copyTour(ProgressBar progressBar, int maxLevel) {
Tour selectedTour = getSelectedTour();
String newName = "";
String newName;
if (selectedTour == null){
//TODO keine tour selected
return "";
progressBar.setProgress(100);
AlertHelper.warn(ConfigHelper.getLangIniString("achtung"),
ConfigHelper.getLangIniString("keinetourselected"),
ConfigHelper.getLangIniString("keinetourselected"));
}else {
newName = selectedTour.getName() + "_copy";
try {
@ -678,21 +685,26 @@ public class ViewModel {
progressBar.addProgress(10);
TourPlaner.addTourMax(new Tour(newName, selectedTour.getDauer(), selectedTour.getMapJson(), selectedTour.getStrecke(), selectedTour.getStart(), selectedTour.getZiel(), logs), progressBar, 70);
String finalNewName = newName;
int steps = progressBar.getProgressSize(logs.size(), maxLevel-10);
logs.forEach(l -> {
TourPlaner.addLog(finalNewName, l);
progressBar.addProgress(steps);
});
if(logs != null && logs.size() != 0) {
int steps = progressBar.getProgressSize(logs.size(), maxLevel - 10);
logs.forEach(l -> {
try {
TourPlaner.addLog(newName, l);
} catch (SQLException throwables) {
LogHelper.error(throwables);
}
progressBar.addProgress(steps);
});
}else {
progressBar.setProgress(maxLevel - 10);
}
getTourData(progressBar, maxLevel);
// getLogData();
selectTour(newName);
progressBar.setProgress(maxLevel);
return newName;
} catch (IOException e) {
} catch (IOException | SQLException e) {
LogHelper.error(e);
progressBar.setProgress(maxLevel);
return "";
}
}
}