diff --git a/src/main/java/fr/abes/kbart2kafka/service/FileService.java b/src/main/java/fr/abes/kbart2kafka/service/FileService.java index e868ac0..6b60d18 100644 --- a/src/main/java/fr/abes/kbart2kafka/service/FileService.java +++ b/src/main/java/fr/abes/kbart2kafka/service/FileService.java @@ -5,6 +5,7 @@ import fr.abes.kbart2kafka.dto.LigneKbartDto; import fr.abes.kbart2kafka.exception.IllegalDateException; import fr.abes.kbart2kafka.exception.IllegalFileFormatException; +import fr.abes.kbart2kafka.utils.PUBLICATION_TYPE; import fr.abes.kbart2kafka.utils.Utils; import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; @@ -13,6 +14,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.stereotype.Service; +import org.yaml.snakeyaml.util.EnumUtils; import java.io.BufferedReader; import java.io.File; @@ -72,8 +74,7 @@ private void executeMultiThread(File fichier) throws IllegalFileFormatException try { kbartsToSend.add(mapper.writeValueAsString(constructDto(tsvElementsOnOneLine, cpt.get(), nbLignesFichier))); } catch (IllegalDateException | IllegalFileFormatException | JsonProcessingException e) { - log.debug("Erreur dans le fichier en entrée à la ligne " + cpt.get() + " : " + e.getMessage()); - log.error(e.getMessage()); + log.error("Erreur dans le fichier en entrée à la ligne " + cpt.get() + " : " + e.getMessage()); isOnError.set(true); } }); @@ -134,6 +135,11 @@ private LigneKbartDto constructDto(String[] line, Integer ligneCourante, Integer kbartLineInDtoObject.setCoverage_depth(line[13]); kbartLineInDtoObject.setNotes(line[14]); kbartLineInDtoObject.setPublisher_name(line[15]); + try { + PUBLICATION_TYPE.valueOf(line[16]); + } catch (IllegalArgumentException ex) { + throw new IllegalFileFormatException("La valeur de PUBLICATION_TYPE est invalide"); + } kbartLineInDtoObject.setPublication_type(line[16]); kbartLineInDtoObject.setDate_monograph_published_print(Utils.reformatDateKbart(line[17])); kbartLineInDtoObject.setDate_monograph_published_online(Utils.reformatDateKbart(line[18])); diff --git a/src/test/java/fr/abes/kbart2kafka/service/FileServiceTest.java b/src/test/java/fr/abes/kbart2kafka/service/FileServiceTest.java deleted file mode 100644 index e36cbe0..0000000 --- a/src/test/java/fr/abes/kbart2kafka/service/FileServiceTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package fr.abes.kbart2kafka.service; - -import com.fasterxml.jackson.databind.ObjectMapper; -import fr.abes.kbart2kafka.configuration.KafkaConfig; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.kafka.core.KafkaTemplate; - -@SpringBootTest(classes = {FileService.class, KafkaConfig.class, ObjectMapper.class}) -public class FileServiceTest { - - @Autowired - FileService fileService; - @Autowired - KafkaTemplate kafkaTemplate; - @Autowired - ObjectMapper objectMapper; - - @Test - void testCalculatePartition() { - Assertions.assertEquals(0, fileService.calculatePartition(2)); - Assertions.assertEquals(1, fileService.calculatePartition(2)); - Assertions.assertEquals(0, fileService.calculatePartition(2)); - } - -}