From af1208cef48864cbd1175894b4fb35bdda8669f2 Mon Sep 17 00:00:00 2001 From: Juraj Roka Date: Fri, 28 Mar 2025 12:23:08 +0100 Subject: [PATCH 1/2] renamed property dspace.url to dspace.ui.url --- dspace-api/src/main/java/org/dspace/api/DSpaceApi.java | 2 +- .../app/rest/hdlresolver/HdlResolverRestController.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/api/DSpaceApi.java b/dspace-api/src/main/java/org/dspace/api/DSpaceApi.java index e0231154b3b9..3637b21ba776 100644 --- a/dspace-api/src/main/java/org/dspace/api/DSpaceApi.java +++ b/dspace-api/src/main/java/org/dspace/api/DSpaceApi.java @@ -96,7 +96,7 @@ public static void handle_HandleManager_registerFinalHandleURL(Logger log, return; } - String url = configurationService.getProperty("dspace.url"); + String url = configurationService.getProperty("dspace.ui.url"); url = url + (url.endsWith("/") ? "" : "/") + "handle/" + pid; /* diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/hdlresolver/HdlResolverRestController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/hdlresolver/HdlResolverRestController.java index ac2a4a1f7df6..be6f4822c273 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/hdlresolver/HdlResolverRestController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/hdlresolver/HdlResolverRestController.java @@ -88,7 +88,7 @@ public ResponseEntity handleController(HttpServletRequest request, @Path *
* Example: * * @@ -118,7 +118,7 @@ public ResponseEntity resolveHandle(HttpServletRequest request, String h *
* Example: *
    - *
  • Request: GET - http://{dspace.url}/listprefixes
  • + *
  • Request: GET - http://{dspace.ui.url}/listprefixes
  • *
  • Response: 200 - ["123456789","prefix1","prefix2"] *
* @@ -144,7 +144,7 @@ public ResponseEntity listPrefixes(HttpServletRequest request) { *
* Example: *
    - *
  • Request: GET - http://{dspace.url}/listhandles/prefix
  • + *
  • Request: GET - http://{dspace.ui.url}/listhandles/prefix
  • *
  • Response: 200 - ["prefix/zero","prefix1/one","prefix2/two"] *
* From aeadc5be5e35c1df9826c5fe6abf3091f609b13a Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Thu, 3 Apr 2025 14:02:28 +0200 Subject: [PATCH 2/2] Return the Item url with the UUID instead of it's `/handle` path, it is more faster. --- .../main/java/org/dspace/api/DSpaceApi.java | 17 ++++++++++- .../dspace/handle/PIDConfigurationTest.java | 29 +++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/api/DSpaceApi.java b/dspace-api/src/main/java/org/dspace/api/DSpaceApi.java index 3637b21ba776..41df83a3d7a1 100644 --- a/dspace-api/src/main/java/org/dspace/api/DSpaceApi.java +++ b/dspace-api/src/main/java/org/dspace/api/DSpaceApi.java @@ -97,7 +97,7 @@ public static void handle_HandleManager_registerFinalHandleURL(Logger log, } String url = configurationService.getProperty("dspace.ui.url"); - url = url + (url.endsWith("/") ? "" : "/") + "handle/" + pid; + url = generateItemURLWithUUID(url, dso); /* * request modification of the PID to point to the correct URL, which @@ -113,4 +113,19 @@ public static void handle_HandleManager_registerFinalHandleURL(Logger log, + " (" + e.toString() + ")"); } } + + /** + * Generate a URL for the given DSpaceObject. The URL consist of the base URL and the ID of the DSpace object. + * E.g. `http://localhost:4000/items/` + * @param url base URL of the DSpace instance + * @param dSpaceObject the DSpace object for which the URL is generated + * @return the generated URL + */ + public static String generateItemURLWithUUID(String url, DSpaceObject dSpaceObject) { + if (dSpaceObject == null) { + log.error("DSpaceObject is null, cannot generate URL"); + return url; + } + return url + (url.endsWith("/") ? "" : "/") + "items/" + dSpaceObject.getID(); + } } diff --git a/dspace-api/src/test/java/org/dspace/handle/PIDConfigurationTest.java b/dspace-api/src/test/java/org/dspace/handle/PIDConfigurationTest.java index 9cc6148f3bbc..a6f7745782f0 100644 --- a/dspace-api/src/test/java/org/dspace/handle/PIDConfigurationTest.java +++ b/dspace-api/src/test/java/org/dspace/handle/PIDConfigurationTest.java @@ -16,6 +16,7 @@ import java.util.UUID; import org.dspace.AbstractUnitTest; +import org.dspace.api.DSpaceApi; import org.dspace.authorize.AuthorizeException; import org.dspace.content.Collection; import org.dspace.content.Community; @@ -99,9 +100,9 @@ public void testInitMultipleCommunityConfigs() { // now check that we have 2 community configurations in the test local.cfg assertEquals(2, pidConfiguration.getPIDCommunityConfigurations().size()); } -// + @Test - public void testInitCommunityConfigSubprefix() { + public void testInitCommunityConfigSubprefix() { PIDConfiguration pidConfiguration = PIDConfiguration.getInstance(); // get the first one and check the subprefix is 1 PIDCommunityConfiguration pidCommunityConfiguration = pidConfiguration.getPIDCommunityConfiguration( @@ -110,7 +111,7 @@ public void testInitCommunityConfigSubprefix() { } @Test - public void testInitCommunityConfigMapShouldNotBeShared() throws NoSuchFieldException, IllegalAccessException { + public void testInitCommunityConfigMapShouldNotBeShared() throws NoSuchFieldException, IllegalAccessException { PIDConfiguration pidConfiguration = PIDConfiguration.getInstance(); PIDCommunityConfiguration pidCommunityConfiguration1 = pidConfiguration.getPIDCommunityConfiguration( @@ -125,4 +126,26 @@ public void testInitCommunityConfigMapShouldNotBeShared() throws NoSuchFieldExc configMap.put("type", "epic"); assertEquals("Com2 should still have local type", "local", pidCommunityConfiguration2.getType()); } + + @Test + public void testGeneratingItemURL() { + String repositoryUrl = "http://localhost:4000/"; + String expectedUrl = repositoryUrl + "items/" + publicItem.getID(); + + String url = DSpaceApi.generateItemURLWithUUID(repositoryUrl, publicItem); + assertEquals(expectedUrl, url); + + // Test with no trailing slash + repositoryUrl = "http://localhost:4000"; + + url = DSpaceApi.generateItemURLWithUUID(repositoryUrl, publicItem); + assertEquals(expectedUrl, url); + + // Test with namespace + repositoryUrl = "http://localhost:4000/namespace"; + expectedUrl = repositoryUrl + "/items/" + publicItem.getID(); + + url = DSpaceApi.generateItemURLWithUUID(repositoryUrl, publicItem); + assertEquals(expectedUrl, url); + } }