Class: Valkyrie::Persistence::Fedora::Persister
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Fedora::Persister
- Defined in:
- lib/valkyrie/persistence/fedora/persister.rb,
lib/valkyrie/persistence/fedora/persister/orm_converter.rb,
lib/valkyrie/persistence/fedora/persister/model_converter.rb,
lib/valkyrie/persistence/fedora/persister/resource_factory.rb
Overview
Persister for Fedora MetadataAdapter.
Defined Under Namespace
Classes: ModelConverter, OrmConverter, ResourceFactory
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
- #delete(resource:) ⇒ Object
-
#initialize(adapter:) ⇒ Persister
constructor
A new instance of Persister.
- #initialize_repository ⇒ Object
-
#save(resource:) ⇒ Valkyrie::Resource
The resource with an ‘#id` value generated by the persistence backend.
-
#save_all(resources:) ⇒ Array<Valkyrie::Resource>
List of resources with an ‘#id` value generated by the persistence backend.
-
#wipe! ⇒ Object
Wipes all data in the persistence backend.
Constructor Details
#initialize(adapter:) ⇒ Persister
Returns a new instance of Persister.
9 10 11 |
# File 'lib/valkyrie/persistence/fedora/persister.rb', line 9 def initialize(adapter:) @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/valkyrie/persistence/fedora/persister.rb', line 7 def adapter @adapter end |
Instance Method Details
#delete(resource:) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/valkyrie/persistence/fedora/persister.rb', line 41 def delete(resource:) if resource.try(:alternate_ids) resource.alternate_ids.each do |alternate_identifier| adapter.persister.delete(resource: adapter.query_service.find_by(id: alternate_identifier)) end end orm = resource_factory.from_resource(resource: resource) orm.delete resource end |
#initialize_repository ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/valkyrie/persistence/fedora/persister.rb', line 62 def initialize_repository @initialized ||= begin resource = ::Ldp::Container::Basic.new(connection, base_path, nil, base_path) resource.save if resource.new? true end end |
#save(resource:) ⇒ Valkyrie::Resource
Returns The resource with an ‘#id` value generated by the persistence backend.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/valkyrie/persistence/fedora/persister.rb', line 14 def save(resource:) initialize_repository resource.created_at ||= Time.current resource.updated_at ||= Time.current ensure_multiple_values!(resource) orm = resource_factory.from_resource(resource: resource) alternate_resources = find_or_create_alternate_ids(resource) if !orm.new? || resource.id cleanup_alternate_resources(resource) if alternate_resources orm.update { |req| req.headers["Prefer"] = "handling=lenient; received=\"minimal\"" } else orm.create end persisted_resource = resource_factory.to_resource(object: orm) alternate_resources ? save_reference_to_resource(persisted_resource, alternate_resources) : persisted_resource end |
#save_all(resources:) ⇒ Array<Valkyrie::Resource>
Returns List of resources with an ‘#id` value generated by the persistence backend.
34 35 36 37 38 |
# File 'lib/valkyrie/persistence/fedora/persister.rb', line 34 def save_all(resources:) resources.map do |resource| save(resource: resource) end end |
#wipe! ⇒ Object
Wipes all data in the persistence backend.
55 56 57 58 59 60 |
# File 'lib/valkyrie/persistence/fedora/persister.rb', line 55 def wipe! connection.delete(base_path) connection.delete("#{base_path}/fcr:tombstone") rescue => error Valkyrie.logger.debug("Failed to wipe Fedora for some reason.") unless error.is_a?(::Ldp::NotFound) end |