Projekt

Obecné

Profil

« Předchozí | Další » 

Revize ba8b306a

Přidáno uživatelem Vojtěch Danišík před asi 4 roky(ů)

re #7886 Assembly validator in progress (validating assembly SQLQuery + locations for existing assembly, not tested for new assembly).
Added comments.
Removing unused imports.

Zobrazit rozdíly:

src/main/java/vldc/aswi/web/controller/AssemblyController.java
2 2

  
3 3
import org.springframework.beans.factory.annotation.Autowired;
4 4
import org.springframework.stereotype.Controller;
5
import org.springframework.ui.Model;
6 5
import org.springframework.ui.ModelMap;
7 6
import org.springframework.validation.BindingResult;
7
import org.springframework.web.bind.WebDataBinder;
8 8
import org.springframework.web.bind.annotation.GetMapping;
9
import org.springframework.web.bind.annotation.InitBinder;
9 10
import org.springframework.web.bind.annotation.ModelAttribute;
10 11
import org.springframework.web.bind.annotation.PostMapping;
11 12
import org.springframework.web.servlet.ModelAndView;
12 13
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
13 14
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 15
import vldc.aswi.service.*;
18 16
import vldc.aswi.service.parameter.ParameterManager;
19 17
import vldc.aswi.service.parameter.ParameterTypeManager;
20
import vldc.aswi.service.parameter.ParameterValueManager;
18
import vldc.aswi.validators.AssemblyValidator;
21 19

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

  
22
/**
23
 * Controller for assembly.
24
 */
27 25
@Controller
28 26
public class AssemblyController {
29 27

  
28
    /** Autowired sql query manager. */
30 29
    @Autowired
31 30
    private SqlQueryManager sqlQueryManager;
32 31

  
32
    /** Autowired assembly manager. */
33 33
    @Autowired
34 34
    private AssemblyManager assemblyManager;
35 35

  
36
    /** Autowired role manager. */
36 37
    @Autowired
37 38
    private RoleManager roleManager;
38 39

  
40
    /** Autowired parameterType manager. */
39 41
    @Autowired
40 42
    private ParameterTypeManager parameterTypeManager;
41 43

  
44
    /** Autowired operator manager. */
42 45
    @Autowired
43 46
    private OperatorManager operatorManager;
44 47

  
48
    /** Autowired function manager. */
45 49
    @Autowired
46 50
    private FunctionManager functionManager;
47 51

  
52
    /** Autowired location manager. */
48 53
    @Autowired
49 54
    private LocationManager locationManager;
50 55

  
56
    /** Autowired parameter manager. */
51 57
    @Autowired
52 58
    private ParameterManager parameterManager;
53 59

  
60
    /** Autowired assembly validator */
54 61
    @Autowired
55
    private ParameterValueManager parameterValueManager;
62
    private AssemblyValidator assemblyValidator;
63

  
64
    /**
65
     * Bind assembly validator.
66
     * @param binder Binder.
67
     */
68
    @InitBinder("assembly")
69
    protected void userBinder(WebDataBinder binder) {
70
        binder.addValidators(this.assemblyValidator);
71
    }
56 72

  
57 73
    @GetMapping("/assembly")
58 74
    public ModelAndView assemblyIndex(@Valid @ModelAttribute("assemblyID") String id) {
......
108 124
    public ModelAndView assemblyEditPostIndex(@Valid @ModelAttribute("assembly") Assembly assembly, @Valid @ModelAttribute("checkboxPublic") String assemblyIsPublic) {
109 125

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

  
112 127
        ModelMap modelMap = modelAndView.getModelMap();
128

  
113 129
        if (assemblyIsPublic.equals("on")) assembly.setIsPublic(1);
114 130
        else assembly.setIsPublic(0);
115 131

  
132
        // TODO: chybí defaultValue.
116 133
        Long assemblyID = this.assemblyManager.updateAssembly(assembly);
117 134
        this.parameterManager.updateParameters(assemblyID, assembly.getParameters());
118 135
        Assembly updatedAssembly = this.assemblyManager.getAssemblyById(assembly.getId());
119 136

  
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 137
        modelMap.addAttribute("assembly", updatedAssembly);
138

  
125 139
        modelMap.addAttribute("allRoles", this.roleManager.getRoles());
126 140
        modelMap.addAttribute("allParameterTypes", this.parameterTypeManager.getParameterTypes());
127 141
        modelMap.addAttribute("allFunctions", this.functionManager.getFunctions());
......
153 167

  
154 168
        ModelMap modelMap = modelAndView.getModelMap();
155 169

  
170
        // TODO: chybí získání default value.
156 171
        Long assemblyId = this.assemblyManager.createAssembly(assembly);
157 172
        this.parameterManager.addParameters(assemblyId, assembly.getParameters());
158 173

  
159 174
        modelAndView.setViewName("redirect:/assembly_edit?assemblyID=" + assembly.getId());
175

  
160 176
        return modelAndView;
161 177
    }
162 178
}

Také k dispozici: Unified diff