Leonardo Vannucci
2018-08-10 09740e77ea352852ff90b738787f7f6aa657b604
Viene generato una url per il download generica che a seconda dell'abilitazione del captcha o meno redirige nell'url corretta
1 files renamed
2 files modified
25 ■■■■■ changed files
dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadController.java 21 ●●●● patch | view | raw | blame | history
dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java 2 ●●● patch | view | raw | blame | history
dg1cloud-core/src/main/resources/templates/downloadFileCaptcha.html 2 ●●● patch | view | raw | blame | history
dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadPageController.java
similarity index 66%rename from dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadPageController.javarename to dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadController.java
....@@ -14,15 +14,17 @@
1414 import it.digione.dg1cloud.recaptcha.DownloadFileCaptchaForm;
1515
1616 @Controller
17
-public class DownloadPageController {
17
+public class DownloadController {
1818
19
- private static final Logger logger = LoggerFactory.getLogger(DownloadPageController.class);
19
+ private static final Logger logger = LoggerFactory.getLogger(DownloadController.class);
2020
21
- @RequestMapping("/downloadPage")
22
- public ModelAndView downloadPage(@RequestParam String fileName, @RequestParam long id,
21
+ @Autowired CaptchaSettings captchaSettings;
22
+
23
+ @RequestMapping("/download")
24
+ public ModelAndView download(@RequestParam String fileName, @RequestParam long id,
2325 @RequestParam(value = "secretKey", required = false) String secretKey) throws IOException {
2426
25
- logger.debug("Preparazione pagina download file {} con id {}", fileName, id);
27
+ logger.debug("Preparazione download file {} con id {}", fileName, id);
2628
2729 DownloadFileCaptchaForm downloadParams = new DownloadFileCaptchaForm();
2830
....@@ -30,7 +32,14 @@
3032 downloadParams.setId(id);
3133 downloadParams.setSecretKey(secretKey);
3234
33
- ModelAndView modelAndView = new ModelAndView("downloadFileCaptcha");
35
+ ModelAndView modelAndView;
36
+
37
+ if ( captchaSettings.isEnabled() == true ) {
38
+ modelAndView = new ModelAndView("downloadFileCaptcha");
39
+ } else {
40
+ modelAndView = new ModelAndView("forward:/downloadFile");
41
+ }
42
+
3443 modelAndView.addObject("downloadFileCaptchaForm", downloadParams);
3544
3645 return modelAndView;
dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java
....@@ -38,7 +38,7 @@
3838 public URL generateUrl(RegDocument regDocument) throws MalformedURLException {
3939 logger.debug("Genero l'url per il record file {} con id {}", regDocument.getFileName(), regDocument.getDocumentId());
4040 UriBuilder uriBuilder = UriComponentsBuilder.fromUriString(appConfig.getExternalBaseUrl());
41
- uriBuilder.path("/downloadPage");
41
+ uriBuilder.path("/download");
4242 uriBuilder.queryParam("fileName", regDocument.getFileName());
4343 uriBuilder.queryParam("id", regDocument.getDocumentId());
4444 if ( Strings.isEmpty(regDocument.getSecretKey()) == false ) {
dg1cloud-core/src/main/resources/templates/downloadFileCaptcha.html
....@@ -19,7 +19,7 @@
1919 <div class="panel-body">
2020 <div class="text-center">
2121 <h3><i class="glyphicon glyphicon-lock" style="font-size:2em;"></i></h3>
22
- <h2 class="text-center" th:text="*{downloadFileCaptchaForm.fileName}"></h2>
22
+ <h2 class="text-center" style="word-wrap: break-word;" th:text="*{downloadFileCaptchaForm.fileName}"></h2>
2323 <div class="panel-body">
2424 <form action="#" th:action="@{/downloadFileCaptcha}" th:object="${downloadFileCaptchaForm}" method="post">
2525 <input type="hidden" th:field="*{id}" />