Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 7638be72

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

re #7886 Assembly validator completed (validating sql query, parameter name in select and parameter location) + displaying temp error message.
Added title for edit / add assembly forms.
Added toString method for all domains.

Zobrazit rozdíly:

src/main/java/vldc/aswi/web/controller/AssemblyController.java
23 23
 * Controller for assembly.
24 24
 */
25 25
@Controller
26
public class AssemblyController {
26
public class AssemblyController extends BasicController {
27 27

  
28 28
    /** Autowired sql query manager. */
29 29
    @Autowired
......
61 61
    @Autowired
62 62
    private AssemblyValidator assemblyValidator;
63 63

  
64
    /** Name of thymeleaf parameter, which will contain text in assembly form. */
65
    private String assemblyTitleName = "title";
66

  
67
    /** Title text for assembly edit form.  */
68
    private String assemblyEditTitleText = "Editace - ";
69

  
70
    /** Title text for new assembly form. */
71
    private String assemblyNewTitleText = "Vytvoření nové sestavy";
72

  
73
    /** Name of thymeleaf parameter, which will contain error text from validator. */
74
    private String assemblyErrorName = "errorText";
75

  
64 76
    /**
65 77
     * Bind assembly validator.
66 78
     * @param binder Binder.
......
102 114
        return modelAndView;
103 115
    }
104 116

  
117
    /**
118
     * Get method for assembly edit.
119
     * @param id - Id of assembly.
120
     * @return ModelAndView for assembly edit.
121
     */
105 122
    @GetMapping("/assembly_edit")
106 123
    public ModelAndView assemblyEditIndex(@Valid @ModelAttribute("assemblyID") String id) {
107 124
        ModelAndView modelAndView = new ModelAndView("assembly_manage");
......
111 128
        Assembly assembly = this.assemblyManager.getAssemblyById(Long.parseLong(id));
112 129

  
113 130
        modelMap.addAttribute("assembly", assembly);
131

  
132
        modelMap.addAttribute(assemblyTitleName, assemblyEditTitleText + " " + assembly.getName());
133

  
114 134
        modelMap.addAttribute("allRoles", this.roleManager.getRoles());
115 135
        modelMap.addAttribute("allParameterTypes", this.parameterTypeManager.getParameterTypes());
116 136
        modelMap.addAttribute("allFunctions", this.functionManager.getFunctions());
......
120 140
        return modelAndView;
121 141
    }
122 142

  
143
    /**
144
     * Post method for assembly edit.
145
     * @param assembly - Edited assembly values.
146
     * @param result - Validator results.
147
     * @param assemblyIsPublic - Attribute indicating if assembly is public or not.
148
     * @return ModelAndView for assembly edit.
149
     */
123 150
    @PostMapping("/assembly_edit")
124
    public ModelAndView assemblyEditPostIndex(@Valid @ModelAttribute("assembly") Assembly assembly, @Valid @ModelAttribute("checkboxPublic") String assemblyIsPublic) {
151
    public ModelAndView assemblyEditPostIndex(@Valid @ModelAttribute("assembly") Assembly assembly, BindingResult result,
152
                                              @Valid @ModelAttribute("checkboxPublic") String assemblyIsPublic) {
125 153

  
126 154
        ModelAndView modelAndView = new ModelAndView("assembly_manage");
127 155
        ModelMap modelMap = modelAndView.getModelMap();
128 156

  
129
        if (assemblyIsPublic.equals("on")) assembly.setIsPublic(1);
130
        else assembly.setIsPublic(0);
157
        if (result.hasErrors()) {
158
            modelMap.addAttribute("assembly", assembly);
159

  
160
            modelMap.addAttribute(assemblyErrorName, getFullErrorMessage(result));
161
            modelMap.addAttribute(assemblyTitleName, assemblyEditTitleText + " " + assembly.getName());
162
        }
163
        else {
164
            if (assemblyIsPublic.equals("on")) assembly.setIsPublic(1);
165
            else assembly.setIsPublic(0);
131 166

  
132
        // TODO: chybí defaultValue.
133
        Long assemblyID = this.assemblyManager.updateAssembly(assembly);
134
        this.parameterManager.updateParameters(assemblyID, assembly.getParameters());
135
        Assembly updatedAssembly = this.assemblyManager.getAssemblyById(assembly.getId());
167
            // TODO: chybí defaultValue.
168
            Long assemblyID = this.assemblyManager.updateAssembly(assembly);
169
            this.parameterManager.updateParameters(assemblyID, assembly.getParameters());
170
            Assembly updatedAssembly = this.assemblyManager.getAssemblyById(assembly.getId());
136 171

  
137
        modelMap.addAttribute("assembly", updatedAssembly);
172
            modelMap.addAttribute("assembly", updatedAssembly);
173
            modelMap.addAttribute(assemblyTitleName, assemblyEditTitleText + " " + updatedAssembly.getName());
174
        }
138 175

  
139 176
        modelMap.addAttribute("allRoles", this.roleManager.getRoles());
140 177
        modelMap.addAttribute("allParameterTypes", this.parameterTypeManager.getParameterTypes());
......
145 182
        return modelAndView;
146 183
    }
147 184

  
185
    /**
186
     * Get method for new assembly form.
187
     * @return ModelAndView for new assembly.
188
     */
148 189
    @GetMapping("/assembly_new")
149 190
    public ModelAndView assemblyNewIndex() {
150 191
        ModelAndView modelAndView = new ModelAndView("assembly_manage");
......
152 193
        ModelMap modelMap = modelAndView.getModelMap();
153 194

  
154 195
        modelMap.addAttribute("assembly", new Assembly());
196

  
197
        modelMap.addAttribute(assemblyTitleName, assemblyNewTitleText);
198

  
155 199
        modelMap.addAttribute("allRoles", this.roleManager.getRoles());
156 200
        modelMap.addAttribute("allParameterTypes", this.parameterTypeManager.getParameterTypes());
157 201
        modelMap.addAttribute("allFunctions", this.functionManager.getFunctions());
......
161 205
        return modelAndView;
162 206
    }
163 207

  
208
    /**
209
     * Post method for new assembly form.
210
     * @param assembly - Assembly values.
211
     * @param result - Validator results.
212
     * @return
213
     */
164 214
    @PostMapping("/assembly_new")
165
    public ModelAndView assemblyNewIndexPost(@Valid @ModelAttribute("assembly") Assembly assembly) {
215
    public ModelAndView assemblyNewIndexPost(@Valid @ModelAttribute("assembly") Assembly assembly, BindingResult result) {
166 216
        ModelAndView modelAndView = new ModelAndView();
167 217

  
218
        if (result.hasErrors()) {
219
            ModelMap modelMap = modelAndView.getModelMap();
220
            modelAndView.setViewName("assembly_manage");
221

  
222
            modelMap.addAttribute("assembly", assembly);
223

  
224
            modelMap.addAttribute(assemblyTitleName, assemblyNewTitleText);
225
            modelMap.addAttribute(assemblyErrorName, getFullErrorMessage(result));
226

  
227
            modelMap.addAttribute("allRoles", this.roleManager.getRoles());
228
            modelMap.addAttribute("allParameterTypes", this.parameterTypeManager.getParameterTypes());
229
            modelMap.addAttribute("allFunctions", this.functionManager.getFunctions());
230
            modelMap.addAttribute("allOperators", this.operatorManager.getOperators());
231
            modelMap.addAttribute("allLocations", this.locationManager.getLocations());
232
        }
233

  
168 234
        ModelMap modelMap = modelAndView.getModelMap();
169 235

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

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

  
176 242
        return modelAndView;
177 243
    }

Také k dispozici: Unified diff