Projekt

Obecné

Profil

Stáhnout (1.97 KB) Statistiky
| Větev: | Revize:
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
}
(1-1/3)