Fix repository sorting order for namespaces

Previously, we only compared a concatenated string in XMLRepositoryDAO.java. This caused a wrong ordering in the back-end repository list and eventually falsely displayed elements in the front-end. 

Example:

"banana/red" (namespace "banana", name "red")
"banana.venezuela/red" (namespace "banana.venezuela", name "red")

On the back-end service, these were sorted as a string and thus in a wrong order "banana.venezuela/red" < "banana/red" (since '.&quot; is smaller than &quot;/&quot; in string comparison).

Co-authored-by: Till-André Diegeler<till-andre.diegeler@cloudogu.com>
Pushed-by: Rene Pfeuffer<rene.pfeuffer@cloudogu.com>
Committed-by: Till-André Diegeler<till-andre.diegeler@cloudogu.com>
Co-authored-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>
Pushed-by: Till-André Diegeler<till-andre.diegeler@cloudogu.com>
This commit is contained in:
Till-André Diegeler
2024-09-23 15:22:26 +02:00
parent a5d9992e65
commit 3f6337b101
4 changed files with 25 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ plugins {
id "org.sonarqube" version "3.0"
id "org.scm-manager.changelog" version "0.2.0"
id 'org.scm-manager.license' version "0.7.1"
id "com.github.hierynomus.license-report" version"0.16.1"
}
changelog {
@@ -139,6 +140,10 @@ license {
}
}
downloadLicenses {
dependencyConfiguration = "runtimeClasspath"
}
import org.gradle.util.VersionNumber
// set build props

View File

@@ -0,0 +1,2 @@
- type: fixed
description: Fix sorting error caused by some namespace/name constellations

View File

@@ -178,7 +178,7 @@ public class XmlRepositoryDAO implements RepositoryDAO {
@Override
public Collection<Repository> getAll() {
return withReadLockedMaps(() -> ImmutableList.copyOf(byNamespaceAndName.values().stream().sorted(Comparator.comparing(v -> v.getNamespaceAndName().toString().toLowerCase())).collect(Collectors.toList())));
return withReadLockedMaps(() -> ImmutableList.copyOf(byNamespaceAndName.values()));
}
@Override

View File

@@ -360,6 +360,18 @@ class XmlRepositoryDAOTest {
verify(locationResolver).updateModificationDate();
}
@Test
void shouldGetAllWithCorrectSorting() {
dao.add(createRepository("banana1", "banana", "red"));
dao.add(createRepository("banana2", "banana.venezuela", "red"));
Collection<Repository> repositories = dao.getAll();
assertThat(repositories)
.hasSize(2)
.extracting("id").containsExactly("banana1", "banana2");
}
private String getXmlFileContent(String id) {
Path storePath = metadataFile(id);
@@ -484,7 +496,11 @@ class XmlRepositoryDAOTest {
Files.copy(metadataUrl.openStream(), repositoryPath.resolve("metadata.xml"));
}
private Repository createRepository(String id, String namespace, String name) {
return new Repository(id, "xml", namespace, name);
}
private Repository createRepository(String id) {
return new Repository(id, "xml", "space", id);
return createRepository(id, "space", id);
}
}