Projekt

Obecné

Profil

Stáhnout (6.2 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.Model;
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.Function;
15
import vldc.aswi.domain.Location;
16
import vldc.aswi.domain.parameter.Parameter;
17
import vldc.aswi.service.*;
18
import vldc.aswi.service.parameter.ParameterManager;
19
import vldc.aswi.service.parameter.ParameterTypeManager;
20
import vldc.aswi.service.parameter.ParameterValueManager;
21

    
22
import javax.validation.Valid;
23
import java.beans.PropertyEditorSupport;
24
import java.util.LinkedList;
25
import java.util.List;
26

    
27
@Controller
28
public class AssemblyController {
29

    
30
    @Autowired
31
    private SqlQueryManager sqlQueryManager;
32

    
33
    @Autowired
34
    private AssemblyManager assemblyManager;
35

    
36
    @Autowired
37
    private RoleManager roleManager;
38

    
39
    @Autowired
40
    private ParameterTypeManager parameterTypeManager;
41

    
42
    @Autowired
43
    private OperatorManager operatorManager;
44

    
45
    @Autowired
46
    private FunctionManager functionManager;
47

    
48
    @Autowired
49
    private LocationManager locationManager;
50

    
51
    @Autowired
52
    private ParameterManager parameterManager;
53

    
54
    @Autowired
55
    private ParameterValueManager parameterValueManager;
56

    
57
    @GetMapping("/assembly")
58
    public ModelAndView assemblyIndex(@Valid @ModelAttribute("assemblyID") String id) {
59
        ModelAndView modelAndView = new ModelAndView("assembly");
60

    
61
        ModelMap modelMap = modelAndView.getModelMap();
62

    
63
        Assembly assembly = this.assemblyManager.getAssemblyById(Long.parseLong(id));
64

    
65
        modelMap.addAttribute("assemblies", this.assemblyManager.getAssemblies());
66
        modelMap.addAttribute("assembly", assembly);
67

    
68
        return modelAndView;
69
    }
70

    
71

    
72
    @PostMapping("/assembly")
73
    public ModelAndView indexPost(@Valid Assembly assembly, BindingResult bindingResult, RedirectAttributes atts) {
74
        ModelAndView modelAndView = new ModelAndView();
75

    
76
        ModelMap modelMap = modelAndView.getModelMap();
77

    
78
        long assemblyID = assembly.getId();
79

    
80
        Assembly assembly2 = this.assemblyManager.getAssemblyById(assemblyID);
81

    
82
        modelMap.addAttribute("assemblies", this.assemblyManager.getAssemblies());
83
        modelMap.addAttribute("assembly", assembly2);
84
        modelMap.addAttribute("contingencyTableRows", this.sqlQueryManager.getContingencyTableRow(assembly2.getSQLQuery()));
85

    
86
        return modelAndView;
87
    }
88

    
89
    @GetMapping("/assembly_edit")
90
    public ModelAndView assemblyEditIndex(@Valid @ModelAttribute("assemblyID") String id) {
91
        ModelAndView modelAndView = new ModelAndView("assembly_manage");
92

    
93
        ModelMap modelMap = modelAndView.getModelMap();
94

    
95
        Assembly assembly = this.assemblyManager.getAssemblyById(Long.parseLong(id));
96

    
97
        modelMap.addAttribute("assembly", assembly);
98
        modelMap.addAttribute("allRoles", this.roleManager.getRoles());
99
        modelMap.addAttribute("allParameterTypes", this.parameterTypeManager.getParameterTypes());
100
        modelMap.addAttribute("allFunctions", this.functionManager.getFunctions());
101
        modelMap.addAttribute("allOperators", this.operatorManager.getOperators());
102
        modelMap.addAttribute("allLocations", this.locationManager.getLocations());
103

    
104
        return modelAndView;
105
    }
106

    
107
    @PostMapping("/assembly_edit")
108
    public ModelAndView assemblyEditPostIndex(@Valid @ModelAttribute("assembly") Assembly assembly, @Valid @ModelAttribute("checkboxPublic") String assemblyIsPublic) {
109

    
110
        ModelAndView modelAndView = new ModelAndView("assembly_manage");
111

    
112
        ModelMap modelMap = modelAndView.getModelMap();
113
        if (assemblyIsPublic.equals("on")) assembly.setIsPublic(1);
114
        else assembly.setIsPublic(0);
115

    
116
        Long assemblyID = this.assemblyManager.updateAssembly(assembly);
117
        this.parameterManager.updateParameters(assemblyID, assembly.getParameters());
118
        Assembly updatedAssembly = this.assemblyManager.getAssemblyById(assembly.getId());
119

    
120
        // TODO: vyzkoušet jestli se dobře vrací ID parameterType a zda se vypisuje název v selectboxu namísto ID !!
121
        // TODO: chybí defaultValue.
122

    
123

    
124
        modelMap.addAttribute("assembly", updatedAssembly);
125
        modelMap.addAttribute("allRoles", this.roleManager.getRoles());
126
        modelMap.addAttribute("allParameterTypes", this.parameterTypeManager.getParameterTypes());
127
        modelMap.addAttribute("allFunctions", this.functionManager.getFunctions());
128
        modelMap.addAttribute("allOperators", this.operatorManager.getOperators());
129
        modelMap.addAttribute("allLocations", this.locationManager.getLocations());
130

    
131
        return modelAndView;
132
    }
133

    
134
    @GetMapping("/assembly_new")
135
    public ModelAndView assemblyNewIndex() {
136
        ModelAndView modelAndView = new ModelAndView("assembly_manage");
137

    
138
        ModelMap modelMap = modelAndView.getModelMap();
139

    
140
        modelMap.addAttribute("assembly", new Assembly());
141
        modelMap.addAttribute("allRoles", this.roleManager.getRoles());
142
        modelMap.addAttribute("allParameterTypes", this.parameterTypeManager.getParameterTypes());
143
        modelMap.addAttribute("allFunctions", this.functionManager.getFunctions());
144
        modelMap.addAttribute("allOperators", this.operatorManager.getOperators());
145
        modelMap.addAttribute("allLocations", this.locationManager.getLocations());
146

    
147
        return modelAndView;
148
    }
149

    
150
    @PostMapping("/assembly_new")
151
    public ModelAndView assemblyNewIndexPost(@Valid @ModelAttribute("assembly") Assembly assembly) {
152
        ModelAndView modelAndView = new ModelAndView();
153

    
154
        ModelMap modelMap = modelAndView.getModelMap();
155

    
156
        Long assemblyId = this.assemblyManager.createAssembly(assembly);
157
        this.parameterManager.addParameters(assemblyId, assembly.getParameters());
158

    
159
        modelAndView.setViewName("redirect:/assembly_edit?assemblyID=" + assembly.getId());
160
        return modelAndView;
161
    }
162
}
(1-1/3)