diff --git a/.gitignore b/.gitignore
index 8b4d85b..ff1c429 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
out/
conf.ini
-log/log4j/log.out/
+log/
reports/
+.idea/dataSources*
\ No newline at end of file
diff --git a/Tourplaner.iml b/Tourplaner.iml
index ceedf37..f60b871 100644
--- a/Tourplaner.iml
+++ b/Tourplaner.iml
@@ -11,5 +11,6 @@
+
\ No newline at end of file
diff --git a/src/tourplaner/business/TourPlaner.java b/src/tourplaner/business/TourPlaner.java
index beae0a1..853a41f 100644
--- a/src/tourplaner/business/TourPlaner.java
+++ b/src/tourplaner/business/TourPlaner.java
@@ -1,10 +1,13 @@
package tourplaner.business;
import org.apache.log4j.Logger;
+import org.apache.pdfbox.exceptions.COSVisitorException;
import tourplaner.data.DbConnect;
import tourplaner.data.PostgresHelper;
+import tourplaner.object.Log;
import tourplaner.object.Tour;
+import java.io.IOException;
import java.util.ArrayList;
/**
@@ -25,9 +28,7 @@ public class TourPlaner{
* @return Alle touren als ArrayList
*/
public static ArrayList getAllTours(){
- DbConnect dbConnect = new DbConnect();
- ArrayList touren = dbConnect.getAllTouren();
- return touren;
+ return new DbConnect().getAllTouren();
}
/**
@@ -37,13 +38,11 @@ public class TourPlaner{
* @return false bei error
*/
public static boolean editTour(String oldname, Tour tour){
- DbConnect dbConnect = new DbConnect();
- return dbConnect.editTour(oldname, tour);
+ return new DbConnect().editTour(oldname, tour);
}
public static boolean delTour(String tourname){
- DbConnect dbConnect = new DbConnect();
- return dbConnect.delTour(tourname);
+ return new DbConnect().delTour(tourname);
}
/**
@@ -52,11 +51,38 @@ public class TourPlaner{
* @return false bei error
*/
public static boolean addTour(Tour newTour){
- DbConnect dbConnect = new DbConnect();
- return dbConnect.addTour(newTour);
+ return new DbConnect().addTour(newTour);
}
+ public static ArrayList getLogs(String tourname){
+ return new DbConnect().getLogs(tourname);
+ }
+
+ public static void doReport(String tourname){
+ try {
+ Reporter.createTourReport(tourname);
+ } catch (IOException e) {
+ LogHelper.error(e.getMessage(), e.getClass().getName());
+ } catch (COSVisitorException e) {
+ LogHelper.error(e.getMessage(), e.getClass().getName());
+ }
+ }
+
+ public static boolean addLog(String tourname, Log log){
+ if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
+ return new DbConnect().addLog(tourname, log);
+ }
+
+ public static boolean delLog(String tourname, String id){
+ return new DbConnect().delLog(tourname, id);
+ }
+
+ public static boolean editLog(String tourname, Log log){
+ if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
+ return new DbConnect().editLog(tourname, log);
+ }
+
public static String getMapJson(String start, String ziel){
// TODO: 14.04.2021 Map Quest
diff --git a/src/tourplaner/data/DbConnect.java b/src/tourplaner/data/DbConnect.java
index 7112486..c76500c 100644
--- a/src/tourplaner/data/DbConnect.java
+++ b/src/tourplaner/data/DbConnect.java
@@ -1,10 +1,14 @@
package tourplaner.data;
+import javafx.geometry.Pos;
+import tourplaner.object.Log;
import tourplaner.object.Tour;
import java.sql.Connection;
+import java.sql.Date;
import java.sql.ResultSet;
import java.sql.Statement;
+import java.time.LocalDate;
import java.util.ArrayList;
/**
@@ -45,9 +49,20 @@ public class DbConnect {
* @return false bei error
*/
public boolean editTour(String oldname, Tour tour) {
- return 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 + "';");
+ String tourname = tour.getName();
+ ArrayList result = new ArrayList<>();
+ ArrayList 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);
}
+ private boolean delLogs(String tourname){
+ return PostgresHelper.executeUpdate("DELETE FROM public.log WHERE tourname = '"+tourname+"'");
+ }
/**
* Fügt eine Tour hinzu
* @param tour Neue Tour
@@ -63,7 +78,70 @@ public class DbConnect {
* @return false bei error
*/
public boolean delTour(String tourname){
- return PostgresHelper.executeUpdate("DELETE FROM public.tour WHERE tourname = '"+tourname+"'");
+ ArrayList result = new ArrayList<>();
+ result.add(delLogs(tourname));
+ result.add(PostgresHelper.executeUpdate("DELETE FROM public.tour WHERE tourname = '"+tourname+"'"));
+ return !result.contains(false);
+ }
+
+ public ArrayList getLogs(String tourname){
+
+ this.c = PostgresHelper.con();
+ String id, bemerkung ;
+ double dauer, strecke, pause, gegangen, avg, hightmeter;
+ Date datum;
+
+ ArrayList logs = new ArrayList<>();
+ try {
+ stmt = this.c.createStatement();
+ ResultSet rs = stmt.executeQuery("SELECT * FROM public.log where tourname = '"+ tourname +"'");
+ while (rs.next()) {
+ id = rs.getString("id");
+ bemerkung = rs.getString("bemerkung");
+ datum = rs.getDate("datum");
+ dauer = rs.getDouble("dauer");
+// avg = rs.getDouble("avg");
+ hightmeter = rs.getDouble("hightmeter");
+ pause = rs.getDouble("pause");
+// gegangen = rs.getDouble("gegangen");
+ strecke = rs.getDouble("strecke");
+ if (!tourname.isEmpty()) {
+ logs.add(new Log(id, dauer, datum.toLocalDate(), strecke, bemerkung,hightmeter, pause));
+ }else {
+ return null;
+ }
+ }
+ rs.close();
+ stmt.close();
+ this.c.close();
+ return logs;
+ } catch (Exception e) {
+ System.err.println(e.getClass().getName() + ": " + e.getMessage());
+ return null;
+ }
+ }
+
+
+ /**
+ * Füght einen Logeintrag ein
+ * @param tourname Zu welcher Tour der Logeintrag gehört
+ * @param log Der Logeintrag
+ * @return false bei error
+ */
+ public boolean addLog(String tourname, Log log){
+ 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) VALUES ('"+tourname+"', '"+log.getId()+"', '"+log.getBemerkung()+"', '"+log.getDatum()+"', "
+ +log.getStrecke()+", "+log.getAvgspeed()+", "+log.getHightmeter()+", "+log.getPause()+", "+log.getGegangen()+", "+log.getDauer()+")");
+ }
+
+ 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()+" WHERE tourname = '"+tourname+"' and id = '"+log.getId()+"'");
+ }
+
+ public boolean delLog(String tourname, String id){
+ System.out.println("DELETE FROM public.log WHERE tourname = '"+tourname+"' and id = '"+id+"'");
+ return PostgresHelper.executeUpdate("DELETE FROM public.log WHERE tourname = '"+tourname+"' and id = '"+id+"'");
}
/**
diff --git a/src/tourplaner/ui/TourplanerController.java b/src/tourplaner/ui/TourplanerController.java
index 8cfc812..16ce388 100644
--- a/src/tourplaner/ui/TourplanerController.java
+++ b/src/tourplaner/ui/TourplanerController.java
@@ -11,6 +11,7 @@ import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import tourplaner.business.ConfigHelper;
import tourplaner.business.LogHelper;
+import tourplaner.business.TourPlaner;
import tourplaner.object.Log;
import tourplaner.object.Tour;
import tourplaner.viewmodels.ViewModel;
@@ -49,13 +50,13 @@ public class TourplanerController implements Initializable {
@FXML
private void editTourBtn(){
this.viewModel.editTour();
- beschreibungTableView.getItems().removeIf(s -> true); //Leert die Table View komplett
- beschreibungTableView.getItems().add(this.viewModel.getTour(this.viewModel.getSelectedTour().getName()));
+ syncTour(this.viewModel.getSelectedTour().getName());
}
@FXML
private void editLogBtn(){
this.viewModel.editLog();
+ syncLogs();
}
/**
* Öffnet github im standart browser
@@ -84,6 +85,19 @@ public class TourplanerController implements Initializable {
this.viewModel.doxygenDocBrowser();
}
+ private void syncTour(String selectedItem){
+ beschreibungTableView.getItems().removeIf(s -> true); //Leert die Table View komplett
+ beschreibungTableView.getItems().add(this.viewModel.getTour(selectedItem));
+ }
+
+ private void syncTourNamen(){
+ TourListView.setItems(this.viewModel.getTourNamen());
+ }
+
+ private void syncLogs(){
+ logTableView.getItems().removeIf(s -> true);
+ logTableView.setItems(this.viewModel.getLogData());
+ }
/**
@@ -95,8 +109,7 @@ public class TourplanerController implements Initializable {
String selectedItem = TourListView.getSelectionModel().getSelectedItem();
this.viewModel.selectTour(selectedItem);
titleTextView.setText(selectedItem);
- beschreibungTableView.getItems().removeIf(s -> true); //Leert die Table View komplett
- beschreibungTableView.getItems().add(this.viewModel.getTour(selectedItem));
+ syncTour(selectedItem);
startCol.setCellValueFactory(new PropertyValueFactory("start"));
zielCol.setCellValueFactory(new PropertyValueFactory("ziel"));
dauerCol.setCellValueFactory(new PropertyValueFactory("dauer"));
@@ -105,6 +118,7 @@ public class TourplanerController implements Initializable {
//Log anzeigen
logTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinelogsvorhanden")));
+ logTableView.getItems().removeIf(s -> true);
logTableView.setItems(this.viewModel.getLogData());
logDauerCol.setCellValueFactory(new PropertyValueFactory("dauer"));
logStreckeCol.setCellValueFactory(new PropertyValueFactory("strecke"));
@@ -163,12 +177,13 @@ public class TourplanerController implements Initializable {
@FXML
private void addLog(){
this.viewModel.addLog();
+ syncLogs();
}
@FXML
private void delLog(){
this.viewModel.delLog();
-
+ syncLogs();
}
/**
@@ -190,7 +205,7 @@ public class TourplanerController implements Initializable {
//Tour list -> links
TourListView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
TourListView.setOrientation(Orientation.VERTICAL);
- TourListView.setItems(this.viewModel.getTourNamen());
+ syncTourNamen();
//Tabs zu Tour -> rechts oben
beschreibungTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinetourselected")));
titleTextView.setText( ConfigHelper.getLangIniString("keinetourselected"));
diff --git a/src/tourplaner/viewmodels/ViewModel.java b/src/tourplaner/viewmodels/ViewModel.java
index 45f5bf2..946ba6f 100644
--- a/src/tourplaner/viewmodels/ViewModel.java
+++ b/src/tourplaner/viewmodels/ViewModel.java
@@ -212,10 +212,11 @@ public class ViewModel {
Log newLog = new Log(this.selectedLog.getId(), dauer, datum, strecke, this.neueBemerkung, hightmeter, pause);
this.logData.removeIf(ld -> ld.getId().equals(this.selectedLog.getId()));
this.logData.add(newLog);
- tourAkt.get().delLog(this.selectedLog.getId());
- tourAkt.get().addLog(newLog);
+// tourAkt.get().delLog(this.selectedLog.getId());
+// tourAkt.get().addLog(newLog);
this.tourData.removeIf(td -> td.getName().equals(this.selectedTour.getName()));
this.tourData.add(tourAkt.get());
+ TourPlaner.editLog(this.selectedTour.getName(), newLog);
}
}
}
@@ -327,6 +328,7 @@ public class ViewModel {
if (date != null) {
Log newLog = new Log(newId.get(), dauer, date, strecke, this.neueBemerkung, hightmeter, pause);
this.logData.add(newLog);
+ TourPlaner.addLog(this.selectedTour.getName(), newLog);
s.addLog(newLog);
}
}
@@ -348,25 +350,8 @@ public class ViewModel {
*/
public void delLog(){
if(this.selectedLog != null) {
- this.logData.removeIf(s -> s.getId().equals(this.selectedLog.getId()));
- AtomicReference tourToEdit = new AtomicReference<>();
- this.tourData.forEach(s -> {
- if (s.getLogs() != null) {
- s.getLogs().forEach(ss -> {
- if (ss.getId().equals(this.selectedLog.getId())) {
- tourToEdit.set(s);
- }
- });
- }
- });
-
- if (tourToEdit.get() != null){
- Tour toEdit = tourToEdit.get();
- toEdit.delLog(this.selectedLog.getId());
- this.tourData.removeIf(s -> s.getName().equals(toEdit.getName()));
- this.tourData.add(toEdit);
+ TourPlaner.delLog(this.selectedTour.getName(), this.selectedLog.getId());
this.selectedLog = null;
- }
}else{
AlertHelper.warn(ConfigHelper.getLangIniString("achtung"),
ConfigHelper.getLangIniString("keinetourselected"),
@@ -406,6 +391,8 @@ public class ViewModel {
}
public ObservableList getLogData() {
+ logData.removeAll();
+ logData.addAll(TourPlaner.getLogs(this.selectedTour.getName()));
return logData;
}
@@ -586,14 +573,7 @@ public class ViewModel {
ConfigHelper.getLangIniString("keinetourselected"),
ConfigHelper.getLangIniString("logtournotselectedmsg"));
}else {
- try {
- Reporter.createTourReport(this.selectedTour.getName());
- } catch (IOException e) {
- LogHelper.error(e.getMessage(), e.getClass().getName());
- } catch (COSVisitorException e) {
- LogHelper.error(e.getMessage(), e.getClass().getName());
- }
-
+ TourPlaner.doReport(this.selectedTour.getName());
}
}
}