Revize 3309eb3e
Přidáno uživatelem Michal Linha před téměř 4 roky(ů)
src/main/java/vldc/aswi/web/controller/ConfigurationController.java | ||
---|---|---|
3 | 3 |
import org.springframework.beans.factory.annotation.Autowired; |
4 | 4 |
import org.springframework.stereotype.Controller; |
5 | 5 |
import org.springframework.ui.ModelMap; |
6 |
import org.springframework.validation.BeanPropertyBindingResult; |
|
6 | 7 |
import org.springframework.validation.BindingResult; |
8 |
import org.springframework.web.bind.WebDataBinder; |
|
7 | 9 |
import org.springframework.web.bind.annotation.*; |
8 | 10 |
import org.springframework.web.servlet.ModelAndView; |
9 | 11 |
import org.springframework.web.servlet.mvc.support.RedirectAttributes; |
... | ... | |
19 | 21 |
import vldc.aswi.service.SqlQueryManager; |
20 | 22 |
import vldc.aswi.utils.AuthControl; |
21 | 23 |
import vldc.aswi.utils.Utils; |
24 |
import vldc.aswi.validators.AssemblyValidator; |
|
25 |
import vldc.aswi.validators.ConfigurationValidator; |
|
26 |
|
|
27 |
import javax.validation.Valid; |
|
22 | 28 |
import java.util.ArrayList; |
23 | 29 |
import java.util.Comparator; |
24 | 30 |
import java.util.List; |
... | ... | |
45 | 51 |
@Autowired |
46 | 52 |
private ConfigurationManager configurationManager; |
47 | 53 |
|
54 |
/** Autowired configuration validator */ |
|
55 |
@Autowired |
|
56 |
private ConfigurationValidator configurationValidator; |
|
57 |
|
|
58 |
/** Name of thymeleaf parameter, which will contain text in assembly form. */ |
|
59 |
private String assemblyTitleName = "title"; |
|
60 |
|
|
61 |
/** Title text for table generation form. */ |
|
62 |
private String generateTableTitleText = "Generování tabulky - "; |
|
63 |
|
|
48 | 64 |
/** |
49 | 65 |
* Opens an configuration page after configuration name was clicked |
50 | 66 |
* @param id ID of configuration |
... | ... | |
96 | 112 |
* @return modelAndView with redirection |
97 | 113 |
*/ |
98 | 114 |
@PostMapping("/configuration") |
99 |
public ModelAndView configurationPost(Configuration newConfiguration, |
|
115 |
public ModelAndView configurationPost(@Valid Configuration newConfiguration,
|
|
100 | 116 |
BindingResult bindingResult, |
101 | 117 |
@RequestParam("configurationID") String id, |
102 | 118 |
@RequestParam(required=false, value="generateTable") String generateTable, |
... | ... | |
119 | 135 |
if (generateTable != null) |
120 | 136 |
{ |
121 | 137 |
prepareForTable(newConfiguration); |
122 |
System.out.println("Generuj tabulku"); |
|
123 |
|
|
124 |
List<ContingencyTableRow> rows = this.sqlQueryManager.getContingencyTableRow(newConfiguration.getAssembly().getSQLQuery(), |
|
125 |
newConfiguration.getParametersInConfiguration()); |
|
126 |
|
|
127 |
modelMap.addAttribute("configurationID", id); |
|
128 |
modelMap.addAttribute("contingencyTableRows", rows); |
|
129 |
Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder()); |
|
130 |
initializeFields(newConfiguration); |
|
131 |
modelMap.addAttribute("configuration", newConfiguration); |
|
132 |
modelMap.addAttribute("comparator", comparator); |
|
133 |
modelMap.addAttribute("formAction", "/configuration?configurationID=" + id); |
|
134 |
modelAndView.setViewName("assembly"); |
|
138 |
BindingResult errors = new BeanPropertyBindingResult(newConfiguration, newConfiguration.getClass().getName()); |
|
139 |
configurationValidator.validate(newConfiguration, errors); |
|
140 |
if (errors.hasErrors()) { |
|
141 |
addConfigurationDataIntoModelAndView(newConfiguration, modelAndView, modelMap); |
|
142 |
|
|
143 |
modelMap.addAttribute(assemblyErrorName, getFullErrorMessage(errors)); |
|
144 |
modelMap.addAttribute(assemblyTitleName, generateTableTitleText + " " + newConfiguration.getName()); |
|
145 |
} |
|
146 |
else { |
|
147 |
List<ContingencyTableRow> rows = this.sqlQueryManager.getContingencyTableRow(newConfiguration); |
|
148 |
System.out.println("Generuj tabulku"); |
|
149 |
modelMap.addAttribute("configurationID", id); |
|
150 |
modelMap.addAttribute("contingencyTableRows", rows); |
|
151 |
addConfigurationDataIntoModelAndView(newConfiguration, modelAndView, modelMap); |
|
152 |
} |
|
135 | 153 |
} |
136 | 154 |
else if (exportXls != null) |
137 | 155 |
{ |
... | ... | |
220 | 238 |
} |
221 | 239 |
} |
222 | 240 |
} |
241 |
|
|
242 |
private void addConfigurationDataIntoModelAndView(Configuration newConfiguration, ModelAndView modelAndView, ModelMap modelMap) { |
|
243 |
Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder()); |
|
244 |
initializeFields(newConfiguration); |
|
245 |
modelMap.addAttribute("configuration", newConfiguration); |
|
246 |
modelMap.addAttribute("comparator", comparator); |
|
247 |
modelMap.addAttribute("formAction", "/assembly?assemblyID=" + newConfiguration.getAssembly().getId()); |
|
248 |
modelAndView.setViewName("assembly"); |
|
249 |
} |
|
223 | 250 |
} |
Také k dispozici: Unified diff
re #7885 added option to show empty rows and columns, bug fixes re #8134 nothing; re #8154 added validator; re #8136 added column names no comments