Skip to content

Commit

Permalink
89779: VersionedHandleIdentifierProviderWithCanonicalHandles fix pt1
Browse files Browse the repository at this point in the history
  • Loading branch information
Atmire-Kristof committed Feb 24, 2023
1 parent 122924a commit 47fab88
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 17 deletions.
Expand Up @@ -13,15 +13,6 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">


<!-- Identifier Service Application Interface. Will be autowired with
any Identifier Providers present in Spring context.
-->
<bean id="org.dspace.identifier.service.IdentifierService"
class="org.dspace.identifier.IdentifierServiceImpl"
autowire="byType"
scope="singleton"/>

<bean id="org.dspace.services.ConfigurationService"
class="org.dspace.servicemanager.config.DSpaceConfigurationService" scope="singleton"/>

Expand All @@ -31,12 +22,6 @@
<property name="configurationService" ref="org.dspace.services.ConfigurationService"/>
</bean-->

<bean id="org.dspace.identifier.VersionedHandleIdentifierProvider"
class="org.dspace.identifier.VersionedHandleIdentifierProvider"
scope="singleton">
<property name="configurationService" ref="org.dspace.services.ConfigurationService"/>
</bean>

<bean name="org.dspace.core.DBConnection" class="org.dspace.core.HibernateDBConnection" lazy-init="true" scope="prototype"/>

<!-- Register all our Flyway callback classes (which run before/after database migrations) -->
Expand Down
@@ -0,0 +1,100 @@
package org.dspace.identifier;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.sql.SQLException;
import java.util.List;

import org.dspace.AbstractIntegrationTestWithDatabase;
import org.dspace.authorize.AuthorizeException;
import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder;
import org.dspace.builder.ItemBuilder;
import org.dspace.builder.VersionBuilder;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.identifier.service.IdentifierService;
import org.dspace.kernel.ServiceManager;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.utils.DSpace;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class VersionedHandleIdentifierProviderTest extends AbstractIntegrationTestWithDatabase {
private ServiceManager serviceManager;

private String handlePrefix;

private Collection collection;
private Item itemV1;
private Item itemV2;
private Item itemV3;

@Before
@Override
public void setUp() throws Exception {
super.setUp();
context.turnOffAuthorisationSystem();

ConfigurationService configurationService = new DSpace().getConfigurationService();
handlePrefix = configurationService.getProperty("handle.prefix");

serviceManager = DSpaceServicesFactory.getInstance().getServiceManager();

parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
collection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection")
.build();
}

private void registerProvider(Class type) {
// Register our new provider
serviceManager.registerServiceClass(type.getName(), type);
IdentifierProvider identifierProvider =
(IdentifierProvider) serviceManager.getServiceByName(type.getName(), type);

// Overwrite the identifier-service's providers with the new one to ensure only this provider is used
IdentifierServiceImpl identifierService = serviceManager.getServicesByType(IdentifierServiceImpl.class).get(0);
identifierService.setProviders(List.of(identifierProvider));
}

private void createVersions() throws SQLException, AuthorizeException {
itemV1 = ItemBuilder.createItem(context, collection)
.withTitle("First version")
.build();
itemV2 = VersionBuilder.createVersion(context, itemV1, "Second version").build().getItem();
itemV3 = VersionBuilder.createVersion(context, itemV1, "Third version").build().getItem();
}

@Test
public void testDefaultVersionedHandleProvider() throws Exception {
registerProvider(VersionedHandleIdentifierProvider.class);
createVersions();

assertEquals(handlePrefix + "/1", itemV1.getHandle());
assertEquals(handlePrefix + "/1.2", itemV2.getHandle());
assertEquals(handlePrefix + "/1.3", itemV3.getHandle());
}

@Test
public void testCanonicalVersionedHandleProvider() throws Exception {
registerProvider(VersionedHandleIdentifierProviderWithCanonicalHandles.class);
createVersions();

assertEquals(handlePrefix + "/1.3", itemV1.getHandle());
assertEquals(handlePrefix + "/1.2", itemV2.getHandle());
assertEquals(handlePrefix + "/1", itemV3.getHandle());
}

@After
@Override
public void destroy() throws Exception {
super.destroy();
// serviceManager.getApplicationContext().refresh();
}
}
2 changes: 0 additions & 2 deletions dspace/config/spring/api/identifier-service.xml
Expand Up @@ -17,11 +17,9 @@
The VersionedHandleIdentifierProvider creates a new versioned
handle for every new version.
-->
<!--
<bean id="org.dspace.identifier.HandleIdentifierProvider" class="org.dspace.identifier.VersionedHandleIdentifierProvider" scope="singleton">
<property name="configurationService" ref="org.dspace.services.ConfigurationService"/>
</bean>
-->
<!--
The VersionedHandleIdentifierProviderWithCanonicalHandles
preserves the first handle for every new version. Whenever
Expand Down

0 comments on commit 47fab88

Please sign in to comment.