mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
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:
@@ -111,7 +111,7 @@ public class RDFConsumer implements Consumer
|
|||||||
Item[] items = b.getItems();
|
Item[] items = b.getItems();
|
||||||
for (Item i : items)
|
for (Item i : items)
|
||||||
{
|
{
|
||||||
DSOIdentifier id = new DSOIdentifier(i);
|
DSOIdentifier id = new DSOIdentifier(i, ctx);
|
||||||
if (!this.toDelete.contains(id) && !this.toConvert.contains(id))
|
if (!this.toDelete.contains(id) && !this.toConvert.contains(id))
|
||||||
{
|
{
|
||||||
this.toConvert.addLast(id);
|
this.toConvert.addLast(id);
|
||||||
@@ -156,7 +156,7 @@ public class RDFConsumer implements Consumer
|
|||||||
Item[] items = bundle.getItems();
|
Item[] items = bundle.getItems();
|
||||||
for (Item i : items)
|
for (Item i : items)
|
||||||
{
|
{
|
||||||
DSOIdentifier id = new DSOIdentifier(i);
|
DSOIdentifier id = new DSOIdentifier(i, ctx);
|
||||||
if (!this.toDelete.contains(id) && !this.toConvert.contains(id))
|
if (!this.toDelete.contains(id) && !this.toConvert.contains(id))
|
||||||
{
|
{
|
||||||
this.toConvert.addLast(id);
|
this.toConvert.addLast(id);
|
||||||
@@ -191,7 +191,7 @@ public class RDFConsumer implements Consumer
|
|||||||
if (event.getEventType() == Event.DELETE)
|
if (event.getEventType() == Event.DELETE)
|
||||||
{
|
{
|
||||||
DSOIdentifier id = new DSOIdentifier(event.getSubjectType(),
|
DSOIdentifier id = new DSOIdentifier(event.getSubjectType(),
|
||||||
event.getSubjectID(), event.getDetail());
|
event.getSubjectID(), event.getDetail(), event.getIdentifiers());
|
||||||
|
|
||||||
if (this.toConvert.contains(id))
|
if (this.toConvert.contains(id))
|
||||||
{
|
{
|
||||||
@@ -222,7 +222,7 @@ public class RDFConsumer implements Consumer
|
|||||||
+ "event with the type REMOVE.");
|
+ "event with the type REMOVE.");
|
||||||
return;
|
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
|
// If an item gets withdrawn, a MODIFIY event is fired. We have to
|
||||||
// delete the item from the triple store instead of converting it.
|
// delete the item from the triple store instead of converting it.
|
||||||
@@ -260,7 +260,7 @@ public class RDFConsumer implements Consumer
|
|||||||
|| event.getEventType() == Event.REMOVE)
|
|| event.getEventType() == Event.REMOVE)
|
||||||
{
|
{
|
||||||
DSOIdentifier id = new DSOIdentifier(Constants.SITE,
|
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);
|
if (!this.toConvert.contains(id)) this.toConvert.add(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -393,12 +393,12 @@ public class RDFConsumer implements Consumer
|
|||||||
throws SQLException {
|
throws SQLException {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RDFUtil.delete(context, id.type, id.id, id.handle);
|
RDFUtil.delete(context, id.type, id.id, id.handle, id.identifiers);
|
||||||
}
|
}
|
||||||
catch (RDFMissingIdentifierException ex)
|
catch (RDFMissingIdentifierException ex)
|
||||||
{
|
{
|
||||||
log.warn("Cannot delete " + Constants.typeText[id.type] + " "
|
log.warn("Cannot delete " + Constants.typeText[id.type] + " "
|
||||||
+ Integer.toString(id.id) + " (handle " + id.handle + "): "
|
+ Integer.toString(id.id) + ": "
|
||||||
+ ex.getMessage(), ex);
|
+ ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,15 +416,17 @@ public class RDFConsumer implements Consumer
|
|||||||
int type;
|
int type;
|
||||||
int id;
|
int id;
|
||||||
String handle;
|
String handle;
|
||||||
|
String[] identifiers;
|
||||||
|
|
||||||
DSOIdentifier(int type, int id, String handle)
|
DSOIdentifier(int type, int id, String handle, String[] identifiers)
|
||||||
{
|
{
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
|
this.identifiers = identifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
DSOIdentifier(DSpaceObject dso)
|
DSOIdentifier(DSpaceObject dso, Context ctx)
|
||||||
{
|
{
|
||||||
if (dso.getType() != Constants.SITE
|
if (dso.getType() != Constants.SITE
|
||||||
&& dso.getType() != Constants.COMMUNITY
|
&& dso.getType() != Constants.COMMUNITY
|
||||||
@@ -437,6 +439,7 @@ public class RDFConsumer implements Consumer
|
|||||||
this.type = dso.getType();
|
this.type = dso.getType();
|
||||||
this.id = dso.getID();
|
this.id = dso.getID();
|
||||||
this.handle = dso.getHandle();
|
this.handle = dso.getHandle();
|
||||||
|
this.identifiers = dso.getIdentifiers(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -81,10 +81,11 @@ public class RDFUtil {
|
|||||||
* identifier assigned to the provided DSO.
|
* identifier assigned to the provided DSO.
|
||||||
*/
|
*/
|
||||||
public static String generateIdentifier(Context context, int type, int id,
|
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,
|
return RDFConfiguration.getURIGenerator().generateIdentifier(context,
|
||||||
type, id, handle);
|
type, id, handle, identifier);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Converts the the provided DSpaceObject into RDF and returns the model.
|
* Converts the the provided DSpaceObject into RDF and returns the model.
|
||||||
@@ -281,11 +282,11 @@ public class RDFUtil {
|
|||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
* @throws RDFMissingIdentifierException In case that no Identifier could be generated.
|
* @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
|
throws SQLException, RDFMissingIdentifierException
|
||||||
{
|
{
|
||||||
String uri = RDFConfiguration.getURIGenerator().generateIdentifier(ctx,
|
String uri = RDFConfiguration.getURIGenerator().generateIdentifier(ctx,
|
||||||
type, id, handle);
|
type, id, handle, identifiers);
|
||||||
if (uri != null)
|
if (uri != null)
|
||||||
{
|
{
|
||||||
RDFConfiguration.getRDFStorage().delete(uri);
|
RDFConfiguration.getRDFStorage().delete(uri);
|
||||||
|
@@ -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();
|
||||||
|
|
||||||
|
}
|
@@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -24,7 +24,8 @@ import org.dspace.utils.DSpace;
|
|||||||
public class HandleURIGenerator implements URIGenerator {
|
public class HandleURIGenerator implements URIGenerator {
|
||||||
private static final Logger log = Logger.getLogger(HandleURIGenerator.class);
|
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)
|
if (type == Constants.SITE)
|
||||||
{
|
{
|
||||||
@@ -59,6 +60,7 @@ public class HandleURIGenerator implements URIGenerator {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return generateIdentifier(context, dso.getType(), dso.getID(), dso.getHandle());
|
return generateIdentifier(context, dso.getType(), dso.getID(),
|
||||||
|
dso.getHandle(), dso.getIdentifiers(context));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,10 +27,10 @@ public class LocalURIGenerator implements URIGenerator {
|
|||||||
private static final Logger log = Logger.getLogger(LocalURIGenerator.class);
|
private static final Logger log = Logger.getLogger(LocalURIGenerator.class);
|
||||||
|
|
||||||
@Override
|
@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
|
throws SQLException
|
||||||
{
|
{
|
||||||
|
|
||||||
String urlPrefix = RDFConfiguration.getDSpaceRDFModuleURI() + "/resource/";
|
String urlPrefix = RDFConfiguration.getDSpaceRDFModuleURI() + "/resource/";
|
||||||
|
|
||||||
if (type == Constants.SITE)
|
if (type == Constants.SITE)
|
||||||
@@ -62,7 +62,7 @@ public class LocalURIGenerator implements URIGenerator {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return generateIdentifier(context, dso.getType(), dso.getID(), dso.getHandle());
|
return generateIdentifier(context, dso.getType(), dso.getID(), dso.getHandle(), dso.getIdentifiers(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,7 @@ public interface URIGenerator {
|
|||||||
* @return May return null, if no URI could be generated.
|
* @return May return null, if no URI could be generated.
|
||||||
* @see org.dspace.rdf.RDFUtil#generateIdentifier(Context, DSpaceObject)
|
* @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;
|
throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user