[TLC-249] Refactor to support better filter usage, PENDING and MINTED status

This commit is contained in:
Kim Shepherd
2022-08-15 16:07:26 +12:00
parent 8fcda7f03a
commit 20aeedfdb3
27 changed files with 995 additions and 227 deletions

View File

@@ -18,6 +18,7 @@ import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.content.MetadataValue;
import org.dspace.content.logic.Filter;
import org.dspace.core.Context;
import org.dspace.identifier.doi.DOIConnector;
import org.dspace.identifier.doi.DOIIdentifierException;
@@ -49,7 +50,12 @@ public class VersionedDOIIdentifierProvider extends DOIIdentifierProvider {
protected VersionHistoryService versionHistoryService;
@Override
public String mint(Context context, DSpaceObject dso)
public String mint(Context context, DSpaceObject dso) throws IdentifierException {
return mint(context, dso, this.filter);
}
@Override
public String mint(Context context, DSpaceObject dso, Filter filter)
throws IdentifierException {
if (!(dso instanceof Item)) {
throw new IdentifierException("Currently only Items are supported for DOIs.");
@@ -79,6 +85,9 @@ public class VersionedDOIIdentifierProvider extends DOIIdentifierProvider {
+ " with ID " + dso.getID() + ".", ex);
}
// Make a call to the filter here to throw an exception instead of carrying on with removal + creation
checkMintable(context, filter, dso);
// check whether we have a DOI in the metadata and if we have to remove it
String metadataDOI = getDOIOutOfObject(dso);
if (metadataDOI != null) {
@@ -111,7 +120,7 @@ public class VersionedDOIIdentifierProvider extends DOIIdentifierProvider {
// ensure DOI exists in our database as well and return.
// this also checks that the doi is not assigned to another dso already.
try {
loadOrCreateDOI(context, dso, versionedDOI);
loadOrCreateDOI(context, dso, versionedDOI, filter);
} catch (SQLException ex) {
log.error(
"A problem with the database connection occurd while processing DOI " + versionedDOI + ".", ex);
@@ -127,7 +136,7 @@ public class VersionedDOIIdentifierProvider extends DOIIdentifierProvider {
// if we have a history, we have a item
doi = makeIdentifierBasedOnHistory(context, dso, history);
} else {
doi = loadOrCreateDOI(context, dso, null).getDoi();
doi = loadOrCreateDOI(context, dso, null, filter).getDoi();
}
} catch (SQLException ex) {
log.error("SQLException while creating a new DOI: ", ex);
@@ -140,7 +149,12 @@ public class VersionedDOIIdentifierProvider extends DOIIdentifierProvider {
}
@Override
public void register(Context context, DSpaceObject dso, String identifier)
public void register(Context context, DSpaceObject dso, String identifier) throws IdentifierException {
register(context, dso, identifier, this.filter);
}
@Override
public void register(Context context, DSpaceObject dso, String identifier, Filter filter)
throws IdentifierException {
if (!(dso instanceof Item)) {
throw new IdentifierException("Currently only Items are supported for DOIs.");
@@ -220,8 +234,14 @@ public class VersionedDOIIdentifierProvider extends DOIIdentifierProvider {
return doiPostfix;
}
// Should never return null!
protected String makeIdentifierBasedOnHistory(Context context, DSpaceObject dso, VersionHistory history)
throws AuthorizeException, SQLException, DOIIdentifierException, IdentifierNotApplicableException {
return makeIdentifierBasedOnHistory(context, dso, history, this.filter);
}
// Should never return null!
protected String makeIdentifierBasedOnHistory(Context context, DSpaceObject dso, VersionHistory history,
Filter filter)
throws AuthorizeException, SQLException, DOIIdentifierException, IdentifierNotApplicableException {
// Mint foreach new version an identifier like: 12345/100.versionNumber
// use the bare handle (g.e. 12345/100) for the first version.
@@ -244,6 +264,9 @@ public class VersionedDOIIdentifierProvider extends DOIIdentifierProvider {
}
if (previousVersionDOI == null) {
// Before continuing with any new DOI creation, apply the filter
checkMintable(context, filter, dso);
// We need to generate a new DOI.
DOI doi = doiService.create(context);
@@ -269,7 +292,7 @@ public class VersionedDOIIdentifierProvider extends DOIIdentifierProvider {
String.valueOf(versionHistoryService.getVersion(context, history, item).getVersionNumber()));
}
loadOrCreateDOI(context, dso, identifier);
loadOrCreateDOI(context, dso, identifier, filter);
return identifier;
}