Revize 74a73b3b
Přidáno uživatelem Vojtěch Danišík před asi 4 roky(ů)
src/main/java/vldc/aswi/web/controller/AssemblyController.java | ||
---|---|---|
22 | 22 |
import vldc.aswi.service.parameter.ParameterManager; |
23 | 23 |
import vldc.aswi.service.parameter.ParameterTypeManager; |
24 | 24 |
import vldc.aswi.validators.AssemblyValidator; |
25 |
import vldc.aswi.utils.Utils; |
|
25 | 26 |
|
26 | 27 |
import javax.validation.Valid; |
27 | 28 |
import java.util.ArrayList; |
... | ... | |
68 | 69 |
@Autowired |
69 | 70 |
private AssemblyValidator assemblyValidator; |
70 | 71 |
|
71 |
@Autowired |
|
72 |
private ConfigurationManager configurationManager; |
|
73 |
|
|
74 | 72 |
/** Name of thymeleaf parameter, which will contain text in assembly form. */ |
75 | 73 |
private String assemblyTitleName = "title"; |
76 | 74 |
|
... | ... | |
92 | 90 |
binder.addValidators(this.assemblyValidator); |
93 | 91 |
} |
94 | 92 |
|
93 |
/** |
|
94 |
* Get method for form, where configuration is created from assembly. |
|
95 |
* @param id - ID of assembly. |
|
96 |
* @return ModelAndView for assembly. |
|
97 |
*/ |
|
95 | 98 |
@GetMapping("/assembly") |
96 |
public ModelAndView assemblyIndex(@Valid @ModelAttribute("assemblyID") String id) {
|
|
99 |
public ModelAndView assemblyGet(@Valid @ModelAttribute("assemblyID") String id) {
|
|
97 | 100 |
ModelAndView modelAndView = new ModelAndView("assembly"); |
98 | 101 |
|
99 | 102 |
ModelMap modelMap = modelAndView.getModelMap(); |
... | ... | |
119 | 122 |
return modelAndView; |
120 | 123 |
} |
121 | 124 |
|
122 |
/** |
|
123 |
* Opens an configuration page after configuration name was clicked |
|
124 |
* @param id ID of configuration |
|
125 |
* @return modelAndView of page to be shown |
|
126 |
*/ |
|
127 |
@GetMapping("/configuration") |
|
128 |
public ModelAndView configurationIndex(@Valid @ModelAttribute("configurationID") String id) { |
|
129 |
ModelAndView modelAndView = new ModelAndView("assembly"); |
|
130 |
|
|
131 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
132 |
|
|
133 |
Configuration configuration = configurationManager.getConfigurationById(Long.parseLong(id)); |
|
134 |
|
|
135 |
initializeFields(configuration); |
|
136 |
|
|
137 |
modelMap.addAttribute("configuration", configuration); |
|
138 |
modelMap.addAttribute("isAssembly", "0"); |
|
139 |
|
|
140 |
return modelAndView; |
|
141 |
} |
|
142 | 125 |
|
143 | 126 |
/** |
144 |
* Saves or edits configuration and redirects to the page with configuration
|
|
145 |
* @param newConfiguration contained with configuration data
|
|
146 |
* @param id ID of configuration, if empty new configuration is created
|
|
147 |
* @param bindingResult binding result
|
|
148 |
* @return modelAndView with redirection
|
|
127 |
* Post method for form, where configuration is created from assembly.
|
|
128 |
* @param assembly - Assembly values.
|
|
129 |
* @param bindingResult - Error results from assembly validators.
|
|
130 |
* @param atts - Redirect attributes.
|
|
131 |
* @return ModelAndView for assembly.
|
|
149 | 132 |
*/ |
150 |
@PostMapping("/configuration") |
|
151 |
public ModelAndView saveConfiguration(@Valid Configuration newConfiguration, BindingResult bindingResult, |
|
152 |
@RequestParam("configurationID") String id) { |
|
153 |
ModelAndView modelAndView = new ModelAndView(); |
|
154 |
|
|
155 |
if (bindingResult.hasErrors()) { |
|
156 |
modelAndView.setViewName("redirect:/"); |
|
157 |
|
|
158 |
return modelAndView; |
|
159 |
} |
|
160 |
|
|
161 |
Configuration configuration = configurationManager.saveConfiguration(newConfiguration, id); |
|
162 |
|
|
163 |
initializeFields(configuration); |
|
164 |
|
|
165 |
modelAndView.setViewName("redirect:/configuration?configurationID=" + configuration.getId()); |
|
166 |
|
|
167 |
return modelAndView; |
|
168 |
} |
|
169 |
|
|
170 | 133 |
@PostMapping("/assembly") |
171 |
public ModelAndView indexPost(@Valid Assembly assembly, BindingResult bindingResult, RedirectAttributes atts) {
|
|
134 |
public ModelAndView assemblyPost(@Valid Assembly assembly, BindingResult bindingResult, RedirectAttributes atts) {
|
|
172 | 135 |
ModelAndView modelAndView = new ModelAndView(); |
173 | 136 |
|
174 | 137 |
ModelMap modelMap = modelAndView.getModelMap(); |
... | ... | |
185 | 148 |
return modelAndView; |
186 | 149 |
} |
187 | 150 |
|
151 |
/** |
|
152 |
* Get method for assembly delete. |
|
153 |
* @param id - ID of assembly. |
|
154 |
* @return ModelAndView for index. |
|
155 |
*/ |
|
156 |
@GetMapping("/assembly_delete") |
|
157 |
public ModelAndView assemblyDeleteGet(@RequestParam("assemblyID") String id) { |
|
158 |
ModelAndView modelAndView = new ModelAndView("redirect:/"); |
|
159 |
|
|
160 |
Long assemblyId = Utils.tryParseLong(id); |
|
161 |
|
|
162 |
if (assemblyId == null) { |
|
163 |
// TODO: print error in index. |
|
164 |
} |
|
165 |
boolean success = this.assemblyManager.deleteAssembly(assemblyId); |
|
166 |
// TODO: check success. |
|
167 |
|
|
168 |
return modelAndView; |
|
169 |
} |
|
170 |
|
|
188 | 171 |
/** |
189 | 172 |
* Get method for assembly edit. |
190 | 173 |
* @param id - Id of assembly. |
191 | 174 |
* @return ModelAndView for assembly edit. |
192 | 175 |
*/ |
193 | 176 |
@GetMapping("/assembly_edit") |
194 |
public ModelAndView assemblyEditIndex(@Valid @ModelAttribute("assemblyID") String id) {
|
|
177 |
public ModelAndView assemblyEditGet(@Valid @ModelAttribute("assemblyID") String id) {
|
|
195 | 178 |
ModelAndView modelAndView = new ModelAndView("assembly_manage"); |
196 | 179 |
|
197 | 180 |
ModelMap modelMap = modelAndView.getModelMap(); |
... | ... | |
219 | 202 |
* @return ModelAndView for assembly edit. |
220 | 203 |
*/ |
221 | 204 |
@PostMapping("/assembly_edit") |
222 |
public ModelAndView assemblyEditPostIndex(@Valid @ModelAttribute("assembly") Assembly assembly, BindingResult result,
|
|
205 |
public ModelAndView assemblyEditPost(@Valid @ModelAttribute("assembly") Assembly assembly, BindingResult result, |
|
223 | 206 |
@Valid @ModelAttribute("checkboxPublic") String assemblyIsPublic) { |
224 | 207 |
|
225 | 208 |
ModelAndView modelAndView = new ModelAndView("assembly_manage"); |
... | ... | |
258 | 241 |
* @return ModelAndView for new assembly. |
259 | 242 |
*/ |
260 | 243 |
@GetMapping("/assembly_new") |
261 |
public ModelAndView assemblyNewIndex() {
|
|
244 |
public ModelAndView assemblyNewGet() {
|
|
262 | 245 |
ModelAndView modelAndView = new ModelAndView("assembly_manage"); |
263 | 246 |
|
264 | 247 |
ModelMap modelMap = modelAndView.getModelMap(); |
... | ... | |
283 | 266 |
* @return |
284 | 267 |
*/ |
285 | 268 |
@PostMapping("/assembly_new") |
286 |
public ModelAndView assemblyNewIndexPost(@Valid @ModelAttribute("assembly") Assembly assembly, BindingResult result) {
|
|
269 |
public ModelAndView assemblyNewPost(@Valid @ModelAttribute("assembly") Assembly assembly, BindingResult result) { |
|
287 | 270 |
ModelAndView modelAndView = new ModelAndView(); |
271 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
288 | 272 |
|
289 | 273 |
if (result.hasErrors()) { |
290 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
291 | 274 |
modelAndView.setViewName("assembly_manage"); |
292 |
|
|
293 | 275 |
modelMap.addAttribute("assembly", assembly); |
294 | 276 |
|
295 |
modelMap.addAttribute(assemblyTitleName, assemblyNewTitleText); |
|
296 | 277 |
modelMap.addAttribute(assemblyErrorName, getFullErrorMessage(result)); |
297 |
|
|
298 |
modelMap.addAttribute("allRoles", this.roleManager.getRoles()); |
|
299 |
modelMap.addAttribute("allParameterTypes", this.parameterTypeManager.getParameterTypes()); |
|
300 |
modelMap.addAttribute("allFunctions", this.functionManager.getFunctions()); |
|
301 |
modelMap.addAttribute("allOperators", this.operatorManager.getOperators()); |
|
302 |
modelMap.addAttribute("allLocations", this.locationManager.getLocations()); |
|
278 |
modelMap.addAttribute(assemblyTitleName, assemblyNewTitleText); |
|
303 | 279 |
} |
280 |
else { |
|
281 |
// TODO: chybí získání default value. |
|
282 |
Long assemblyId = this.assemblyManager.createAssembly(assembly); |
|
283 |
this.parameterManager.addParameters(assemblyId, assembly.getParameters()); |
|
304 | 284 |
|
305 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
306 |
|
|
307 |
// TODO: chybí získání default value. |
|
308 |
Long assemblyId = this.assemblyManager.createAssembly(assembly); |
|
309 |
this.parameterManager.addParameters(assemblyId, assembly.getParameters()); |
|
310 |
|
|
311 |
modelAndView.setViewName("redirect:/assembly_edit?assemblyID=" + assemblyId); |
|
285 |
modelAndView.setViewName("redirect:/assembly_edit?assemblyID=" + assemblyId); |
|
286 |
} |
|
312 | 287 |
|
313 | 288 |
return modelAndView; |
314 | 289 |
} |
315 |
|
|
316 |
/** |
|
317 |
* Initializes fields of a given configuration |
|
318 |
* @param configuration configuration which fields should be initialized |
|
319 |
*/ |
|
320 |
private void initializeFields(Configuration configuration) { |
|
321 |
for(ParameterInConfiguration parameterInConfiguration : configuration.getParametersInConfiguration()) { |
|
322 |
if(parameterInConfiguration.getLocation() == null) { |
|
323 |
parameterInConfiguration.setLocation(new Location()); |
|
324 |
} |
|
325 |
if(parameterInConfiguration.getOperator() == null) { |
|
326 |
parameterInConfiguration.setOperator(new Operator()); |
|
327 |
} |
|
328 |
if(parameterInConfiguration.getFunctions() == null) { |
|
329 |
parameterInConfiguration.setFunctions(new ArrayList<>()); |
|
330 |
} |
|
331 |
} |
|
332 |
} |
|
333 | 290 |
} |
Také k dispozici: Unified diff
re #7887 Deleting configurations and assemblies, Minor restructuralization.