diff --git a/.gitignore b/.gitignore index bae2fd6..f3279aa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .project .vscode target +*.csv diff --git a/src/main/java/de/hsel/spm/baudas/web/Data.java b/src/main/java/de/hsel/spm/baudas/web/Data.java index d5f47e2..6c8d159 100644 --- a/src/main/java/de/hsel/spm/baudas/web/Data.java +++ b/src/main/java/de/hsel/spm/baudas/web/Data.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.time.LocalDateTime; import java.util.UUID; import java.util.concurrent.ConcurrentLinkedQueue; @@ -36,7 +37,7 @@ public class Data { //cleanup old files if (files.isEmpty()) { try { - Files.list(Paths.get("target/")).forEach(path -> { + Files.list(Paths.get("")).forEach(path -> { if (path.toFile().getName().endsWith(".csv")) { try { Files.delete(path); @@ -60,11 +61,11 @@ public class Data { System.out.println("failed to delete file..."); } path = Paths.get(getFileName(uuid)); - files.offer(new SavedFile(uuid, name)); + files.offer(new SavedFile(uuid, name, LocalDateTime.now())); } else { - files.add(new SavedFile(uuid, name)); + files.add(new SavedFile(uuid, name, LocalDateTime.now())); path = Paths.get(getFileName(uuid)); } return path; @@ -91,6 +92,6 @@ public class Data { @Contract(pure = true) @NotNull private static String getFileName(@NotNull UUID uuid) { - return "target/" + uuid + ".csv"; + return uuid + ".csv"; } } \ No newline at end of file diff --git a/src/main/java/de/hsel/spm/baudas/web/SavedFile.java b/src/main/java/de/hsel/spm/baudas/web/SavedFile.java index f568faf..c0ae3fa 100644 --- a/src/main/java/de/hsel/spm/baudas/web/SavedFile.java +++ b/src/main/java/de/hsel/spm/baudas/web/SavedFile.java @@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.ToString; +import java.time.LocalDateTime; import java.util.UUID; /** @@ -20,4 +21,5 @@ class SavedFile { private UUID uuid; private String name; + private LocalDateTime date; } \ No newline at end of file diff --git a/src/main/java/de/hsel/spm/baudas/web/ShoppingTimesDiagram.java b/src/main/java/de/hsel/spm/baudas/web/ShoppingTimesDiagram.java index 41a491e..11b6c69 100644 --- a/src/main/java/de/hsel/spm/baudas/web/ShoppingTimesDiagram.java +++ b/src/main/java/de/hsel/spm/baudas/web/ShoppingTimesDiagram.java @@ -9,6 +9,7 @@ import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; @@ -21,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; +import java.util.UUID; /** * changes data from shopping times diagram into a readable format for chart.js @@ -48,15 +50,16 @@ public class ShoppingTimesDiagram extends HttpServlet { Gson gson = new Gson(); - SavedFile file = Data.getFiles().peek(); - if (file == null) { + + if (req.getParameter("id") == null) { result.put("labels", definedOrder); out.print(gson.toJson(result)); return; } + UUID uuid = UUID.fromString(req.getParameter("id")); + File file = Data.get(uuid); - assert file.getUuid() != null; - ShoppingTimes shoppingTimes = new ShoppingTimes(Data.get(file.getUuid())); + ShoppingTimes shoppingTimes = new ShoppingTimes(file); Map map = shoppingTimes.getResult(); Set days = new TreeSet<>(); diff --git a/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java b/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java index 905c8a5..9230839 100644 --- a/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java +++ b/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java @@ -8,6 +8,7 @@ import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; @@ -17,6 +18,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; /** * changes data from week overview into readable format for chart.js @@ -43,16 +45,19 @@ public class WeekOverviewDiagram extends HttpServlet { Gson gson = new Gson(); - SavedFile file = Data.getFiles().peek(); - if (file == null) { + + if (req.getParameter("id") == null) { result.put("labels", definedOrder); result.put("count", new ArrayList<>()); result.put("revenue", new ArrayList<>()); out.print(gson.toJson(result)); return; } - assert file.getUuid() != null; - WeekOverview overview = new WeekOverview(Data.get(file.getUuid())); + + UUID uuid = UUID.fromString(req.getParameter("id")); + File file = Data.get(uuid); + + WeekOverview overview = new WeekOverview(file); List count = new ArrayList<>(); List revenue = new ArrayList<>(); diff --git a/src/main/webapp/footer.jsp b/src/main/webapp/footer.jsp index e74138a..e6dd7bc 100644 --- a/src/main/webapp/footer.jsp +++ b/src/main/webapp/footer.jsp @@ -7,7 +7,11 @@ - + + + diff --git a/src/main/webapp/header.jsp b/src/main/webapp/header.jsp index c7bd797..77aceae 100644 --- a/src/main/webapp/header.jsp +++ b/src/main/webapp/header.jsp @@ -23,11 +23,11 @@