From de27d8b4411108143e9c9312fc2dd8ac968b434b Mon Sep 17 00:00:00 2001 From: amvanbaren Date: Tue, 30 Jan 2024 13:58:53 +0200 Subject: [PATCH] Make versions endpoint case insensitive --- .../java/org/eclipse/openvsx/LocalRegistryService.java | 8 ++++---- .../repositories/ExtensionVersionJooqRepository.java | 8 ++++---- .../eclipse/openvsx/repositories/RepositoryService.java | 4 ---- .../openvsx/repositories/RepositoryServiceSmokeTest.java | 1 - 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java b/server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java index 3ab8fd014..6596fd3fc 100644 --- a/server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java +++ b/server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java @@ -121,17 +121,17 @@ public ExtensionJson getExtension(String namespace, String extensionName, String @Override public VersionsJson getVersions(String namespace, String extension, String targetPlatform, int size, int offset) { var pageRequest = PageRequest.of((offset/size), size); - var page = targetPlatform == null - ? repositories.findActiveVersionStringsSorted(namespace, extension, pageRequest) - : repositories.findActiveVersionStringsSorted(namespace, extension, targetPlatform, pageRequest); + var page = repositories.findActiveVersionStringsSorted(namespace, extension, targetPlatform, pageRequest); var json = new VersionsJson(); json.offset = (int) page.getPageable().getOffset(); json.totalSize = (int) page.getTotalElements(); + var namespaceLowerCase = namespace.toLowerCase(); + var extensionLowerCase = extension.toLowerCase(); json.versions = page.get() .collect(Collectors.toMap( version -> version, - version -> UrlUtil.createApiVersionUrl(UrlUtil.getBaseUrl(), namespace, extension, targetPlatform, version), + version -> UrlUtil.createApiVersionUrl(UrlUtil.getBaseUrl(), namespaceLowerCase, extensionLowerCase, targetPlatform, version), (v1, v2) -> v1, LinkedHashMap::new )); diff --git a/server/src/main/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepository.java b/server/src/main/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepository.java index c24be691b..40f319d18 100644 --- a/server/src/main/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepository.java +++ b/server/src/main/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepository.java @@ -81,8 +81,8 @@ public Page findActiveVersionStringsSorted(String namespace, String exte .join(EXTENSION).on(EXTENSION.ID.eq(EXTENSION_VERSION.EXTENSION_ID)) .join(NAMESPACE).on(NAMESPACE.ID.eq(EXTENSION.NAMESPACE_ID)) .where(EXTENSION_VERSION.ACTIVE.eq(true)) - .and(NAMESPACE.NAME.eq(namespace)) - .and(EXTENSION.NAME.eq(extension)); + .and(NAMESPACE.NAME.equalIgnoreCase(namespace)) + .and(EXTENSION.NAME.equalIgnoreCase(extension)); if(targetPlatform != null) { totalQuery = totalQuery.and(EXTENSION_VERSION.TARGET_PLATFORM.eq(targetPlatform)); @@ -90,8 +90,8 @@ public Page findActiveVersionStringsSorted(String namespace, String exte var conditions = new ArrayList(); conditions.add(EXTENSION_VERSION.ACTIVE.eq(true)); - conditions.add(NAMESPACE.NAME.eq(namespace)); - conditions.add(EXTENSION.NAME.eq(extension)); + conditions.add(NAMESPACE.NAME.equalIgnoreCase(namespace)); + conditions.add(EXTENSION.NAME.equalIgnoreCase(extension)); if(targetPlatform != null) { conditions.add(EXTENSION_VERSION.TARGET_PLATFORM.eq(targetPlatform)); } diff --git a/server/src/main/java/org/eclipse/openvsx/repositories/RepositoryService.java b/server/src/main/java/org/eclipse/openvsx/repositories/RepositoryService.java index c7c5550f8..247c0682c 100644 --- a/server/src/main/java/org/eclipse/openvsx/repositories/RepositoryService.java +++ b/server/src/main/java/org/eclipse/openvsx/repositories/RepositoryService.java @@ -149,10 +149,6 @@ public Page findActiveVersionsSorted(String namespace, String return extensionVersionRepo.findByTargetPlatformAndExtensionNameIgnoreCaseAndExtensionNamespaceNameIgnoreCase(targetPlatform, extension, namespace, page.withSort(VERSIONS_SORT)); } - public Page findActiveVersionStringsSorted(String namespace, String extension, PageRequest page) { - return extensionVersionJooqRepo.findActiveVersionStringsSorted(namespace, extension, null, page); - } - public Page findActiveVersionStringsSorted(String namespace, String extension, String targetPlatform, PageRequest page) { return extensionVersionJooqRepo.findActiveVersionStringsSorted(namespace, extension, targetPlatform, page); } diff --git a/server/src/test/java/org/eclipse/openvsx/repositories/RepositoryServiceSmokeTest.java b/server/src/test/java/org/eclipse/openvsx/repositories/RepositoryServiceSmokeTest.java index 409d4d8bd..b2dcfb434 100644 --- a/server/src/test/java/org/eclipse/openvsx/repositories/RepositoryServiceSmokeTest.java +++ b/server/src/test/java/org/eclipse/openvsx/repositories/RepositoryServiceSmokeTest.java @@ -178,7 +178,6 @@ void testExecuteQueries() { () -> repositories.deleteAllKeyPairs(), () -> repositories.findActiveVersionsSorted("namespaceName", "extensionName", PageRequest.ofSize(1)), () -> repositories.findActiveVersionsSorted("namespaceName", "extensionName", "targetPlatform", PageRequest.ofSize(1)), - () -> repositories.findActiveVersionStringsSorted("namespaceName", "extensionName", PageRequest.ofSize(1)), () -> repositories.findActiveVersionStringsSorted("namespaceName", "extensionName", "targetPlatform", PageRequest.ofSize(1)), () -> repositories.findVersionStringsSorted(extension, "targetPlatform", true), () -> repositories.findVersionStringsSorted(extension, "targetPlatform", true),