From 2946f46c3724b47c516f1c5d9cdaf5cab707d871 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Mon, 11 Sep 2023 07:03:37 +0200 Subject: [PATCH] Fix gathering content providers by search --- .../org/argeo/cms/acr/CmsContentSession.java | 15 +++++++------ .../src/org/argeo/cms/acr/MountManager.java | 21 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/org.argeo.cms/src/org/argeo/cms/acr/CmsContentSession.java b/org.argeo.cms/src/org/argeo/cms/acr/CmsContentSession.java index 290552f64..832054e03 100644 --- a/org.argeo.cms/src/org/argeo/cms/acr/CmsContentSession.java +++ b/org.argeo.cms/src/org/argeo/cms/acr/CmsContentSession.java @@ -206,18 +206,21 @@ class CmsContentSession implements ProvidedSession, UuidIdentified { NavigableMap contentProviders = contentRepository.getMountManager() .findContentProviders(scopePath); for (Map.Entry contentProvider : contentProviders.entrySet()) { + assert scopePath.startsWith(contentProvider.getKey()) + : "scopePath=" + scopePath + ", contentProvider path=" + contentProvider.getKey(); // TODO deal with depth String relPath; - if (scopePath.startsWith(contentProvider.getKey())) { - relPath = scopePath.substring(contentProvider.getKey().length()); - } else { - relPath = null; - } +// if (scopePath.startsWith(contentProvider.getKey())) { + relPath = scopePath.substring(contentProvider.getKey().length() + 1, scopePath.length()); +// } +// else { +// relPath = null; +// } SearchPartition searchPartition = new SearchPartition(s, relPath, contentProvider.getValue()); searchPartitions.put(contentProvider.getKey(), searchPartition); } } - if(searchPartitions.isEmpty()) + if (searchPartitions.isEmpty()) return Stream.empty(); return StreamSupport.stream(new SearchPartitionsSpliterator(searchPartitions), true); } diff --git a/org.argeo.cms/src/org/argeo/cms/acr/MountManager.java b/org.argeo.cms/src/org/argeo/cms/acr/MountManager.java index 75ca427c7..90d621b76 100644 --- a/org.argeo.cms/src/org/argeo/cms/acr/MountManager.java +++ b/org.argeo.cms/src/org/argeo/cms/acr/MountManager.java @@ -51,10 +51,10 @@ class MountManager { synchronized ContentProvider findContentProvider(String path) { // if (ContentUtils.EMPTY.equals(path)) // return partitions.firstEntry().getValue(); - Map.Entry entry = partitions.floorEntry(path); - if (entry == null) - throw new IllegalArgumentException("No entry provider found for path '" + path + "'"); - String mountPath = entry.getKey(); + Map.Entry floorEntry = partitions.floorEntry(path); + if (floorEntry == null) + throw new IllegalArgumentException("No floor entry provider found for path '" + path + "'"); + String mountPath = floorEntry.getKey(); if (!path.startsWith(mountPath)) { // FIXME make it more robust and find when there is no content provider String[] parent = ContentUtils.getParentPath(path); @@ -62,15 +62,22 @@ class MountManager { // throw new IllegalArgumentException("Path " + path + " doesn't have a content // provider"); } - ContentProvider contentProvider = entry.getValue(); + ContentProvider contentProvider = floorEntry.getValue(); assert mountPath.equals(contentProvider.getMountPath()); return contentProvider; } - /** All content provider under this path. */ + /** All content providers under this path. */ synchronized NavigableMap findContentProviders(String path) { + Map.Entry floorEntry = partitions.floorEntry(path); + if (floorEntry == null) + throw new IllegalArgumentException("No floor entry provider found for path '" + path + "'"); + // we first find the parent provider + String parentProviderPath = floorEntry.getKey(); + // then gather all sub-providers NavigableMap res = new TreeMap<>(); - tail: for (Map.Entry provider : partitions.tailMap(path).entrySet()) { + res.put(floorEntry.getKey(), floorEntry.getValue()); + tail: for (Map.Entry provider : partitions.tailMap(parentProviderPath).entrySet()) { if (!provider.getKey().startsWith(path)) break tail; res.put(provider.getKey(), provider.getValue()); -- 2.30.2