class PreparationService {

    public Stream<PreparationDTO> listAll(String name, String folderPath, String path, Sort sort, Order order) {
        if (path != null) {
            // Transform path argument into folder path + preparation name
            if (path.contains(PATH_SEPARATOR.toString())) {
                // Special case the path should start with /
                if (!path.startsWith(PATH_SEPARATOR.toString())) {
                    path = PATH_SEPARATOR.toString().concat(path);
                }
                folderPath = StringUtils.substringBeforeLast(path, PATH_SEPARATOR.toString());
                // Special case if the preparation is in the root folder
                if (org.apache.commons.lang3.StringUtils.isEmpty(folderPath)) {
                    folderPath = PATH_SEPARATOR.toString();
                }
                name = StringUtils.substringAfterLast(path, PATH_SEPARATOR.toString());
            } else {
                // the preparation is in the root folder
                folderPath = PATH_SEPARATOR.toString();
                name = path;
                LOGGER.warn("Using path argument without '{}'. {} filter has been transformed into {}{}.",
                        PATH_SEPARATOR, path, PATH_SEPARATOR, name);
            }
        }
        return listAll(filterPreparation().byName(name).withNameExactMatch(true).byFolderPath(folderPath), sort, order);
    }

}