From 283c70ccef3501d6ddec3c30b8149adc73be95e7 Mon Sep 17 00:00:00 2001
From: EryneKL <97091460+EryneKL@users.noreply.github.com>
Date: Wed, 4 Oct 2023 10:29:37 +0200
Subject: [PATCH 1/8] =?UTF-8?q?FEAT=20:=20CDE-195-creer-consumer-pour-gene?=
=?UTF-8?q?rer-les-2-fichiers-de-log=20=20=20=20=20=20-=20mise=20=C3=A0=20?=
=?UTF-8?q?jour=20de=20la=20version=20de=20oracle=20database=20jdbc=20=20?=
=?UTF-8?q?=20=20=20=20-=20ajout=20de=20la=20cr=C3=A9ation=20de=20fichiers?=
=?UTF-8?q?=20de=20log=20dans=20la=20m=C3=A9thode=20listenInfoKbart2KafkaA?=
=?UTF-8?q?ndErrorKbart2Kafka?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 2 +-
.../abes/logskbart/kafka/KbartListener.java | 3 +
.../fr/abes/logskbart/kafka/LogsListener.java | 82 +++++++++++++++++--
.../abes/logskbart/service/KbartService.java | 3 +
.../logskbart/service/KbartToTsvService.java | 3 +
5 files changed, 83 insertions(+), 10 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4aafb71..9ad72e1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -98,7 +98,7 @@
com.oracle.database.jdbc
ojdbc8
- 21.3.0.0
+ 21.9.0.0
diff --git a/src/main/java/fr/abes/logskbart/kafka/KbartListener.java b/src/main/java/fr/abes/logskbart/kafka/KbartListener.java
index c5f9bda..d645735 100644
--- a/src/main/java/fr/abes/logskbart/kafka/KbartListener.java
+++ b/src/main/java/fr/abes/logskbart/kafka/KbartListener.java
@@ -19,6 +19,9 @@
@Service
@Slf4j
public class KbartListener {
+
+ // TODO Supprimer ce listener
+
@Autowired
private ObjectMapper mapper;
diff --git a/src/main/java/fr/abes/logskbart/kafka/LogsListener.java b/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
index f6f2726..ceb6f9c 100644
--- a/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
+++ b/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
@@ -1,19 +1,26 @@
package fr.abes.logskbart.kafka;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.abes.logskbart.dto.Kbart2KafkaDto;
import fr.abes.logskbart.entity.logs.LogKbart;
import fr.abes.logskbart.repository.logs.LogKbartRepository;
import fr.abes.logskbart.utils.UtilsMapper;
+import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.common.header.Header;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
+import java.io.IOException;
+import java.nio.file.*;
import java.sql.Date;
import java.sql.Timestamp;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+@Slf4j
@Service
public class LogsListener {
@@ -26,13 +33,70 @@ public class LogsListener {
@Autowired
private LogKbartRepository repository;
- @KafkaListener(topics = {"infokbart2kafka", "errorkbart2kafka"}, groupId = "logskbart", containerFactory = "kafkaLogsListenerContainerFactory")
- public void listenInfoKbart2KafkaAndErrorKbart2Kafka(ConsumerRecord message) throws JsonProcessingException {
- Kbart2KafkaDto dto = mapper.readValue(message.value(), Kbart2KafkaDto.class);
- LogKbart entity = logsMapper.map(dto, LogKbart.class);
- Timestamp timestamp = new Timestamp(message.timestamp());
- entity.setTimestamp(new Date(timestamp.getTime()));
- entity.setPackageName(message.key());
- repository.save(entity);
+ /**
+ * Ecoute les topic de log d'erreurs et de fin de traitement bestPpn et génère un fichier err pour chaque fichier kbart
+ * @param message le message kafka
+ * @throws IOException exception levée
+ */
+ @KafkaListener(topics = {"errorkbart2kafka", "bestppn.endoftraitment"}, groupId = "logskbart", containerFactory = "kafkaLogsListenerContainerFactory")
+ public void listenInfoKbart2KafkaAndErrorKbart2Kafka(ConsumerRecord message) throws IOException {
+
+ if (!message.value().equals("OK")) {
+ Kbart2KafkaDto dto = mapper.readValue(message.value(), Kbart2KafkaDto.class);
+ LogKbart entity = logsMapper.map(dto, LogKbart.class);
+ Timestamp timestamp = new Timestamp(message.timestamp());
+ entity.setTimestamp(new Date(timestamp.getTime()));
+ entity.setPackageName(message.key().replaceAll("\\[line\\s:\\s\\d+\\]", ""));
+
+ // Si la ligne de log sur le topic errorkbart2kafka est de type ERROR
+ if (entity.getLevel().toString().equals("ERROR")) {
+ String nbrLine = message.key().substring(message.key().indexOf(".tsv")+4).replaceAll("\\[line\\s:\\s", "").replaceAll("]", "");
+ String fileName = message.key().replaceAll(".tsv\\[line\\s:\\s\\d+\\]", ".err");
+ String line = "LINE : " + nbrLine + " - MESSAGE : " + dto.getMessage();
+
+ // Vérifie qu'un fichier portant le nom du kbart en cours existe
+ Path of = Path.of(fileName);
+ if (Files.exists(of)) {
+ // Inscrit la ligne dedans
+ Files.write(of, (line + System.lineSeparator()).getBytes(), StandardOpenOption.APPEND);
+ } else if (!Files.exists(of)) {
+ try {
+ // Créer le fichier et inscrit la ligne dedans
+ Files.createFile(of);
+ Files.write(of, (line + System.lineSeparator()).getBytes(), StandardOpenOption.APPEND);
+ log.info("Fichier temporaire créé.");
+ } catch (SecurityException | IOException e) {
+ log.error("Erreur lors de la création du fichier temporaire. " + e);
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ // Inscrit l'entity en BDD
+ repository.save(entity);
+
+ } else if (message.value().contains("OK")) { // Si la ligne sur le topic bestppn.endoftraitment contient OK
+
+ // Créer un nouveau Path avec le FileName (en remplaçant l'extension par .err)
+ Path source = null;
+ for (Header header : message.headers().toArray()) {
+ if (header.key().equals("FileName")) {
+ source = Path.of(new String(header.value()).replaceAll(".tsv", ".err"));
+ break;
+ }
+ }
+
+ // Copie le fichier existant vers le répertoire temporaire en ajoutant sa date de création
+ assert source != null;
+ if (Files.exists(source)) {
+ LocalDateTime time = LocalDateTime.now();
+ DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss", Locale.FRANCE);
+ String date = format.format(time);
+ Path target = Path.of("tempLog\\" + date + "_" + source);
+
+ Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
+ log.info("Fichier de log transféré dans le dossier temporaire.");
+ }
+ }
}
}
diff --git a/src/main/java/fr/abes/logskbart/service/KbartService.java b/src/main/java/fr/abes/logskbart/service/KbartService.java
index 1b9aa56..9b97aa8 100644
--- a/src/main/java/fr/abes/logskbart/service/KbartService.java
+++ b/src/main/java/fr/abes/logskbart/service/KbartService.java
@@ -7,6 +7,9 @@
@Service
public class KbartService {
+
+ // TODO Supprimer cette classe
+
private final KbartLoaderFactory factory;
private final Environment env;
diff --git a/src/main/java/fr/abes/logskbart/service/KbartToTsvService.java b/src/main/java/fr/abes/logskbart/service/KbartToTsvService.java
index 0ea2801..0d129a4 100644
--- a/src/main/java/fr/abes/logskbart/service/KbartToTsvService.java
+++ b/src/main/java/fr/abes/logskbart/service/KbartToTsvService.java
@@ -20,6 +20,9 @@
@Service
public class KbartToTsvService implements KbartLoader {
+
+ // TODO supprimer cette classe
+
@Value("${path.tsvFile}")
private String pathToFichier;
From 2fe40c885b9fb28cdfef6e2f6602fa355e90c790 Mon Sep 17 00:00:00 2001
From: EryneKL <97091460+EryneKL@users.noreply.github.com>
Date: Wed, 4 Oct 2023 10:42:30 +0200
Subject: [PATCH 2/8] =?UTF-8?q?FEAT=20:=20CDE-195-creer-consumer-pour-gene?=
=?UTF-8?q?rer-les-2-fichiers-de-log=20=20=20=20=20=20-=20ajout=20de=20la?=
=?UTF-8?q?=20cr=C3=A9ation=20=C3=A0=20la=20vol=C3=A9e=20du=20r=C3=A9perto?=
=?UTF-8?q?ire=20tempLog?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/fr/abes/logskbart/kafka/LogsListener.java | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/main/java/fr/abes/logskbart/kafka/LogsListener.java b/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
index ceb6f9c..80c48b0 100644
--- a/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
+++ b/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
@@ -92,6 +92,9 @@ public void listenInfoKbart2KafkaAndErrorKbart2Kafka(ConsumerRecord
Date: Thu, 5 Oct 2023 11:28:15 +0200
Subject: [PATCH 3/8] =?UTF-8?q?FEAT=20:=20CDE-195-creer-consumer-pour-gene?=
=?UTF-8?q?rer-les-2-fichiers-de-log=20=20=20=20=20=20-=20ajout=20d'un=20c?=
=?UTF-8?q?ontr=C3=B4le=20sur=20la=20cr=C3=A9ation=20du=20r=C3=A9pertoire?=
=?UTF-8?q?=20temporaire?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/fr/abes/logskbart/kafka/LogsListener.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/main/java/fr/abes/logskbart/kafka/LogsListener.java b/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
index 80c48b0..5058bad 100644
--- a/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
+++ b/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
@@ -12,6 +12,7 @@
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
+import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.sql.Date;
@@ -93,10 +94,15 @@ public void listenInfoKbart2KafkaAndErrorKbart2Kafka(ConsumerRecord
Date: Thu, 5 Oct 2023 15:57:33 +0200
Subject: [PATCH 4/8] Enlever les listeners kafka du topic packageKbart
---
.../abes/logskbart/kafka/KbartListener.java | 48 ---------------
.../abes/logskbart/service/KbartLoader.java | 7 ---
.../logskbart/service/KbartLoaderFactory.java | 22 -------
.../abes/logskbart/service/KbartService.java | 23 --------
.../logskbart/service/KbartToBddService.java | 58 -------------------
.../logskbart/service/KbartToTsvService.java | 47 ---------------
src/main/resources/application-dev.properties | 2 -
.../resources/application-prod.properties | 4 +-
.../resources/application-test.properties | 2 -
9 files changed, 1 insertion(+), 212 deletions(-)
delete mode 100644 src/main/java/fr/abes/logskbart/kafka/KbartListener.java
delete mode 100644 src/main/java/fr/abes/logskbart/service/KbartLoader.java
delete mode 100644 src/main/java/fr/abes/logskbart/service/KbartLoaderFactory.java
delete mode 100644 src/main/java/fr/abes/logskbart/service/KbartService.java
delete mode 100644 src/main/java/fr/abes/logskbart/service/KbartToBddService.java
delete mode 100644 src/main/java/fr/abes/logskbart/service/KbartToTsvService.java
diff --git a/src/main/java/fr/abes/logskbart/kafka/KbartListener.java b/src/main/java/fr/abes/logskbart/kafka/KbartListener.java
deleted file mode 100644
index c5f9bda..0000000
--- a/src/main/java/fr/abes/logskbart/kafka/KbartListener.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package fr.abes.logskbart.kafka;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import fr.abes.logskbart.dto.PackageKbartDto;
-import fr.abes.logskbart.dto.PackageKbartDtoKafka;
-import fr.abes.logskbart.exception.IllegalDateException;
-import fr.abes.logskbart.exception.IllegalPackageException;
-import fr.abes.logskbart.exception.IllegalProviderException;
-import fr.abes.logskbart.service.KbartService;
-import fr.abes.logskbart.utils.Utils;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.kafka.clients.consumer.ConsumerRecord;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.kafka.annotation.KafkaListener;
-import org.springframework.stereotype.Service;
-
-
-@Service
-@Slf4j
-public class KbartListener {
- @Autowired
- private ObjectMapper mapper;
-
- @Autowired
- private KbartService service;
-
- @KafkaListener(topics = {"packageKbart"}, groupId = "lignesKbart", containerFactory = "kafkaKbartListenerContainerFactory")
- public void listenKbartFromKafka(ConsumerRecord lignesKbart) {
- PackageKbartDto packageKbartDto = new PackageKbartDto();
- try {
- packageKbartDto.setPackageName(Utils.extractPackageName(lignesKbart.key()));
- packageKbartDto.setProvider(Utils.extractProvider(lignesKbart.key()));
- packageKbartDto.setDatePackage(Utils.extractDate(lignesKbart.key()));
- PackageKbartDtoKafka packageFromKafka = mapper.readValue(lignesKbart.value(), PackageKbartDtoKafka.class);
- packageKbartDto.setLigneKbartDtos(packageFromKafka.getKbartDtos());
-
- //traitement de la liste de dto à traiter en fonction
- service.chargerKbart(packageKbartDto);
- } catch (IllegalPackageException | IllegalProviderException | IllegalDateException e) {
- log.error("Erreur dans les données en entrée, provider / nom de package ou format de date incorrect");
- } catch (JsonProcessingException e) {
- log.error(e.getMessage());
- }
- }
-
-
-}
diff --git a/src/main/java/fr/abes/logskbart/service/KbartLoader.java b/src/main/java/fr/abes/logskbart/service/KbartLoader.java
deleted file mode 100644
index a1a569d..0000000
--- a/src/main/java/fr/abes/logskbart/service/KbartLoader.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package fr.abes.logskbart.service;
-
-import fr.abes.logskbart.dto.PackageKbartDto;
-
-public interface KbartLoader {
- void chargerPackageKbart(PackageKbartDto packageKbartDto);
-}
diff --git a/src/main/java/fr/abes/logskbart/service/KbartLoaderFactory.java b/src/main/java/fr/abes/logskbart/service/KbartLoaderFactory.java
deleted file mode 100644
index fb33d99..0000000
--- a/src/main/java/fr/abes/logskbart/service/KbartLoaderFactory.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package fr.abes.logskbart.service;
-
-import fr.abes.logskbart.utils.LoaderType;
-import org.springframework.stereotype.Service;
-
-@Service
-public class KbartLoaderFactory {
- private final KbartToTsvService kbartToTsvService;
- private final KbartToBddService kbartToBddService;
-
- public KbartLoaderFactory(KbartToTsvService kbartToTsvService, KbartToBddService kbartToBddService) {
- this.kbartToTsvService = kbartToTsvService;
- this.kbartToBddService = kbartToBddService;
- }
-
- public KbartLoader getLoader(LoaderType type) {
- return switch (type) {
- case tsv -> kbartToTsvService;
- case bdd -> kbartToBddService;
- };
- }
-}
diff --git a/src/main/java/fr/abes/logskbart/service/KbartService.java b/src/main/java/fr/abes/logskbart/service/KbartService.java
deleted file mode 100644
index 1b9aa56..0000000
--- a/src/main/java/fr/abes/logskbart/service/KbartService.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package fr.abes.logskbart.service;
-
-import fr.abes.logskbart.dto.PackageKbartDto;
-import fr.abes.logskbart.utils.LoaderType;
-import org.springframework.core.env.Environment;
-import org.springframework.stereotype.Service;
-
-@Service
-public class KbartService {
- private final KbartLoaderFactory factory;
-
- private final Environment env;
-
- public KbartService(KbartLoaderFactory factory, Environment env) {
- this.factory = factory;
- this.env = env;
- }
-
- public void chargerKbart(PackageKbartDto packageKbart) {
- KbartLoader loader = factory.getLoader(LoaderType.valueOf(env.getProperty("LOADERTYPE")));
- loader.chargerPackageKbart(packageKbart);
- }
-}
diff --git a/src/main/java/fr/abes/logskbart/service/KbartToBddService.java b/src/main/java/fr/abes/logskbart/service/KbartToBddService.java
deleted file mode 100644
index 2e84428..0000000
--- a/src/main/java/fr/abes/logskbart/service/KbartToBddService.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package fr.abes.logskbart.service;
-
-import fr.abes.logskbart.dto.PackageKbartDto;
-import fr.abes.logskbart.entity.bacon.LigneKbart;
-import fr.abes.logskbart.entity.bacon.Provider;
-import fr.abes.logskbart.entity.bacon.ProviderPackage;
-import fr.abes.logskbart.entity.bacon.ProviderPackageId;
-import fr.abes.logskbart.repository.bacon.LigneKbartRepository;
-import fr.abes.logskbart.repository.bacon.ProviderPackageRepository;
-import fr.abes.logskbart.repository.bacon.ProviderRepository;
-import fr.abes.logskbart.utils.UtilsMapper;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-import java.util.Optional;
-
-@Service
-public class KbartToBddService implements KbartLoader {
- private final ProviderPackageRepository providerPackageRepository;
- private final ProviderRepository providerRepository;
- private final LigneKbartRepository ligneKbartRepository;
-
- private final UtilsMapper mapper;
-
- public KbartToBddService(ProviderPackageRepository providerPackageRepository, ProviderRepository providerRepository, LigneKbartRepository ligneKbartRepository, UtilsMapper mapper) {
- this.providerPackageRepository = providerPackageRepository;
- this.providerRepository = providerRepository;
- this.ligneKbartRepository = ligneKbartRepository;
- this.mapper = mapper;
- }
-
- @Override
- public void chargerPackageKbart(PackageKbartDto packageKbartDto) {
- ProviderPackage providerPackage = handlePackageAndProvider(packageKbartDto);
- List ligneKbarts = mapper.mapList(packageKbartDto.getLigneKbartDtos(), LigneKbart.class);
- ligneKbarts.forEach(ligne -> ligne.setProviderPackage(providerPackage));
- ligneKbartRepository.saveAll(ligneKbarts);
- }
-
- private ProviderPackage handlePackageAndProvider(PackageKbartDto packageKbartDto) {
- //on vérifie si le package existe dans la base pour une date de chargement donnée
- //récupération provider
- Optional providerOpt = providerRepository.findByProvider(packageKbartDto.getProvider());
- if (providerOpt.isPresent()) {
- Provider provider = providerOpt.get();
- ProviderPackageId providerPackageId = new ProviderPackageId(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), provider.getIdtProvider());
- Optional providerPackage = providerPackageRepository.findByProviderPackageId(providerPackageId);
- //pas d'info de package, on le crée
- return providerPackage.orElseGet(() -> providerPackageRepository.save(new ProviderPackage(providerPackageId, 'N')));
- } else {
- //pas de provider, ni de package, on les crée tous les deux
- Provider newProvider = new Provider(packageKbartDto.getProvider());
- Provider savedProvider = providerRepository.save(newProvider);
- ProviderPackage providerPackage = new ProviderPackage(new ProviderPackageId(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), savedProvider.getIdtProvider()), 'N');
- return providerPackageRepository.save(providerPackage);
- }
- }
-}
diff --git a/src/main/java/fr/abes/logskbart/service/KbartToTsvService.java b/src/main/java/fr/abes/logskbart/service/KbartToTsvService.java
deleted file mode 100644
index 0ea2801..0000000
--- a/src/main/java/fr/abes/logskbart/service/KbartToTsvService.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package fr.abes.logskbart.service;
-
-import com.opencsv.bean.CsvBindByName;
-import com.opencsv.bean.CsvBindByPosition;
-import com.opencsv.bean.StatefulBeanToCsv;
-import com.opencsv.bean.StatefulBeanToCsvBuilder;
-import com.opencsv.exceptions.CsvDataTypeMismatchException;
-import com.opencsv.exceptions.CsvRequiredFieldEmptyException;
-import fr.abes.logskbart.dto.LigneKbartDto;
-import fr.abes.logskbart.dto.PackageKbartDto;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.stream.Collectors;
-
-@Service
-public class KbartToTsvService implements KbartLoader {
- @Value("${path.tsvFile}")
- private String pathToFichier;
-
- @Override
- public void chargerPackageKbart(PackageKbartDto packageKbartDto) {
- try (Writer writer = new FileWriter(pathToFichier + packageKbartDto.getPackageName())) {
- writer.append(buildHeader(LigneKbartDto.class));
- StatefulBeanToCsv sbc = new StatefulBeanToCsvBuilder(writer).withSeparator('\t').withApplyQuotesToAll(false).build();
- sbc.write(packageKbartDto.getLigneKbartDtos());
- } catch (IOException | CsvRequiredFieldEmptyException | CsvDataTypeMismatchException e) {
- throw new RuntimeException(e);
- }
-
- }
-
- private String buildHeader(Class clazz) {
- return Arrays.stream(clazz.getDeclaredFields())
- .filter(f -> f.getAnnotation(CsvBindByPosition.class) != null
- && f.getAnnotation(CsvBindByName.class) != null)
- .sorted(Comparator.comparing(f -> f.getAnnotation(CsvBindByPosition.class).position()))
- .map(f -> f.getAnnotation(CsvBindByName.class).column())
- .collect(Collectors.joining("\t")) + "\n";
- }
-
-}
diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties
index d5bfe04..edcc3d7 100644
--- a/src/main/resources/application-dev.properties
+++ b/src/main/resources/application-dev.properties
@@ -27,8 +27,6 @@ spring.jpa.bacon.hibernate.ddl-auto=none
spring.jpa.bacon.show-sql=true
spring.sql.bacon.init.mode=never
-path.tsvFile=/tmp/
-
logging.config=classpath:log4j2-dev.xml
logging.level.root=INFO
logging.level.fr.abes=DEBUG
diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties
index af25484..aa83cf4 100644
--- a/src/main/resources/application-prod.properties
+++ b/src/main/resources/application-prod.properties
@@ -27,8 +27,6 @@ spring.jpa.bacon.hibernate.ddl-auto=none
spring.jpa.bacon.show-sql=true
spring.sql.bacon.init.mode=never
-path.tsvFile=/tmp/
-
logging.config=classpath:log4j2-prod.xml
logging.level.root=ERROR
-logging.level.fr.abes=ERROR
\ No newline at end of file
+logging.level.fr.abes=ERROR
diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties
index b2be49e..a1faf50 100644
--- a/src/main/resources/application-test.properties
+++ b/src/main/resources/application-test.properties
@@ -27,8 +27,6 @@ spring.jpa.bacon.hibernate.ddl-auto=none
spring.jpa.bacon.show-sql=true
spring.sql.bacon.init.mode=never
-path.tsvFile=/tmp/
-
logging.config=classpath:log4j2-test.xml
logging.level.root=INFO
logging.level.fr.abes=INFO
From 8562e02688469c392c8d7840abfddc39a03f5584 Mon Sep 17 00:00:00 2001
From: EryneKL <97091460+EryneKL@users.noreply.github.com>
Date: Tue, 10 Oct 2023 08:40:12 +0200
Subject: [PATCH 5/8] =?UTF-8?q?FEAT=20:=20CDE-195-creer-consumer-pour-gene?=
=?UTF-8?q?rer-les-2-fichiers-de-log=20=20=20=20=20=20-=20modification=20d?=
=?UTF-8?q?u=20fichier=20de=20log=20en=20fichier=20tabul=C3=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/fr/abes/logskbart/kafka/LogsListener.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/main/java/fr/abes/logskbart/kafka/LogsListener.java b/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
index 5058bad..ef4432b 100644
--- a/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
+++ b/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
@@ -53,7 +53,7 @@ public void listenInfoKbart2KafkaAndErrorKbart2Kafka(ConsumerRecord
Date: Tue, 10 Oct 2023 16:06:13 +0200
Subject: [PATCH 6/8] =?UTF-8?q?FIX=20:=20CDE-195-creer-consumer-pour-gener?=
=?UTF-8?q?er-les-2-fichiers-de-log=20=20=20=20=20=20-=20correction=20d'un?=
=?UTF-8?q?=20contr=C3=B4le=20dysfonctionnel?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/fr/abes/logskbart/kafka/LogsListener.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/main/java/fr/abes/logskbart/kafka/LogsListener.java b/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
index ef4432b..3b2c9b4 100644
--- a/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
+++ b/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
@@ -79,7 +79,7 @@ public void listenInfoKbart2KafkaAndErrorKbart2Kafka(ConsumerRecord
Date: Thu, 26 Oct 2023 11:17:54 +0200
Subject: [PATCH 7/8] =?UTF-8?q?CDE-249=20:=20FIX=20:=20correction=20entit?=
=?UTF-8?q?=C3=A9s=20suite=20=C3=A0=20modification=20bdd=20Bacon?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../logskbart/entity/bacon/LigneKbart.java | 18 ++++----
.../entity/bacon/ProviderPackage.java | 19 ++++++--
.../entity/bacon/ProviderPackageId.java | 46 -------------------
.../bacon/ProviderPackageRepository.java | 5 +-
.../logskbart/service/KbartToBddService.java | 8 ++--
5 files changed, 30 insertions(+), 66 deletions(-)
delete mode 100644 src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackageId.java
diff --git a/src/main/java/fr/abes/logskbart/entity/bacon/LigneKbart.java b/src/main/java/fr/abes/logskbart/entity/bacon/LigneKbart.java
index 9f2922c..a0567cc 100644
--- a/src/main/java/fr/abes/logskbart/entity/bacon/LigneKbart.java
+++ b/src/main/java/fr/abes/logskbart/entity/bacon/LigneKbart.java
@@ -8,7 +8,7 @@
import java.util.Date;
@Entity
-@Table(name = "LIGNE_KBART_CONVERGENCE")
+@Table(name = "LIGNE_KBART")
@Setter @Getter
public class LigneKbart implements Serializable {
@Id
@@ -65,13 +65,15 @@ public class LigneKbart implements Serializable {
private String precedeingPublicationTitleId;
@Column(name = "ACCESS_TYPE")
private String accessType;
- @ManyToOne(targetEntity = ProviderPackage.class, cascade = CascadeType.REMOVE, optional = false)
- @JoinColumns({
- @JoinColumn(name = "PROVIDER_PACKAGE_PACKAGE", referencedColumnName = "PACKAGE"),
- @JoinColumn(name = "PROVIDER_PACKAGE_DATE_P", referencedColumnName = "DATE_P"),
- @JoinColumn(name = "PROVIDER_PACKAGE_IDT_PROVIDER", referencedColumnName = "PROVIDER_IDT_PROVIDER"
- )})
- private ProviderPackage providerPackage;
+ @Column(name = "PACKAGE")
+ private String packageName;
+ @Column(name = "DATE_P")
+ private Date dateP;
+ @Column(name = "PROVIDER_IDT_PROVIDER")
+ private Integer providerIdtProvider;
@Column(name = "BEST_PPN")
private String bestPpn;
+ @ManyToOne(targetEntity = ProviderPackage.class, cascade = CascadeType.REMOVE, optional = false)
+ @JoinColumn(name = "ID_PROVIDER_PACKAGE", referencedColumnName = "ID_PROVIDER_PACKAGE")
+ private ProviderPackage providerPackage;
}
diff --git a/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackage.java b/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackage.java
index 0f4421b..e1c62b5 100644
--- a/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackage.java
+++ b/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackage.java
@@ -7,6 +7,7 @@
import lombok.Setter;
import java.io.Serializable;
+import java.util.Date;
@Entity
@Table(name = "PROVIDER_PACKAGE")
@@ -14,8 +15,16 @@
@AllArgsConstructor
@NoArgsConstructor
public class ProviderPackage implements Serializable {
- @EmbeddedId
- private ProviderPackageId providerPackageId;
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "ID_PROVIDER_PACKAGE")
+ private Integer providerPackageId;
+ @Column(name = "PACKAGE")
+ private String packageName;
+ @Column(name = "DATE_P")
+ private Date dateP;
+ @Column(name = "PROVIDER_IDT_PROVIDER")
+ private Integer providerIdtProvider;
@Column(name = "LABEL_ABES")
private char labelAbes;
@@ -24,8 +33,10 @@ public class ProviderPackage implements Serializable {
@JoinColumn(referencedColumnName = "IDT_PROVIDER", insertable = false, updatable = false)
private Provider provider;
- public ProviderPackage(ProviderPackageId providerPackageId, char labelAbes) {
- this.providerPackageId = providerPackageId;
+ public ProviderPackage(String packageName, Date dateP, Integer providerIdtProvider, char labelAbes) {
+ this.packageName = packageName;
+ this.dateP = dateP;
+ this.providerIdtProvider = providerIdtProvider;
this.labelAbes = labelAbes;
}
}
diff --git a/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackageId.java b/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackageId.java
deleted file mode 100644
index 0c7d45f..0000000
--- a/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackageId.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package fr.abes.logskbart.entity.bacon;
-
-import jakarta.persistence.Column;
-import jakarta.persistence.Embeddable;
-import jakarta.persistence.JoinColumn;
-import jakarta.persistence.ManyToOne;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-
-import java.io.Serializable;
-import java.util.Date;
-import java.util.Objects;
-
-
-@Embeddable
-@Getter
-@NoArgsConstructor
-public class ProviderPackageId implements Serializable {
- @Column(name = "PACKAGE")
- private String packageName;
- @Column(name = "DATE_P")
- private Date dateP;
- @Column(name = "PROVIDER_IDT_PROVIDER")
- private Integer providerIdtProvider;
-
- public ProviderPackageId(String packageName, Date datePackage, Integer idtProvider) {
- this.packageName = packageName;
- this.dateP = datePackage;
- this.providerIdtProvider = idtProvider;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof ProviderPackageId)) return false;
- ProviderPackageId that = (ProviderPackageId) o;
- return Objects.equals(getProviderIdtProvider(), that.getProviderIdtProvider()) &&
- Objects.equals(getDateP(), that.getDateP()) &&
- Objects.equals(getPackageName(), that.getPackageName());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(getProviderIdtProvider(), getDateP(), getPackageName());
- }
-}
diff --git a/src/main/java/fr/abes/logskbart/repository/bacon/ProviderPackageRepository.java b/src/main/java/fr/abes/logskbart/repository/bacon/ProviderPackageRepository.java
index 7a6cc33..f0cbc94 100644
--- a/src/main/java/fr/abes/logskbart/repository/bacon/ProviderPackageRepository.java
+++ b/src/main/java/fr/abes/logskbart/repository/bacon/ProviderPackageRepository.java
@@ -2,7 +2,6 @@
import fr.abes.logskbart.configuration.BaconDbConfiguration;
import fr.abes.logskbart.entity.bacon.ProviderPackage;
-import fr.abes.logskbart.entity.bacon.ProviderPackageId;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@@ -11,6 +10,6 @@
@Repository
@BaconDbConfiguration
-public interface ProviderPackageRepository extends JpaRepository {
- Optional findByProviderPackageId(ProviderPackageId providerPackageId);
+public interface ProviderPackageRepository extends JpaRepository {
+ Optional findByPackageNameAndDatePAndProviderIdtProvider(String packageName, Date dateP, Integer providerIdtProvider);
}
diff --git a/src/main/java/fr/abes/logskbart/service/KbartToBddService.java b/src/main/java/fr/abes/logskbart/service/KbartToBddService.java
index 2e84428..7916152 100644
--- a/src/main/java/fr/abes/logskbart/service/KbartToBddService.java
+++ b/src/main/java/fr/abes/logskbart/service/KbartToBddService.java
@@ -4,7 +4,6 @@
import fr.abes.logskbart.entity.bacon.LigneKbart;
import fr.abes.logskbart.entity.bacon.Provider;
import fr.abes.logskbart.entity.bacon.ProviderPackage;
-import fr.abes.logskbart.entity.bacon.ProviderPackageId;
import fr.abes.logskbart.repository.bacon.LigneKbartRepository;
import fr.abes.logskbart.repository.bacon.ProviderPackageRepository;
import fr.abes.logskbart.repository.bacon.ProviderRepository;
@@ -43,15 +42,14 @@ private ProviderPackage handlePackageAndProvider(PackageKbartDto packageKbartDto
Optional providerOpt = providerRepository.findByProvider(packageKbartDto.getProvider());
if (providerOpt.isPresent()) {
Provider provider = providerOpt.get();
- ProviderPackageId providerPackageId = new ProviderPackageId(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), provider.getIdtProvider());
- Optional providerPackage = providerPackageRepository.findByProviderPackageId(providerPackageId);
+ Optional providerPackage = providerPackageRepository.findByPackageNameAndDatePAndProviderIdtProvider(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), provider.getIdtProvider());
//pas d'info de package, on le crée
- return providerPackage.orElseGet(() -> providerPackageRepository.save(new ProviderPackage(providerPackageId, 'N')));
+ return providerPackage.orElseGet(() -> providerPackageRepository.save(new ProviderPackage(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), provider.getIdtProvider(), 'N')));
} else {
//pas de provider, ni de package, on les crée tous les deux
Provider newProvider = new Provider(packageKbartDto.getProvider());
Provider savedProvider = providerRepository.save(newProvider);
- ProviderPackage providerPackage = new ProviderPackage(new ProviderPackageId(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), savedProvider.getIdtProvider()), 'N');
+ ProviderPackage providerPackage = new ProviderPackage(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), savedProvider.getIdtProvider(), 'N');
return providerPackageRepository.save(providerPackage);
}
}
From e2014b717ca11c4037a77a51637f02b523a64307 Mon Sep 17 00:00:00 2001
From: SamuelQuetin
Date: Thu, 26 Oct 2023 15:32:56 +0200
Subject: [PATCH 8/8] fix topic gestion listeneur
---
src/main/java/fr/abes/logskbart/kafka/KbartListener.java | 0
src/main/java/fr/abes/logskbart/kafka/LogsListener.java | 4 ++--
2 files changed, 2 insertions(+), 2 deletions(-)
delete mode 100644 src/main/java/fr/abes/logskbart/kafka/KbartListener.java
diff --git a/src/main/java/fr/abes/logskbart/kafka/KbartListener.java b/src/main/java/fr/abes/logskbart/kafka/KbartListener.java
deleted file mode 100644
index e69de29..0000000
diff --git a/src/main/java/fr/abes/logskbart/kafka/LogsListener.java b/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
index 3b2c9b4..44d3a1a 100644
--- a/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
+++ b/src/main/java/fr/abes/logskbart/kafka/LogsListener.java
@@ -42,7 +42,7 @@ public class LogsListener {
@KafkaListener(topics = {"errorkbart2kafka", "bestppn.endoftraitment"}, groupId = "logskbart", containerFactory = "kafkaLogsListenerContainerFactory")
public void listenInfoKbart2KafkaAndErrorKbart2Kafka(ConsumerRecord message) throws IOException {
- if (!message.value().equals("OK")) {
+ if (message.topic().equals("errorkbart2kafka")) {
Kbart2KafkaDto dto = mapper.readValue(message.value(), Kbart2KafkaDto.class);
LogKbart entity = logsMapper.map(dto, LogKbart.class);
Timestamp timestamp = new Timestamp(message.timestamp());
@@ -79,7 +79,7 @@ public void listenInfoKbart2KafkaAndErrorKbart2Kafka(ConsumerRecord