Skip to content

Commit

Permalink
Merge pull request #141 from abes-esr/develop
Browse files Browse the repository at this point in the history
merge dev to test
  • Loading branch information
pierre-maraval authored Jan 7, 2025
2 parents 78be64a + 4309fe2 commit af3e152
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<groupId>fr.abes</groupId>
<artifactId>kbart2kafka</artifactId>
<version>1.0.3</version>
<version>1.0.4-SNAPSHOT</version>
<packaging>jar</packaging>
<name>kbart2kafka</name>
<description>chargement d'un fichier kbart dans kafka</description>
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.StandardCharsets;
import java.util.List;

@Slf4j
public class CheckFiles {
Expand Down Expand Up @@ -47,17 +48,31 @@ public static void isFileWithTSVExtension(File file) throws IllegalFileFormatExc
throw new IllegalFileFormatException("le fichier n'est pas au format tsv");
}

public static void checkPublicationTitle(File file) throws IllegalFileFormatException, IOException {
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
List<String> lines = reader.lines().toList();

if(lines.stream().anyMatch(line ->
line.split("\t")[0] == null || line.split("\t")[0].isEmpty()
)){
throw new IllegalFileFormatException("Le fichier a une ligne qui ne contient pas de publication_title");
}
}
}

/**
* Détecte si le fichier présente des tabulations
* @param file fichier en entrée
* @throws IOException erreur avec le fichier en entrée
*/
public static void detectTabulations(File file) throws IOException, IllegalFileFormatException {
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
if (!line.contains("\t"))
throw new IllegalFileFormatException("Le fichier ne contient pas de tabulation");
List<String> lines = reader.lines().toList();

if(lines.stream().anyMatch(line ->
(!line.contains("\t") && !(line.isBlank() && lines.lastIndexOf(line) == lines.size() -1)) // && isNotLast and blank
)){
throw new IllegalFileFormatException("Le fichier ne contient pas de tabulation");
}
}
}
Expand Down Expand Up @@ -96,6 +111,7 @@ public static void verifyFile(File file, String header) throws IllegalFileFormat
isFileWithTSVExtension(file);
detectTabulations(file);
detectHeaderPresence(header, file, isBypassOptionPresent);
checkPublicationTitle(file);
}

public static void isValidUtf8(String input) throws IllegalFileFormatException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/log4j2-all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- CONSOLE -->
<Console name="Console">
<PatternLayout
pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{dark,yellow}: %msg%n%throwable" />
pattern="%style{%d{ISO8601}}{white} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{dark,yellow}: %msg%n%throwable" />
</Console>
</Appenders>

Expand Down

0 comments on commit af3e152

Please sign in to comment.