Skip to content

Commit

Permalink
Merge pull request #107 from abes-esr/develop
Browse files Browse the repository at this point in the history
merge dev vers test
  • Loading branch information
SamuelQuetin authored Nov 29, 2024
2 parents f4d3696 + 53a84b0 commit 1dd4089
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 323 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ WORKDIR /app/
COPY --from=build-image /build/target/sudoc.jar /app/sudoc.jar
ENV TZ=Europe/Paris
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENTRYPOINT ["java","-XX:MaxRAMPercentage=75","-XX:+UseG1GC","-XX:ConcGCThreads=5","-XX:+ExitOnOutOfMemoryError","-XX:MaxGCPauseMillis=100","-jar","/app/sudoc.jar"]
COPY ./docker/docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
4 changes: 4 additions & 0 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "Démarrage de l'application Java..."
java -XX:MaxRAMPercentage=75 -XX:+UseG1GC -XX:ConcGCThreads=5 -XX:+ExitOnOutOfMemoryError -XX:MaxGCPauseMillis=100 -jar /app/sudoc.jar
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<groupId>fr.abes</groupId>
<artifactId>sudoc</artifactId>
<version>1.0.4</version>
<version>1.0.5-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sudoc</name>
<description>webservices de récupération de ppns dans le sudoc</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ public List<String> isbnToPpn(String isbn) throws UncategorizedSQLException {
}


public String baconProvider035(Integer provider) throws SQLRecoverableException, UncategorizedSQLException {
StringBuilder request = new StringBuilder("SELECT AUTORITES.BACON_PROVIDER_035_JSON(");
request.append(provider);
request.append(") as data_xml from DUAL");
return baseXmlJdbcTemplate.queryForObject(request.toString(), String.class);
}


