eulfedora.models - Fedora models

DigitalObject

class eulfedora.models.DigitalObject(api, pid=None, create=False)

A single digital object in a Fedora respository, with methods and properties to easy creating, accessing, and updating a Fedora object or any of its component parts.

add_relationship(rel_uri, object)

Add a new relationship to the RELS-EXT for this object. Calls API_M.addRelationship().

Example usage:

isMemberOfCollection = "info:fedora/fedora-system:def/relations-external#isMemberOfCollection"
collection_uri = "info:fedora/foo:456"
object.add_relationship(isMemberOfCollection, collection_uri)
Parameters:
  • rel_uri – URI for the new relationship
  • object – related object; can be DigitalObject or string; if string begins with info:fedora/ it will be treated as a resource, otherwise it will be treated as a literal
Return type:

boolean

dc

XML-specific version of Datastream. Datastreams are initialized as instances of XmlDatastreamObject. An additional, optional parameter objtype is passed to the Datastream object to configure the type of eulxml.xmlmap.XmlObject that should be used for datastream content.

Example usage:

from eulxml.xmlmap.dc import DublinCore

class MyDigitalObject(DigitalObject):
    dc = XmlDatastream("DC", "Dublin Core", DublinCore)
default_pidspace

Default namespace to use when generating new PIDs in get_default_pid() (by default, calls Fedora getNextPid, which will use Fedora-configured namespace if default_pidspace is not set).

ds_list

Dictionary of all datastreams that belong to this object in Fedora. Key is datastream id, value is an ObjectDatastream for that datastream.

Only retrieved when requested; cached after first retrieval.

exists

Does the object exist in Fedora?

getDatastreamObject(dsid)

Get any datastream on this object as a DatastreamObject

getDatastreamProfile(dsid)

Get information about a particular datastream belonging to this object.

Parameters:dsid – datastream id
Return type:DatastreamProfile
getProfile()

Get information about this object (label, owner, date created, etc.).

Return type:ObjectProfile
get_default_pid()

Get the next default pid when creating and ingesting a new DigitalObject instance without specifying a pid. By default, calls ApiFacade.getNextPID() with the configured class default_pidspace (if specified) as the pid namespace.

If your project requires custom pid logic (e.g., object pids are based on an external pid generator), you should extend DigitalObject and override this method.

has_model(model)

Check if this object subscribes to the specified content model.

