Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions dspace-api/src/main/java/org/dspace/api/DSpaceApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public static void handle_HandleManager_registerFinalHandleURL(Logger log,
return;
}

String url = configurationService.getProperty("dspace.url");
url = url + (url.endsWith("/") ? "" : "/") + "handle/" + pid;
String url = configurationService.getProperty("dspace.ui.url");
url = generateItemURLWithUUID(url, dso);

/*
* request modification of the PID to point to the correct URL, which
Expand All @@ -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/<UUID>`
* @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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public ResponseEntity<String> handleController(HttpServletRequest request, @Path
* </br>
* Example:
* <ul>
* <li>Request: GET - http://{dspace.url}/hdlresolver/handleIdExample/1</li>
* <li>Request: GET - http://{dspace.ui.url}/hdlresolver/handleIdExample/1</li>
* <li>Response: 200 - ["http://localhost/handle/hanldeIdExample1"]
* </ul>
*
Expand Down Expand Up @@ -118,7 +118,7 @@ public ResponseEntity<String> resolveHandle(HttpServletRequest request, String h
* </br>
* Example:
* <ul>
* <li>Request: GET - http://{dspace.url}/listprefixes</li>
* <li>Request: GET - http://{dspace.ui.url}/listprefixes</li>
* <li>Response: 200 - ["123456789","prefix1","prefix2"]
* </ul>
*
Expand All @@ -144,7 +144,7 @@ public ResponseEntity<String> listPrefixes(HttpServletRequest request) {
* </br>
* Example:
* <ul>
* <li>Request: GET - http://{dspace.url}/listhandles/prefix</li>
* <li>Request: GET - http://{dspace.ui.url}/listhandles/prefix</li>
* <li>Response: 200 - ["prefix/zero","prefix1/one","prefix2/two"]
* </ul>
*
Expand Down