Skip to content

Commit

Permalink
Ufal be/handleserver fix (#446)
Browse files Browse the repository at this point in the history
* fixed dead handle null

* fixed null services
  • Loading branch information
MajoBerger authored Sep 28, 2023
1 parent fb252cf commit d49f106
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
4 changes: 4 additions & 0 deletions dspace-api/src/main/java/org/dspace/handle/Handle.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.dspace.handle;

import java.util.Date;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
Expand Down Expand Up @@ -146,6 +147,9 @@ public void setUrl(String url) {
}

public Boolean getDead() {
if (Objects.isNull(dead)) {
return false;
}
return dead;
}

Expand Down
45 changes: 27 additions & 18 deletions dspace-api/src/main/java/org/dspace/handle/HandlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
*
* @author Peter Breton
* modified for LINDAT/CLARIN
* @version $Revision$
* @author Milan Majchrak (milan.majchrak at dataquest.sk)
* @version $Revision$
*/
@Component
public class HandlePlugin implements HandleStorage {
Expand Down Expand Up @@ -144,7 +144,7 @@ public void init(StreamTable st) throws Exception {
*/
@Override
public void setHaveNA(byte[] theHandle, boolean haveit)
throws HandleException {
throws HandleException {
// Not implemented
if (log.isInfoEnabled()) {
log.info("Called setHaveNA (not implemented)");
Expand All @@ -156,7 +156,7 @@ public void setHaveNA(byte[] theHandle, boolean haveit)
*/
@Override
public void createHandle(byte[] theHandle, HandleValue[] values)
throws HandleException {
throws HandleException {
// Not implemented
if (log.isInfoEnabled()) {
log.info("Called createHandle (not implemented)");
Expand All @@ -181,7 +181,7 @@ public boolean deleteHandle(byte[] theHandle) throws HandleException {
*/
@Override
public void updateValue(byte[] theHandle, HandleValue[] values)
throws HandleException {
throws HandleException {
// Not implemented
if (log.isInfoEnabled()) {
log.info("Called updateValue (not implemented)");
Expand Down Expand Up @@ -212,7 +212,7 @@ public void checkpointDatabase() throws HandleException {

/**
* HandleStorage interface shutdown() method.
* <P>
* <p>
* For DSpace, we need to destroy the kernel created in init().
*/
@Override
Expand Down Expand Up @@ -301,7 +301,7 @@ public byte[][] getRawHandleValues(byte[] theHandle, int[] indexList,

String[] alternativePrefixes = PIDConfiguration.getAlternativePrefixes(handle_parts[0]);

for ( String alternativePrefix : alternativePrefixes ) {
for (String alternativePrefix : alternativePrefixes) {
String alternativeHandle = handleClarinService.completeHandle(
alternativePrefix, handle_parts[1]);
url = handleClarinService.resolveToURL(context, alternativeHandle);
Expand All @@ -321,7 +321,7 @@ public byte[][] getRawHandleValues(byte[] theHandle, int[] indexList,

ResolvedHandle rh = null;
if (url.startsWith(MAGIC_BEAN)) {
String[] splits = url.split(MAGIC_BEAN,10);
String[] splits = url.split(MAGIC_BEAN, 10);
if (splits.length < 8) {
throw new RuntimeException("Cannot resolve external handle with magicLindat string, " +
"because the external handle do not have enough information.");
Expand Down Expand Up @@ -374,6 +374,7 @@ public boolean haveNA(byte[] theHandle) throws HandleException {
if (log.isInfoEnabled()) {
log.info("Called haveNA");
}
loadServices();

/*
* Naming authority Handles are in the form: 0.NA/1721.1234
Expand Down Expand Up @@ -420,9 +421,9 @@ public boolean haveNA(byte[] theHandle) throws HandleException {
*/
@Override
public Enumeration getHandlesForNA(byte[] theNAHandle)
throws HandleException {
throws HandleException {
String naHandle = Util.decodeString(theNAHandle);

loadServices();
if (log.isInfoEnabled()) {
log.info("Called getHandlesForNA for NA " + naHandle);
}
Expand Down Expand Up @@ -466,20 +467,26 @@ public Enumeration getHandlesForNA(byte[] theNAHandle)
*/
private static void loadServices() {
// services are loaded
if (Objects.nonNull(handleService) && Objects.nonNull(configurationService) &&
Objects.nonNull(itemService) && Objects.nonNull(handleClarinService)) {
return;
if (Objects.nonNull(handleService)) {
handleService = HandleServiceFactory.getInstance().getHandleService();
}

if (Objects.nonNull(configurationService)) {
configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
}

if (Objects.nonNull(itemService)) {
itemService = ContentServiceFactory.getInstance().getItemService();
}

// Get a reference to the HandleService & ConfigurationService
handleService = HandleServiceFactory.getInstance().getHandleService();
configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
itemService = ContentServiceFactory.getInstance().getItemService();
handleClarinService = ContentServiceFactory.getInstance().getHandleClarinService();
if (Objects.nonNull(handleClarinService)) {
handleClarinService = ContentServiceFactory.getInstance().getHandleClarinService();
}
}

/**
* Load the repository email from the configuration. The mail is in the property `help.mail`.
*
* @return configured repository mail as String or return null if it is not configured
*/
public static String getRepositoryEmail() {
Expand Down Expand Up @@ -510,6 +517,7 @@ public static String getRepositoryEmail() {

/**
* Load the repository name from the configuration. The name is in the property `dspace.name`.
*
* @return configured repository name as String or return null if it is not configured
*/
public static String getRepositoryName() {
Expand Down Expand Up @@ -538,6 +546,7 @@ public static String getRepositoryName() {

/**
* Load the canonical handle prefix from the configuration. The prefix is in the property `handle.canonical.prefix`.
*
* @return canonical handle prefix as String or return DEFAULT_CANONICAL_HANDLE_PREFIX = `http://hdl.handle.net/`
*/
public static String getCanonicalHandlePrefix() {
Expand Down Expand Up @@ -619,7 +628,7 @@ public ResolvedHandle(String url, DSpaceObject dso) {
init(url, title, repository, submitdate, reportemail);
}

private <K,V> V getOrDefault (Map<K,V> map, K key, V defaultValue) {
private <K, V> V getOrDefault(Map<K, V> map, K key, V defaultValue) {
if (map.containsKey(key)) {
return map.get(key);
} else {
Expand Down

0 comments on commit d49f106

Please sign in to comment.