Parameters:model – URI for the content model, as a string (currently only accepted in info:fedora/foo:### format)
Return type:boolean
has_requisite_content_models

Does the object have the expected content models for this type of DigitalObject ?

label

object label

owner

object owner

pidspace

Fedora pidspace of this object

rels_ext

RDF-specific version of Datastream. Datastreams are initialized as instances of RdfDatastreamObject.

Example usage:

class MyDigitalObject(DigitalObject):
    rels_ext = RdfDatastream("RELS-EXT", "External Relations")
save(logMessage=None)

Save to Fedora any parts of this object that have been modified (object profile or any datastream content or info). If a failure occurs at any point on saving any of the parts of the object, will back out any changes that have been made and raise a DigitalObjectSaveFailure with information about where the failure occurred and whether or not it was recoverable.

If the object is new, ingest it. If object profile information has been modified before saving, this data is used in the ingest. Datastreams are initialized to sensible defaults: XML objects are created using their default constructor, and RDF graphs start empty. If they’re updated before saving then those updates are included in the initial version. Datastream profile information is initialized from defaults specified in the Datastream declaration, though it too can be overridden prior to the initial save.

state

object state (Active/Inactive/Deleted)

uri

Fedora URI for this object (info:fedora/foo:### form of object pid)

uriref

Fedora URI for this object, as an rdflib URI object

Custom Exception

class eulfedora.models.DigitalObjectSaveFailure(pid, failure, to_be_saved, saved, cleaned)

Custom exception class for when a save error occurs part-way through saving an instance of DigitalObject. This exception should contain enough information to determine where the save failed, and whether or not any changes saved before the failure were successfully rolled back.

These properties are available:
  • obj_pid - pid of the DigitalObject instance that failed to save
  • failure - string indicating where the failure occurred (either a datastream ID or ‘object profile’)
  • to_be_saved - list of datastreams that were modified and should have been saved
  • saved - list of datastreams that were successfully saved before failure occurred
  • cleaned - list of saved datastreams that were successfully rolled back
  • not_cleaned - saved datastreams that were not rolled back
  • recovered - boolean, True indicates all saved datastreams were rolled back

Datastream

Datastream Descriptors

class eulfedora.models.Datastream(id, label, defaults={})

Datastream descriptor to simplify configuration and access to datastreams that belong to a particular DigitalObject.

When accessed, will initialize a DatastreamObject and cache it on the DigitalObject that it belongs to.

Example usage:

class MyDigitalObject(DigitalObject):
    text = Datastream("TEXT", "Text content", defaults={'mimetype': 'text/plain'})

All other configuration defaults are passed on to the DatastreamObject.

class eulfedora.models.XmlDatastream(id, label, objtype=None, defaults={})

XML-specific version of Datastream. Datastreams are initialized as instances of XmlDatastreamObject. An additional, optional parameter objtype is passed to the Datastream object to configure the type of eulxml.xmlmap.XmlObject that should be used for datastream content.

Example usage:

from eulxml.xmlmap.dc import DublinCore

class MyDigitalObject(DigitalObject):
    dc = XmlDatastream("DC", "Dublin Core", DublinCore)
class eulfedora.models.RdfDatastream(id, label, defaults={})

RDF-specific version of Datastream. Datastreams are initialized as instances of RdfDatastreamObject.

Example usage:

class MyDigitalObject(DigitalObject):
    rels_ext = RdfDatastream("RELS-EXT", "External Relations")

Datastream Objects

class eulfedora.models.DatastreamObject(obj, id, label, mimetype=None, versionable=False, state='A', format=None, control_group='M', checksum=None, checksum_type='MD5')

Object to ease accessing and updating a datastream belonging to a Fedora object. Handles datastream content as well as datastream profile information. Content and datastream info are only pulled from Fedora when content and info fields are accessed.

Intended to be used with DigitalObject and intialized via Datastream.

Initialization parameters:
param obj:the DigitalObject that this datastream belongs to.
param id:datastream id
param label:default datastream label
param mimetype:default datastream mimetype
param versionable:
 default configuration for datastream versioning
param state:default configuration for datastream state
param format:default configuration for datastream format URI
param checksum:default configuration for datastream checksum
param format:default configuration for datastream checksum type
content

contents of the datastream; only pulled from Fedora when accessed, cached after first access

isModified()

Check if either the datastream content or profile fields have changed and should be saved to Fedora.

Return type:boolean
label

datastream label

mimetype

datastream mimetype

save(logmessage=None)

Save datastream content and any changed datastream profile information to Fedora.

Return type:boolean for success
size

Size of the datastream content

state

datastream state (Active/Inactive/Deleted)

undo_last_save(logMessage=None)

Undo the last change made to the datastream content and profile, effectively reverting to the object state in Fedora as of the specified timestamp.

For a versioned datastream, this will purge the most recent datastream. For an unversioned datastream, this will overwrite the last changes with a cached version of any content and/or info pulled from Fedora.

versionable

boolean; indicates if Fedora is configured to version the datastream

class eulfedora.models.XmlDatastreamObject(obj, id, label, objtype=<class 'eulxml.xmlmap.core.XmlObject'>, **kwargs)

Extends DatastreamObject in order to initialize datastream content as an instance of a specified XmlObject.

See DatastreamObject for more details. Has one additional parameter:

Parameters:objtype – xml object type to use for datastream content; if not specified, defaults to XmlObject
class eulfedora.models.RdfDatastreamObject(obj, id, label, mimetype=None, versionable=False, state='A', format=None, control_group='M', checksum=None, checksum_type='MD5')

Extends DatastreamObject in order to initialize datastream content as an RDF graph.

replace_uri(src, dest)

Replace a uri reference everywhere it appears in the graph with another one. It could appear as the subject, predicate, or object of a statement, so for each position loop through each statement that uses the reference in that position, remove the old statement, and add the replacement.