Leonardo Vannucci
2018-09-19 751c7ee02cb896717c84ea1eefd0982ed8bd303b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package it.digione.dg1cloud.controller;
 
import java.io.FileNotFoundException;
 
import javax.validation.Valid;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
 
import it.digione.dg1cloud.form.DownloadFileCaptchaForm;
import it.digione.dg1cloud.service.Utils;
 
@Controller
@RequestMapping("/downloadFileCaptcha")
public class DownloadFileCaptchaController {
   
   @Autowired private Utils utils;
   
   @ModelAttribute("downloadFileCaptchaForm")
   public DownloadFileCaptchaForm downloadFileCaptchaForm() {
       return new DownloadFileCaptchaForm();
   }
 
   @PostMapping
   public Object handleDownloadFileCaptcha(@ModelAttribute("downloadFileCaptchaForm") @Valid DownloadFileCaptchaForm form,
                                   BindingResult result) throws FileNotFoundException{
       
       ModelAndView modelAndView;
       if (result.hasErrors()){
           modelAndView = new ModelAndView("downloadFileCaptcha");
           modelAndView.addObject(result);
           modelAndView.addObject("downloadFileCaptchaForm", form);
           
           return modelAndView;
       } else {
           return utils.getDownloadResponseEntity(form.getFileName(), form.getId(), form.getSecretKey());
       }
       
   }
}