1
|
package vldc.aswi.web.controller;
|
2
|
|
3
|
import oracle.jdbc.proxy.annotation.Post;
|
4
|
import org.springframework.beans.factory.annotation.Autowired;
|
5
|
import org.springframework.stereotype.Controller;
|
6
|
import org.springframework.ui.ModelMap;
|
7
|
import org.springframework.validation.BindingResult;
|
8
|
import org.springframework.web.bind.annotation.GetMapping;
|
9
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
10
|
import org.springframework.web.bind.annotation.PostMapping;
|
11
|
import org.springframework.web.servlet.ModelAndView;
|
12
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
13
|
import vldc.aswi.domain.Assembly;
|
14
|
import vldc.aswi.domain.Role;
|
15
|
import vldc.aswi.service.*;
|
16
|
import vldc.aswi.service.parameter.ParameterTypeManager;
|
17
|
|
18
|
import javax.validation.Valid;
|
19
|
import java.util.ArrayList;
|
20
|
import java.util.List;
|
21
|
|
22
|
@Controller
|
23
|
public class AssemblyController {
|
24
|
|
25
|
@Autowired
|
26
|
private SqlQueryManager sqlQueryManager;
|
27
|
|
28
|
@Autowired
|
29
|
private AssemblyManager assemblyManager;
|
30
|
|
31
|
@Autowired
|
32
|
private RoleManager roleManager;
|
33
|
|
34
|
@Autowired
|
35
|
private ParameterTypeManager parameterTypeManager;
|
36
|
|
37
|
@Autowired
|
38
|
private OperatorManager operatorManager;
|
39
|
|
40
|
@Autowired
|
41
|
private FunctionManager functionManager;
|
42
|
|
43
|
@Autowired
|
44
|
private LocationManager locationManager;
|
45
|
|
46
|
@GetMapping("/assembly")
|
47
|
public ModelAndView assemblyIndex(@Valid @ModelAttribute("assemblyID") String id) {
|
48
|
ModelAndView modelAndView = new ModelAndView("assembly");
|
49
|
|
50
|
ModelMap modelMap = modelAndView.getModelMap();
|
51
|
|
52
|
Assembly assembly = assemblyManager.getAssemblyById(Long.parseLong(id));
|
53
|
|
54
|
modelMap.addAttribute("assemblies", assemblyManager.getAssemblies());
|
55
|
modelMap.addAttribute("assembly", assembly);
|
56
|
|
57
|
return modelAndView;
|
58
|
}
|
59
|
|
60
|
|
61
|
@PostMapping("/assembly")
|
62
|
public ModelAndView indexPost(@Valid Assembly assembly, BindingResult bindingResult, RedirectAttributes atts) {
|
63
|
ModelAndView modelAndView = new ModelAndView();
|
64
|
|
65
|
ModelMap modelMap = modelAndView.getModelMap();
|
66
|
|
67
|
long assemblyID = assembly.getId();
|
68
|
|
69
|
Assembly assembly2 = assemblyManager.getAssemblyById(assemblyID);
|
70
|
|
71
|
modelMap.addAttribute("assemblies", assemblyManager.getAssemblies());
|
72
|
modelMap.addAttribute("assembly", assembly2);
|
73
|
modelMap.addAttribute("contingencyTableRows", sqlQueryManager.getContingencyTableRow(assembly2.getSQLQuery()));
|
74
|
|
75
|
return modelAndView;
|
76
|
}
|
77
|
|
78
|
@GetMapping("/assembly_edit")
|
79
|
public ModelAndView assemblyEditIndex(@Valid @ModelAttribute("assemblyID") String id) {
|
80
|
ModelAndView modelAndView = new ModelAndView("assembly_manage");
|
81
|
|
82
|
ModelMap modelMap = modelAndView.getModelMap();
|
83
|
|
84
|
Assembly assembly = assemblyManager.getAssemblyById(Long.parseLong(id));
|
85
|
|
86
|
modelMap.addAttribute("assembly", assembly);
|
87
|
modelMap.addAttribute("roles", roleManager.getRoles());
|
88
|
modelMap.addAttribute("rolesWithAccess", assembly.getRoles());
|
89
|
modelMap.addAttribute("parameters", assembly.getParameters());
|
90
|
modelMap.addAttribute("parameterTypes", parameterTypeManager.getParameterTypes());
|
91
|
modelMap.addAttribute("functions", functionManager.getFunctions());
|
92
|
modelMap.addAttribute("operators", operatorManager.getOperators());
|
93
|
modelMap.addAttribute("locations", locationManager.getLocations());
|
94
|
|
95
|
return modelAndView;
|
96
|
}
|
97
|
|
98
|
@GetMapping("/assembly_new")
|
99
|
public ModelAndView assemblyNewIndex() {
|
100
|
ModelAndView modelAndView = new ModelAndView("assembly_manage");
|
101
|
|
102
|
ModelMap modelMap = modelAndView.getModelMap();
|
103
|
|
104
|
modelMap.addAttribute("assembly", new Assembly());
|
105
|
modelMap.addAttribute("roles", roleManager.getRoles());
|
106
|
|
107
|
return modelAndView;
|
108
|
}
|
109
|
|
110
|
@PostMapping("/assembly_new")
|
111
|
public ModelAndView assemblyNewIndexPost() {
|
112
|
ModelAndView modelAndView = new ModelAndView("assembly_manage");
|
113
|
|
114
|
ModelMap modelMap = modelAndView.getModelMap();
|
115
|
|
116
|
modelMap.addAttribute("assembly", new Assembly());
|
117
|
modelMap.addAttribute("roles", roleManager.getRoles());
|
118
|
|
119
|
return modelAndView;
|
120
|
}
|
121
|
}
|