Revize 2868bb9a
Přidáno uživatelem Vojtěch Danišík před asi 5 roky(ů)
src/main/java/vldc/aswi/database/DatabaseInterface.java | ||
---|---|---|
19 | 19 |
@Component |
20 | 20 |
public class DatabaseInterface { |
21 | 21 |
|
22 |
private static JdbcTemplate jdbcTemplate = null;
|
|
22 |
private JdbcTemplate jdbcTemplate = null; |
|
23 | 23 |
|
24 | 24 |
public DatabaseInterface(JdbcTemplate jdbcTemplate) { |
25 | 25 |
this.jdbcTemplate = jdbcTemplate; |
26 | 26 |
} |
27 | 27 |
|
28 |
public static Map<String, TableColumn> executeQueryAndReturnTableColumns(String sqlQuery) {
|
|
28 |
public Map<String, TableColumn> executeQueryAndReturnTableColumns(String sqlQuery) { |
|
29 | 29 |
return jdbcTemplate.query( |
30 | 30 |
sqlQuery, |
31 | 31 |
new ResultSetExtractor<Map<String, TableColumn>>() { |
src/main/java/vldc/aswi/domain/Assembly.java | ||
---|---|---|
29 | 29 |
@Column(name = "poradi") |
30 | 30 |
private int order; |
31 | 31 |
|
32 |
@Column(name = "verejny") |
|
33 |
private int isPublic; |
|
34 |
|
|
32 | 35 |
/** List of configurations, which using this assembly. */ |
33 | 36 |
@OneToMany(mappedBy = "assembly") |
34 | 37 |
private List<Configuration> configurations; |
... | ... | |
55 | 58 |
* @param SQLQuery - SQL query which gets data from database. |
56 | 59 |
* @param order - Specific order of assembly in list of assemblies. |
57 | 60 |
*/ |
58 |
public Assembly(String name, String SQLQuery, int order) { |
|
61 |
public Assembly(String name, String SQLQuery, int order, int isPublic) {
|
|
59 | 62 |
this.setName(name); |
60 | 63 |
this.setSQLQuery(SQLQuery); |
61 | 64 |
this.setOrder(order); |
65 |
this.setIsPublic(isPublic); |
|
62 | 66 |
} |
63 | 67 |
} |
src/main/java/vldc/aswi/service/AssemblyManager.java | ||
---|---|---|
14 | 14 |
* @return List of assemblies. |
15 | 15 |
*/ |
16 | 16 |
List<Assembly> getAssemblies(); |
17 |
|
|
18 |
Assembly getAssemblyById(Long id); |
|
17 | 19 |
} |
src/main/java/vldc/aswi/service/AssemblyManagerImpl.java | ||
---|---|---|
47 | 47 |
this.assemblyRepository.findAll().forEach(retVal::add); |
48 | 48 |
return retVal; |
49 | 49 |
} |
50 |
|
|
51 |
@Override |
|
52 |
public Assembly getAssemblyById(Long id) { |
|
53 |
return assemblyRepository.getById(id); |
|
54 |
} |
|
50 | 55 |
} |
src/main/java/vldc/aswi/web/controller/AssemblyController.java | ||
---|---|---|
1 |
package vldc.aswi.web.controller; |
|
2 |
|
|
3 |
import org.springframework.beans.factory.annotation.Autowired; |
|
4 |
import org.springframework.stereotype.Controller; |
|
5 |
import org.springframework.ui.ModelMap; |
|
6 |
import org.springframework.web.bind.annotation.GetMapping; |
|
7 |
import org.springframework.web.bind.annotation.ModelAttribute; |
|
8 |
import org.springframework.web.bind.annotation.PostMapping; |
|
9 |
import org.springframework.web.servlet.ModelAndView; |
|
10 |
import vldc.aswi.domain.Assembly; |
|
11 |
import vldc.aswi.service.AssemblyManager; |
|
12 |
import vldc.aswi.service.SqlQueryManager; |
|
13 |
|
|
14 |
import javax.validation.Valid; |
|
15 |
|
|
16 |
@Controller |
|
17 |
public class AssemblyController { |
|
18 |
|
|
19 |
@Autowired |
|
20 |
private SqlQueryManager sqlQueryManager; |
|
21 |
|
|
22 |
@Autowired |
|
23 |
private AssemblyManager assemblyManager; |
|
24 |
|
|
25 |
@GetMapping("/assembly") |
|
26 |
public ModelAndView assemblyIndex(@Valid @ModelAttribute("assemblyID") String id) { |
|
27 |
ModelAndView modelAndView = new ModelAndView("assembly"); |
|
28 |
|
|
29 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
30 |
|
|
31 |
Assembly selectedAssembly = assemblyManager.getAssemblyById(Long.parseLong(id)); |
|
32 |
|
|
33 |
modelMap.addAttribute("assemblies", assemblyManager.getAssemblies()); |
|
34 |
modelMap.addAttribute("selectedAssembly", selectedAssembly); |
|
35 |
modelMap.addAttribute("contingencyTableRows", sqlQueryManager.getContingencyTableRow(selectedAssembly.getSQLQuery())); |
|
36 |
|
|
37 |
return modelAndView; |
|
38 |
} |
|
39 |
|
|
40 |
|
|
41 |
@PostMapping("/assembly") |
|
42 |
public ModelAndView indexPost(@Valid @ModelAttribute("assemblyID") String id) { |
|
43 |
ModelAndView modelAndView = new ModelAndView(); |
|
44 |
|
|
45 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
46 |
|
|
47 |
Assembly selectedAssembly = assemblyManager.getAssemblyById(Long.parseLong(id)); |
|
48 |
|
|
49 |
modelMap.addAttribute("assemblies", assemblyManager.getAssemblies()); |
|
50 |
modelMap.addAttribute("selectedAssembly", selectedAssembly); |
|
51 |
modelMap.addAttribute("contingencyTableRows", sqlQueryManager.getContingencyTableRow(selectedAssembly.getSQLQuery())); |
|
52 |
|
|
53 |
return modelAndView; |
|
54 |
} |
|
55 |
} |
src/main/java/vldc/aswi/web/controller/IndexController.java | ||
---|---|---|
4 | 4 |
import org.springframework.stereotype.Controller; |
5 | 5 |
import org.springframework.ui.ModelMap; |
6 | 6 |
import org.springframework.web.bind.annotation.GetMapping; |
7 |
import org.springframework.web.bind.annotation.ModelAttribute; |
|
8 |
import org.springframework.web.bind.annotation.PostMapping; |
|
7 | 9 |
import org.springframework.web.servlet.ModelAndView; |
8 | 10 |
import vldc.aswi.database.DatabaseInterface; |
11 |
import vldc.aswi.domain.Assembly; |
|
9 | 12 |
import vldc.aswi.model.table.TableColumn; |
10 | 13 |
import vldc.aswi.model.table.contingencyTable.ContingencyTableRow; |
11 | 14 |
import vldc.aswi.model.table.contingencyTable.ContingencyTableRowCell; |
15 |
import vldc.aswi.service.AssemblyManager; |
|
12 | 16 |
import vldc.aswi.service.SqlQueryManager; |
13 | 17 |
import vldc.aswi.utils.Converter; |
14 | 18 |
|
15 | 19 |
import javax.sql.DataSource; |
20 |
import javax.validation.Valid; |
|
16 | 21 |
import java.util.ArrayList; |
17 | 22 |
import java.util.List; |
18 | 23 |
import java.util.Map; |
... | ... | |
23 | 28 |
@Autowired |
24 | 29 |
private SqlQueryManager sqlQueryManager; |
25 | 30 |
|
31 |
@Autowired |
|
32 |
private AssemblyManager assemblyManager; |
|
33 |
|
|
26 | 34 |
@GetMapping("/") |
27 |
public ModelAndView index() throws Exception {
|
|
35 |
public ModelAndView index() { |
|
28 | 36 |
ModelAndView modelAndView = new ModelAndView("index"); |
29 | 37 |
|
30 | 38 |
ModelMap modelMap = modelAndView.getModelMap(); |
31 | 39 |
|
32 |
String sqlQuery = "SELECT SP.fakulta_SP as fakulta_studia, " + |
|
33 |
"SP.kodSP_i as program_studia, " + |
|
34 |
"fn_meaning2(SP.typ,'TYP_OBORU') as typ_studia, " + |
|
35 |
"fn_meaning2(SP.forma,'FORMA_OBORU_NEW') as forma_studia, " + |
|
36 |
"decode(SP.vykazovan,'A',ST.vykazovan,'N') as vykazovan_na_SIMS, " + |
|
37 |
"ST.os_cislo as studium, fn_meaning2(ST.stav,'STAV_STUDENTA') as stav_studia, " + |
|
38 |
"OS.prijmeni || ' ' || OS.jmeno as osoba, " + |
|
39 |
"trunc((sysdate - OS.datum_naroz) / 365) as vek, " + |
|
40 |
"1 as pocet " + |
|
41 |
"FROM studijni_programy SP, studenti ST, osoby OS " + |
|
42 |
"WHERE SP.stpridno = ST.stpridno AND ST.osobidno = OS.osobidno AND ROWNUM <= 500"; |
|
43 |
|
|
44 |
modelMap.addAttribute("message", "Hello World!"); |
|
45 |
modelMap.addAttribute("contingencyTableRows", sqlQueryManager.getContingencyTableRow(sqlQuery)); |
|
40 |
modelMap.addAttribute("assemblies", assemblyManager.getAssemblies()); |
|
41 |
|
|
42 |
return modelAndView; |
|
43 |
} |
|
44 |
|
|
45 |
@PostMapping("/") |
|
46 |
public ModelAndView indexPost(@Valid @ModelAttribute("assemblyID") String id) { |
|
47 |
ModelAndView modelAndView = new ModelAndView(); |
|
48 |
modelAndView.setViewName("redirect:/assembly"); |
|
46 | 49 |
|
47 | 50 |
return modelAndView; |
48 | 51 |
} |
src/main/webapp/WEB-INF/templates/assembly.html | ||
---|---|---|
1 |
<!DOCTYPE html> |
|
2 |
|
|
3 |
<html |
|
4 |
xmlns:th="http://www.thymeleaf.org" |
|
5 |
lang="cs" |
|
6 |
> |
|
7 |
<head th:replace="fragments/headers :: head(~{::title})"> |
|
8 |
<title>Title</title> |
|
9 |
</head> |
|
10 |
<body> |
|
11 |
<nav th:replace="fragments/headers :: nav"></nav> |
|
12 |
<form method="post" th:action="@{/assembly}"> |
|
13 |
<table> |
|
14 |
<tr th:each="iassembly : ${assemblies}"> |
|
15 |
<div> |
|
16 |
<td> |
|
17 |
<span th:text="${iassembly.name}"></span> |
|
18 |
<button name="assemblyID" type="submit" th:value="${iassembly.id}">Select</button> |
|
19 |
</td> |
|
20 |
</div> |
|
21 |
</tr> |
|
22 |
</table> |
|
23 |
</form> |
|
24 |
<br> |
|
25 |
<span>Název sestavy: </span> |
|
26 |
<span th:text="${selectedAssembly.name}"></span> |
|
27 |
<br> |
|
28 |
<span>SQL dotaz: </span> |
|
29 |
<span th:text="${selectedAssembly.SQLQuery}"></span> |
|
30 |
<br> |
|
31 |
<span>Veřejný: </span> |
|
32 |
<span th:if="${selectedAssembly.isPublic} == 0">Ne</span> |
|
33 |
<span th:unless="${selectedAssembly.isPublic} == 0">Ano</span> |
|
34 |
<br> |
|
35 |
|
|
36 |
<table> |
|
37 |
<tr th:each="contingencyTableRow : ${contingencyTableRows}"> |
|
38 |
<div th:if="${contingencyTableRow.isHeader()}"> |
|
39 |
<th th:each="contingencyTableRowCell : ${contingencyTableRow.getCells()}"> |
|
40 |
<span th:text="${contingencyTableRowCell.getValue()}"></span> |
|
41 |
</th> |
|
42 |
</div> |
|
43 |
<div th:unless="${contingencyTableRow.isHeader()}"> |
|
44 |
<td th:each="contingencyTableRowCell : ${contingencyTableRow.getCells()}"> |
|
45 |
<span th:text="${contingencyTableRowCell.getValue()}"></span> |
|
46 |
</td> |
|
47 |
</div> |
|
48 |
</tr> |
|
49 |
</table> |
|
50 |
</body> |
|
51 |
</html> |
src/main/webapp/WEB-INF/templates/index.html | ||
---|---|---|
9 | 9 |
</head> |
10 | 10 |
<body> |
11 | 11 |
<nav th:replace="fragments/headers :: nav"></nav> |
12 |
<div th:text="${message}"></div> |
|
13 |
<table> |
|
14 |
<tr th:each="contingencyTableRow : ${contingencyTableRows}"> |
|
15 |
<div th:if="${contingencyTableRow.isHeader()}"> |
|
16 |
<th th:each="contingencyTableRowCell : ${contingencyTableRow.getCells()}"> |
|
17 |
<span th:text="${contingencyTableRowCell.getValue()}"></span> |
|
18 |
</th> |
|
19 |
</div> |
|
20 |
<div th:unless="${contingencyTableRow.isHeader()}"> |
|
21 |
<td th:each="contingencyTableRowCell : ${contingencyTableRow.getCells()}"> |
|
22 |
<span th:text="${contingencyTableRowCell.getValue()}"></span> |
|
23 |
</td> |
|
24 |
</div> |
|
25 |
</tr> |
|
26 |
</table> |
|
12 |
|
|
13 |
<form method="post" th:action="@{/}"> |
|
14 |
<table> |
|
15 |
<tr th:each="iassembly : ${assemblies}"> |
|
16 |
<div> |
|
17 |
<td> |
|
18 |
<span th:text="${iassembly.name}"></span> |
|
19 |
<button name="assemblyID" type="submit" th:value="${iassembly.id}">Select</button> |
|
20 |
</td> |
|
21 |
</div> |
|
22 |
</tr> |
|
23 |
</table> |
|
24 |
</form> |
|
27 | 25 |
</body> |
28 | 26 |
</html> |
Také k dispozici: Unified diff
re #7871 Displaying list of assemblies + displaying result table of selected assembly.