Update CreateMissingIdentifiers to better identify when CanonicalHandles provider is enabled. Update CreateMissingIdentifiersIT to verify that we are accurately resetting to our default IdentifierProvider

(cherry picked from commit 2385c13f2d)
This commit is contained in:
Tim Donohue
2024-11-08 10:17:31 -06:00
committed by github-actions[bot]
parent 7ee4ba1a28
commit ad6d2eb014
4 changed files with 33 additions and 23 deletions

View File

@@ -10,6 +10,7 @@ package org.dspace.ctask.general;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@@ -25,7 +26,6 @@ import org.dspace.identifier.IdentifierProvider;
import org.dspace.identifier.VersionedHandleIdentifierProviderWithCanonicalHandles; import org.dspace.identifier.VersionedHandleIdentifierProviderWithCanonicalHandles;
import org.dspace.identifier.factory.IdentifierServiceFactory; import org.dspace.identifier.factory.IdentifierServiceFactory;
import org.dspace.identifier.service.IdentifierService; import org.dspace.identifier.service.IdentifierService;
import org.dspace.services.factory.DSpaceServicesFactory;
/** /**
* Ensure that an object has all of the identifiers that it should, minting them * Ensure that an object has all of the identifiers that it should, minting them
@@ -45,20 +45,6 @@ public class CreateMissingIdentifiers
return Curator.CURATE_SKIP; return Curator.CURATE_SKIP;
} }
// XXX Temporary escape when an incompatible provider is configured.
// XXX Remove this when the provider is fixed.
boolean compatible = DSpaceServicesFactory
.getInstance()
.getServiceManager()
.getServiceByName(
VersionedHandleIdentifierProviderWithCanonicalHandles.class.getCanonicalName(),
IdentifierProvider.class) == null;
if (!compatible) {
setResult("This task is not compatible with VersionedHandleIdentifierProviderWithCanonicalHandles");
return Curator.CURATE_ERROR;
}
// XXX End of escape
String typeText = Constants.typeText[dso.getType()]; String typeText = Constants.typeText[dso.getType()];
// Get a Context // Get a Context
@@ -75,6 +61,18 @@ public class CreateMissingIdentifiers
.getInstance() .getInstance()
.getIdentifierService(); .getIdentifierService();
// XXX Temporary escape when an incompatible provider is configured.
// XXX Remove this when the provider is fixed.
List<IdentifierProvider> providerList = identifierService.getProviders();
boolean compatible =
providerList.stream().noneMatch(p -> p instanceof VersionedHandleIdentifierProviderWithCanonicalHandles);
if (!compatible) {
setResult("This task is not compatible with VersionedHandleIdentifierProviderWithCanonicalHandles");
return Curator.CURATE_ERROR;
}
// XXX End of escape
// Register any missing identifiers. // Register any missing identifiers.
try { try {
identifierService.register(context, dso); identifierService.register(context, dso);

View File

@@ -57,6 +57,11 @@ public class IdentifierServiceImpl implements IdentifierService {
} }
} }
@Override
public List<IdentifierProvider> getProviders() {
return this.providers;
}
/** /**
* Reserves identifiers for the item * Reserves identifiers for the item
* *

View File

@@ -19,6 +19,7 @@ import org.dspace.identifier.Identifier;
import org.dspace.identifier.IdentifierException; import org.dspace.identifier.IdentifierException;
import org.dspace.identifier.IdentifierNotFoundException; import org.dspace.identifier.IdentifierNotFoundException;
import org.dspace.identifier.IdentifierNotResolvableException; import org.dspace.identifier.IdentifierNotResolvableException;
import org.dspace.identifier.IdentifierProvider;
/** /**
* @author Fabio Bolognesi (fabio at atmire dot com) * @author Fabio Bolognesi (fabio at atmire dot com)
@@ -194,4 +195,9 @@ public interface IdentifierService {
void delete(Context context, DSpaceObject dso, String identifier) void delete(Context context, DSpaceObject dso, String identifier)
throws AuthorizeException, SQLException, IdentifierException; throws AuthorizeException, SQLException, IdentifierException;
/**
* Get List of currently enabled IdentifierProviders
* @return List of enabled IdentifierProvider objects.
*/
List<IdentifierProvider> getProviders();
} }

View File

@@ -60,14 +60,7 @@ public class CreateMissingIdentifiersIT
.build(); .build();
/* /*
* Curate with default Handle Provider * First, install an incompatible provider to make the task fail.
*/
curator.curate(context, item);
int status = curator.getStatus(TASK_NAME);
assertEquals("Curation should succeed", Curator.CURATE_SUCCESS, status);
/*
* Now install an incompatible provider to make the task fail.
*/ */
registerProvider(VersionedHandleIdentifierProviderWithCanonicalHandles.class); registerProvider(VersionedHandleIdentifierProviderWithCanonicalHandles.class);
@@ -81,5 +74,13 @@ public class CreateMissingIdentifiersIT
unregisterProvider(VersionedHandleIdentifierProviderWithCanonicalHandles.class); unregisterProvider(VersionedHandleIdentifierProviderWithCanonicalHandles.class);
// Re-register the default provider (for later tests which may depend on it) // Re-register the default provider (for later tests which may depend on it)
registerProvider(VersionedHandleIdentifierProvider.class); registerProvider(VersionedHandleIdentifierProvider.class);
/*
* Now, verify curate with default Handle Provider works
* (and that our re-registration of the default provider above was successful)
*/
curator.curate(context, item);
int status = curator.getStatus(TASK_NAME);
assertEquals("Curation should succeed", Curator.CURATE_SUCCESS, status);
} }
} }