From 8383b7b2f6a7c44ee70a5929207cc871d0876600 Mon Sep 17 00:00:00 2001 From: Quentin Guillemin Date: Thu, 22 Dec 2022 17:02:23 +0100 Subject: [PATCH] feat: adjust cache duration in application.yml --- .../service/gar/ServiceGarHttpGet.java | 8 ++++++-- src/main/resources/application.yml | 6 +++--- .../rest/ApiRessourcesDiffusablesControllerTest.java | 12 +++++------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/fr/recia/ressourcesdiffusablesapi/service/gar/ServiceGarHttpGet.java b/src/main/java/fr/recia/ressourcesdiffusablesapi/service/gar/ServiceGarHttpGet.java index 64d5f81..1d898b4 100644 --- a/src/main/java/fr/recia/ressourcesdiffusablesapi/service/gar/ServiceGarHttpGet.java +++ b/src/main/java/fr/recia/ressourcesdiffusablesapi/service/gar/ServiceGarHttpGet.java @@ -30,7 +30,10 @@ public class ServiceGarHttpGet implements ServiceGar { @Autowired private ServiceCacheHistorique serviceCacheHistorique; - @Value("${service-gar-http-get.ressources-diffusables-uri:}") + @Value("${service-gar-http-get.cache-duration}") + private int cacheDuration; + + @Value("${service-gar-http-get.ressources-diffusables-uri}") private String ressourcesDiffusablesUri; @Value("${service-gar-http-get.download-location-path}") @@ -99,7 +102,8 @@ private void ajouterRessource(RessourceDiffusable ressourceDiffusable) { } private void verifValidite() { - if (this.dateTelechargement == null || SECONDS.between(this.dateTelechargement, LocalDateTime.now()) > 86400) { // 24h. + if (log.isDebugEnabled()) log.debug("Check validity of file"); + if (this.dateTelechargement == null || SECONDS.between(this.dateTelechargement, LocalDateTime.now()) > this.cacheDuration) { this.telechargerFichier(); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index ea4e0fb..e13ac98 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -19,6 +19,7 @@ spring: config.import: classpath:private.yml # Variables privées à ne pas diffuser. service-gar-http-get: + cache-duration: 86400 # 24h. ressources-diffusables-uri: '=== Ressources Diffusables URI ===' # Variable privée surchargée dans private.yml. download-location-path: 'src/main/resources/downloads/ressourcesDiffusables.json' # Le fichier sera toujours JSON. @@ -28,9 +29,8 @@ security-configuration: cors: enable: true allow-credentials: true - allowed-origins: > # IP = PC de Anaël via VPN. - http://localhost:8080, - http://192.168.36.10:8080, + allowed-origins: > + http://localhost:5173, https://*.giprecia.net exposed-headers: > x-auth-token, diff --git a/src/test/java/fr/recia/ressourcesdiffusablesapi/web/rest/ApiRessourcesDiffusablesControllerTest.java b/src/test/java/fr/recia/ressourcesdiffusablesapi/web/rest/ApiRessourcesDiffusablesControllerTest.java index 483b209..b3ed76b 100644 --- a/src/test/java/fr/recia/ressourcesdiffusablesapi/web/rest/ApiRessourcesDiffusablesControllerTest.java +++ b/src/test/java/fr/recia/ressourcesdiffusablesapi/web/rest/ApiRessourcesDiffusablesControllerTest.java @@ -1,12 +1,5 @@ package fr.recia.ressourcesdiffusablesapi.web.rest; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import javax.annotation.PostConstruct; - import fr.recia.ressourcesdiffusablesapi.service.gar.ServiceGar; import fr.recia.ressourcesdiffusablesapi.test.TestUtil; import lombok.extern.slf4j.Slf4j; @@ -22,6 +15,11 @@ import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import javax.annotation.PostConstruct; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + @ExtendWith(SpringExtension.class) @Slf4j @SpringBootTest