Uses all possible identifiers to generate URIs.

This commit enables dspace-rdf to use all PersistentIdentifiers minted
by DSpace and not only handles. It makes advantage of the changes
introduced to DSpace by DS-1990. Persistent Identifers should and will
be used as fully functional http URIs only (e.g. a DOI will be used in
the form http://dx.doi.org/<doi> and not as doi:<doi>).
This commit is contained in:
Pascal-Nicolas Becker
2014-09-11 11:49:41 +02:00
parent 4b250862fc
commit 3d8acfedea
7 changed files with 117 additions and 19 deletions

View File

@@ -111,7 +111,7 @@ public class RDFConsumer implements Consumer
Item[] items = b.getItems();
for (Item i : items)
{
DSOIdentifier id = new DSOIdentifier(i);
DSOIdentifier id = new DSOIdentifier(i, ctx);
if (!this.toDelete.contains(id) && !this.toConvert.contains(id))
{
this.toConvert.addLast(id);
@@ -156,7 +156,7 @@ public class RDFConsumer implements Consumer
Item[] items = bundle.getItems();
for (Item i : items)
{
DSOIdentifier id = new DSOIdentifier(i);
DSOIdentifier id = new DSOIdentifier(i, ctx);
if (!this.toDelete.contains(id) && !this.toConvert.contains(id))
{
this.toConvert.addLast(id);
@@ -191,7 +191,7 @@ public class RDFConsumer implements Consumer
if (event.getEventType() == Event.DELETE)
{
DSOIdentifier id = new DSOIdentifier(event.getSubjectType(),
event.getSubjectID(), event.getDetail());
event.getSubjectID(), event.getDetail(), event.getIdentifiers());
if (this.toConvert.contains(id))
{
@@ -222,7 +222,7 @@ public class RDFConsumer implements Consumer
+ "event with the type REMOVE.");
return;
}
DSOIdentifier id = new DSOIdentifier(dso);
DSOIdentifier id = new DSOIdentifier(dso, ctx);
// If an item gets withdrawn, a MODIFIY event is fired. We have to
// delete the item from the triple store instead of converting it.
@@ -260,7 +260,7 @@ public class RDFConsumer implements Consumer
|| event.getEventType() == Event.REMOVE)
{
DSOIdentifier id = new DSOIdentifier(Constants.SITE,
Site.SITE_ID, Site.getSiteHandle());
Site.SITE_ID, Site.getSiteHandle(), new String[] {Site.getSiteHandle()});
if (!this.toConvert.contains(id)) this.toConvert.add(id);
return;
}
@@ -393,12 +393,12 @@ public class RDFConsumer implements Consumer
throws SQLException {
try
{
RDFUtil.delete(context, id.type, id.id, id.handle);
RDFUtil.delete(context, id.type, id.id, id.handle, id.identifiers);
}
catch (RDFMissingIdentifierException ex)
{
log.warn("Cannot delete " + Constants.typeText[id.type] + " "
+ Integer.toString(id.id) + " (handle " + id.handle + "): "
+ Integer.toString(id.id) + ": "
+ ex.getMessage(), ex);
}
}
@@ -416,15 +416,17 @@ public class RDFConsumer implements Consumer
int type;
int id;
String handle;
String[] identifiers;
DSOIdentifier(int type, int id, String handle)
DSOIdentifier(int type, int id, String handle, String[] identifiers)
{
this.type = type;
this.id = id;
this.handle = handle;
this.identifiers = identifiers;
}
DSOIdentifier(DSpaceObject dso)
DSOIdentifier(DSpaceObject dso, Context ctx)
{
if (dso.getType() != Constants.SITE
&& dso.getType() != Constants.COMMUNITY
@@ -437,6 +439,7 @@ public class RDFConsumer implements Consumer
this.type = dso.getType();
this.id = dso.getID();
this.handle = dso.getHandle();
this.identifiers = dso.getIdentifiers(ctx);
}
@Override

View File

@@ -81,10 +81,11 @@ public class RDFUtil {
* identifier assigned to the provided DSO.
*/
public static String generateIdentifier(Context context, int type, int id,
String handle) throws SQLException
String handle, String[] identifier)
throws SQLException
{
return RDFConfiguration.getURIGenerator().generateIdentifier(context,
type, id, handle);
type, id, handle, identifier);
}
/**
* Converts the the provided DSpaceObject into RDF and returns the model.
@@ -281,11 +282,11 @@ public class RDFUtil {
* @throws SQLException
* @throws RDFMissingIdentifierException In case that no Identifier could be generated.
*/
public static void delete(Context ctx, int type, int id, String handle)
public static void delete(Context ctx, int type, int id, String handle, String[] identifiers)
throws SQLException, RDFMissingIdentifierException
{
String uri = RDFConfiguration.getURIGenerator().generateIdentifier(ctx,
type, id, handle);
type, id, handle, identifiers);
if (uri != null)
{
RDFConfiguration.getRDFStorage().delete(uri);

View File

@@ -0,0 +1,22 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.rdf.storage;
/**
* Extends the DOIURIGenerator but uses handles as fallback to DOIs.
* @author pbecker
*/
public class DOIHandleURIGenerator
extends DOIURIGenerator
implements URIGenerator
{
protected final static URIGenerator fallback = new HandleURIGenerator();
}

View File

@@ -0,0 +1,70 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.rdf.storage;
import org.apache.log4j.Logger;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.identifier.DOI;
import org.dspace.identifier.IdentifierException;
import java.sql.SQLException;
/**
*
* @author pbecker
*/
public class DOIURIGenerator
implements URIGenerator
{
private static final Logger log = Logger.getLogger(DOIURIGenerator.class);
/*
* Currently (August 31 2014, in preparation of DSpace 5.0) DSpace supports DOIs for items only. This fallback
* will be used to generate an URI, whenever no DOI was found that could be used to.
*/
protected final static URIGenerator fallback = new LocalURIGenerator();
@Override
public String generateIdentifier(Context context, int type, int id, String handle, String[] identifiers) throws SQLException {
if (type != Constants.SITE
&& type != Constants.COMMUNITY
&& type != Constants.COLLECTION
&& type != Constants.ITEM)
{
return null;
}
String doi = null;
for (String identifier : identifiers)
{
try
{
doi = DOI.DOIToExternalForm(identifier);
} catch (IdentifierException ex) {
// identifier is not a DOI: no problem, keep on looking.
}
}
if (doi != null) {
return doi;
} else {
log.info("Didn't find a DOI for " + Constants.typeText[type] + ", id " + Integer.toString(id)
+ ", will use fallback URIGenerator.");
return fallback.generateIdentifier(context, type, id, handle, identifiers);
}
}
public String generateIdentifier(Context context, DSpaceObject dso)
throws SQLException
{
return generateIdentifier(context, dso.getType(), dso.getID(), dso.getHandle(), dso.getIdentifiers(context));
}
}

View File

@@ -24,7 +24,8 @@ import org.dspace.utils.DSpace;
public class HandleURIGenerator implements URIGenerator {
private static final Logger log = Logger.getLogger(HandleURIGenerator.class);
public String generateIdentifier(Context context, int type, int id, String handle)
public String generateIdentifier(Context context, int type, int id,
String handle, String[] identifiers)
{
if (type == Constants.SITE)
{
@@ -59,6 +60,7 @@ public class HandleURIGenerator implements URIGenerator {
return null;
}
return generateIdentifier(context, dso.getType(), dso.getID(), dso.getHandle());
return generateIdentifier(context, dso.getType(), dso.getID(),
dso.getHandle(), dso.getIdentifiers(context));
}
}

View File

@@ -27,10 +27,10 @@ public class LocalURIGenerator implements URIGenerator {
private static final Logger log = Logger.getLogger(LocalURIGenerator.class);
@Override
public String generateIdentifier(Context context, int type, int id, String handle)
public String generateIdentifier(Context context, int type, int id,
String handle, String[] identifiers)
throws SQLException
{
String urlPrefix = RDFConfiguration.getDSpaceRDFModuleURI() + "/resource/";
if (type == Constants.SITE)
@@ -62,7 +62,7 @@ public class LocalURIGenerator implements URIGenerator {
return null;
}
return generateIdentifier(context, dso.getType(), dso.getID(), dso.getHandle());
return generateIdentifier(context, dso.getType(), dso.getID(), dso.getHandle(), dso.getIdentifiers(context));
}
}

View File

@@ -40,7 +40,7 @@ public interface URIGenerator {
* @return May return null, if no URI could be generated.
* @see org.dspace.rdf.RDFUtil#generateIdentifier(Context, DSpaceObject)
*/
public String generateIdentifier(Context context, int type, int id, String handle)
public String generateIdentifier(Context context, int type, int id, String handle, String[] identifiers)
throws SQLException;
/**