Skip to content

Commit

Permalink
Merge pull request #8860 from 4Science/DURACOM-127
Browse files Browse the repository at this point in the history
[DURACOM-127] check if versioning is enabled for versioned identifier providers
  • Loading branch information
tdonohue committed Jun 1, 2023
2 parents 5be09e3 + 78f91b0 commit 379db2a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
Expand Up @@ -27,13 +27,14 @@
import org.dspace.versioning.VersionHistory;
import org.dspace.versioning.service.VersionHistoryService;
import org.dspace.versioning.service.VersioningService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
* @author Marsa Haoua
* @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
*/
Expand All @@ -49,6 +50,19 @@ public class VersionedDOIIdentifierProvider extends DOIIdentifierProvider {
@Autowired(required = true)
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
public String mint(Context context, DSpaceObject dso) throws IdentifierException {
return mint(context, dso, this.filter);
Expand Down
Expand Up @@ -35,6 +35,7 @@
import org.dspace.versioning.VersionHistory;
import org.dspace.versioning.service.VersionHistoryService;
import org.dspace.versioning.service.VersioningService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -45,7 +46,7 @@
* @author Pascal-Nicolas Becker (dspace at pascal dash becker dot de)
*/
@Component
public class VersionedHandleIdentifierProvider extends IdentifierProvider {
public class VersionedHandleIdentifierProvider extends IdentifierProvider implements InitializingBean {
/**
* log4j category
*/
Expand All @@ -71,6 +72,19 @@ public class VersionedHandleIdentifierProvider extends IdentifierProvider {
@Autowired(required = true)
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
public boolean supports(Class<? extends Identifier> identifier) {
return Handle.class.isAssignableFrom(identifier);
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.dspace.versioning.VersionHistory;
import org.dspace.versioning.service.VersionHistoryService;
import org.dspace.versioning.service.VersioningService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -39,7 +40,8 @@
* @author Ben Bosman (ben at atmire dot com)
*/
@Component
public class VersionedHandleIdentifierProviderWithCanonicalHandles extends IdentifierProvider {
public class VersionedHandleIdentifierProviderWithCanonicalHandles extends IdentifierProvider
implements InitializingBean {
/**
* log4j category
*/
Expand All @@ -65,6 +67,19 @@ public class VersionedHandleIdentifierProviderWithCanonicalHandles extends Ident
@Autowired(required = true)
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
public boolean supports(Class<? extends Identifier> identifier) {
return Handle.class.isAssignableFrom(identifier);
Expand Down

0 comments on commit 379db2a

Please sign in to comment.