Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

develop to main #63

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/java/fr/abes/bestppn/kafka/TopicConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.apache.logging.log4j.ThreadContext;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Service;

import java.io.IOException;
Expand Down Expand Up @@ -140,7 +139,7 @@ private void handleFichier(String filename) {
log.error("Fichier " + filename + " : Une erreur s'est produite dans le traitement du fichier");
} else {
String providerName = Utils.extractProvider(filename);
service.commitDatas(providerName, filename, workInProgress.get(filename).isBypassed());
service.commitDatas(providerName, filename);
//quel que soit le résultat du traitement, on envoie le rapport par mail
log.info("Nombre de best ppn trouvé : " + workInProgress.get(filename).getExecutionReport().getNbBestPpnFind() + "/" + workInProgress.get(filename).getExecutionReport().getNbtotalLines());
logFileService.createExecutionReport(filename, workInProgress.get(filename).getExecutionReport(), workInProgress.get(filename).isForced());
Expand Down

This file was deleted.

27 changes: 12 additions & 15 deletions src/main/java/fr/abes/bestppn/service/BestPpnService.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package fr.abes.bestppn.service;

import fr.abes.bestppn.model.BestPpn;
import fr.abes.bestppn.exception.BestPpnException;
import fr.abes.bestppn.exception.IllegalDoiException;
import fr.abes.bestppn.kafka.TopicProducer;
import fr.abes.bestppn.model.BestPpn;
import fr.abes.bestppn.model.dto.kafka.LigneKbartDto;
import fr.abes.bestppn.model.dto.wscall.PpnWithTypeDto;
import fr.abes.bestppn.model.dto.wscall.ResultDat2PpnWebDto;
import fr.abes.bestppn.model.dto.wscall.ResultWsSudocDto;
import fr.abes.bestppn.model.entity.basexml.notice.NoticeXml;
import fr.abes.bestppn.utils.*;
import io.netty.handler.logging.LogLevel;
import lombok.Getter;
Expand Down Expand Up @@ -126,27 +124,26 @@ private void feedPpnListFromPrint(LigneKbartDto kbart, String provider, Map<Stri

private void feedPpnListFromDat(LigneKbartDto kbart, Map<String, Integer> ppnElecScoredList, Set<String> ppnPrintResultList, String providerName) throws IOException, URISyntaxException {
sendLog(LogLevel.INFO, "Entrée dans dat2ppn");
ResultDat2PpnWebDto resultDat2PpnWeb = null;
ResultWsSudocDto resultCallWs = null;
if (!kbart.getAnneeFromDate_monograph_published_online().isEmpty()) {
sendLog(LogLevel.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(), providerName);
resultCallWs = service.callDat2Ppn(kbart.getAnneeFromDate_monograph_published_online(), kbart.getAuthor(), kbart.getPublicationTitle(), providerName);
} else if (ppnElecScoredList.isEmpty() && !kbart.getAnneeFromDate_monograph_published_print().isEmpty()) {
sendLog(LogLevel.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(), providerName);
resultCallWs = service.callDat2Ppn(kbart.getAnneeFromDate_monograph_published_print(), kbart.getAuthor(), kbart.getPublicationTitle(), providerName);
}
if(resultDat2PpnWeb != null && !resultDat2PpnWeb.getPpns().isEmpty()) {
sendLog(LogLevel.INFO, resultDat2PpnWeb.toString());
for (String ppn : resultDat2PpnWeb.getPpns()) {
NoticeXml notice = noticeService.getNoticeByPpn(ppn);
if (notice.isNoticeElectronique()) {
if (checkUrlService.checkUrlInNotice(ppn, kbart.getTitleUrl())) {
if(resultCallWs != null && !resultCallWs.getPpns().isEmpty()) {
sendLog(LogLevel.INFO, resultCallWs.toString());
for (PpnWithTypeDto ppn : resultCallWs.getPpns()) {
if (ppn.getTypeSupport().equals(TYPE_SUPPORT.ELECTRONIQUE)) {
if (ppn.isProviderPresent() || checkUrlService.checkUrlInNotice(ppn.getPpn(), kbart.getTitleUrl())) {
sendLog(LogLevel.INFO, "ppn : " + ppn + " / score : " + scoreDat2Ppn);
ppnElecScoredList.put(ppn, scoreDat2Ppn);
ppnElecScoredList.put(ppn.getPpn(), scoreDat2Ppn);
} else {
sendLog(LogLevel.ERROR, "Le PPN " + ppn + " n'a pas de provider trouvé");
}
} else if (notice.isNoticeImprimee()) {
ppnPrintResultList.add(ppn);
} else if (ppn.getTypeSupport().equals(TYPE_SUPPORT.IMPRIME)) {
ppnPrintResultList.add(ppn.getPpn());
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/fr/abes/bestppn/service/KbartService.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ public void processConsumerRecord(LigneKbartDto ligneFromKafka, String providerN
}

@Transactional
public void commitDatas(String providerName, String filename, Boolean isBypassed) throws IllegalPackageException, IllegalDateException, ExecutionException, InterruptedException, IOException {
public void commitDatas(String providerName, String filename) throws IllegalPackageException, IllegalDateException, ExecutionException, InterruptedException, IOException {
Optional<Provider> providerOpt = providerService.findByProvider(providerName);
ProviderPackage provider = providerService.handlerProvider(providerOpt, filename, providerName);
if (!isBypassed) {
if (!workInProgress.get(filename).isBypassed()) {
producer.sendKbart(workInProgress.get(filename).getKbartToSend(), provider, filename);
producer.sendPrintNotice(workInProgress.get(filename).getPpnToCreate(), filename);
producer.sendPpnExNihilo(workInProgress.get(filename).getPpnFromKbartToCreate(), provider, filename);
} else {
workInProgress.get(filename).setBypassed(isBypassed);
producer.sendBypassToLoad(workInProgress.get(filename).getKbartToSend(), provider, filename);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/fr/abes/bestppn/service/WsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.abes.bestppn.exception.IllegalDoiException;
import fr.abes.bestppn.model.dto.wscall.ResultDat2PpnWebDto;
import fr.abes.bestppn.model.dto.wscall.ResultWsSudocDto;
import fr.abes.bestppn.model.dto.wscall.SearchDatWebDto;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -113,15 +112,15 @@ private ResultWsSudocDto getResultWsSudocDto(String type, String id, @Nullable S
return result;
}

public ResultDat2PpnWebDto callDat2Ppn(String date, String author, String title, String providerName) throws JsonProcessingException {
public ResultWsSudocDto callDat2Ppn(String date, String author, String title, String providerName) throws JsonProcessingException {
SearchDatWebDto searchDatWebDto = new SearchDatWebDto(title, providerName);
if (author != null && !author.isEmpty()) {
searchDatWebDto.setAuteur(author);
}
if (date != null && !date.isEmpty()) {
searchDatWebDto.setDate(Integer.valueOf(date));
}
ResultDat2PpnWebDto result = mapper.readValue(postCall(urlDat2Ppn, mapper.writeValueAsString(searchDatWebDto)), ResultDat2PpnWebDto.class);
ResultWsSudocDto result = mapper.readValue(postCall(urlDat2Ppn, mapper.writeValueAsString(searchDatWebDto)), ResultWsSudocDto.class);
result.setUrl(urlDat2Ppn + "/" + mapper.writeValueAsString(searchDatWebDto));
return result;
}
Expand Down
26 changes: 10 additions & 16 deletions src/test/java/fr/abes/bestppn/service/BestPpnServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import fr.abes.bestppn.model.dto.kafka.LigneKbartDto;
import fr.abes.bestppn.exception.BestPpnException;
import fr.abes.bestppn.exception.IllegalDoiException;
import fr.abes.bestppn.kafka.TopicProducer;
import fr.abes.bestppn.model.BestPpn;
import fr.abes.bestppn.model.dto.kafka.LigneKbartDto;
import fr.abes.bestppn.model.dto.wscall.PpnWithTypeDto;
import fr.abes.bestppn.model.dto.wscall.ResultDat2PpnWebDto;
import fr.abes.bestppn.model.dto.wscall.ResultWsSudocDto;
import fr.abes.bestppn.model.entity.basexml.notice.NoticeXml;
import fr.abes.bestppn.exception.BestPpnException;
import fr.abes.bestppn.exception.IllegalDoiException;
import fr.abes.bestppn.kafka.TopicProducer;
import fr.abes.bestppn.utils.DESTINATION_TOPIC;
import fr.abes.bestppn.utils.TYPE_DOCUMENT;
import fr.abes.bestppn.utils.TYPE_SUPPORT;
import fr.abes.bestppn.utils.Utils;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.ThreadContext;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -347,7 +348,7 @@ void getBestPpnTest04() throws IOException, URISyntaxException {


@Test
@DisplayName("Test printFromPrint & 2 printFromDat ")
@DisplayName("Test 1 printFromDat ")
void getBestPpnTest06() throws IOException, BestPpnException, URISyntaxException, IllegalDoiException {
String provider = "";

Expand All @@ -364,9 +365,9 @@ void getBestPpnTest06() throws IOException, BestPpnException, URISyntaxException
resultPrint.setPpns(ppnWithTypePrintDto);

// Create a ResultDat2PpnWebDto
ResultDat2PpnWebDto resultDat2PpnWeb = new ResultDat2PpnWebDto();
resultDat2PpnWeb.addPpn("300000001");
resultDat2PpnWeb.addPpn("300000002");
List<PpnWithTypeDto> ppnWithTypeDat = Lists.newArrayList( new PpnWithTypeDto("300000002", TYPE_SUPPORT.IMPRIME, TYPE_DOCUMENT.MONOGRAPHIE, true));
ResultWsSudocDto resultDat2PpnWeb = new ResultWsSudocDto();
resultDat2PpnWeb.setPpns(ppnWithTypeDat);

// Create a LigneKbartDto
LigneKbartDto kbart = new LigneKbartDto();
Expand All @@ -382,8 +383,6 @@ void getBestPpnTest06() throws IOException, BestPpnException, URISyntaxException
// Mock
Mockito.when(service.callOnlineId2Ppn(kbart.getPublicationType(), kbart.getOnlineIdentifier(), provider)).thenReturn(resultElec);
Mockito.when(service.callPrintId2Ppn(kbart.getPublicationType(), kbart.getPrintIdentifier(), provider)).thenReturn(resultPrint);
Mockito.when(noticeService.getNoticeByPpn("300000001")).thenReturn(noticeElec);
Mockito.when(noticeService.getNoticeByPpn("300000002")).thenReturn(noticePrint);
Mockito.when(service.callDat2Ppn(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(resultDat2PpnWeb);

// Appel de la méthode
Expand Down Expand Up @@ -606,11 +605,6 @@ void getBestPpnTest09() throws IOException, BestPpnException, URISyntaxException
resultPrint.setPpns(ppnWithTypeDto3);
Mockito.when(service.callPrintId2Ppn(kbart.getPublicationType(), kbart.getPrintIdentifier(), provider)).thenReturn(resultPrint);

//Mock du service callDat2Ppn -> les ppn auront un score de 20
ResultDat2PpnWebDto resultDat2PpnWeb = new ResultDat2PpnWebDto();
resultDat2PpnWeb.addPpn("300000001");
resultDat2PpnWeb.addPpn("300000002");

ThreadContext.put("package","truc_truc_2000-12-31.tsv");
Mockito.when(checkUrlService.checkUrlInNotice(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
// Appel du service
Expand Down
Loading