Leonardo Vannucci
2019-04-30 d50b201eb6593d5090e3cad496895ced88a5a7c3
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
46
47
package it.digione.dg1cloud.controller;
 
import java.io.IOException;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
 
import it.digione.dg1cloud.form.DownloadFileCaptchaForm;
import it.digione.dg1cloud.recaptcha.CaptchaSettings;
 
@Controller
public class DownloadController {
   
   private static final Logger logger = LoggerFactory.getLogger(DownloadController.class);
   
   @Autowired CaptchaSettings captchaSettings;
   
   @RequestMapping("/download")
   public ModelAndView download(@RequestParam String fileName, @RequestParam long id,
                               @RequestParam(value = "secretKey", required = false) String secretKey) throws IOException {
       
       logger.debug("Preparazione download file {} con id {}", fileName, id);
       
       DownloadFileCaptchaForm downloadParams = new DownloadFileCaptchaForm();
       
       downloadParams.setFileName(fileName);
       downloadParams.setId(id);
       downloadParams.setSecretKey(secretKey);
       
       ModelAndView modelAndView;
       
       if ( captchaSettings.isEnabled() == true ) {
           modelAndView = new ModelAndView("downloadFileCaptcha");
       } else {
           modelAndView = new ModelAndView("forward:/downloadFile");
       }
       
       modelAndView.addObject("downloadFileCaptchaForm", downloadParams);
       
       return modelAndView;
   }
}