Package org.dspace.rdf
Class RDFUtil
- java.lang.Object
-
- org.dspace.rdf.RDFUtil
-
public class RDFUtil extends Object
- Author:
- Pascal-Nicolas Becker (dspace -at- pascal -hyphen- becker -dot- de)
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONTENT_NEGOTIATION_KEYstatic StringCONTEXT_PATH_KEYProperty key to load the URL of the dspace-rdf module.static StringCONVERTER_DSOTYPES_KEYKey of the Property to load the types of DSpaceObjects that should get converted.static StringSPARQL_ENDPOINT_KEYProperty key to load the public address of the SPARQL endpoint.static StringSTORAGE_GRAPHSTORE_ENDPOINT_KEYProperty key to load the address of the SPARQL 1.1 GRAPH STORE HTTP PROTOCOL endpoint.static StringSTORAGE_GRAPHSTORE_LOGIN_KEYProperty key to load the username if authentication for the graph store endpoint is required.static StringSTORAGE_GRAPHSTORE_PASSWORD_KEYProperty key to load the password if authentication for the graph store endpoint is required.static StringSTORAGE_SPARQL_ENDPOINT_KEYProperty key to load the address of the SPARQL endpoint to use within DSpace.static StringSTORAGE_SPARQL_LOGIN_KEYProperty key to load the username if authentication for the internal SPARQL endpoint is required.static StringSTORAGE_SPARQL_PASSWORD_KEYProperty key to load the password if authentication for the internal SPARQL endpoint is required.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.hp.hpl.jena.rdf.model.Modelconvert(Context context, DSpaceObject dso)Converts the the provided DSpaceObject into RDF and returns the model.static com.hp.hpl.jena.rdf.model.ModelconvertAndStore(Context context, DSpaceObject dso)Converts a DSpaceObject into RDF data and stores them using the configuredRDFStorage.static voiddelete(String uri)Deletes the data identified by the URI from the triple store.static voiddelete(Context ctx, int type, UUID id, String handle, List<String> identifiers)This is a shortcut to generate an RDF identifier for a DSpaceObject and to delete the identified data from the named graph.static StringgenerateIdentifier(Context context, int type, UUID id, String handle, List<String> identifier)Generates a URI identifying the provided DSpaceObject.static StringgenerateIdentifier(Context context, DSpaceObject dso)Generates a URI identifying the provided DSpaceObject.static voidisPublic(Context context, DSpaceObject dso)Checks whether the provided DSpaceObject is readable within the provided context and if the DSO is an Item whether it is archived, discoverable and not withdrawn.static booleanisPublicBoolean(Context context, DSpaceObject dso)Does the same asisPublic(Context, DSpaceObject)but returns a boolean instead of throwing exceptions.static com.hp.hpl.jena.rdf.model.ModelloadModel(String identifier)Loads converted data of a DSpaceObject identified by the URI provided asidentifier.
-
-
-
Field Detail
-
CONTENT_NEGOTIATION_KEY
public static final String CONTENT_NEGOTIATION_KEY
- See Also:
- Constant Field Values
-
CONVERTER_DSOTYPES_KEY
public static final String CONVERTER_DSOTYPES_KEY
Key of the Property to load the types of DSpaceObjects that should get converted.- See Also:
- Constant Field Values
-
STORAGE_GRAPHSTORE_PASSWORD_KEY
public static final String STORAGE_GRAPHSTORE_PASSWORD_KEY
Property key to load the password if authentication for the graph store endpoint is required.- See Also:
- Constant Field Values
-
CONTEXT_PATH_KEY
public static final String CONTEXT_PATH_KEY
Property key to load the URL of the dspace-rdf module. This is necessary to create links from the UI to RDF representation of DSpaceObjects.- See Also:
- Constant Field Values
-
SPARQL_ENDPOINT_KEY
public static final String SPARQL_ENDPOINT_KEY
Property key to load the public address of the SPARQL endpoint.- See Also:
- Constant Field Values
-
STORAGE_SPARQL_LOGIN_KEY
public static final String STORAGE_SPARQL_LOGIN_KEY
Property key to load the username if authentication for the internal SPARQL endpoint is required.- See Also:
- Constant Field Values
-
STORAGE_SPARQL_PASSWORD_KEY
public static final String STORAGE_SPARQL_PASSWORD_KEY
Property key to load the password if authentication for the internal SPARQL endpoint is required.- See Also:
- Constant Field Values
-
STORAGE_GRAPHSTORE_ENDPOINT_KEY
public static final String STORAGE_GRAPHSTORE_ENDPOINT_KEY
Property key to load the address of the SPARQL 1.1 GRAPH STORE HTTP PROTOCOL endpoint.- See Also:
- Constant Field Values
-
STORAGE_SPARQL_ENDPOINT_KEY
public static final String STORAGE_SPARQL_ENDPOINT_KEY
Property key to load the address of the SPARQL endpoint to use within DSpace. If the property is empty or does not exist, the public SPARQL endpoint will be used.- See Also:
- Constant Field Values
-
STORAGE_GRAPHSTORE_LOGIN_KEY
public static final String STORAGE_GRAPHSTORE_LOGIN_KEY
Property key to load the username if authentication for the graph store endpoint is required.- See Also:
- Constant Field Values
-
-
Method Detail
-
loadModel
public static com.hp.hpl.jena.rdf.model.Model loadModel(String identifier)
Loads converted data of a DSpaceObject identified by the URI provided asidentifier. This method uses the RDFStorage configurated in the DSpace configuration. Close the model (Model.close()) as soon as possible to free system resources.- Parameters:
identifier- A URI representing the object you want to load data about.- Returns:
- A model containing the RDF data to the specified identifier or null if no data could be found.
-
generateIdentifier
public static String generateIdentifier(Context context, DSpaceObject dso) throws SQLException
Generates a URI identifying the provided DSpaceObject. This method automatically loads and instantiates the URIGenerator configured in DSpace configuration. Please note that URIs can be generated for DSpaceObjects of the type SITE, COMMUNITY, COLLECTION or ITEM only. Currently dspace-rdf doesn't support Bundles or Bitstreams as independent entity.- Parameters:
context- DSpace Context.dso- DSpace Object you want to get an identifier for.- Returns:
- URI to identify the DSO or null if no URI could be generated. This can happen f.e. if you use a URIGenerator that uses persistent identifier like DOIs or Handles but there is no such identifier assigned to the provided DSO.
- Throws:
SQLException- An exception that provides information on a database access error or other errors.
-
generateIdentifier
public static String generateIdentifier(Context context, int type, UUID id, String handle, List<String> identifier) throws SQLException
Generates a URI identifying the provided DSpaceObject. This method automatically loads and instantiates the URIGenerator configured in DSpace configuration. Please note that URIs can be generated for DSpaceObjects of the type SITE, COMMUNITY, COLLECTION or ITEM only. Currently dspace-rdf doesn't support Bundles or Bitstreams as independent entity.- Parameters:
context- DSpace Context.type- Type of the DSpaceObject you want to generate a URI for (e.g.Constants.ITEM.id- UUID of the DSpaceObject you want to generate a URI for.handle- Handle of the DSpaceObject you want to generate a URI for.identifier- identifiers of the object.- Returns:
- URI to identify the DSO or null if no URI could be generated. This can happen f.e. if you use a URIGenerator that uses persistent identifier like DOIs or Handles but there is no such identifier assigned to the provided DSO.
- Throws:
SQLException- An exception that provides information on a database access error or other errors.
-
convert
public static com.hp.hpl.jena.rdf.model.Model convert(Context context, DSpaceObject dso) throws org.dspace.rdf.RDFMissingIdentifierException, SQLException, ItemNotArchivedException, ItemWithdrawnException, ItemNotDiscoverableException, AuthorizeException, IllegalArgumentException
Converts the the provided DSpaceObject into RDF and returns the model. Please note that dspace-rdf doesn't support Bundles or Bitstreams as independent entity. You can convert DSpaceObjects of type SITE, COMMUNITY, COLLECTION or ITEM.- Parameters:
context- Consider that the converted data will be stored in a triple store, that is outside the range of the DSpace authorization mechanism. Unless you are really sure what you are doing, you should provide the context of an anonymous user here, as the triple store probably provides a public SPARQL endpoint.dso- DSpaceObject to convert.- Returns:
- The converted data or null if the conversion result is empty. Remember to close the model as soon as you don't need it anymore.
- Throws:
org.dspace.rdf.RDFMissingIdentifierException- If no identifier could be generated.SQLException- if database errorItemNotArchivedException- If you want to convert an Item that is not archived.ItemWithdrawnException- If you want to convert an Item that is withdrawn.ItemNotDiscoverableException- If you want to convert an Item that is not discoverable.AuthorizeException- If the DSpaceObject does not have READ permissions with the provided context.IllegalArgumentException- If the DSpaceObject is not of type SITE, COMMUNITY, COLLECTION or ITEM.
-
convertAndStore
public static com.hp.hpl.jena.rdf.model.Model convertAndStore(Context context, DSpaceObject dso) throws org.dspace.rdf.RDFMissingIdentifierException, SQLException, ItemNotArchivedException, ItemWithdrawnException, ItemNotDiscoverableException, AuthorizeException, IllegalArgumentException
Converts a DSpaceObject into RDF data and stores them using the configuredRDFStorage. Please note that dspace-rdf doesn't support Bundles or Bitstreams as independent entity. You can convert DSpaceObjects of type SITE, COMMUNITY, COLLECTION or ITEM.- Parameters:
context- Consider that the converted data will be stored in a triple store, that is outside the range of the DSpace authorization mechanism. Unless you are really sure what you are doing, you should provide the context of an anonymous user here, as the triple store probably provides a public SPARQL endpoint.dso- DSpaceObject to convert.- Returns:
- The converted data or null if the conversion result is empty. Remember to close the model as soon as you don't need it anymore.
- Throws:
org.dspace.rdf.RDFMissingIdentifierException- If no identifier could be generated.SQLException- if database errorItemNotArchivedException- If you want to convert an Item that is not archived.ItemWithdrawnException- If you want to convert an Item that is withdrawn.ItemNotDiscoverableException- If you want to convert an Item that is not discoverable.AuthorizeException- If the DSpaceObject does not have READ permissions with the provided context.IllegalArgumentException- If the DSpaceObject is not of type SITE, COMMUNITY, COLLECTION or ITEM.
-
isPublic
public static void isPublic(Context context, DSpaceObject dso) throws SQLException, ItemNotArchivedException, ItemWithdrawnException, ItemNotDiscoverableException, AuthorizeException
Checks whether the provided DSpaceObject is readable within the provided context and if the DSO is an Item whether it is archived, discoverable and not withdrawn.- Parameters:
context- Consider that the converted data will be stored in a triple store, that is outside the range of the DSpace authorization mechanism. Unless you are really sure what you are doing, you should provide the context of an anonymous user here, as the triple store probably provides a public SPARQL endpoint.dso- The DSpaceObjet to check.- Throws:
SQLException- if database errorItemNotArchivedException- Ifdsois an Item and is not archived.ItemWithdrawnException- Ifdsois an Item and is withdrawn.ItemNotDiscoverableException- Ifdsois an Item and is not discoverable.AuthorizeException- Ifcontextdoes not grantREADpermissions fordso.
-
isPublicBoolean
public static boolean isPublicBoolean(Context context, DSpaceObject dso) throws SQLException
Does the same asisPublic(Context, DSpaceObject)but returns a boolean instead of throwing exceptions. For those who don't want to deal with catching exceptions.- Parameters:
context- Consider that the converted data will be stored in a triple store, that is outside the range of the DSpace authorization mechanism. Unless you are really sure what you are doing, you should provide the context of an anonymous user here, as the triple store probably provides a public SPARQL endpoint.dso- The DSpaceObjet to check.- Returns:
- true if
isPublic(Context, DSpaceObject)doesn't throw an exception, false if it did. - Throws:
SQLException- if database error
-
delete
public static void delete(String uri)
Deletes the data identified by the URI from the triple store.- Parameters:
uri- URI to identify the named graph to delete.
-
delete
public static void delete(Context ctx, int type, UUID id, String handle, List<String> identifiers) throws SQLException, org.dspace.rdf.RDFMissingIdentifierException
This is a shortcut to generate an RDF identifier for a DSpaceObject and to delete the identified data from the named graph.- Parameters:
ctx- The relevant DSpace Context.type- DSpaceObject type (e.g.Constants.ITEM).id- Id of the DspaceObject.handle- Handle of the DSpaceObject.identifiers- list of identifiers- Throws:
SQLException- if database errororg.dspace.rdf.RDFMissingIdentifierException- In case that no Identifier could be generated.
-
-