[DURACOM-127] check if versioning is enabled for versioned identifier providers

This commit is contained in:
Francesco Pio Scognamiglio
2023-05-22 11:09:43 +02:00
parent 6fd31622ae
commit 8ddf4702af
3 changed files with 46 additions and 3 deletions

View File

@@ -27,13 +27,14 @@ import org.dspace.versioning.Version;
import org.dspace.versioning.VersionHistory; import org.dspace.versioning.VersionHistory;
import org.dspace.versioning.service.VersionHistoryService; import org.dspace.versioning.service.VersionHistoryService;
import org.dspace.versioning.service.VersioningService; import org.dspace.versioning.service.VersioningService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
/** /**
* @author Marsa Haoua * @author Marsa Haoua
* @author Pascal-Nicolas Becker (dspace at pascal dash becker dot de) * @author Pascal-Nicolas Becker (dspace at pascal dash becker dot de)
*/ */
public class VersionedDOIIdentifierProvider extends DOIIdentifierProvider { public class VersionedDOIIdentifierProvider extends DOIIdentifierProvider implements InitializingBean {
/** /**
* log4j category * log4j category
*/ */
@@ -49,6 +50,19 @@ public class VersionedDOIIdentifierProvider extends DOIIdentifierProvider {
@Autowired(required = true) @Autowired(required = true)
protected VersionHistoryService versionHistoryService; protected VersionHistoryService versionHistoryService;
/**
* After all the properties are set check that the versioning is enabled
*
* @throws Exception throws an exception if this isn't the case
*/
@Override
public void afterPropertiesSet() throws Exception {
if (!configurationService.getBooleanProperty("versioning.enabled", true)) {
throw new RuntimeException("the " + VersionedDOIIdentifierProvider.class.getName() +
" is enabled, but the versioning is disabled.");
}
}
@Override @Override
public String mint(Context context, DSpaceObject dso) throws IdentifierException { public String mint(Context context, DSpaceObject dso) throws IdentifierException {
return mint(context, dso, this.filter); return mint(context, dso, this.filter);

View File

@@ -35,6 +35,7 @@ import org.dspace.versioning.Version;
import org.dspace.versioning.VersionHistory; import org.dspace.versioning.VersionHistory;
import org.dspace.versioning.service.VersionHistoryService; import org.dspace.versioning.service.VersionHistoryService;
import org.dspace.versioning.service.VersioningService; import org.dspace.versioning.service.VersioningService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -45,7 +46,7 @@ import org.springframework.stereotype.Component;
* @author Pascal-Nicolas Becker (dspace at pascal dash becker dot de) * @author Pascal-Nicolas Becker (dspace at pascal dash becker dot de)
*/ */
@Component @Component
public class VersionedHandleIdentifierProvider extends IdentifierProvider { public class VersionedHandleIdentifierProvider extends IdentifierProvider implements InitializingBean {
/** /**
* log4j category * log4j category
*/ */
@@ -71,6 +72,19 @@ public class VersionedHandleIdentifierProvider extends IdentifierProvider {
@Autowired(required = true) @Autowired(required = true)
protected ContentServiceFactory contentServiceFactory; protected ContentServiceFactory contentServiceFactory;
/**
* After all the properties are set check that the versioning is enabled
*
* @throws Exception throws an exception if this isn't the case
*/
@Override
public void afterPropertiesSet() throws Exception {
if (!configurationService.getBooleanProperty("versioning.enabled", true)) {
throw new RuntimeException("the " + VersionedHandleIdentifierProvider.class.getName() +
" is enabled, but the versioning is disabled.");
}
}
@Override @Override
public boolean supports(Class<? extends Identifier> identifier) { public boolean supports(Class<? extends Identifier> identifier) {
return Handle.class.isAssignableFrom(identifier); return Handle.class.isAssignableFrom(identifier);

View File

@@ -30,6 +30,7 @@ import org.dspace.versioning.Version;
import org.dspace.versioning.VersionHistory; import org.dspace.versioning.VersionHistory;
import org.dspace.versioning.service.VersionHistoryService; import org.dspace.versioning.service.VersionHistoryService;
import org.dspace.versioning.service.VersioningService; import org.dspace.versioning.service.VersioningService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -39,7 +40,8 @@ import org.springframework.stereotype.Component;
* @author Ben Bosman (ben at atmire dot com) * @author Ben Bosman (ben at atmire dot com)
*/ */
@Component @Component
public class VersionedHandleIdentifierProviderWithCanonicalHandles extends IdentifierProvider { public class VersionedHandleIdentifierProviderWithCanonicalHandles extends IdentifierProvider
implements InitializingBean {
/** /**
* log4j category * log4j category
*/ */
@@ -65,6 +67,19 @@ public class VersionedHandleIdentifierProviderWithCanonicalHandles extends Ident
@Autowired(required = true) @Autowired(required = true)
private ItemService itemService; private ItemService itemService;
/**
* After all the properties are set check that the versioning is enabled
*
* @throws Exception throws an exception if this isn't the case
*/
@Override
public void afterPropertiesSet() throws Exception {
if (!configurationService.getBooleanProperty("versioning.enabled", true)) {
throw new RuntimeException("the " + VersionedHandleIdentifierProviderWithCanonicalHandles.class.getName() +
" is enabled, but the versioning is disabled.");
}
}
@Override @Override
public boolean supports(Class<? extends Identifier> identifier) { public boolean supports(Class<? extends Identifier> identifier) {
return Handle.class.isAssignableFrom(identifier); return Handle.class.isAssignableFrom(identifier);