Projekt

Obecné

Profil

Stáhnout (2.18 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.ModelMap;
6
import org.springframework.web.bind.annotation.GetMapping;
7
import org.springframework.web.bind.annotation.ModelAttribute;
8
import org.springframework.web.bind.annotation.PostMapping;
9
import org.springframework.web.servlet.ModelAndView;
10
import vldc.aswi.database.DatabaseInterface;
11
import vldc.aswi.domain.Assembly;
12
import vldc.aswi.domain.parameter.Parameter;
13
import vldc.aswi.model.table.TableColumn;
14
import vldc.aswi.model.table.contingencyTable.ContingencyTableRow;
15
import vldc.aswi.model.table.contingencyTable.ContingencyTableRowCell;
16
import vldc.aswi.service.AssemblyManager;
17
import vldc.aswi.service.SqlQueryManager;
18
import vldc.aswi.utils.Converter;
19

    
20
import javax.sql.DataSource;
21
import javax.validation.Valid;
22
import java.util.ArrayList;
23
import java.util.List;
24
import java.util.Map;
25

    
26
@Controller
27
public class IndexController {
28

    
29
	@Autowired
30
	private SqlQueryManager sqlQueryManager;
31

    
32
	@Autowired
33
	private AssemblyManager assemblyManager;
34

    
35
	@GetMapping("/")
36
	public ModelAndView index() {
37
		ModelAndView modelAndView = new ModelAndView("index");
38

    
39
		ModelMap modelMap = modelAndView.getModelMap();
40

    
41
		List<Assembly> assemblies = assemblyManager.getAssemblies();
42

    
43
		List<String> attributes = new ArrayList<>();
44
		for(Assembly assembly : assemblies) {
45
			int i = 0;
46
			StringBuilder stringBuilder = new StringBuilder("");
47
			for(Parameter parameter : assembly.getParameters()) {
48
				stringBuilder.append(parameter.getName());
49
				i++;
50
				if(i == 3) {
51
					stringBuilder.append(",...");
52
					break;
53
				}
54
				else if(i == assembly.getParameters().size()) {
55
					break;
56
				}
57
				else {
58
					stringBuilder.append(", ");
59
				}
60
			}
61
			attributes.add(stringBuilder.toString());
62
		}
63

    
64
		modelMap.addAttribute("assemblies", assemblies);
65
		modelMap.addAttribute("attributes", attributes);
66

    
67
		return modelAndView;
68
	}
69

    
70
	@PostMapping("/")
71
	public ModelAndView indexPost(@Valid @ModelAttribute("assemblyID") String id) {
72
		ModelAndView modelAndView = new ModelAndView();
73
		modelAndView.setViewName("redirect:/assembly");
74

    
75
		return modelAndView;
76
	}
77

    
78
}
(2-2/3)