From 976ccfd41407e537cb7c30f6b3190ee0f3678b93 Mon Sep 17 00:00:00 2001 From: gibert Date: Thu, 26 Sep 2024 17:19:31 +0200 Subject: [PATCH] correction bug sur nom de l'index (les suppressions ne fonctionnaient plus) --- .../writer/ESDeleteWriter.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/fr/abes/theses_batch_indexation/writer/ESDeleteWriter.java b/src/main/java/fr/abes/theses_batch_indexation/writer/ESDeleteWriter.java index 421acb8..a4caa27 100644 --- a/src/main/java/fr/abes/theses_batch_indexation/writer/ESDeleteWriter.java +++ b/src/main/java/fr/abes/theses_batch_indexation/writer/ESDeleteWriter.java @@ -3,6 +3,7 @@ import co.elastic.clients.elasticsearch.core.BulkRequest; import co.elastic.clients.elasticsearch.core.BulkResponse; import co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem; +import fr.abes.theses_batch_indexation.configuration.JobConfig; import fr.abes.theses_batch_indexation.database.DbService; import fr.abes.theses_batch_indexation.database.TableIndexationES; import fr.abes.theses_batch_indexation.database.TheseModel; @@ -15,6 +16,7 @@ import org.springframework.stereotype.Component; import java.util.List; +import java.util.Objects; @Slf4j @Component @@ -30,6 +32,9 @@ public class ESDeleteWriter implements ItemWriter { @Autowired MappingJobName mappingJobName; + @Autowired + JobConfig jobConfig; + @Override public void write(List items) throws Exception { @@ -39,25 +44,22 @@ public void write(List items) throws Exception { for (TheseModel theseModel : items) { br.operations(op -> op - .delete(d->d.index(nomIndex.toLowerCase()) - .id(theseModel.getNnt() == null? theseModel.getIdSujet() : theseModel.getNnt()) - ) - ); - } + .delete(d -> d.index(nomIndex.toLowerCase()) + .id(theseModel.getNnt() == null ? theseModel.getIdSujet() : theseModel.getNnt()) + ) + ); + } BulkResponse result = proxyRetry.executerDansES(br); - for (BulkResponseItem item: result.items()) { + for (BulkResponseItem item : result.items()) { if (item.error() != null) { log.error(item.error().reason().concat(" pour ").concat(item.id())); - } - else { - switch (nomIndex) { - case "theses" : - dbService.supprimerTheseATraiter(item.id(), TableIndexationES.suppression_es_these); - case "thematiques": - dbService.supprimerTheseATraiter(item.id(), TableIndexationES.suppression_es_thematique); - } + } else { + if (Objects.equals(nomIndex, jobConfig.getThesesIndex())) + dbService.supprimerTheseATraiter(item.id(), TableIndexationES.suppression_es_these); + if (Objects.equals(nomIndex, jobConfig.getThematiquesIndex())) + dbService.supprimerTheseATraiter(item.id(), TableIndexationES.suppression_es_thematique); } } }