Skip to content

Commit

Permalink
Merge pull request #74 from abes-esr/develop
Browse files Browse the repository at this point in the history
FIX : gestion des exceptions sudoc dans création notice elect à parti…
  • Loading branch information
SamuelQuetin authored Sep 23, 2024
2 parents 0afde38 + 3d79d0d commit 67ab398
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
29 changes: 15 additions & 14 deletions src/main/java/fr/abes/kafkatosudoc/kafka/KbartListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class KbartListener {

private final Map<String, WorkInProgress<LigneKbartImprime>> workInProgressMapImprime;

private Lock lock;
private final Lock lock;


public KbartListener(UtilsMapper mapper, BaconService baconService, EmailService emailService, Map<String, WorkInProgress<LigneKbartConnect>> workInProgressMap, Map<String, WorkInProgress<LigneKbartConnect>> workInProgressMapExNihilo, Map<String, WorkInProgress<LigneKbartImprime>> workInProgressMapImprime) {
Expand Down Expand Up @@ -451,21 +451,17 @@ public void listenKbartFromKafkaImprime(ConsumerRecord<String, LigneKbartImprime
log.debug("Traitement des notices existantes dans le Sudoc à partir de imprimé");

String provider = CheckFiles.getProviderFromFilename(filename);
String packageName = CheckFiles.getPackageFromFilename(filename);
SudocService service = new SudocService();
NoticeConcrete noticeElec = null;
try {
//authentification sur la base maitre du sudoc pour récupérer la notice imprimée
service.authenticate(serveurSudoc, portSudoc, loginSudoc, passwordSudoc);
if (this.workInProgressMapImprime.get(filename).getListeNotices() != null && !this.workInProgressMapImprime.get(filename).getListeNotices().isEmpty()) {
for (LigneKbartImprime ligneKbartImprime : this.workInProgressMapImprime.get(filename).getListeNotices()) {
noticeElec = creerNoticeAPartirImprime(ligneKbartImprime, provider, packageName, service);
creerNoticeAPartirImprime(ligneKbartImprime, provider, filename, service);
}
}
} catch (CBSException | ZoneException e) {
log.error(e.getMessage());
this.workInProgressMapImprime.get(filename).addErrorMessagesImprime(lignesKbart.value().getPpn().toString(), noticeElec != null ? noticeElec.getNoticeBiblio().toString() : "pas de notice trouvée", e.getMessage());
} catch (IOException e) {
}
catch (IOException e) {
//cas d'une erreur de communication avec le Sudoc, on se relogge au cbs, et on retry la méthode
try {
log.debug("erreur de communication avec le Sudoc, tentative de reconnexion");
Expand All @@ -474,6 +470,8 @@ public void listenKbartFromKafkaImprime(ConsumerRecord<String, LigneKbartImprime
} catch (CBSException | IOException ex) {
log.error(ex.getMessage());
}
} catch (CBSException e) {
this.workInProgressMapImprime.get(filename).addErrorMessagesImprime(String.valueOf(lignesKbart.value().getPpn()), null, "Erreur d'authentification au Sudoc : " + e.getMessage());
} finally {
try {
// On déconnecte du Sudoc, on envoie les messages d'erreurs s'il y a des erreurs et on supprime le WorkInProgress
Expand All @@ -489,9 +487,10 @@ public void listenKbartFromKafkaImprime(ConsumerRecord<String, LigneKbartImprime

}

@Retryable(maxAttempts = 4, retryFor = IOException.class, noRetryFor = {CBSException.class}, backoff = @Backoff(delay = 1000, multiplier = 2))
private NoticeConcrete creerNoticeAPartirImprime(LigneKbartImprime ligneKbartImprime, String provider, String packageName, SudocService service) throws ZoneException, CBSException, IOException {
NoticeConcrete noticeElec;
@Retryable(maxAttempts = 4, retryFor = IOException.class, backoff = @Backoff(delay = 1000, multiplier = 2))
private void creerNoticeAPartirImprime(LigneKbartImprime ligneKbartImprime, String provider, String filename, SudocService service) throws IOException {
String packageName = CheckFiles.getPackageFromFilename(filename);
NoticeConcrete noticeElec = new NoticeConcrete();
KbartAndImprimeDto kbartAndImprimeDto = new KbartAndImprimeDto();
kbartAndImprimeDto.setKbart(mapper.map(ligneKbartImprime, LigneKbartImprime.class));
try {
Expand All @@ -507,14 +506,16 @@ private NoticeConcrete creerNoticeAPartirImprime(LigneKbartImprime ligneKbartImp
service.addLibelleNoticeBouquetInPpn(noticeElec.getNoticeBiblio(), provider + "_" + packageName);
service.creerNotice(noticeElec);
log.debug("Création notice à partir de l'imprimée terminée");
return noticeElec;
} catch (IOException e) {
} catch (CBSException | ZoneException e) {
log.error(e.getMessage());
this.workInProgressMapImprime.get(filename).addErrorMessagesImprime(ligneKbartImprime.getPpn().toString(), (noticeElec.getNoticeBiblio() != null) ? noticeElec.getNoticeBiblio().toString() : "Notice non récupérée", e.getMessage());
} catch (IOException e) {
//cas d'une erreur de communication avec le Sudoc, on se relogge au cbs, et on retry la méthode
try {
log.debug("erreur de communication avec le Sudoc, tentative de reconnexion");
service.disconnect();
service.authenticate(serveurSudoc, portSudoc, loginSudoc, passwordSudoc);
} catch (CBSException | IOException ex) {
} catch (CBSException ex) {
log.error(ex.getMessage());
}
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void addNotice(T notice) {
}

public void incrementCurrentNbLignes() {
log.debug("Thread : " + Thread.currentThread().getName() + " | Current line : " + this.currentNbLines.incrementAndGet() + " | total lines : " + this.getNbLinesTotal());
log.debug("Current line : " + this.currentNbLines.incrementAndGet() + " | total lines : " + this.getNbLinesTotal());
}

public void addErrorMessagesConnectionCbs(String message) {
Expand Down

0 comments on commit 67ab398

Please sign in to comment.