From 11e831a2183bfc14121ebe8c3ff5ec620b25754c Mon Sep 17 00:00:00 2001 From: EryneKL <97091460+EryneKL@users.noreply.github.com> Date: Thu, 21 Dec 2023 14:36:33 +0100 Subject: [PATCH 1/3] =?UTF-8?q?FEAT=20:=20CDE-46-exclusion-de-packages-ou-?= =?UTF-8?q?de-providers=20=20=20=20=20=20-=20ajout=20d'un=20contr=C3=B4le?= =?UTF-8?q?=20sur=20le=20nom=20du=20fichier=20dans=20la=20m=C3=A9thode=20d?= =?UTF-8?q?etectFileName()=20(CheckFiles.java)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java b/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java index 189dde3..d5d68de 100644 --- a/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java +++ b/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java @@ -14,7 +14,7 @@ public class CheckFiles { public static void detectFileName(File file) throws IllegalFileFormatException { String filename = file.getName(); - if (!filename.matches("([a-zA-Z0-9\\-]+_){3}(\\d{4}-\\d{2}-\\d{2})+(_FORCE)?+(.tsv)$")) { + if (!filename.matches("([a-zA-Z0-9\\-]+_){3}(\\d{4}-\\d{2}-\\d{2})+(_FORCE)?+(.tsv)$") && !filename.matches("([a-zA-Z0-9\\-]+_){3}(\\d{4}-\\d{2}-\\d{2})+(_BYPASS)?+(.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"); } From 3311e599dd9250971ecb7dc047b11c5d9988cac4 Mon Sep 17 00:00:00 2001 From: EryneKL <97091460+EryneKL@users.noreply.github.com> Date: Fri, 22 Dec 2023 10:38:17 +0100 Subject: [PATCH 2/3] =?UTF-8?q?FEAT=20:=20CDE-46-exclusion-de-packages-ou-?= =?UTF-8?q?de-providers=20=20=20=20=20=20-=20ajout=20d'un=20contr=C3=B4le?= =?UTF-8?q?=20sur=20le=20header=20du=20fichier=20dans=20la=20m=C3=A9thode?= =?UTF-8?q?=20detectHeaderPresence()=20(CheckFiles.java)=20=20=20=20=20=20?= =?UTF-8?q?-=20adaptation=20des=20TU?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/abes/kbart2kafka/utils/CheckFiles.java | 15 +++++++++------ .../abes/kbart2kafka/utils/CheckFilesTest.java | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java b/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java index d5d68de..970d952 100644 --- a/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java +++ b/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java @@ -12,12 +12,12 @@ @Slf4j public class CheckFiles { - public static void detectFileName(File file) throws IllegalFileFormatException { + public static Boolean detectFileName(File file) throws IllegalFileFormatException { String filename = file.getName(); if (!filename.matches("([a-zA-Z0-9\\-]+_){3}(\\d{4}-\\d{2}-\\d{2})+(_FORCE)?+(.tsv)$") && !filename.matches("([a-zA-Z0-9\\-]+_){3}(\\d{4}-\\d{2}-\\d{2})+(_BYPASS)?+(.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"); - } + } else return filename.matches("([a-zA-Z0-9\\-]+_){3}(\\d{4}-\\d{2}-\\d{2})+(_BYPASS)?+(.tsv)$"); } public static void detectProvider(File file) throws IllegalProviderException { @@ -73,10 +73,13 @@ public static void detectTabulations(File file) throws IOException, IllegalFileF * @param file fichier en entrée * @throws IOException impossible de lire le fichier */ - public static void detectHeaderPresence(String header, File file) throws IOException, IllegalFileFormatException { + public static void detectHeaderPresence(String header, File file, Boolean isBypassOptionPresent) throws IOException, IllegalFileFormatException { try (BufferedReader reader = new BufferedReader(new FileReader(file))) { String line = reader.readLine(); - if(!line.contains(header)) { + if(isBypassOptionPresent && line.contains("best_ppn")) { + log.error("Message envoyé : {}", "L'en tete du fichier est incorrecte."); + throw new IllegalFileFormatException("L'en tete du fichier est incorrecte. L'option _BYPASS n'est pas compatible avec la présence d'une colonne best_pnn."); + } else if(!line.contains(header)) { log.error("Message envoyé : {}", "L'en tete du fichier est incorrecte."); throw new IllegalFileFormatException("L'en tete du fichier est incorrecte."); } @@ -92,10 +95,10 @@ public static void detectHeaderPresence(String header, File file) throws IOExcep * @throws IOException Impossible de lire le fichier */ public static void verifyFile(File file, String header) throws IllegalFileFormatException, IOException, IllegalProviderException { - detectFileName(file); + Boolean isBypassOptionPresent = detectFileName(file); detectProvider(file); isFileWithTSVExtension(file); detectTabulations(file); - detectHeaderPresence(header, file); + detectHeaderPresence(header, file, isBypassOptionPresent); } } diff --git a/src/test/java/fr/abes/kbart2kafka/utils/CheckFilesTest.java b/src/test/java/fr/abes/kbart2kafka/utils/CheckFilesTest.java index caf897c..aecf55b 100644 --- a/src/test/java/fr/abes/kbart2kafka/utils/CheckFilesTest.java +++ b/src/test/java/fr/abes/kbart2kafka/utils/CheckFilesTest.java @@ -85,11 +85,24 @@ void detectTabulations() throws IOException, IllegalFileFormatException { void detectOfHeaderPresence() throws IOException, IllegalFileFormatException { this.file = new File("test.tsv"); FileUtils.writeStringToFile(file, "test\ttest\ttest", StandardCharsets.UTF_8, true); - CheckFiles.detectHeaderPresence("test", file); + CheckFiles.detectHeaderPresence("test", file, false); this.file2 = new File("test2.tsv"); FileUtils.writeStringToFile(file2, "toto\ttata\ttiti", StandardCharsets.UTF_8, true); - IllegalFileFormatException erreur = Assertions.assertThrows(IllegalFileFormatException.class, () -> CheckFiles.detectHeaderPresence("test", file2)); + IllegalFileFormatException erreur = Assertions.assertThrows(IllegalFileFormatException.class, () -> CheckFiles.detectHeaderPresence("test", file2, false)); Assertions.assertEquals("L'en tete du fichier est incorrecte.", erreur.getMessage()); } + + @Test + void detectOptionError() throws IOException { + this.file = new File("test3_BYPASS.tsv"); + FileUtils.writeStringToFile(file, "test\ttest\ttest\tbest_ppn", StandardCharsets.UTF_8, true); + IllegalFileFormatException erreur1 = Assertions.assertThrows(IllegalFileFormatException.class, () -> CheckFiles.detectHeaderPresence("test\ttest\ttest\tbest_ppn", file, true)); + Assertions.assertEquals("L'en tete du fichier est incorrecte. L'option _BYPASS n'est pas compatible avec la présence d'une colonne best_pnn.", erreur1.getMessage()); + + this.file2 = new File("test3_BYPASS_FORCE.tsv"); + FileUtils.writeStringToFile(file2, "test\ttest\ttest", StandardCharsets.UTF_8, true); + IllegalFileFormatException erreur2 = Assertions.assertThrows(IllegalFileFormatException.class, () -> CheckFiles.detectFileName(file2)); + Assertions.assertEquals("Le nom du fichier test3_BYPASS_FORCE.tsv n'est pas correct", erreur2.getMessage()); + } } From 15e2fbcfd458454fec82ffedb4972550b4ec0cfe Mon Sep 17 00:00:00 2001 From: EryneKL <97091460+EryneKL@users.noreply.github.com> Date: Thu, 4 Jan 2024 11:11:38 +0100 Subject: [PATCH 3/3] =?UTF-8?q?FEAT=20:=20CDE-46-exclusion-de-packages-ou-?= =?UTF-8?q?de-providers=20=20=20=20=20=20-=20refactor=20du=20contr=C3=B4le?= =?UTF-8?q?=20sur=20le=20filename=20du=20fichier=20dans=20la=20m=C3=A9thod?= =?UTF-8?q?e=20detectFileName()=20(CheckFiles.java)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java b/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java index 970d952..9b5e0e0 100644 --- a/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java +++ b/src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java @@ -14,10 +14,10 @@ public class CheckFiles { public static Boolean detectFileName(File file) throws IllegalFileFormatException { String filename = file.getName(); - if (!filename.matches("([a-zA-Z0-9\\-]+_){3}(\\d{4}-\\d{2}-\\d{2})+(_FORCE)?+(.tsv)$") && !filename.matches("([a-zA-Z0-9\\-]+_){3}(\\d{4}-\\d{2}-\\d{2})+(_BYPASS)?+(.tsv)$")) { + if (!filename.matches("([a-zA-Z0-9\\-]+_){3}(\\d{4}-\\d{2}-\\d{2})+(_FORCE|_BYPASS)?+(.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"); - } else return filename.matches("([a-zA-Z0-9\\-]+_){3}(\\d{4}-\\d{2}-\\d{2})+(_BYPASS)?+(.tsv)$"); + } else return filename.matches("([a-zA-Z0-9\\-]+_){3}(\\d{4}-\\d{2}-\\d{2})+(_BYPASS)+(.tsv)$"); } public static void detectProvider(File file) throws IllegalProviderException {