commit 2868bb9adeeaab6c5717de80120136e8d72b86b8
Author: Vojtěch Danišík <32537562+danisik@users.noreply.github.com>
Date:   Thu Apr 16 16:28:45 2020 +0200

    re #7871 Displaying list of assemblies + displaying result table of selected assembly.

diff --git a/src/main/java/vldc/aswi/database/DatabaseInterface.java b/src/main/java/vldc/aswi/database/DatabaseInterface.java
index 9498e788..bb9ef89f 100644
--- a/src/main/java/vldc/aswi/database/DatabaseInterface.java
+++ b/src/main/java/vldc/aswi/database/DatabaseInterface.java
@@ -19,13 +19,13 @@ import java.util.Map;
 @Component
 public class DatabaseInterface {
 
-    private static JdbcTemplate jdbcTemplate = null;
+    private JdbcTemplate jdbcTemplate = null;
 
     public DatabaseInterface(JdbcTemplate jdbcTemplate) {
         this.jdbcTemplate = jdbcTemplate;
     }
 
-    public static Map<String, TableColumn> executeQueryAndReturnTableColumns(String sqlQuery) {
+    public Map<String, TableColumn> executeQueryAndReturnTableColumns(String sqlQuery) {
         return jdbcTemplate.query(
                 sqlQuery,
                 new ResultSetExtractor<Map<String, TableColumn>>() {
diff --git a/src/main/java/vldc/aswi/domain/Assembly.java b/src/main/java/vldc/aswi/domain/Assembly.java
index 3c362f7d..54c965f7 100644
--- a/src/main/java/vldc/aswi/domain/Assembly.java
+++ b/src/main/java/vldc/aswi/domain/Assembly.java
@@ -29,6 +29,9 @@ public class Assembly extends EntityParent {
     @Column(name = "poradi")
     private int order;
 
+    @Column(name = "verejny")
+    private int isPublic;
+
     /** List of configurations, which using this assembly. */
     @OneToMany(mappedBy = "assembly")
     private List<Configuration> configurations;
@@ -55,9 +58,10 @@ public class Assembly extends EntityParent {
      * @param SQLQuery - SQL query which gets data from database.
      * @param order - Specific order of assembly in list of assemblies.
      */
-    public Assembly(String name, String SQLQuery, int order) {
+    public Assembly(String name, String SQLQuery, int order, int isPublic) {
         this.setName(name);
         this.setSQLQuery(SQLQuery);
         this.setOrder(order);
+        this.setIsPublic(isPublic);
     }
 }
diff --git a/src/main/java/vldc/aswi/service/AssemblyManager.java b/src/main/java/vldc/aswi/service/AssemblyManager.java
index f9e6f4f5..8f0dedd4 100644
--- a/src/main/java/vldc/aswi/service/AssemblyManager.java
+++ b/src/main/java/vldc/aswi/service/AssemblyManager.java
@@ -14,4 +14,6 @@ public interface AssemblyManager {
      * @return List of assemblies.
      */
     List<Assembly> getAssemblies();
+
+    Assembly getAssemblyById(Long id);
 }
diff --git a/src/main/java/vldc/aswi/service/AssemblyManagerImpl.java b/src/main/java/vldc/aswi/service/AssemblyManagerImpl.java
index 6e5a9757..4edeff6d 100644
--- a/src/main/java/vldc/aswi/service/AssemblyManagerImpl.java
+++ b/src/main/java/vldc/aswi/service/AssemblyManagerImpl.java
@@ -47,4 +47,9 @@ public class AssemblyManagerImpl implements AssemblyManager {
         this.assemblyRepository.findAll().forEach(retVal::add);
         return retVal;
     }
+
+    @Override
+    public Assembly getAssemblyById(Long id) {
+        return assemblyRepository.getById(id);
+    }
 }
diff --git a/src/main/java/vldc/aswi/web/controller/AssemblyController.java b/src/main/java/vldc/aswi/web/controller/AssemblyController.java
new file mode 100644
index 00000000..6158a480
--- /dev/null
+++ b/src/main/java/vldc/aswi/web/controller/AssemblyController.java
@@ -0,0 +1,55 @@
+package vldc.aswi.web.controller;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.servlet.ModelAndView;
+import vldc.aswi.domain.Assembly;
+import vldc.aswi.service.AssemblyManager;
+import vldc.aswi.service.SqlQueryManager;
+
+import javax.validation.Valid;
+
+@Controller
+public class AssemblyController {
+
+    @Autowired
+    private SqlQueryManager sqlQueryManager;
+
+    @Autowired
+    private AssemblyManager assemblyManager;
+
+    @GetMapping("/assembly")
+    public ModelAndView assemblyIndex(@Valid @ModelAttribute("assemblyID") String id) {
+        ModelAndView modelAndView = new ModelAndView("assembly");
+
+        ModelMap modelMap = modelAndView.getModelMap();
+
+        Assembly selectedAssembly = assemblyManager.getAssemblyById(Long.parseLong(id));
+
+        modelMap.addAttribute("assemblies", assemblyManager.getAssemblies());
+        modelMap.addAttribute("selectedAssembly", selectedAssembly);
+        modelMap.addAttribute("contingencyTableRows", sqlQueryManager.getContingencyTableRow(selectedAssembly.getSQLQuery()));
+
+        return modelAndView;
+    }
+
+
+    @PostMapping("/assembly")
+    public ModelAndView indexPost(@Valid @ModelAttribute("assemblyID") String id) {
+        ModelAndView modelAndView = new ModelAndView();
+
+        ModelMap modelMap = modelAndView.getModelMap();
+
+        Assembly selectedAssembly = assemblyManager.getAssemblyById(Long.parseLong(id));
+
+        modelMap.addAttribute("assemblies", assemblyManager.getAssemblies());
+        modelMap.addAttribute("selectedAssembly", selectedAssembly);
+        modelMap.addAttribute("contingencyTableRows", sqlQueryManager.getContingencyTableRow(selectedAssembly.getSQLQuery()));
+
+        return modelAndView;
+    }
+}
diff --git a/src/main/java/vldc/aswi/web/controller/IndexController.java b/src/main/java/vldc/aswi/web/controller/IndexController.java
index 5eabae21..7beed8e9 100644
--- a/src/main/java/vldc/aswi/web/controller/IndexController.java
+++ b/src/main/java/vldc/aswi/web/controller/IndexController.java
@@ -4,15 +4,20 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.servlet.ModelAndView;
 import vldc.aswi.database.DatabaseInterface;
+import vldc.aswi.domain.Assembly;
 import vldc.aswi.model.table.TableColumn;
 import vldc.aswi.model.table.contingencyTable.ContingencyTableRow;
 import vldc.aswi.model.table.contingencyTable.ContingencyTableRowCell;
+import vldc.aswi.service.AssemblyManager;
 import vldc.aswi.service.SqlQueryManager;
 import vldc.aswi.utils.Converter;
 
 import javax.sql.DataSource;
+import javax.validation.Valid;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -23,26 +28,24 @@ public class IndexController {
 	@Autowired
 	private SqlQueryManager sqlQueryManager;
 
+	@Autowired
+	private AssemblyManager assemblyManager;
+
 	@GetMapping("/")
-	public ModelAndView index() throws Exception {
+	public ModelAndView index() {
 		ModelAndView modelAndView = new ModelAndView("index");
 
 		ModelMap modelMap = modelAndView.getModelMap();
 
-		String sqlQuery = "SELECT SP.fakulta_SP as fakulta_studia, " +
-				"SP.kodSP_i as program_studia, " +
-				"fn_meaning2(SP.typ,'TYP_OBORU') as typ_studia, " +
-				"fn_meaning2(SP.forma,'FORMA_OBORU_NEW') as forma_studia, " +
-				"decode(SP.vykazovan,'A',ST.vykazovan,'N') as vykazovan_na_SIMS, " +
-				"ST.os_cislo as studium, fn_meaning2(ST.stav,'STAV_STUDENTA') as stav_studia, " +
-				"OS.prijmeni || ' ' || OS.jmeno as osoba, " +
-				"trunc((sysdate - OS.datum_naroz) / 365) as vek, " +
-				"1 as pocet " +
-				"FROM studijni_programy SP, studenti ST, osoby OS " +
-				"WHERE SP.stpridno = ST.stpridno AND ST.osobidno = OS.osobidno AND ROWNUM <= 500";
-
-		modelMap.addAttribute("message", "Hello World!");
-		modelMap.addAttribute("contingencyTableRows", sqlQueryManager.getContingencyTableRow(sqlQuery));
+		modelMap.addAttribute("assemblies", assemblyManager.getAssemblies());
+
+		return modelAndView;
+	}
+
+	@PostMapping("/")
+	public ModelAndView indexPost(@Valid @ModelAttribute("assemblyID") String id) {
+		ModelAndView modelAndView = new ModelAndView();
+		modelAndView.setViewName("redirect:/assembly");
 
 		return modelAndView;
 	}
diff --git a/src/main/webapp/WEB-INF/templates/assembly.html b/src/main/webapp/WEB-INF/templates/assembly.html
new file mode 100644
index 00000000..05a08dfb
--- /dev/null
+++ b/src/main/webapp/WEB-INF/templates/assembly.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+
+<html
+        xmlns:th="http://www.thymeleaf.org"
+        lang="cs"
+>
+<head th:replace="fragments/headers :: head(~{::title})">
+    <title>Title</title>
+</head>
+<body>
+<nav th:replace="fragments/headers :: nav"></nav>
+<form method="post" th:action="@{/assembly}">
+    <table>
+        <tr th:each="iassembly : ${assemblies}">
+            <div>
+                <td>
+                    <span th:text="${iassembly.name}"></span>
+                    <button name="assemblyID" type="submit" th:value="${iassembly.id}">Select</button>
+                </td>
+            </div>
+        </tr>
+    </table>
+</form>
+<br>
+<span>Název sestavy: </span>
+<span th:text="${selectedAssembly.name}"></span>
+<br>
+<span>SQL dotaz: </span>
+<span th:text="${selectedAssembly.SQLQuery}"></span>
+<br>
+<span>Veřejný: </span>
+<span th:if="${selectedAssembly.isPublic} == 0">Ne</span>
+<span th:unless="${selectedAssembly.isPublic} == 0">Ano</span>
+<br>
+
+<table>
+    <tr th:each="contingencyTableRow : ${contingencyTableRows}">
+        <div th:if="${contingencyTableRow.isHeader()}">
+            <th th:each="contingencyTableRowCell : ${contingencyTableRow.getCells()}">
+                <span th:text="${contingencyTableRowCell.getValue()}"></span>
+            </th>
+        </div>
+        <div th:unless="${contingencyTableRow.isHeader()}">
+            <td th:each="contingencyTableRowCell : ${contingencyTableRow.getCells()}">
+                <span th:text="${contingencyTableRowCell.getValue()}"></span>
+            </td>
+        </div>
+    </tr>
+</table>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/templates/index.html b/src/main/webapp/WEB-INF/templates/index.html
index 56019bd7..12deaed1 100644
--- a/src/main/webapp/WEB-INF/templates/index.html
+++ b/src/main/webapp/WEB-INF/templates/index.html
@@ -9,20 +9,18 @@
 	</head>
 	<body>
 		<nav th:replace="fragments/headers :: nav"></nav>
-		<div th:text="${message}"></div>
-		<table>
-			<tr th:each="contingencyTableRow : ${contingencyTableRows}">
-				<div th:if="${contingencyTableRow.isHeader()}">
-					<th th:each="contingencyTableRowCell : ${contingencyTableRow.getCells()}">
-						<span th:text="${contingencyTableRowCell.getValue()}"></span>
-					</th>
-				</div>
-				<div th:unless="${contingencyTableRow.isHeader()}">
-					<td th:each="contingencyTableRowCell : ${contingencyTableRow.getCells()}">
-						<span th:text="${contingencyTableRowCell.getValue()}"></span>
-					</td>
-				</div>
-			</tr>
-		</table>
+
+		<form method="post" th:action="@{/}">
+			<table>
+				<tr th:each="iassembly : ${assemblies}">
+					<div>
+						<td>
+							<span th:text="${iassembly.name}"></span>
+							<button name="assemblyID" type="submit" th:value="${iassembly.id}">Select</button>
+						</td>
+					</div>
+				</tr>
+			</table>
+		</form>
 	</body>
 </html>
