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());
|
}
|
|
}
|
}
|