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 Details

    • CONTENT_NEGOTIATION_KEY

      public static final String CONTENT_NEGOTIATION_KEY
      See Also:
    • 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:
    • 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:
    • 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:
    • SPARQL_ENDPOINT_KEY

      public static final String SPARQL_ENDPOINT_KEY
      Property key to load the public address of the SPARQL endpoint.
      See Also:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
  • Method Details

    • loadModel

      public static org.apache.jena.rdf.model.Model loadModel(String identifier)
      Loads converted data of a DSpaceObject identified by the URI provided as identifier. This method uses the RDFStorage configured 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 org.apache.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 error
      ItemNotArchivedException - 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 org.apache.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 configured RDFStorage. 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 error
      ItemNotArchivedException - 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

      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 error
      ItemNotArchivedException - If dso is an Item and is not archived.
      ItemWithdrawnException - If dso is an Item and is withdrawn.
      ItemNotDiscoverableException - If dso is an Item and is not discoverable.
      AuthorizeException - If context does not grant READ permissions for dso.
    • isPublicBoolean

      public static boolean isPublicBoolean(Context context, DSpaceObject dso) throws SQLException
      Does the same as isPublic(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 error
      org.dspace.rdf.RDFMissingIdentifierException - In case that no Identifier could be generated.