public List<String> doiToPpn(String doi) throws UncategorizedSQLException {
StringBuilder request = new StringBuilder("SELECT distinct ppn from AUTORITES.biblio_table_fouretout where cle1='DOI' and cle2='");
request.append(doi.toLowerCase());
Expand Down
28 changes: 11 additions & 17 deletions src/main/java/fr/abes/sudoc/controller/SudocController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,21 @@
import fr.abes.sudoc.exception.IllegalPpnException;
import fr.abes.sudoc.exception.ZoneNotFoundException;
import fr.abes.sudoc.service.*;
import fr.abes.sudoc.utils.ExecutionTime;
import fr.abes.sudoc.utils.TYPE_ID;
import fr.abes.sudoc.utils.TYPE_SUPPORT;
import fr.abes.sudoc.utils.Utilitaire;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Slf4j
@RestController
@RequestMapping("/api/v1")
public class SudocController {


private final IdentifiantFactory factory;

private final SudocService service;
Expand All @@ -55,10 +49,10 @@ public ResultWsDto onlineIdentifier2Ppn(@PathVariable String type, @PathVariable
TYPE_ID enumType = Utilitaire.getEnumFromString(type);
IIdentifiantService service = factory.getService(enumType);
if (service.checkFormat(onlineIdentifier)) {
log.debug("Recherche des ppn pour l'identifiant onlineIdentifier n° " + onlineIdentifier + " avec le service " + enumType);
log.debug("Recherche des ppn pour l'identifiant onlineIdentifier n° {} avec le service {}", onlineIdentifier, enumType);
List<String> listPpn = service.getPpnFromIdentifiant(onlineIdentifier);
for (String ppn : listPpn) {
log.debug("onlineIdentifier n° " + onlineIdentifier + " <-> ppn n° " + ppn);
log.debug("onlineIdentifier n° {} <-> ppn n° {}", onlineIdentifier, ppn);
feedResultatWithNotice(resultat, providerDto, ppn);
}
}
Expand All @@ -68,7 +62,7 @@ public ResultWsDto onlineIdentifier2Ppn(@PathVariable String type, @PathVariable
} catch (IllegalStateException ex) {
throw new IllegalArgumentException("Le type " + type + " est incorrect. Les types acceptés sont : monograph, serial");
} catch (IOException ex) {
log.error("erreur dans la récupération de la notice correspondant à l'identifiant " + onlineIdentifier);
log.error("erreur dans la récupération de la notice correspondant à l'online identifier {}", onlineIdentifier);
throw new IOException(ex);
}
return resultat;
Expand All @@ -84,9 +78,9 @@ public ResultWsDto printIdentifier2Ppn(@PathVariable String type, @PathVariable
TYPE_ID enumType = Utilitaire.getEnumFromString(type);
IIdentifiantService service = factory.getService(enumType);
if (service.checkFormat(printIdentifier)) {
log.debug("Recherche des ppn pour l'identifiant printIdentifier n° " + printIdentifier + " avec le service " + enumType);
log.debug("Recherche des ppn pour l'identifiant printIdentifier n° {} avec le service {}", printIdentifier, enumType);
for (String ppn : service.getPpnFromIdentifiant(printIdentifier)) {
log.debug("printIdentifier n° " + printIdentifier + " <-> ppn n° " + ppn);
log.debug("printIdentifier n° {} <-> ppn n° {}", printIdentifier, ppn);
NoticeXml notice = noticeService.getNoticeByPpn(ppn);
if (!notice.isDeleted()) {
if (notice.isNoticeImprimee()) {
Expand Down Expand Up @@ -127,7 +121,7 @@ public ResultWsDto printIdentifier2Ppn(@PathVariable String type, @PathVariable
} catch (IllegalStateException ex) {
throw new IllegalArgumentException("Le type " + type + " est incorrect. Les types acceptés sont : monograph, serial");
} catch (IOException ex) {
log.error("erreur dans la récupération de la notice correspondant à l'identifiant " + printIdentifier);
log.error("erreur dans la récupération de la notice correspondant à au print identifier {}", printIdentifier);
throw new IOException(ex);
}
}
Expand All @@ -141,21 +135,21 @@ public ResultWsDto doiIdentifier2Ppn(@RequestParam(name = "doi") String doi_iden
try {
IIdentifiantService service = factory.getService(TYPE_ID.DOI);
if (service.checkFormat(doi_identifier)) {
log.debug("Recherche des ppn pour l'identifiant doi_identifier n° " + doi_identifier + " avec le service DOI");
log.debug("Recherche des ppn pour l'identifiant doi_identifier n° {} avec le service DOI", doi_identifier);
for(String ppn : service.getPpnFromIdentifiant(doi_identifier) ) {
log.debug("doi_identifier n° " + doi_identifier + " <-> ppn n° " + ppn);
log.debug("doi_identifier n° {} <-> ppn n° {}", doi_identifier, ppn);
feedResultatWithNotice(resultat, providerDto, ppn);
}
} else {
throw new IllegalArgumentException("Le DOI n'est pas au bon format");
}
} catch (IOException ex) {
log.error("Erreur dans la récupération de la notice correspondant à l'identifiant");
log.error("Erreur dans la récupération de la notice correspondant au doi {}", doi_identifier);
throw new IOException(ex);
} catch (ZoneNotFoundException e) {
throw new IOException(e.getMessage());
} catch (IllegalPpnException e) {
log.info("Aucune notice ne correspond à l'identifiant " + doi_identifier);
log.info("Aucune notice ne correspond au doi {}", doi_identifier);
//res.addErreur("Aucune notice ne correspond à l'identifiant " + doi_identifier);
}
return resultat;
Expand Down Expand Up @@ -189,7 +183,7 @@ public ResultWsDto datToPpn(@Valid @RequestBody SearchDatWebDto request) throws
}
try {
for (String ppn : service.getPpnFromDat(request.getDate(), request.getAuteur(), request.getTitre())) {
log.debug("dat2ppn : date : " + request.getDate() + " / auteur : " + request.getAuteur() + " / titre : " + request.getTitre() + " <-> ppn n° " + ppn);
log.debug("dat2ppn : date : {} / auteur : {} / titre : {} <-> ppn n° {}", request.getDate(), request.getAuteur(), request.getTitre(), ppn);
feedResultatWithNotice(resultat, providerDto, ppn);
}
} catch (CBSException | ZoneNotFoundException ex) {
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/fr/abes/sudoc/dto/provider035/BaconDto.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/java/fr/abes/sudoc/dto/provider035/ElementDto.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/fr/abes/sudoc/dto/provider035/QueryDto.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/java/fr/abes/sudoc/dto/provider035/ResultDto.java

This file was deleted.

This file was deleted.

20 changes: 20 additions & 0 deletions src/main/java/fr/abes/sudoc/entity/Provider035.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.abes.sudoc.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data;

import java.io.Serializable;

@Entity
@Data
@Table(name = "PROVIDER_035", schema = "BACON")
public class Provider035 implements Serializable {
@Id
@Column(name = "IDT_PROVIDER")
private Integer id;
@Column(name = "VALEUR_035")
private String valeur;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package fr.abes.sudoc.repository;

import fr.abes.sudoc.entity.Provider035;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface Provider035Repository extends JpaRepository<Provider035, Integer> {
}
4 changes: 3 additions & 1 deletion src/main/java/fr/abes/sudoc/service/DoiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public List<String> getPpnFromIdentifiant(String doi) throws IOException, Illega
if (result.size() != 1) {
throw new IllegalPpnException("Plusieurs résultats à la recherche sur doi " + doi);
} else {
return Collections.singletonList(result.get(0));
List<String> retour = new ArrayList<>();
retour.add(result.get(0));
return retour;
}
} catch (UncategorizedSQLException ex) {
throw new IOException("Incident technique lors de l'accès à la base de données");
Expand Down
60 changes: 14 additions & 46 deletions src/main/java/fr/abes/sudoc/service/ProviderService.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
package fr.abes.sudoc.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.abes.sudoc.component.BaseXmlFunctionsCaller;
import fr.abes.sudoc.dto.provider.ElementDto;
import fr.abes.sudoc.dto.provider035.ResultProvider035Dto;
import fr.abes.sudoc.entity.Provider;
import fr.abes.sudoc.entity.Provider035;
import fr.abes.sudoc.entity.notice.NoticeXml;
import fr.abes.sudoc.repository.Provider035Repository;
import fr.abes.sudoc.repository.ProviderRepository;
import fr.abes.sudoc.utils.ExecutionTime;
import fr.abes.sudoc.utils.Utilitaire;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.sql.SQLRecoverableException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
public class ProviderService {

private final BaseXmlFunctionsCaller caller;

private final ObjectMapper objectMapper;

private final ProviderRepository providerRepository;

private final Provider035Repository provider035Repository;


@Cacheable("providerCache")
public Optional<ElementDto> getProviderDisplayName(Optional<String> shortname) {
Expand All @@ -49,46 +38,25 @@ public Optional<ElementDto> getProviderDisplayName(Optional<String> shortname) {
return providerDisplayName;
}


public List<String> getProviderFor035(Integer provider) throws IOException {
List<String> listValeurs = new ArrayList<>();
try {
ResultProvider035Dto result = objectMapper.readValue(caller.baconProvider035(provider), ResultProvider035Dto.class);
if (result.getBacon().getQuery().getResult() != null) {
String valeur035 = result.getBacon().getQuery().getResult().getElements().getValeur035();
if (valeur035 != null) {
listValeurs.addAll(Arrays.stream(valeur035.split("\\|")).toList());
}
}
} catch (JsonProcessingException ex) {
throw new IOException("Impossible de récupérer les ppns correspondant à cet identifiant");
} catch (SQLRecoverableException ex) {
throw new IOException("Incident technique lors de l'accès à la base de données");
}
return listValeurs;
public String getProviderFor035(Integer provider) {
Optional<Provider035> valeur035Opt = provider035Repository.findById(provider);
return valeur035Opt.map(Provider035::getValeur).orElse(null);
}

public boolean checkProviderDansNoticeGeneral(Optional<ElementDto> providerDisplayName, NoticeXml notice) throws IOException {
if (providerDisplayName.isPresent()) {
return this.checkProviderDansNotice(providerDisplayName.get().getDisplayName(), notice)
|| this.checkProviderDansNotice(providerDisplayName.get().getProvider(), notice)
|| this.checkProviderIn035(providerDisplayName.get().getIdProvider(), notice);
}
return true;
return providerDisplayName.map(elementDto -> this.checkProviderDansNotice(elementDto.getDisplayName(), notice)
|| this.checkProviderDansNotice(elementDto.getProvider(), notice)
|| this.checkProviderIn035(elementDto.getIdProvider(), notice)).orElse(true);
}

private boolean checkProviderDansNotice(String provider, NoticeXml notice) {
return notice.checkProviderInZone(provider, "210", "c")
|| notice.checkProviderInZone(provider, "214", "c");
}

private boolean checkProviderIn035(Integer providerIdt, NoticeXml notice) throws IOException {
List<String> providers035 = this.getProviderFor035(providerIdt);
for (String provider035 : providers035) {
if (notice.checkProviderIn035a(provider035)) {
return true;
}
}
return false;
private boolean checkProviderIn035(Integer providerIdt, NoticeXml notice) {
String provider035 = this.getProviderFor035(providerIdt);
return provider035 != null && notice.checkProviderIn035a(provider035);

}
}
8 changes: 5 additions & 3 deletions src/main/java/fr/abes/sudoc/service/SudocService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import fr.abes.cbs.process.ProcessCBS;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -41,11 +40,14 @@ public List<String> getPpnFromDat(Integer annee, String auteur, String titre) th
if (auteur != null) {
this.query = "tno t ; che aut " + auteur + " et mti " + titre;
} else {
this.query = "tno t ; che mti " + titre;
if (titre != null)
this.query = "tno t ; che mti " + titre;
else return new ArrayList<>();

}
}

log.debug("requête : " + this.query);
log.debug("requête : {}", this.query);
cbs.search(this.query);
return switch (cbs.getNbNotices()) {
case 0 -> new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/fr/abes/sudoc/service/IsbnServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void checkFormatIsbn13Characters() {
Assertions.assertTrue(isbnService.checkFormat(isbn2));

String isbn3 = "123-45-67-891-010";
Assertions.assertTrue(isbnService.checkFormat(isbn3));
Assertions.assertFalse(isbnService.checkFormat(isbn3));

String isbn4 = "123--45-67-891-010";
Assertions.assertFalse(isbnService.checkFormat(isbn4));
Expand Down
Loading

0 comments on commit 1dd4089

Please sign in to comment.