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.validation.BindingResult;
|
7
|
import org.springframework.web.bind.annotation.GetMapping;
|
8
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
9
|
import org.springframework.web.bind.annotation.PostMapping;
|
10
|
import org.springframework.web.servlet.ModelAndView;
|
11
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
12
|
import vldc.aswi.domain.Assembly;
|
13
|
import vldc.aswi.service.AssemblyManager;
|
14
|
import vldc.aswi.service.SqlQueryManager;
|
15
|
|
16
|
import javax.validation.Valid;
|
17
|
|
18
|
@Controller
|
19
|
public class AssemblyController {
|
20
|
|
21
|
@Autowired
|
22
|
private SqlQueryManager sqlQueryManager;
|
23
|
|
24
|
@Autowired
|
25
|
private AssemblyManager assemblyManager;
|
26
|
|
27
|
@GetMapping("/assembly")
|
28
|
public ModelAndView assemblyIndex(@Valid @ModelAttribute("assemblyID") String id) {
|
29
|
ModelAndView modelAndView = new ModelAndView("assembly");
|
30
|
|
31
|
ModelMap modelMap = modelAndView.getModelMap();
|
32
|
|
33
|
Assembly assembly = assemblyManager.getAssemblyById(Long.parseLong(id));
|
34
|
|
35
|
modelMap.addAttribute("assemblies", assemblyManager.getAssemblies());
|
36
|
modelMap.addAttribute("assembly", assembly);
|
37
|
|
38
|
return modelAndView;
|
39
|
}
|
40
|
|
41
|
|
42
|
@PostMapping("/assembly")
|
43
|
public ModelAndView indexPost(@Valid Assembly assembly, BindingResult bindingResult, RedirectAttributes atts) {
|
44
|
ModelAndView modelAndView = new ModelAndView();
|
45
|
|
46
|
ModelMap modelMap = modelAndView.getModelMap();
|
47
|
|
48
|
long assemblyID = assembly.getId();
|
49
|
System.out.println(assemblyID);
|
50
|
Assembly assembly2 = assemblyManager.getAssemblyById(assemblyID);
|
51
|
|
52
|
|
53
|
modelMap.addAttribute("assemblies", assemblyManager.getAssemblies());
|
54
|
modelMap.addAttribute("assembly", assembly2);
|
55
|
modelMap.addAttribute("contingencyTableRows", sqlQueryManager.getContingencyTableRow(assembly2.getSQLQuery()));
|
56
|
|
57
|
return modelAndView;
|
58
|
}
|
59
|
|
60
|
@GetMapping("/assembly_edit")
|
61
|
public ModelAndView assemblyEditIndex(@Valid @ModelAttribute("assemblyID") String id) {
|
62
|
ModelAndView modelAndView = new ModelAndView("assembly_edit");
|
63
|
|
64
|
ModelMap modelMap = modelAndView.getModelMap();
|
65
|
|
66
|
Assembly assembly = assemblyManager.getAssemblyById(Long.parseLong(id));
|
67
|
|
68
|
modelMap.addAttribute("assemblies", assemblyManager.getAssemblies());
|
69
|
modelMap.addAttribute("assembly", assembly);
|
70
|
|
71
|
return modelAndView;
|
72
|
}
|
73
|
}
|