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

Merge develop dans main #74

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
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
Loading