Skip to content

Commit

Permalink
Fix : Correction calcul nombre total de lignes
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-maraval committed May 17, 2024
1 parent 8b9b99d commit 3c9fddf
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/main/java/fr/abes/kafkatosudoc/kafka/KbartListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,22 @@ public KbartListener(UtilsMapper mapper, BaconService baconService, EmailService
public void listenKbartToCreateFromKafka(ConsumerRecord<String, LigneKbartConnect> lignesKbart) throws IOException {
log.debug("Entrée dans création à partir du kbart");
String filename = lignesKbart.key();
if (!this.workInProgressMap.containsKey(filename))
if (!this.workInProgressMap.containsKey(filename)) {
this.workInProgressMap.put(lignesKbart.key(), new WorkInProgress<>());
lignesKbart.headers().forEach(header -> {
if (header.key().equals("nbLinesTotal")) { //Si on est à la dernière ligne du fichier
this.workInProgressMap.get(filename).setNbLinesTotal(Integer.parseInt(new String(header.value()))); //on indique le nb total de lignes du fichier
}
});
}

this.workInProgressMap.get(filename).incrementCurrentNbLignes();
if (lignesKbart.value().getBESTPPN() != null && !lignesKbart.value().getBESTPPN().isEmpty()) {
//on alimente la liste des notices d'un package qui sera traitée intégralement
this.workInProgressMap.get(filename).addNotice(lignesKbart.value());
}
this.workInProgressMap.get(filename).incrementCurrentNbLignes();
lignesKbart.headers().forEach(header -> {
if (header.key().equals("nbLinesTotal")) { //Si on est à la dernière ligne du fichier
this.workInProgressMap.get(filename).setNbLinesTotal(Integer.parseInt(new String(header.value()))); //on indique le nb total de lignes du fichier
}
});

log.debug("Current line : " + this.workInProgressMap.get(filename).getCurrentNbLines() + " / total lines : " + this.workInProgressMap.get(filename).getNbLinesTotal());
//Si le nombre de lignes traitées est égal au nombre de lignes total du fichier, on est arrivé en fin de fichier, on traite dans le sudoc
if (this.workInProgressMap.get(filename).getCurrentNbLines().equals(this.workInProgressMap.get(filename).getNbLinesTotal())) {
log.debug("Traitement des notices existantes dans le Sudoc à partir du kbart");
Expand Down Expand Up @@ -293,11 +296,12 @@ public void listenKbartToDeleteFromKafka(ConsumerRecord<String, GenericRecord> p

/**
* Méthode permettant de délier les notices liées à une notice bouquet, cette méthode ne traite qu'un lot de 1000 notices maximum
* @param service méthodes permettant d'accéder au cbs
* @param provider provider
*
* @param service méthodes permettant d'accéder au cbs
* @param provider provider
* @param packageName nom du package supprimé
* @param listError liste des erreurs éventuelles
* @throws CBSException erreur de validation du cbs
* @param listError liste des erreurs éventuelles
* @throws CBSException erreur de validation du cbs
* @throws CommException erreur de communication avec le cbs
*/
@Retryable(maxAttempts = 4, retryFor = CommException.class, noRetryFor = {CBSException.class}, backoff = @Backoff(delay = 1000, multiplier = 2))
Expand Down Expand Up @@ -352,7 +356,6 @@ private void suppressionLien469(SudocService service, List<String> listError, in
}



/**
* @param ligneKbart : enregistrement dans Kafka
*/
Expand Down Expand Up @@ -439,7 +442,6 @@ private void creerNoticeExNihilo(LigneKbartConnect ligneKbartConnect, String pro
*/
@KafkaListener(topics = {"${topic.name.source.kbart.imprime}"}, groupId = "${topic.groupid.source.imprime}", containerFactory = "kafkaKbartListenerContainerFactory")
public void listenKbartFromKafkaImprime(ConsumerRecord<String, LigneKbartImprime> lignesKbart) {
log.debug("entree dans création from imprimé et kbart");
String filename = lignesKbart.key();

// S'il s'agit d'un premier message d'un fichier kbart, on créé un WorkInProgress avec le nom du fichier et le nombre total de ligne
Expand Down

0 comments on commit 3c9fddf

Please sign in to comment.