Revize 9e9e8d67
Přidáno uživatelem Michal Linha před asi 4 roky(ů)
src/main/java/vldc/aswi/web/controller/ConfigurationController.java | ||
---|---|---|
7 | 7 |
import org.springframework.stereotype.Controller; |
8 | 8 |
import org.springframework.ui.ModelMap; |
9 | 9 |
import org.springframework.validation.BindingResult; |
10 |
import org.springframework.web.bind.annotation.GetMapping; |
|
11 |
import org.springframework.web.bind.annotation.ModelAttribute; |
|
12 |
import org.springframework.web.bind.annotation.PostMapping; |
|
13 |
import org.springframework.web.bind.annotation.RequestParam; |
|
10 |
import org.springframework.web.bind.annotation.*; |
|
14 | 11 |
import org.springframework.web.servlet.ModelAndView; |
12 |
import vldc.aswi.domain.Assembly; |
|
15 | 13 |
import vldc.aswi.domain.Configuration; |
16 | 14 |
import vldc.aswi.domain.Location; |
17 | 15 |
import vldc.aswi.domain.Operator; |
18 | 16 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
17 |
import vldc.aswi.model.table.contingencyTable.ContingencyTableRow; |
|
18 |
import vldc.aswi.service.AssemblyManager; |
|
19 | 19 |
import vldc.aswi.service.ConfigurationManager; |
20 |
import vldc.aswi.service.LocationManager; |
|
20 | 21 |
import vldc.aswi.service.SqlQueryManager; |
21 | 22 |
import vldc.aswi.utils.AuthControl; |
22 | 23 |
import vldc.aswi.utils.Utils; |
... | ... | |
32 | 33 |
@Controller |
33 | 34 |
public class ConfigurationController extends BasicController{ |
34 | 35 |
|
36 |
/** Autowired location manager. */ |
|
37 |
@Autowired |
|
38 |
private LocationManager locationManager; |
|
39 |
|
|
40 |
/** Autowired assembly manager. */ |
|
41 |
@Autowired |
|
42 |
private AssemblyManager assemblyManager; |
|
43 |
|
|
35 | 44 |
/** Autowired sql query manager. */ |
36 | 45 |
@Autowired |
37 | 46 |
private SqlQueryManager sqlQueryManager; |
... | ... | |
86 | 95 |
* @return modelAndView with redirection |
87 | 96 |
*/ |
88 | 97 |
@PostMapping("/configuration") |
89 |
public ModelAndView configurationPost( Configuration newConfiguration,
|
|
98 |
public ModelAndView configurationPost(Configuration newConfiguration, |
|
90 | 99 |
BindingResult bindingResult, |
91 | 100 |
@RequestParam("configurationID") String id, |
92 | 101 |
@RequestParam(required=false, value="generateTable") String generateTable, |
... | ... | |
94 | 103 |
@RequestParam(required=false, value="exportPdf") String exportPdf, |
95 | 104 |
@RequestParam(required=false, value="saveConfiguration") String saveConfiguration) |
96 | 105 |
{ |
106 |
ModelAndView modelAndView = new ModelAndView(); |
|
107 |
|
|
97 | 108 |
if (generateTable != null) |
98 | 109 |
{ |
110 |
prepareForTable(newConfiguration); |
|
99 | 111 |
System.out.println("Generuj tabulku"); |
112 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
113 |
modelMap.addAttribute("configurationID", id); |
|
114 |
modelMap.addAttribute("contingencyTableRows", this.sqlQueryManager.getContingencyTableRow(newConfiguration)); |
|
115 |
Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder()); |
|
116 |
initializeFields(newConfiguration); |
|
117 |
modelMap.addAttribute("configuration", newConfiguration); |
|
118 |
modelMap.addAttribute("comparator", comparator); |
|
119 |
modelMap.addAttribute("formAction", "/configuration?configurationID=" + id); |
|
120 |
modelAndView.setViewName("assembly"); |
|
100 | 121 |
} |
101 | 122 |
else if (exportXls != null) |
102 | 123 |
{ |
... | ... | |
109 | 130 |
else if (saveConfiguration != null) |
110 | 131 |
{ |
111 | 132 |
System.out.println("ulož konfiguraci"); |
112 |
}
|
|
133 |
Configuration configuration = configurationManager.saveConfiguration(newConfiguration, id);
|
|
113 | 134 |
|
135 |
initializeFields(configuration); |
|
114 | 136 |
|
115 |
ModelAndView modelAndView = new ModelAndView(); |
|
137 |
modelAndView.setViewName("redirect:/configuration?configurationID=" + configuration.getId()); |
|
138 |
} |
|
116 | 139 |
|
117 | 140 |
if (bindingResult.hasErrors()) { |
118 | 141 |
// TODO: 04.05.2020 Error message |
... | ... | |
123 | 146 |
|
124 | 147 |
|
125 | 148 |
|
126 |
Configuration configuration = configurationManager.saveConfiguration(newConfiguration, id); |
|
127 | 149 |
|
128 |
this.sqlQueryManager.getContingencyTableRow(configuration.getAssembly().getSQLQuery()); |
|
129 |
|
|
130 |
initializeFields(configuration); |
|
131 |
|
|
132 |
modelAndView.setViewName("redirect:/configuration?configurationID=" + configuration.getId()); |
|
133 | 150 |
|
134 | 151 |
return modelAndView; |
135 | 152 |
} |
... | ... | |
172 | 189 |
} |
173 | 190 |
} |
174 | 191 |
} |
192 |
|
|
193 |
/** |
|
194 |
* Prepares the configuration for contingency table generation. Initializes assembly and parameters of parameters in |
|
195 |
* configuration. |
|
196 |
* @param configuration configuration to be prepared. |
|
197 |
*/ |
|
198 |
private void prepareForTable(Configuration configuration) { |
|
199 |
Assembly assembly = assemblyManager.getAssemblyById(configuration.getAssembly().getId()); |
|
200 |
configuration.setAssembly(assembly); |
|
201 |
|
|
202 |
for(int i = 0; i < configuration.getParametersInConfiguration().size(); i++) { |
|
203 |
ParameterInConfiguration parameterInConfiguration = configuration.getParametersInConfiguration().get(i); |
|
204 |
parameterInConfiguration.setParameter(assembly.getParameters().get(i)); |
|
205 |
if (parameterInConfiguration.getLocation() != null) { |
|
206 |
parameterInConfiguration.setLocation(locationManager.getLocationById(parameterInConfiguration.getLocation().getId())); |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
175 | 210 |
} |
Také k dispozici: Unified diff
re #7885 added SUM and ability to work with multiple values and sorted parameters in configuration, optimization