diff --git a/commons/commons-api/src/main/java/fr/gouv/vitamui/commons/api/utils/OntologyServiceReader.java b/commons/commons-api/src/main/java/fr/gouv/vitamui/commons/api/utils/OntologyServiceReader.java index 6c0be40bc3f..ed734cc8930 100644 --- a/commons/commons-api/src/main/java/fr/gouv/vitamui/commons/api/utils/OntologyServiceReader.java +++ b/commons/commons-api/src/main/java/fr/gouv/vitamui/commons/api/utils/OntologyServiceReader.java @@ -41,7 +41,6 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -55,13 +54,13 @@ public class OntologyServiceReader { private static final ObjectMapper objectMapper = new ObjectMapper(); - public static List readExternalOntologiesFromFile(Integer tenantId, String ontologiesFilePath) + public static List readExternalOntologiesFromFile(Integer tenantId, String ontologiesFilePath) throws IOException { - List ontologyDtoList = new ArrayList<>(); + List ontologyDtoList; LOGGER.debug("Read ontologies list from file {} for tenant {}", ontologiesFilePath, tenantId); - File file = new File( ontologiesFilePath); + File file = new File(ontologiesFilePath); StringBuilder resultStringBuilder = new StringBuilder(); try (BufferedReader bufferedReader @@ -71,18 +70,19 @@ public static List readExternalOntologiesFromFile(Integer tenantId, resultStringBuilder.append(line).append("\n"); } } catch (FileNotFoundException notFoundException) { - LOGGER.error("Can not find the ontologies list file {} ", notFoundException); + LOGGER.info("No external ontologies file provided "); return Collections.emptyList(); } try { ontologyDtoList = objectMapper.readValue(resultStringBuilder.toString(), new TypeReference<>() { }); } catch (JsonProcessingException exception) { - LOGGER.error("Can not parse the ontologies file{}", exception); + LOGGER.error("Can not parse the ontologies file {}", ontologiesFilePath); return Collections.emptyList(); } - return ontologyDtoList.stream().filter(ontologyDto -> ontologyDto.getTenantIds().contains(DEFAULT_TENANT_IDENTIFIER) || + return ontologyDtoList.stream() + .filter(ontologyDto -> ontologyDto.getTenantIds().contains(DEFAULT_TENANT_IDENTIFIER) || ontologyDto.getTenantIds().contains(tenantId)) .collect(Collectors.toList()); }