diff --git a/src/main/java/fr/abes/bestppn/controller/BestPpnController.java b/src/main/java/fr/abes/bestppn/controller/BestPpnController.java index a4b0a57..38dfa53 100644 --- a/src/main/java/fr/abes/bestppn/controller/BestPpnController.java +++ b/src/main/java/fr/abes/bestppn/controller/BestPpnController.java @@ -1,8 +1,8 @@ package fr.abes.bestppn.controller; -import fr.abes.bestppn.dto.PpnControllerDto; +import fr.abes.bestppn.dto.BestPpnDto; import fr.abes.bestppn.dto.kafka.LigneKbartDto; -import fr.abes.bestppn.dto.kafka.PpnDto; +import fr.abes.bestppn.model.BestPpn; import fr.abes.bestppn.exception.BestPpnException; import fr.abes.bestppn.exception.IllegalDoiException; import fr.abes.bestppn.service.BestPpnService; @@ -41,12 +41,12 @@ public BestPpnController(BestPpnService service) { } ) @GetMapping(value = "/bestPpn") - public PpnControllerDto bestPpn(@RequestParam(name = "provider") String provider, @RequestParam(name = "publication_title", required = false) String publicationTitle, - @RequestParam(name = "publication_type") String publicationType, @RequestParam(name = "online_identifier", required = false) String onlineIdentifier, - @RequestParam(name = "print_identifier", required = false) String printIdentifier, @RequestParam(name = "titleUrl", required = false) String titleUrl, - @RequestParam(name = "date_monograph_published_online", required = false) String dateMonographPublishedOnline, @RequestParam(name = "date_monograph_published_print", required = false) String dateMonographPublishedPrint, - @RequestParam(name = "first_author", required = false) String firstAuthor, @RequestParam(name = "force", required = false) Boolean force, - @RequestParam(name = "log", required = false) Boolean log) throws IOException { + public BestPpnDto bestPpn(@RequestParam(name = "provider") String provider, @RequestParam(name = "publication_title", required = false) String publicationTitle, + @RequestParam(name = "publication_type") String publicationType, @RequestParam(name = "online_identifier", required = false) String onlineIdentifier, + @RequestParam(name = "print_identifier", required = false) String printIdentifier, @RequestParam(name = "titleUrl", required = false) String titleUrl, + @RequestParam(name = "date_monograph_published_online", required = false) String dateMonographPublishedOnline, @RequestParam(name = "date_monograph_published_print", required = false) String dateMonographPublishedPrint, + @RequestParam(name = "first_author", required = false) String firstAuthor, @RequestParam(name = "force", required = false) Boolean force, + @RequestParam(name = "log", required = false) Boolean log) throws IOException { try { LigneKbartDto ligneKbartDto = new LigneKbartDto(); ligneKbartDto.setPublicationType(publicationType); @@ -59,14 +59,14 @@ public PpnControllerDto bestPpn(@RequestParam(name = "provider") String provider ligneKbartDto.setFirstAuthor((firstAuthor != null) ? firstAuthor : ""); boolean injectKafka = (force != null) ? force : false; boolean sendLog = (log != null) ? log : false; - PpnDto ppnDto = service.getBestPpn(ligneKbartDto, provider, injectKafka, sendLog); - return new PpnControllerDto(ppnDto.getPpn(), ppnDto.getTypeSupport(), ppnDto.getLogs()); + BestPpn bestPpn = service.getBestPpn(ligneKbartDto, provider, injectKafka, sendLog); + return new BestPpnDto(bestPpn.getPpn(), bestPpn.getTypeSupport(), bestPpn.getLogs()); } catch (URISyntaxException e) { throw new IllegalArgumentException("Une url dans le champ title_url du kbart n'est pas correcte"); } catch (BestPpnException | RestClientException | IllegalArgumentException | IllegalDoiException e) { List logs = new ArrayList<>(); logs.add(e.getMessage()); - return new PpnControllerDto(logs); + return new BestPpnDto(logs); } } } diff --git a/src/main/java/fr/abes/bestppn/dto/PpnControllerDto.java b/src/main/java/fr/abes/bestppn/dto/BestPpnDto.java similarity index 80% rename from src/main/java/fr/abes/bestppn/dto/PpnControllerDto.java rename to src/main/java/fr/abes/bestppn/dto/BestPpnDto.java index a969e3c..833f544 100644 --- a/src/main/java/fr/abes/bestppn/dto/PpnControllerDto.java +++ b/src/main/java/fr/abes/bestppn/dto/BestPpnDto.java @@ -12,7 +12,7 @@ @Getter @Setter @NoArgsConstructor -public class PpnControllerDto { +public class BestPpnDto { @Nullable @JsonInclude(JsonInclude.Include.NON_NULL) private String ppn; @@ -25,13 +25,13 @@ public class PpnControllerDto { @JsonInclude(JsonInclude.Include.NON_NULL) private List logs; - public PpnControllerDto (String ppn, TYPE_SUPPORT typeSupport, List logs) { + public BestPpnDto(String ppn, TYPE_SUPPORT typeSupport, List logs) { this.ppn = ppn; this.typeSupport = typeSupport; this.logs = logs; } - public PpnControllerDto (List logs) { + public BestPpnDto(List logs) { this.logs = logs; } } diff --git a/src/main/java/fr/abes/bestppn/dto/kafka/PpnDto.java b/src/main/java/fr/abes/bestppn/model/BestPpn.java similarity index 75% rename from src/main/java/fr/abes/bestppn/dto/kafka/PpnDto.java rename to src/main/java/fr/abes/bestppn/model/BestPpn.java index 87bd419..c5878b6 100644 --- a/src/main/java/fr/abes/bestppn/dto/kafka/PpnDto.java +++ b/src/main/java/fr/abes/bestppn/model/BestPpn.java @@ -1,4 +1,4 @@ -package fr.abes.bestppn.dto.kafka; +package fr.abes.bestppn.model; import fr.abes.bestppn.utils.DESTINATION_TOPIC; import fr.abes.bestppn.utils.TYPE_SUPPORT; @@ -12,7 +12,7 @@ @Getter @Setter @NoArgsConstructor -public class PpnDto { +public class BestPpn { @Nullable private String ppn; @@ -26,24 +26,24 @@ public class PpnDto { @Nullable private List logs; - public PpnDto (String ppn, DESTINATION_TOPIC destination) { + public BestPpn(String ppn, DESTINATION_TOPIC destination) { this.ppn = ppn; this.destination = destination; } - public PpnDto (String ppn, DESTINATION_TOPIC destination, TYPE_SUPPORT typeSupport) { + public BestPpn(String ppn, DESTINATION_TOPIC destination, TYPE_SUPPORT typeSupport) { this.ppn = ppn; this.destination = destination; this.typeSupport = typeSupport; } - public PpnDto (String ppn, DESTINATION_TOPIC destination, List logs) { + public BestPpn(String ppn, DESTINATION_TOPIC destination, List logs) { this.ppn = ppn; this.destination = destination; this.logs = logs; } - public PpnDto (String ppn, DESTINATION_TOPIC destination, TYPE_SUPPORT typeSupport, List logs) { + public BestPpn(String ppn, DESTINATION_TOPIC destination, TYPE_SUPPORT typeSupport, List logs) { this.ppn = ppn; this.destination = destination; this.typeSupport = typeSupport; diff --git a/src/main/java/fr/abes/bestppn/service/BestPpnService.java b/src/main/java/fr/abes/bestppn/service/BestPpnService.java index 0e347a0..0696491 100644 --- a/src/main/java/fr/abes/bestppn/service/BestPpnService.java +++ b/src/main/java/fr/abes/bestppn/service/BestPpnService.java @@ -1,7 +1,7 @@ package fr.abes.bestppn.service; import fr.abes.bestppn.dto.kafka.LigneKbartDto; -import fr.abes.bestppn.dto.kafka.PpnDto; +import fr.abes.bestppn.model.BestPpn; import fr.abes.bestppn.dto.wscall.PpnWithTypeDto; import fr.abes.bestppn.dto.wscall.ResultDat2PpnWebDto; import fr.abes.bestppn.dto.wscall.ResultWsSudocDto; @@ -50,7 +50,7 @@ public class BestPpnService { private List kbartLineLogs; @Setter - private Boolean sendLogs; + private Boolean isSendLogs; public BestPpnService(WsService service, NoticeService noticeService, TopicProducer topicProducer, CheckUrlService checkUrlService) { this.service = service; @@ -59,10 +59,10 @@ public BestPpnService(WsService service, NoticeService noticeService, TopicProdu this.checkUrlService = checkUrlService; } - public PpnDto getBestPpn(LigneKbartDto kbart, String provider, boolean injectKafka, boolean sendLogs) throws IOException, BestPpnException, URISyntaxException, RestClientException, IllegalArgumentException, IllegalDoiException { + public BestPpn getBestPpn(LigneKbartDto kbart, String provider, boolean injectKafka, boolean sendLogs) throws IOException, BestPpnException, URISyntaxException, RestClientException, IllegalArgumentException, IllegalDoiException { kbartLineLogs = new ArrayList<>(); - this.sendLogs = sendLogs; + this.isSendLogs = sendLogs; Map ppnElecScoredList = new HashMap<>(); Set ppnPrintResultList = new HashSet<>(); @@ -92,7 +92,7 @@ public PpnDto getBestPpn(LigneKbartDto kbart, String provider, boolean injectKaf } private void feedPpnListFromOnline(LigneKbartDto kbart, String provider, Map ppnElecScoredList, Set ppnPrintResultList) throws IOException, URISyntaxException, IllegalArgumentException, BestPpnException { - if (sendLogs) kbartLineLogs.add("Entrée dans onlineId2Ppn"); + if (isSendLogs) kbartLineLogs.add("Entrée dans onlineId2Ppn"); log.debug("Entrée dans onlineId2Ppn"); try { setScoreToEveryPpnFromResultWS(service.callOnlineId2Ppn(kbart.getPublicationType(), kbart.getOnlineIdentifier(), provider), kbart.getTitleUrl(), this.scoreOnlineId2PpnElect, ppnElecScoredList, ppnPrintResultList); @@ -102,7 +102,7 @@ private void feedPpnListFromOnline(LigneKbartDto kbart, String provider, Map ppnElecScoredList, Set ppnPrintResultList) throws IOException, URISyntaxException, IllegalArgumentException, BestPpnException { - if (sendLogs) kbartLineLogs.add("Entrée dans printId2Ppn"); + if (isSendLogs) kbartLineLogs.add("Entrée dans printId2Ppn"); log.debug("Entrée dans printId2Ppn"); try { ResultWsSudocDto resultCallWs = service.callPrintId2Ppn(kbart.getPublicationType(), kbart.getPrintIdentifier(), provider); @@ -122,17 +122,17 @@ private void feedPpnListFromPrint(LigneKbartDto kbart, String provider, Map ppnElecScoredList, Set ppnPrintResultList) throws IOException { ResultDat2PpnWebDto resultDat2PpnWeb = null; if (!kbart.getAnneeFromDate_monograph_published_online().isEmpty()) { - if (sendLogs) kbartLineLogs.add("Appel dat2ppn : date_monograph_published_online : " + kbart.getAnneeFromDate_monograph_published_online() + " / publication_title : " + kbart.getPublicationTitle() + " auteur : " + kbart.getAuthor()); + if (isSendLogs) kbartLineLogs.add("Appel dat2ppn : date_monograph_published_online : " + kbart.getAnneeFromDate_monograph_published_online() + " / publication_title : " + kbart.getPublicationTitle() + " auteur : " + kbart.getAuthor()); log.debug("Appel dat2ppn : date_monograph_published_online : " + kbart.getAnneeFromDate_monograph_published_online() + " / publication_title : " + kbart.getPublicationTitle() + " auteur : " + kbart.getAuthor()); resultDat2PpnWeb = service.callDat2Ppn(kbart.getAnneeFromDate_monograph_published_online(), kbart.getAuthor(), kbart.getPublicationTitle()); } else if (ppnElecScoredList.isEmpty() && !kbart.getAnneeFromDate_monograph_published_print().isEmpty()) { - if (sendLogs) kbartLineLogs.add("Appel dat2ppn : date_monograph_published_print : " + kbart.getAnneeFromDate_monograph_published_print() + " / publication_title : " + kbart.getPublicationTitle() + " auteur : " + kbart.getAuthor()); + if (isSendLogs) kbartLineLogs.add("Appel dat2ppn : date_monograph_published_print : " + kbart.getAnneeFromDate_monograph_published_print() + " / publication_title : " + kbart.getPublicationTitle() + " auteur : " + kbart.getAuthor()); log.debug("Appel dat2ppn : date_monograph_published_print : " + kbart.getAnneeFromDate_monograph_published_print() + " / publication_title : " + kbart.getPublicationTitle() + " auteur : " + kbart.getAuthor()); resultDat2PpnWeb = service.callDat2Ppn(kbart.getAnneeFromDate_monograph_published_print(), kbart.getAuthor(), kbart.getPublicationTitle()); } if(resultDat2PpnWeb != null && !resultDat2PpnWeb.getPpns().isEmpty()) { for (String ppn : resultDat2PpnWeb.getPpns()) { - if (sendLogs) kbartLineLogs.add("résultat : ppn " + ppn); + if (isSendLogs) kbartLineLogs.add("résultat : ppn " + ppn); log.debug("résultat : ppn " + ppn); NoticeXml notice = noticeService.getNoticeByPpn(ppn); if (notice.isNoticeElectronique()) { @@ -151,7 +151,7 @@ private void feedPpnListFromDoi(String doi, String provider, Map ppnWithTypeDto.getTypeSupport().equals(TYPE_SUPPORT.ELECTRONIQUE)).count(); for (PpnWithTypeDto ppn : resultCallWs.getPpns()) { if(ppn.getTypeSupport().equals(TYPE_SUPPORT.IMPRIME)) { - if (sendLogs) kbartLineLogs.add("PPN Imprimé : " + ppn); + if (isSendLogs) kbartLineLogs.add("PPN Imprimé : " + ppn); log.info("PPN Imprimé : " + ppn); ppnPrintResultList.add(ppn.getPpn()); } else if (ppn.getTypeDocument() != TYPE_DOCUMENT.MONOGRAPHIE || ppn.isProviderPresent() || checkUrlService.checkUrlInNotice(ppn.getPpn(), titleUrl)){ setScoreToPpnElect(score, ppnElecResultList, nbPpnElec, ppn); } else { - if (sendLogs) kbartLineLogs.add("Le PPN " + ppn + " n'a pas de provider trouvé"); + if (isSendLogs) kbartLineLogs.add("Le PPN " + ppn + " n'a pas de provider trouvé"); log.error("Le PPN " + ppn + " n'a pas de provider trouvé"); } } @@ -183,33 +183,33 @@ private void setScoreToPpnElect(int score, Map ppnElecScoredLis } else { ppnElecScoredList.put(ppn.getPpn(), (score / nbPpnElec)); } - if (sendLogs) kbartLineLogs.add("PPN Electronique : " + ppn + " / score : " + ppnElecScoredList.get(ppn.getPpn())); + if (isSendLogs) kbartLineLogs.add("PPN Electronique : " + ppn + " / score : " + ppnElecScoredList.get(ppn.getPpn())); log.info("PPN Electronique : " + ppn + " / score : " + ppnElecScoredList.get(ppn.getPpn())); } - public PpnDto getBestPpnByScore(LigneKbartDto kbart, Map ppnElecResultList, Set ppnPrintResultList, boolean isForced) throws BestPpnException { + public BestPpn getBestPpnByScore(LigneKbartDto kbart, Map ppnElecResultList, Set ppnPrintResultList, boolean isForced) throws BestPpnException { Map ppnElecScore = Utils.getMaxValuesFromMap(ppnElecResultList); return switch (ppnElecScore.size()) { case 0 -> { - if (sendLogs) kbartLineLogs.add("Aucun ppn électronique trouvé. " + kbart); + if (isSendLogs) kbartLineLogs.add("Aucun ppn électronique trouvé. " + kbart); log.info("Aucun ppn électronique trouvé. " + kbart); yield switch (ppnPrintResultList.size()) { case 0 -> { kbart.setErrorType("Aucun ppn trouvé"); - if(sendLogs) { - yield new PpnDto(null, DESTINATION_TOPIC.NO_PPN_FOUND_SUDOC, kbartLineLogs); + if(isSendLogs) { + yield new BestPpn(null, DESTINATION_TOPIC.NO_PPN_FOUND_SUDOC, kbartLineLogs); } else { - yield new PpnDto(null, DESTINATION_TOPIC.NO_PPN_FOUND_SUDOC); + yield new BestPpn(null, DESTINATION_TOPIC.NO_PPN_FOUND_SUDOC); } } case 1 -> { kbart.setErrorType("Ppn imprimé trouvé : " + ppnPrintResultList.stream().toList().get(0)); - if(sendLogs) { + if(isSendLogs) { kbartLineLogs.add("Ppn imprimé trouvé : " + ppnPrintResultList.stream().toList().get(0)); - yield new PpnDto(ppnPrintResultList.stream().toList().get(0),DESTINATION_TOPIC.PRINT_PPN_SUDOC, TYPE_SUPPORT.IMPRIME, kbartLineLogs); + yield new BestPpn(ppnPrintResultList.stream().toList().get(0),DESTINATION_TOPIC.PRINT_PPN_SUDOC, TYPE_SUPPORT.IMPRIME, kbartLineLogs); } else { - yield new PpnDto(ppnPrintResultList.stream().toList().get(0),DESTINATION_TOPIC.PRINT_PPN_SUDOC, TYPE_SUPPORT.IMPRIME); + yield new BestPpn(ppnPrintResultList.stream().toList().get(0),DESTINATION_TOPIC.PRINT_PPN_SUDOC, TYPE_SUPPORT.IMPRIME); } } @@ -219,11 +219,11 @@ yield switch (ppnPrintResultList.size()) { // vérification du forçage if (isForced) { log.error(errorString); - if (sendLogs) { + if (isSendLogs) { kbartLineLogs.add("Plusieurs ppn imprimés (" + String.join(", ", ppnPrintResultList) + ") ont été trouvés."); - yield new PpnDto("",DESTINATION_TOPIC.BEST_PPN_BACON, kbartLineLogs); + yield new BestPpn("",DESTINATION_TOPIC.BEST_PPN_BACON, kbartLineLogs); } else { - yield new PpnDto("",DESTINATION_TOPIC.BEST_PPN_BACON); + yield new BestPpn("",DESTINATION_TOPIC.BEST_PPN_BACON); } } else { throw new BestPpnException(errorString); @@ -232,10 +232,10 @@ yield switch (ppnPrintResultList.size()) { }; } case 1 -> { - if (sendLogs) { - yield new PpnDto(ppnElecScore.keySet().stream().findFirst().get(), DESTINATION_TOPIC.BEST_PPN_BACON, TYPE_SUPPORT.ELECTRONIQUE, kbartLineLogs); + if (isSendLogs) { + yield new BestPpn(ppnElecScore.keySet().stream().findFirst().get(), DESTINATION_TOPIC.BEST_PPN_BACON, TYPE_SUPPORT.ELECTRONIQUE, kbartLineLogs); } else { - yield new PpnDto(ppnElecScore.keySet().stream().findFirst().get(), DESTINATION_TOPIC.BEST_PPN_BACON, TYPE_SUPPORT.ELECTRONIQUE); + yield new BestPpn(ppnElecScore.keySet().stream().findFirst().get(), DESTINATION_TOPIC.BEST_PPN_BACON, TYPE_SUPPORT.ELECTRONIQUE); } } @@ -246,11 +246,11 @@ yield switch (ppnPrintResultList.size()) { // vérification du forçage if (isForced) { log.error(errorString); - if (sendLogs) { + if (isSendLogs) { kbartLineLogs.add(errorString); - yield new PpnDto("", DESTINATION_TOPIC.BEST_PPN_BACON, kbartLineLogs); + yield new BestPpn("", DESTINATION_TOPIC.BEST_PPN_BACON, kbartLineLogs); } else { - yield new PpnDto("", DESTINATION_TOPIC.BEST_PPN_BACON); + yield new BestPpn("", DESTINATION_TOPIC.BEST_PPN_BACON); } } else { throw new BestPpnException(errorString); @@ -258,4 +258,9 @@ yield switch (ppnPrintResultList.size()) { } }; } + + public void sendLog(String log, Boolean sendlogs) { + + } + } diff --git a/src/main/java/fr/abes/bestppn/service/KbartService.java b/src/main/java/fr/abes/bestppn/service/KbartService.java index 4d2bf1b..b4ab032 100644 --- a/src/main/java/fr/abes/bestppn/service/KbartService.java +++ b/src/main/java/fr/abes/bestppn/service/KbartService.java @@ -2,7 +2,7 @@ import fr.abes.LigneKbartImprime; import fr.abes.bestppn.dto.kafka.LigneKbartDto; -import fr.abes.bestppn.dto.kafka.PpnDto; +import fr.abes.bestppn.model.BestPpn; import fr.abes.bestppn.entity.bacon.Provider; import fr.abes.bestppn.entity.bacon.ProviderPackage; import fr.abes.bestppn.exception.BestPpnException; @@ -59,13 +59,13 @@ public void processConsumerRecord(LigneKbartDto ligneFromKafka, String providerN log.info("Début calcul BestPpn pour la ligne " + ligneFromKafka); if (ligneFromKafka.isBestPpnEmpty()) { log.info(ligneFromKafka.toString()); - PpnDto ppnDto = service.getBestPpn(ligneFromKafka, providerName, isForced, false); - switch (ppnDto.getDestination()) { + BestPpn bestPpn = service.getBestPpn(ligneFromKafka, providerName, isForced, false); + switch (bestPpn.getDestination()) { case BEST_PPN_BACON -> { - ligneFromKafka.setBestPpn(ppnDto.getPpn()); + ligneFromKafka.setBestPpn(bestPpn.getPpn()); executionReportService.addNbBestPpnFind(); } - case PRINT_PPN_SUDOC -> ppnToCreate.add(getLigneKbartImprime(ppnDto, ligneFromKafka)); + case PRINT_PPN_SUDOC -> ppnToCreate.add(getLigneKbartImprime(bestPpn, ligneFromKafka)); case NO_PPN_FOUND_SUDOC -> { if (ligneFromKafka.getPublicationType().equals("monograph")) { ppnFromKbartToCreate.add(ligneFromKafka); @@ -95,9 +95,9 @@ public void clearListesKbart() { ppnFromKbartToCreate.clear(); } - private static LigneKbartImprime getLigneKbartImprime(PpnDto ppnDto, LigneKbartDto ligneFromKafka) { + private static LigneKbartImprime getLigneKbartImprime(BestPpn bestPpn, LigneKbartDto ligneFromKafka) { return LigneKbartImprime.newBuilder() - .setPpn(ppnDto.getPpn()) + .setPpn(bestPpn.getPpn()) .setPublicationTitle(ligneFromKafka.getPublicationTitle()) .setPrintIdentifier(ligneFromKafka.getPrintIdentifier()) .setOnlineIdentifier(ligneFromKafka.getOnlineIdentifier()) diff --git a/src/test/java/fr/abes/bestppn/controller/BestPpnControllerTest.java b/src/test/java/fr/abes/bestppn/controller/BestPpnControllerTest.java index cf0a10d..608e992 100644 --- a/src/test/java/fr/abes/bestppn/controller/BestPpnControllerTest.java +++ b/src/test/java/fr/abes/bestppn/controller/BestPpnControllerTest.java @@ -3,10 +3,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import fr.abes.bestppn.configuration.MapperConfig; import fr.abes.bestppn.configuration.RestConfiguration; -import fr.abes.bestppn.dto.kafka.PpnDto; +import fr.abes.bestppn.model.BestPpn; import fr.abes.bestppn.exception.BestPpnException; import fr.abes.bestppn.exception.ExceptionControllerHandler; -import fr.abes.bestppn.exception.IllegalDoiException; import fr.abes.bestppn.service.BestPpnService; import fr.abes.bestppn.utils.DESTINATION_TOPIC; import org.junit.jupiter.api.Assertions; @@ -60,7 +59,7 @@ void init() { @Test @DisplayName("test controller with wrong number of parameters") void testBestPpnControllerWrongNumberOfParameters() throws Exception { - Mockito.when(service.getBestPpn(Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(new PpnDto("1111111111", DESTINATION_TOPIC.BEST_PPN_BACON)); + Mockito.when(service.getBestPpn(Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(new BestPpn("1111111111", DESTINATION_TOPIC.BEST_PPN_BACON)); this.mockMvc.perform(get("/api/v1/bestPpn").characterEncoding(StandardCharsets.UTF_8)) .andExpect(status().isBadRequest()) .andExpect(result -> Assertions.assertTrue((result.getResolvedException() instanceof MissingServletRequestParameterException))) @@ -94,7 +93,7 @@ void testBestPpnControllerBestPpnException() throws Exception { @Test @DisplayName("test controller Ok") void testBestPpnControllerOk() throws Exception { - Mockito.when(service.getBestPpn(Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(new PpnDto("1111111111", DESTINATION_TOPIC.BEST_PPN_BACON)); + Mockito.when(service.getBestPpn(Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(new BestPpn("1111111111", DESTINATION_TOPIC.BEST_PPN_BACON)); this.mockMvc.perform(get("/api/v1/bestPpn?provider=cairn&publication_type=monograph&print_identifier=9781111111111&title_url=test").characterEncoding(StandardCharsets.UTF_8)) .andExpect(status().isOk()) .andExpect(result -> Assertions.assertTrue(result.getResponse().getContentAsString(StandardCharsets.UTF_8).contains("111111111"))); diff --git a/src/test/java/fr/abes/bestppn/service/BestPpnServiceTest.java b/src/test/java/fr/abes/bestppn/service/BestPpnServiceTest.java index f0620e8..155e963 100644 --- a/src/test/java/fr/abes/bestppn/service/BestPpnServiceTest.java +++ b/src/test/java/fr/abes/bestppn/service/BestPpnServiceTest.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import fr.abes.bestppn.dto.kafka.LigneKbartDto; -import fr.abes.bestppn.dto.kafka.PpnDto; +import fr.abes.bestppn.model.BestPpn; import fr.abes.bestppn.dto.wscall.PpnWithTypeDto; import fr.abes.bestppn.dto.wscall.ResultDat2PpnWebDto; import fr.abes.bestppn.dto.wscall.ResultWsSudocDto; @@ -122,7 +122,7 @@ void getBestPpnTest01() throws IOException, BestPpnException, URISyntaxException Mockito.when(noticeService.getNoticeByPpn(Mockito.anyString())).thenReturn(this.noticeElec); // Appel du service - PpnDto result = bestPpnService.getBestPpn(kbart, provider, false, false); + BestPpn result = bestPpnService.getBestPpn(kbart, provider, false, false); // Vérification Assertions.assertEquals("100000001", result.getPpn()); @@ -173,7 +173,7 @@ void getBestPpnTest01_WithProviderInNoticeIsPresent() throws IOException, BestPp Mockito.when(noticeService.getNoticeByPpn(Mockito.anyString())).thenReturn(this.noticeElec); // Appel du service - PpnDto result = bestPpnService.getBestPpn(kbart, provider, false, false); + BestPpn result = bestPpnService.getBestPpn(kbart, provider, false, false); // Vérification Assertions.assertEquals("100000001", result.getPpn()); @@ -231,7 +231,7 @@ void getBestPpnTest02() throws IOException, BestPpnException, URISyntaxException Mockito.when(noticeService.getNoticeByPpn(Mockito.anyString())).thenReturn(this.noticeElec); // Appel du service - PpnDto result = bestPpnService.getBestPpn(kbart, provider, false, false); + BestPpn result = bestPpnService.getBestPpn(kbart, provider, false, false); // Vérification Assertions.assertEquals("100000001", result.getPpn()); @@ -289,7 +289,7 @@ void getBestPpnTest03() throws IOException, BestPpnException, URISyntaxException Mockito.when(noticeService.getNoticeByPpn(Mockito.anyString())).thenReturn(this.noticeElec); // Appel du service - PpnDto result = bestPpnService.getBestPpn(kbart, provider, false, false); + BestPpn result = bestPpnService.getBestPpn(kbart, provider, false, false); // Vérification Assertions.assertEquals("100000001", result.getPpn()); @@ -387,7 +387,7 @@ void getBestPpnTest06() throws IOException, BestPpnException, URISyntaxException Mockito.when(service.callDat2Ppn(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(resultDat2PpnWeb); // Appel de la méthode - PpnDto result = bestPpnService.getBestPpn(kbart, provider, false, false); + BestPpn result = bestPpnService.getBestPpn(kbart, provider, false, false); // Vérification Assertions.assertEquals("300000001", result.getPpn()); @@ -429,7 +429,7 @@ void getBestPpnTest06_NoBestPpnByDat2Ppn() throws IOException, BestPpnException, Mockito.when(noticeService.getNoticeByPpn("300000002")).thenReturn(noticePrint); // Appel de la méthode - PpnDto result = bestPpnService.getBestPpn(kbart, provider, false, false); + BestPpn result = bestPpnService.getBestPpn(kbart, provider, false, false); // Vérification Assertions.assertNull(result.getPpn()); @@ -481,7 +481,7 @@ void getBestPpnTest07() throws IOException, BestPpnException, URISyntaxException Mockito.when(noticeService.getNoticeByPpn(Mockito.anyString())).thenReturn(this.noticeElec); // Appel du service - PpnDto result = bestPpnService.getBestPpn(kbart, provider, false, false); + BestPpn result = bestPpnService.getBestPpn(kbart, provider, false, false); // Vérification Assertions.assertEquals("100000001", result.getPpn()); @@ -532,7 +532,7 @@ void getBestPpnTest08() throws IOException, BestPpnException, URISyntaxException Mockito.when(checkUrlService.checkUrlInNotice(Mockito.anyString(), Mockito.any())).thenReturn(true); // Appel du service - PpnDto result = bestPpnService.getBestPpn(kbart, provider, false, false); + BestPpn result = bestPpnService.getBestPpn(kbart, provider, false, false); // Vérification Assertions.assertEquals("200000001", result.getPpn()); @@ -614,7 +614,7 @@ void getBestPpnTest09() throws IOException, BestPpnException, URISyntaxException ThreadContext.put("package","truc_truc_2000-12-31.tsv"); Mockito.when(checkUrlService.checkUrlInNotice(Mockito.anyString(), Mockito.anyString())).thenReturn(true); // Appel du service - PpnDto result = bestPpnService.getBestPpn(kbart, provider, false, false); + BestPpn result = bestPpnService.getBestPpn(kbart, provider, false, false); // Vérification Assertions.assertEquals("123456789", result.getPpn()); @@ -629,8 +629,8 @@ void bestPpnWithScoreTest1() throws BestPpnException { ppnElecResultList.put("100000001", 10); Set ppnPrintResultList = new HashSet<>(); - bestPpnService.setSendLogs(false); - PpnDto result = bestPpnService.getBestPpnByScore(kbart, ppnElecResultList, ppnPrintResultList, false); + bestPpnService.setIsSendLogs(false); + BestPpn result = bestPpnService.getBestPpnByScore(kbart, ppnElecResultList, ppnPrintResultList, false); Assertions.assertEquals("100000001", result.getPpn()); Assertions.assertEquals(DESTINATION_TOPIC.BEST_PPN_BACON, result.getDestination()); } @@ -644,8 +644,8 @@ void bestPpnWithScoreTest2() throws BestPpnException { ppnElecResultList.put("100000002", 10); Set ppnPrintResultList = new HashSet<>(); - bestPpnService.setSendLogs(false); - PpnDto result = bestPpnService.getBestPpnByScore(kbart, ppnElecResultList, ppnPrintResultList, false); + bestPpnService.setIsSendLogs(false); + BestPpn result = bestPpnService.getBestPpnByScore(kbart, ppnElecResultList, ppnPrintResultList, false); Assertions.assertEquals("100000002", result.getPpn()); Assertions.assertEquals(DESTINATION_TOPIC.BEST_PPN_BACON, result.getDestination()); } @@ -659,8 +659,8 @@ void bestPpnWithScoreTest3() throws BestPpnException { ppnElecResultList.put("100000002", 10); Set ppnPrintResultList = new HashSet<>(); - bestPpnService.setSendLogs(false); - PpnDto result = bestPpnService.getBestPpnByScore(kbart, ppnElecResultList, ppnPrintResultList, true); + bestPpnService.setIsSendLogs(false); + BestPpn result = bestPpnService.getBestPpnByScore(kbart, ppnElecResultList, ppnPrintResultList, true); Assertions.assertEquals("", result.getPpn()); } @@ -675,8 +675,8 @@ void bestPpnWithScoreTest4() throws BestPpnException { ppnPrintResultList.add("100000001"); ppnPrintResultList.add("100000002"); - bestPpnService.setSendLogs(false); - PpnDto result = bestPpnService.getBestPpnByScore(kbart, ppnElecResultList, ppnPrintResultList, true); + bestPpnService.setIsSendLogs(false); + BestPpn result = bestPpnService.getBestPpnByScore(kbart, ppnElecResultList, ppnPrintResultList, true); Assertions.assertEquals("", result.getPpn()); }