diff --git a/src/main/java/fr/abes/sudoc/component/BaseXmlFunctionsCaller.java b/src/main/java/fr/abes/sudoc/component/BaseXmlFunctionsCaller.java index 165185b..a3dca1b 100644 --- a/src/main/java/fr/abes/sudoc/component/BaseXmlFunctionsCaller.java +++ b/src/main/java/fr/abes/sudoc/component/BaseXmlFunctionsCaller.java @@ -45,7 +45,7 @@ public String baconProvider035(Integer provider) throws SQLRecoverableException, } - public String doiToPpn(String doi) throws UncategorizedSQLException, EmptyResultDataAccessException { + public List doiToPpn(String doi) throws UncategorizedSQLException { 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()); @@ -53,6 +53,6 @@ public String doiToPpn(String doi) throws UncategorizedSQLException, EmptyResult 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); + return baseXmlJdbcTemplate.queryForList(request.toString(), String.class); } } diff --git a/src/main/java/fr/abes/sudoc/service/DoiService.java b/src/main/java/fr/abes/sudoc/service/DoiService.java index 514fadd..6277970 100644 --- a/src/main/java/fr/abes/sudoc/service/DoiService.java +++ b/src/main/java/fr/abes/sudoc/service/DoiService.java @@ -32,12 +32,17 @@ public boolean checkFormat(String doi) { @Override public List getPpnFromIdentifiant(String doi) throws IOException, IllegalPpnException { try { - return Collections.singletonList(caller.doiToPpn(doi)); + List result = caller.doiToPpn(doi); + if (result.isEmpty()) + throw new IllegalPpnException("Aucune notice ne correspond à la recherche sur le doi " + doi); + else + if (result.size() != 1) { + throw new IllegalPpnException("Plusieurs résultats à la recherche sur doi " + doi); + } else { + return Collections.singletonList(result.get(0)); + } } 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"); } } - }