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 11b6c69..ed40db8 100644 --- a/src/main/java/de/hsel/spm/baudas/web/ShoppingTimesDiagram.java +++ b/src/main/java/de/hsel/spm/baudas/web/ShoppingTimesDiagram.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.UUID; +import java.util.regex.Pattern; /** * changes data from shopping times diagram into a readable format for chart.js @@ -34,6 +35,8 @@ import java.util.UUID; @WebServlet("/shopping_times") public class ShoppingTimesDiagram extends HttpServlet { + private static Map cache = new HashMap<>(); + private static final long serialVersionUID = 6567531484L; @Override @@ -50,13 +53,21 @@ public class ShoppingTimesDiagram extends HttpServlet { Gson gson = new Gson(); - - if (req.getParameter("id") == null) { - result.put("labels", definedOrder); - out.print(gson.toJson(result)); + String id = req.getParameter("id"); + boolean match = Pattern.matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}", id); + if (id == null || !match) { return; } - UUID uuid = UUID.fromString(req.getParameter("id")); + + UUID uuid = UUID.fromString(id); + + + if(cache.containsKey(uuid)) { + out.print(gson.toJson(cache.get(uuid))); + return; + } + + File file = Data.get(uuid); ShoppingTimes shoppingTimes = new ShoppingTimes(file); @@ -81,7 +92,7 @@ public class ShoppingTimesDiagram extends HttpServlet { } } - + cache.put(uuid, result); out.print(gson.toJson(result)); } diff --git a/src/main/java/de/hsel/spm/baudas/web/TopFlopArticleDiagram.java b/src/main/java/de/hsel/spm/baudas/web/TopFlopArticleDiagram.java index 2d6692f..660d6e3 100644 --- a/src/main/java/de/hsel/spm/baudas/web/TopFlopArticleDiagram.java +++ b/src/main/java/de/hsel/spm/baudas/web/TopFlopArticleDiagram.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.util.*; +import java.util.regex.Pattern; /** * @author Johannes Theiner @@ -23,6 +24,8 @@ import java.util.*; @WebServlet("/top_flop") public class TopFlopArticleDiagram extends HttpServlet { + private static Map cache = new HashMap<>(); + private static final long serialVersionUID = 6567531464214L; @Override @@ -34,7 +37,19 @@ public class TopFlopArticleDiagram extends HttpServlet { Gson gson = new Gson(); - UUID uuid = UUID.fromString(req.getParameter("id")); + String id = req.getParameter("id"); + boolean match = Pattern.matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}", id); + if(id == null || !match) { + return; + } + + UUID uuid = UUID.fromString(id); + + if(cache.containsKey(uuid)) { + out.println(gson.toJson(cache.get(uuid))); + return; + } + File file = Data.get(uuid); TopFlopArticle articles = new TopFlopArticle(file); @@ -53,6 +68,8 @@ public class TopFlopArticleDiagram extends HttpServlet { result.put("labels", labels); result.put("data", data); + + cache.put(uuid, result); out.print(gson.toJson(result)); } } \ No newline at end of file diff --git a/src/main/java/de/hsel/spm/baudas/web/Upload.java b/src/main/java/de/hsel/spm/baudas/web/Upload.java index 28f7c9d..11f7794 100644 --- a/src/main/java/de/hsel/spm/baudas/web/Upload.java +++ b/src/main/java/de/hsel/spm/baudas/web/Upload.java @@ -48,7 +48,5 @@ public class Upload extends HttpServlet { } Files.copy(inputStream, path, StandardCopyOption.REPLACE_EXISTING); - - resp.sendRedirect(""); } } \ No newline at end of file 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 9230839..6f8534f 100644 --- a/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java +++ b/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.regex.Pattern; /** * changes data from week overview into readable format for chart.js @@ -30,6 +31,8 @@ import java.util.UUID; @WebServlet("/week_overview") public class WeekOverviewDiagram extends HttpServlet { + private static Map cache = new HashMap<>(); + private static final long serialVersionUID = 8484151844118L; @@ -45,16 +48,20 @@ public class WeekOverviewDiagram extends HttpServlet { Gson gson = new Gson(); + String id = req.getParameter("id"); + boolean match = Pattern.matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}", id); - if (req.getParameter("id") == null) { - result.put("labels", definedOrder); - result.put("count", new ArrayList<>()); - result.put("revenue", new ArrayList<>()); - out.print(gson.toJson(result)); + + if (id == null || !match) { + return; + } + + UUID uuid = UUID.fromString(id); + if(cache.containsKey(uuid)) { + out.println(gson.toJson(cache.get(uuid))); return; } - UUID uuid = UUID.fromString(req.getParameter("id")); File file = Data.get(uuid); WeekOverview overview = new WeekOverview(file); @@ -79,6 +86,7 @@ public class WeekOverviewDiagram extends HttpServlet { result.put("count", count); result.put("revenue", revenue); + cache.put(uuid, result); out.print(gson.toJson(result)); } } \ No newline at end of file diff --git a/src/main/webapp/footer.jsp b/src/main/webapp/footer.jsp index 5e91340..175265d 100644 --- a/src/main/webapp/footer.jsp +++ b/src/main/webapp/footer.jsp @@ -12,6 +12,7 @@ M.AutoInit(); + diff --git a/src/main/webapp/header.jsp b/src/main/webapp/header.jsp index 5cd9784..a3a8979 100644 --- a/src/main/webapp/header.jsp +++ b/src/main/webapp/header.jsp @@ -12,6 +12,7 @@ media="screen,projection"/> + @@ -37,7 +38,7 @@