Skip to content

Commit

Permalink
CDE-328 : Fix : Correction regexp pour controle nom du fichier
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-maraval committed Dec 19, 2023
1 parent e1795fc commit d9d7792
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java
Original file line number Diff line number Diff line change
@@ -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");
}
4 changes: 2 additions & 2 deletions src/test/java/fr/abes/kbart2kafka/utils/CheckFilesTest.java
Original file line number Diff line number Diff line change
@@ -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")) {

0 comments on commit d9d7792

Please sign in to comment.