From 09740e77ea352852ff90b738787f7f6aa657b604 Mon Sep 17 00:00:00 2001
From: Leonardo Vannucci <leonardo.vannucci@grupposistematica.it>
Date: Fri, 10 Aug 2018 09:49:15 +0200
Subject: [PATCH] Viene generato una url per il download generica che a seconda dell'abilitazione del captcha o meno redirige nell'url corretta
---
dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java | 2 +-
dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadController.java | 21 +++++++++++++++------
dg1cloud-core/src/main/resources/templates/downloadFileCaptcha.html | 2 +-
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadPageController.java b/dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadController.java
similarity index 66%
rename from dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadPageController.java
rename to dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadController.java
index 8ce7a97..5ee6cc7 100644
--- a/dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadPageController.java
+++ b/dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadController.java
@@ -14,15 +14,17 @@
import it.digione.dg1cloud.recaptcha.DownloadFileCaptchaForm;
@Controller
-public class DownloadPageController {
+public class DownloadController {
- private static final Logger logger = LoggerFactory.getLogger(DownloadPageController.class);
+ private static final Logger logger = LoggerFactory.getLogger(DownloadController.class);
- @RequestMapping("/downloadPage")
- public ModelAndView downloadPage(@RequestParam String fileName, @RequestParam long id,
+ @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 pagina download file {} con id {}", fileName, id);
+ logger.debug("Preparazione download file {} con id {}", fileName, id);
DownloadFileCaptchaForm downloadParams = new DownloadFileCaptchaForm();
@@ -30,7 +32,14 @@
downloadParams.setId(id);
downloadParams.setSecretKey(secretKey);
- ModelAndView modelAndView = new ModelAndView("downloadFileCaptcha");
+ ModelAndView modelAndView;
+
+ if ( captchaSettings.isEnabled() == true ) {
+ modelAndView = new ModelAndView("downloadFileCaptcha");
+ } else {
+ modelAndView = new ModelAndView("forward:/downloadFile");
+ }
+
modelAndView.addObject("downloadFileCaptchaForm", downloadParams);
return modelAndView;
diff --git a/dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java b/dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java
index 4c54b5d..1ebd03e 100644
--- a/dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java
+++ b/dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java
@@ -38,7 +38,7 @@
public URL generateUrl(RegDocument regDocument) throws MalformedURLException {
logger.debug("Genero l'url per il record file {} con id {}", regDocument.getFileName(), regDocument.getDocumentId());
UriBuilder uriBuilder = UriComponentsBuilder.fromUriString(appConfig.getExternalBaseUrl());
- uriBuilder.path("/downloadPage");
+ uriBuilder.path("/download");
uriBuilder.queryParam("fileName", regDocument.getFileName());
uriBuilder.queryParam("id", regDocument.getDocumentId());
if ( Strings.isEmpty(regDocument.getSecretKey()) == false ) {
diff --git a/dg1cloud-core/src/main/resources/templates/downloadFileCaptcha.html b/dg1cloud-core/src/main/resources/templates/downloadFileCaptcha.html
index 79218f2..8aa9595 100644
--- a/dg1cloud-core/src/main/resources/templates/downloadFileCaptcha.html
+++ b/dg1cloud-core/src/main/resources/templates/downloadFileCaptcha.html
@@ -19,7 +19,7 @@
<div class="panel-body">
<div class="text-center">
<h3><i class="glyphicon glyphicon-lock" style="font-size:2em;"></i></h3>
- <h2 class="text-center" th:text="*{downloadFileCaptchaForm.fileName}"></h2>
+ <h2 class="text-center" style="word-wrap: break-word;" th:text="*{downloadFileCaptchaForm.fileName}"></h2>
<div class="panel-body">
<form action="#" th:action="@{/downloadFileCaptcha}" th:object="${downloadFileCaptchaForm}" method="post">
<input type="hidden" th:field="*{id}" />
--
Gitblit v1.6.2