Skip to content

Commit

Permalink
Merge pull request #74 from abes-esr/develop
Browse files Browse the repository at this point in the history
Merge develop dans main
  • Loading branch information
pierre-maraval authored Feb 5, 2024
2 parents cca4415 + de4d86e commit 9e7e9ab
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/fr/abes/sudoc/service/DoiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public boolean checkFormat(String doi) {

public List<String> getPpnFromIdentifiant(String doi) throws IllegalPpnException, IOException {
try{
return Utilitaire.parseJson(caller.doiToPpn(doi));
return Utilitaire.parseJsonDoi(caller.doiToPpn(doi));
} catch (UncategorizedSQLException ex){
throw new IllegalPpnException("Aucune notice ne correspond à la recherche");
} catch (JsonProcessingException ex) {
Expand Down
34 changes: 27 additions & 7 deletions src/main/java/fr/abes/sudoc/utils/Utilitaire.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,54 @@ private static void extractPpnFromNode(List<String> listePpn, JsonNode sudocnode
JsonNode record = elements.next();
listePpn.add(record.path("ppn").asText());
}
}
else {
} else {
listePpn.add(elements.next().asText());
}
}
}

public static List<String> parseJsonDoi(String json) throws JsonProcessingException {
//la correspondance pouvant retourner plusieurs fois un ppn, on crée une multimap pour récupérer le résultat
List<String> listePpn = new ArrayList<>();
//parse de l'input json
ObjectMapper objectMapper = new ObjectMapper();
JsonNode sudocnode = objectMapper.readTree(json);
JsonNode resultsNode = sudocnode.findValue("results");
if (resultsNode != null) {
Iterator<JsonNode> elements = resultsNode.elements();
while (elements.hasNext()) {
JsonNode record = elements.next();
listePpn.add(record.findValue("ppn").asText());
}
}
return listePpn;
}


/**
* Méthode permettant de remplacer les caractères diacritiques d'une chaine par leur équivalent non diacritique
*
* @param src chaine à transformer
* @return chaine transformée
*/
public static String replaceDiacritics(String src) {
StringBuffer result = new StringBuffer();
if(src!=null && src.length()!=0) {
if (src != null && src.length() != 0) {
int index = -1;
char c;
String chars= "àâäéèêëîïôöùûüç";
String replace= "aaaeeeeiioouuuc";
for(int i=0; i<src.length(); i++) {
String chars = "àâäéèêëîïôöùûüç";
String replace = "aaaeeeeiioouuuc";
for (int i = 0; i < src.length(); i++) {
c = src.charAt(i);
if( (index=chars.indexOf(c))!=-1 )
if ((index = chars.indexOf(c)) != -1)
result.append(replace.charAt(index));
else
result.append(c);
}
}
return result.toString();
}


}

19 changes: 19 additions & 0 deletions src/test/java/fr/abes/sudoc/utils/UtilitaireTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ void testParseJson6() throws JsonProcessingException {
Assertions.assertEquals("222222222", ppns.get(3));
}

@Test
@DisplayName("parseJsonDoi : 1 seul résultat")
void testParseJsonDoi1() throws JsonProcessingException {
String json = "{\"sudoc\":{\"results\":{\"result\":{\"ppn\":\"198471483\",\"doi\":\"10.1039/9781849733458\"}}}}";
List<String> ppns = Utilitaire.parseJsonDoi(json);
Assertions.assertEquals(1, ppns.size());
Assertions.assertEquals("198471483", ppns.get(0));
}

@Test
@DisplayName("parseJsonDoi : 1 seul résultat")
void testParseJsonDoi2() throws JsonProcessingException {
String json = "{\"sudoc\":{\"results\":[{\"result\":{\"ppn\":\"224633333\",\"doi\":\"10.1002/9781118444726\"}},{\"result\":{\"ppn\":\"17886594X\",\"doi\":\"10.1002/9781118444726\"}}]}}";
List<String> ppns = Utilitaire.parseJsonDoi(json);
Assertions.assertEquals(2, ppns.size());
Assertions.assertEquals("224633333", ppns.get(0));
Assertions.assertEquals("17886594X", ppns.get(1));
}

@Test
@DisplayName("test replaceDiacritics")
void testReplaceDiacritics() {
Expand Down

0 comments on commit 9e7e9ab

Please sign in to comment.