Skip to content

Commit

Permalink
FEAT : CDE-302 accéder aux logs de l'algo vest-ppn sur la prod :
Browse files Browse the repository at this point in the history
     - renommage de la classe PpnDto.java en BestPpn.java et déplacemment dans le package \model
     - renommage de la classe PpnControllerDto.java en BestPpnDto.java
  • Loading branch information
EryneKL committed Dec 12, 2023
1 parent d907e9e commit c933c04
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 79 deletions.
22 changes: 11 additions & 11 deletions src/main/java/fr/abes/bestppn/controller/BestPpnController.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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<String> logs = new ArrayList<>();
logs.add(e.getMessage());
return new PpnControllerDto(logs);
return new BestPpnDto(logs);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Getter
@Setter
@NoArgsConstructor
public class PpnControllerDto {
public class BestPpnDto {
@Nullable
@JsonInclude(JsonInclude.Include.NON_NULL)
private String ppn;
Expand All @@ -25,13 +25,13 @@ public class PpnControllerDto {
@JsonInclude(JsonInclude.Include.NON_NULL)
private List<String> logs;

public PpnControllerDto (String ppn, TYPE_SUPPORT typeSupport, List<String> logs) {
public BestPpnDto(String ppn, TYPE_SUPPORT typeSupport, List<String> logs) {
this.ppn = ppn;
this.typeSupport = typeSupport;
this.logs = logs;
}

public PpnControllerDto (List<String> logs) {
public BestPpnDto(List<String> logs) {
this.logs = logs;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +12,7 @@
@Getter
@Setter
@NoArgsConstructor
public class PpnDto {
public class BestPpn {

@Nullable
private String ppn;
Expand All @@ -26,24 +26,24 @@ public class PpnDto {
@Nullable
private List<String> 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<String> logs) {
public BestPpn(String ppn, DESTINATION_TOPIC destination, List<String> logs) {
this.ppn = ppn;
this.destination = destination;
this.logs = logs;
}

public PpnDto (String ppn, DESTINATION_TOPIC destination, TYPE_SUPPORT typeSupport, List<String> logs) {
public BestPpn(String ppn, DESTINATION_TOPIC destination, TYPE_SUPPORT typeSupport, List<String> logs) {
this.ppn = ppn;
this.destination = destination;
this.typeSupport = typeSupport;
Expand Down
65 changes: 35 additions & 30 deletions src/main/java/fr/abes/bestppn/service/BestPpnService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -50,7 +50,7 @@ public class BestPpnService {
private List<String> kbartLineLogs;

@Setter
private Boolean sendLogs;
private Boolean isSendLogs;

public BestPpnService(WsService service, NoticeService noticeService, TopicProducer topicProducer, CheckUrlService checkUrlService) {
this.service = service;
Expand All @@ -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<String, Integer> ppnElecScoredList = new HashMap<>();
Set<String> ppnPrintResultList = new HashSet<>();

Expand Down Expand Up @@ -92,7 +92,7 @@ public PpnDto getBestPpn(LigneKbartDto kbart, String provider, boolean injectKaf
}

private void feedPpnListFromOnline(LigneKbartDto kbart, String provider, Map<String, Integer> ppnElecScoredList, Set<String> 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);
Expand All @@ -102,7 +102,7 @@ private void feedPpnListFromOnline(LigneKbartDto kbart, String provider, Map<Str
}

private void feedPpnListFromPrint(LigneKbartDto kbart, String provider, Map<String, Integer> ppnElecScoredList, Set<String> 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);
Expand All @@ -122,17 +122,17 @@ private void feedPpnListFromPrint(LigneKbartDto kbart, String provider, Map<Stri
private void feedPpnListFromDat(LigneKbartDto kbart, Map<String, Integer> ppnElecScoredList, Set<String> 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()) {
Expand All @@ -151,7 +151,7 @@ private void feedPpnListFromDoi(String doi, String provider, Map<String, Integer
if(ppn.getTypeSupport().equals(TYPE_SUPPORT.ELECTRONIQUE)){
setScoreToPpnElect(scoreDoi2Ppn,ppnElecScoredList,nbPpnElec,ppn);
} else {
if (sendLogs) kbartLineLogs.add("PPN Imprimé : " + ppn);
if (isSendLogs) kbartLineLogs.add("PPN Imprimé : " + ppn);
log.info("PPN Imprimé : " + ppn);
ppnPrintResultList.add(ppn.getPpn());
}
Expand All @@ -163,13 +163,13 @@ private void setScoreToEveryPpnFromResultWS(ResultWsSudocDto resultCallWs, Strin
int nbPpnElec = (int) resultCallWs.getPpns().stream().filter(ppnWithTypeDto -> 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é");
}
}
Expand All @@ -183,33 +183,33 @@ private void setScoreToPpnElect(int score, Map<String, Integer> 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<String, Integer> ppnElecResultList, Set<String> ppnPrintResultList, boolean isForced) throws BestPpnException {
public BestPpn getBestPpnByScore(LigneKbartDto kbart, Map<String, Integer> ppnElecResultList, Set<String> ppnPrintResultList, boolean isForced) throws BestPpnException {
Map<String, Integer> 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);
}
}

Expand All @@ -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);
Expand All @@ -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);
}
}

Expand All @@ -246,16 +246,21 @@ 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);
}
}
};
}

public void sendLog(String log, Boolean sendlogs) {

}

}
Loading

0 comments on commit c933c04

Please sign in to comment.