commit f2181c0eac00e418c91ca121d7e78526998e42d9
Author: Tomáš Šimandl <tomas.simandl@gmail.com>
Date:   Mon Aug 27 10:35:55 2018 +0200

    loading of saved diagrams

diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/LoadGraphData.java b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/LoadGraphData.java
index a6e1cb8..5a0e054 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/LoadGraphData.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/LoadGraphData.java
@@ -8,6 +8,8 @@ import cz.zcu.kiv.offscreen.graph.loader.DemoDiagramLoader;
 import cz.zcu.kiv.offscreen.graph.loader.GraphJSONDataLoader;
 import cz.zcu.kiv.offscreen.graph.loader.JSONConfigLoader;
 import cz.zcu.kiv.offscreen.loader.configuration.ConfigurationLoader;
+import cz.zcu.kiv.offscreen.user.DB;
+import cz.zcu.kiv.offscreen.user.Diagram;
 import net.sf.json.JSONObject;
 
 import javax.servlet.ServletException;
@@ -35,23 +37,38 @@ public class LoadGraphData extends HttpServlet {
 
         if (request.getSession().getAttribute("demo_id") == null) {
 
-            String jsonToDisplay = (String)request.getSession().getAttribute("json_graph");
-            request.getSession().removeAttribute("json_graph");
+            String diagram_id = request.getParameter("diagramId");
 
-            if (!Strings.isNullOrEmpty(jsonToDisplay)) {
-                GraphManager graphManager = new GraphJSONDataLoader(jsonToDisplay).LoadData();
-                String configLocation = ConfigurationLoader.getConfigLocation(request.getServletContext());
-                JSONConfigLoader configLoader = new JSONConfigLoader(graphManager, configLocation);
-                Graph graph = graphManager.createGraph(configLoader);
-                GraphExport export = new GraphExport(graph);
-                JSONObject json = JSONObject.fromObject(export);
+            if (diagram_id == null) {
+                String jsonToDisplay;
+                jsonToDisplay = (String)request.getSession().getAttribute("json_graph");
+                request.getSession().removeAttribute("json_graph");
 
-                String resultJsonString = json.toString();
+                if (!Strings.isNullOrEmpty(jsonToDisplay)) {
+                    GraphManager graphManager = new GraphJSONDataLoader(jsonToDisplay).LoadData();
+                    String configLocation = ConfigurationLoader.getConfigLocation(request.getServletContext());
+                    JSONConfigLoader configLoader = new JSONConfigLoader(graphManager, configLocation);
+                    Graph graph = graphManager.createGraph(configLoader);
+                    GraphExport export = new GraphExport(graph);
+                    JSONObject json = JSONObject.fromObject(export);
+
+                    String resultJsonString = json.toString();
+
+                    response.getWriter().write(resultJsonString);
+                } else {
+                    response.getWriter().write("");
+                }
 
-                response.getWriter().write(resultJsonString);
             } else {
-                response.getWriter().write("");
+                // TODO check user permissions to this graph
+                Integer diagramId = Integer.parseInt(diagram_id);
+
+                DB db = new DB(getServletContext());
+                Diagram diagram = new Diagram(db, diagramId);
+                response.getWriter().write(diagram.getJsonDiagram());
             }
+
+
         } else {
             String demoId = request.getSession().getAttribute("demo_id").toString();
             String path = "/WEB-INF" + File.separator + "demoDiagram" + File.separator + demoId + ".json";
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java b/sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java
index 4743ca8..d30c437 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java
@@ -50,6 +50,22 @@ public class Diagram {
         return -1;
     }
 
+    public String getJsonDiagram(){
+        if(this.id < 0) return "";
+
+        String qy = "SELECT graph_json FROM diagram WHERE id = '" + this.id + "'";
+        ResultSet rs = db.exQuery(qy);
+
+        try{
+            if (rs != null && rs.next()) {
+                return rs.getString("graph_json");
+            }
+        }  catch (SQLException e){
+            e.printStackTrace();
+        }
+        return "";
+    }
+
     /**
      * Method return map of values of actual diagram or empty map if id of diagram is invalid.
      *
diff --git a/sources/src/main/webapp/logged_user_menu.jsp b/sources/src/main/webapp/logged_user_menu.jsp
index 810b5b8..671884e 100644
--- a/sources/src/main/webapp/logged_user_menu.jsp
+++ b/sources/src/main/webapp/logged_user_menu.jsp
@@ -7,7 +7,7 @@
 	<ul>	
 		<c:forEach items="${diagramNames}" var="diagramName">
 			<li id="diagram_id_${diagramName.id}">
-				<a href="<%= getServletContext().getInitParameter("HOME_URL") %>?diagram_id=${diagramName.id}&diagram_hash=${diagramName.hash}">${diagramName.name}</a><a href="#" onclick="return deleteDiagram(${diagramName.id});"><img src="images/button_cancel.png" alt="odstranit" class="imgDelete"/></a>
+				<a href="/graph?diagramId=${diagramPublic.id}">${diagramName.name}</a><a href="#" onclick="return deleteDiagram(${diagramName.id});"><img src="images/button_cancel.png" alt="odstranit" class="imgDelete"/></a>
 			</li>
 		</c:forEach>
 		<li id="diagram_id_new">
@@ -21,7 +21,7 @@
 	<ul>	
 		<c:forEach items="${diagramPublic}" var="diagramPublic">
 			<li id="public_diagram_id_${diagramPublic.id}">
-				<a href="<%= getServletContext().getInitParameter("HOME_URL") %>?diagram_id=${diagramPublic.id}&diagram_hash=${diagramPublic.hash}">${diagramPublic.name}</a>
+				<a href="/graph?diagramId=${diagramPublic.id}">${diagramPublic.name}</a>
 			</li>
 		</c:forEach>
 	</ul>
diff --git a/sources/src/main/webapp/showGraph.jsp b/sources/src/main/webapp/showGraph.jsp
index c8c1620..ed9ba56 100644
--- a/sources/src/main/webapp/showGraph.jsp
+++ b/sources/src/main/webapp/showGraph.jsp
@@ -227,7 +227,7 @@
 		app.HOME_URL = '<%=getPath%>imiger/';
 
 		$(document).ready(function() {
-			var loaderFn = app.diagramLoader('<%=request.getParameter("diagram_id")%>', '<%=request.getParameter("diagram_hash")%>');
+			var loaderFn = app.diagramLoader('<%=request.getParameter("diagramId")%>', '<%=request.getParameter("diagram_hash")%>');
 
 			app.run(loaderFn);
 		});
