Skip to content

Commit

Permalink
Merge pull request #91 from abes-esr/CDE-434-sudoc-api-corriger-les-tu
Browse files Browse the repository at this point in the history
Cde 434 sudoc api corriger les tu
  • Loading branch information
SamuelQuetin authored Sep 5, 2024
2 parents b8ec099 + 4605512 commit ac4670f
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 170 deletions.
36 changes: 19 additions & 17 deletions src/main/java/fr/abes/sudoc/component/BaseXmlFunctionsCaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import fr.abes.sudoc.utils.ExecutionTime;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.annotations.ColumnTransformer;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.UncategorizedSQLException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.sql.SQLRecoverableException;
import java.util.List;

@Slf4j
@Component
Expand All @@ -19,25 +21,22 @@ public BaseXmlFunctionsCaller(JdbcTemplate baseXmlJdbcTemplate) {
}

@ExecutionTime
@ColumnTransformer(read = "XMLSERIALIZE (CONTENT data_xml as CLOB)", write = "NULLSAFE_XMLTYPE(?)")
public String issnToPpn(String issn) throws SQLRecoverableException, UncategorizedSQLException {
StringBuilder request = new StringBuilder("SELECT AUTORITES.ISSN2PPNJSON('");
public List<String> issnToPpn(String issn) throws UncategorizedSQLException {
StringBuilder request = new StringBuilder("SELECT distinct ppn from AUTORITES.biblio_table_fouretout where cle1='ISSN' and cle2='");
request.append(issn);
request.append("') as data_xml from DUAL");
return baseXmlJdbcTemplate.queryForObject(request.toString(), String.class);
request.append("'");
return baseXmlJdbcTemplate.queryForList(request.toString(), String.class);
}

@ExecutionTime
@ColumnTransformer(read = "XMLSERIALIZE (CONTENT data_xml as CLOB)", write = "NULLSAFE_XMLTYPE(?)")
public String isbnToPpn(String isbn) throws SQLRecoverableException, UncategorizedSQLException {
StringBuilder request = new StringBuilder("SELECT AUTORITES.ISBN2PPNJSON('");
request.append(isbn);
request.append("') as data_xml from DUAL");
return baseXmlJdbcTemplate.queryForObject(request.toString(), String.class);
public List<String> isbnToPpn(String isbn) throws UncategorizedSQLException {
StringBuilder request = new StringBuilder("SELECT distinct ppn from AUTORITES.biblio_table_fouretout where cle1='ISBN' and cle2='");
request.append(isbn);
request.append("'");
return baseXmlJdbcTemplate.queryForList(request.toString(), String.class);
}

@ExecutionTime
@ColumnTransformer(read = "XMLSERIALIZE (CONTENT data_xml as CLOB)", write = "NULLSAFE_XMLTYPE(?)")
public String baconProvider035(Integer provider) throws SQLRecoverableException, UncategorizedSQLException {
StringBuilder request = new StringBuilder("SELECT AUTORITES.BACON_PROVIDER_035_JSON(");
request.append(provider);
Expand All @@ -46,11 +45,14 @@ public String baconProvider035(Integer provider) throws SQLRecoverableException,
}

@ExecutionTime
@ColumnTransformer(read = "XMLSERIALIZE (CONTENT data_xml as CLOB)", write = "NULLSAFE_XMLTYPE(?)")
public String doiToPpn(String doi) throws SQLRecoverableException, UncategorizedSQLException {
StringBuilder request = new StringBuilder("select XMLTRANSFORM(XMLROOT(XMLElement(\"sudoc\",AUTORITES.DOI2PNN('");
request.append(doi);
request.append("')),version '1.0\" encoding=\"UTF-8'),lexsl) from xsl_html where idxsl='JSON'");
public String doiToPpn(String doi) throws UncategorizedSQLException, EmptyResultDataAccessException {
StringBuilder request = new StringBuilder("select a.ppn from autorites.biblio_table_FRBR_0xx a where ");
request.append("upper(SUBSTR(a.datas,1,50)) = '");
request.append(doi.toUpperCase());
request.append("' and a.tag='017$a' ");
request.append("and a.id in (select /*+ no_index(b BIBLIO_TABLE_FRBR_0XX_IDX_DATA) */ id from autorites.biblio_table_FRBR_0xx b where ");
request.append("a.id=b.id and ");
request.append("b.tag='017$2' and SUBSTR(b.datas,1,50)='DOI' and a.POSFIELD=b.POSFIELD and b.POSSUBFIELD='2')");
return baseXmlJdbcTemplate.queryForObject(request.toString(), String.class);
}
}
65 changes: 2 additions & 63 deletions src/main/java/fr/abes/sudoc/configuration/BaseXMLOracleConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,69 +19,8 @@

@Configuration
@EnableCaching
@EnableJpaRepositories(transactionManagerRef = "baseXmlTransactionManager",
entityManagerFactoryRef = "baseXmlEntityManager",
basePackages = "fr.abes.sudoc.repository")
@EnableJpaRepositories(
basePackages = {"fr.abes.sudoc.repository", "fr.abes.sudoc.entity"})
public class BaseXMLOracleConfig {
@Value("${spring.jpa.basexml.database-platform}")
protected String platform;
@Value("${spring.jpa.basexml.hibernate.ddl-auto}")
protected String ddlAuto;
@Value("${spring.jpa.basexml.generate-ddl}")
protected boolean generateDdl;
@Value("${spring.jpa.basexml.properties.hibernate.dialect}")
protected String dialect;
@Value("${spring.jpa.basexml.show-sql}")
private boolean showsql;
@Value("${spring.sql.basexml.init.mode}")
private String initMode;

@Bean
@ConfigurationProperties(prefix = "spring.datasource.basexml")
public DataSource baseXmlDataSource() {
return DataSourceBuilder.create().build();
}

@Bean
public LocalContainerEntityManagerFactoryBean baseXmlEntityManager() {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(baseXmlDataSource());
em.setPackagesToScan(
new String[] { "fr.abes.sudoc.entity" });
configHibernate(em, platform, showsql, dialect, ddlAuto, generateDdl, initMode);
return em;
}

private void configHibernate(LocalContainerEntityManagerFactoryBean em, String platform, boolean showsql, String dialect, String ddlAuto, boolean generateDdl, String initMode) {
HibernateJpaVendorAdapter vendorAdapter
= new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(generateDdl);
vendorAdapter.setShowSql(showsql);
vendorAdapter.setDatabasePlatform(platform);
em.setJpaVendorAdapter(vendorAdapter);
HashMap<String, Object> properties = new HashMap<>();
properties.put("hibernate.format_sql", true);
properties.put("hibernate.hbm2ddl.auto", ddlAuto);
properties.put("hibernate.dialect", dialect);
properties.put("logging.level.org.hibernate", "DEBUG");
properties.put("hibernate.type", "trace");
properties.put("spring.sql.init.mode", initMode);
em.setJpaPropertyMap(properties);
}

@Bean
public PlatformTransactionManager baseXmlTransactionManager() {
JpaTransactionManager transactionManager
= new JpaTransactionManager();
transactionManager.setEntityManagerFactory(
baseXmlEntityManager().getObject());
return transactionManager;
}

@Bean
public JdbcTemplate baseXmlJdbcTemplate() {
return new JdbcTemplate(baseXmlDataSource());
}

}
15 changes: 3 additions & 12 deletions src/main/java/fr/abes/sudoc/controller/SudocController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class SudocController {

@ExecutionTime
@GetMapping(value = {"/online_identifier_2_ppn/{type}/{onlineIdentifier}", "/online_identifier_2_ppn/{type}/{onlineIdentifier}/{provider}"}, produces = MediaType.APPLICATION_JSON_VALUE)
public ResultWsDto onlineIdentifier2Ppn(@PathVariable String type, @PathVariable String onlineIdentifier, @PathVariable(required = false) Optional<String> provider) throws IOException, ZoneNotFoundException {
public ResultWsDto onlineIdentifier2Ppn(@PathVariable String type, @PathVariable String onlineIdentifier, @PathVariable(required = false) Optional<String> provider) throws IOException, ZoneNotFoundException, IllegalPpnException {
log.debug("-----------------------------------------------------------");
log.debug("ONLINE IDENTIFIER 2 PPN");
ResultWsDto resultat = new ResultWsDto();
Expand All @@ -64,16 +64,13 @@ public ResultWsDto onlineIdentifier2Ppn(@PathVariable String type, @PathVariable
} catch (IOException ex) {
log.error("erreur dans la récupération de la notice correspondant à l'identifiant " + onlineIdentifier);
throw new IOException(ex);
} catch (IllegalPpnException ex) {
log.warn("Impossible de retrouver une notice correspondant à l'identifiant " + onlineIdentifier);
// throw new IOException(ex); // Pas besoin de throw, il y a juste pas de ppn assosier à cet onlineId
}
return resultat;
}

@ExecutionTime
@GetMapping(value = {"/print_identifier_2_ppn/{type}/{printIdentifier}","/print_identifier_2_ppn/{type}/{printIdentifier}/{provider}"}, produces = MediaType.APPLICATION_JSON_VALUE)
public ResultWsDto printIdentifier2Ppn(@PathVariable String type, @PathVariable String printIdentifier, @PathVariable Optional<String> provider) throws IOException, ZoneNotFoundException {
public ResultWsDto printIdentifier2Ppn(@PathVariable String type, @PathVariable String printIdentifier, @PathVariable Optional<String> provider) throws IOException, ZoneNotFoundException, IllegalPpnException {
log.debug("-----------------------------------------------------------");
log.debug("PRINT IDENTIFIER 2 PPN");
ResultWsDto resultat = new ResultWsDto();
Expand Down Expand Up @@ -127,16 +124,12 @@ public ResultWsDto printIdentifier2Ppn(@PathVariable String type, @PathVariable
} catch (IOException ex) {
log.error("erreur dans la récupération de la notice correspondant à l'identifiant " + printIdentifier);
throw new IOException(ex);
} catch (IllegalPpnException ex){
log.warn("Impossible de retrouver une notice correspondant à l'identifiant " + printIdentifier);
}
return resultat;
}

@ExecutionTime
@GetMapping(value = {"/doi_identifier_2_ppn"}, produces = MediaType.APPLICATION_JSON_VALUE)
public ResultWsDto doiIdentifier2Ppn(@RequestParam(name = "doi") String doi_identifier, @RequestParam(name = "provider") Optional<String> provider) throws IOException {
log.debug("-----------------------------------------------------------");
public ResultWsDto doiIdentifier2Ppn(@RequestParam(name = "doi") String doi_identifier, @RequestParam(name = "provider") Optional<String> provider) throws IOException, IllegalPpnException {
log.debug("DOI IDENTIFIER 2 PPN");
ResultWsDto resultat = new ResultWsDto();
Optional<ElementDto> providerDto = this.providerService.getProviderDisplayName(provider);
Expand All @@ -154,8 +147,6 @@ public ResultWsDto doiIdentifier2Ppn(@RequestParam(name = "doi") String doi_iden
} catch (IOException ex) {
log.error("Erreur dans la récupération de la notice correspondant à l'identifiant");
throw new IOException(ex);
} catch (IllegalPpnException e) {
throw new IOException("Aucun identifiant ne correspond à la notice");
} catch (ZoneNotFoundException e) {
throw new IOException(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ protected ResponseEntity<Object> handleZoneNotFoundException(ZoneNotFoundExcepti
return buildResponseEntity(new ApiReturnError(HttpStatus.BAD_REQUEST, error, ex));
}

@ExceptionHandler(IllegalPpnException.class)
protected ResponseEntity<Object> handleIllegalPpnException(IllegalPpnException ex) {
String warn = ex.getMessage();
log.warn(warn);
return buildResponseEntity(new ApiReturnError(HttpStatus.NO_CONTENT, warn, ex));
}

@ExceptionHandler(IOException.class)
protected ResponseEntity<Object> handleIOException(IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fr.abes.sudoc.exception;

public class IllegalPpnException extends Throwable {
public class IllegalPpnException extends Exception {
public IllegalPpnException(String s) {
super(s);
}
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/fr/abes/sudoc/service/DoiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
import fr.abes.sudoc.component.BaseXmlFunctionsCaller;
import fr.abes.sudoc.exception.IllegalPpnException;
import fr.abes.sudoc.utils.Utilitaire;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.UncategorizedSQLException;
import org.springframework.stereotype.Service;

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

@Service
Expand All @@ -25,15 +29,15 @@ public boolean checkFormat(String doi) {
return doi != null && doi.matches(doiPattern);
}

public List<String> getPpnFromIdentifiant(String doi) throws IllegalPpnException, IOException {
try{
return Utilitaire.parseJsonDoi(caller.doiToPpn(doi));
} catch (UncategorizedSQLException ex){
throw new IllegalPpnException("Aucune notice ne correspond à la recherche");
} catch (JsonProcessingException ex) {
throw new IOException("Impossible de récupérer les ppns correspondant à cet identifiant");
} catch (SQLRecoverableException ex) {
@Override
public List<String> getPpnFromIdentifiant(String doi) throws IOException, IllegalPpnException {
try {

return Collections.singletonList(caller.doiToPpn(doi));
} catch (UncategorizedSQLException ex) {
throw new IOException("Incident technique lors de l'accès à la base de données");
} catch (EmptyResultDataAccessException ex) {
throw new IllegalPpnException("Aucune notice ne correspond à la recherche");
}
}

Expand Down
10 changes: 3 additions & 7 deletions src/main/java/fr/abes/sudoc/service/IsbnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ public boolean checkFormat(String isbn) {
}

@Override
public List<String> getPpnFromIdentifiant(String isbn) throws IllegalPpnException, IOException {
public List<String> getPpnFromIdentifiant(String isbn) throws IOException {
try{
return Utilitaire.parseJson(caller.isbnToPpn(isbn));
} catch (UncategorizedSQLException ex){
throw new IllegalPpnException("Aucune notice ne correspond à la recherche");
} catch (JsonProcessingException ex) {
throw new IOException("Impossible de récupérer les ppns correspondant à cet identifiant");
} catch (SQLRecoverableException ex) {
return caller.isbnToPpn(isbn.replace("-", ""));
} catch (UncategorizedSQLException ex) {
throw new IOException("Incident technique lors de l'accès à la base de données");
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/fr/abes/sudoc/service/IssnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.IOException;
import java.sql.SQLRecoverableException;
import java.util.Collections;
import java.util.List;

@Service
Expand All @@ -25,14 +26,10 @@ public boolean checkFormat(String issn) {
}

@Override
public List<String> getPpnFromIdentifiant(String issn) throws IllegalPpnException, IOException {
public List<String> getPpnFromIdentifiant(String issn) throws IOException {
try{
return Utilitaire.parseJson(caller.issnToPpn(issn));
} catch (UncategorizedSQLException ex){
throw new IllegalPpnException("Aucune notice ne correspond à la recherche");
} catch (JsonProcessingException ex) {
throw new IOException("Impossible de récupérer les ppns correspondant à cet identifiant");
} catch (SQLRecoverableException ex) {
return caller.issnToPpn(issn.replace("-", ""));
} catch (UncategorizedSQLException ex) {
throw new IOException("Incident technique lors de l'accès à la base de données");
}
}
Expand Down
24 changes: 14 additions & 10 deletions src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
spring.datasource.basexml.jdbcurl=
spring.datasource.basexml.username=
spring.datasource.basexml.password=
spring.datasource.basexml.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.hikari.maximum-pool-size=100
spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.idle-timeout=60000

spring.jpa.basexml.generate-ddl=false
spring.jpa.basexml.show-sql=false
spring.jpa.basexml.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect
spring.jpa.basexml.hibernate.ddl-auto=none
spring.jpa.basexml.database-platform=org.hibernate.dialect.OracleDialect
spring.sql.basexml.init.mode=never
spring.jpa.generate-ddl=false
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.database-platform=org.hibernate.dialect.OracleDialect
spring.sql.init.mode=never

# Access CBS
sudoc.serveur=
Expand Down
24 changes: 14 additions & 10 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
spring.datasource.basexml.jdbcurl=
spring.datasource.basexml.username=
spring.datasource.basexml.password=
spring.datasource.basexml.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.hikari.maximum-pool-size=100
spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.idle-timeout=60000

spring.jpa.basexml.generate-ddl=false
spring.jpa.basexml.show-sql=false
spring.jpa.basexml.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect
spring.jpa.basexml.hibernate.ddl-auto=none
spring.jpa.basexml.database-platform=org.hibernate.dialect.OracleDialect
spring.sql.basexml.init.mode=never
spring.jpa.generate-ddl=false
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.database-platform=org.hibernate.dialect.OracleDialect
spring.sql.init.mode=never

# Access CBS
sudoc.serveur=
Expand Down
24 changes: 14 additions & 10 deletions src/main/resources/application-test.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
spring.datasource.basexml.jdbcurl=
spring.datasource.basexml.username=
spring.datasource.basexml.password=
spring.datasource.basexml.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.hikari.maximum-pool-size=100
spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.idle-timeout=60000

spring.jpa.basexml.generate-ddl=false
spring.jpa.basexml.show-sql=false
spring.jpa.basexml.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect
spring.jpa.basexml.hibernate.ddl-auto=none
spring.jpa.basexml.database-platform=org.hibernate.dialect.OracleDialect
spring.sql.basexml.init.mode=never
spring.jpa.generate-ddl=false
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.database-platform=org.hibernate.dialect.OracleDialect
spring.sql.init.mode=never

# Access CBS
sudoc.serveur=
Expand Down
Loading

0 comments on commit ac4670f

Please sign in to comment.