From d9d7792602a782f6ddd4f4925a15d9848b697f48 Mon Sep 17 00:00:00 2001 From: pierre-maraval Date: Tue, 19 Dec 2023 10:52:17 +0100 Subject: [PATCH] CDE-328 : Fix : Correction regexp pour controle nom du fichier --- src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java | 3 ++- src/test/java/fr/abes/kbart2kafka/utils/CheckFilesTest.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java b/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java index 3ec2017..8dd4dfc 100644 --- a/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java +++ b/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java @@ -14,7 +14,8 @@ public class CheckFiles { public static void detectFileName(File file) throws IllegalFileFormatException { String filename = file.getName(); - if(!filename.matches("([a-zA-Z0-9\\-_]+_[a-zA-Z0-9\\-]+_)+(\\d{4}-\\d{2}-\\d{2})+(_FORCE)?+(.tsv)$")){ + //if(!filename.matches("([a-zA-Z0-9\\-_]+_[a-zA-Z0-9\\-]+_)+(\\d{4}-\\d{2}-\\d{2})+(_FORCE)?+(.tsv)$")){ + if (!filename.matches("([a-zA-Z0-9\\-]+_){3}(\\d{4}-\\d{2}-\\d{2})+(_FORCE)?+(.tsv)$")) { log.error("Message envoyé : {}", "Le nom du fichier n'est pas correct"); throw new IllegalFileFormatException("Le nom du fichier "+ filename +" n'est pas correct"); } diff --git a/src/test/java/fr/abes/kbart2kafka/utils/CheckFilesTest.java b/src/test/java/fr/abes/kbart2kafka/utils/CheckFilesTest.java index 3d26134..caf897c 100644 --- a/src/test/java/fr/abes/kbart2kafka/utils/CheckFilesTest.java +++ b/src/test/java/fr/abes/kbart2kafka/utils/CheckFilesTest.java @@ -41,10 +41,10 @@ void isFileWithTSVExtension() throws IllegalFileFormatException { @Test void detectFileName() throws IllegalFileFormatException { - this.file = new File("test_test_test_test1_1234-12-12.tsv"); + this.file = new File("test_test_test_1234-12-12.tsv"); CheckFiles.detectFileName(file); - this.file2 = new File("test_test_test_test1_1234-12-12_FORCE.tsv"); + this.file2 = new File("test_test_test_1234-12-12_FORCE.tsv"); CheckFiles.detectFileName(file2); for(String name : Lists.newArrayList("123", "test_1234-12-12.tsv", "test_test_134-12-12.tsv", "test_test_1344-12-12.tsvf", "test_test_1344-12-123.tsv", "test_test_test_test1_1234-12-12_force.tsv")) {