Class: Valkyrie::Persistence::Fedora::Persister::OrmConverter
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Fedora::Persister::OrmConverter
- Defined in:
- lib/valkyrie/persistence/fedora/persister/orm_converter.rb
Overview
Responsible for converting LDP::Container::Basic to Resource
Defined Under Namespace
Classes: GraphToAttributes
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#attributes ⇒ Hash
Generate a Hash resulting from the mapping of Fedora LDP graphs to Valkyrie Resource attributes For example: { :internal_resource => “CustomResource”, :created_at => 2018-08-08 15:45:03 UTC, […] id => #<Valkyrie::ID:0x00007ff821e9cb38 @id=“9e5aef75-f4cc-42f4-b050-0eadeeab908d”, new_record => false }.
-
#convert ⇒ Valkyrie::Resource
Convert a Fedora LDP container to a Valkyrie Resource.
-
#id ⇒ Valkyrie::ID
Generate the Valkyrie ID from the existing Fedora LDP resource property Should no such property exist, the URI for the LDP resource is used to mint a new one.
-
#id_property ⇒ String
Retrieve the RDF property for the Valkyrie ID.
-
#initialize(object:, adapter:) ⇒ OrmConverter
constructor
A new instance of OrmConverter.
-
#populate_native_lock(resource) ⇒ Object
Get Fedora’s lastModified value from the LDP response.
Constructor Details
#initialize(object:, adapter:) ⇒ OrmConverter
Returns a new instance of OrmConverter.
11 12 13 14 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 11 def initialize(object:, adapter:) @object = object @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
6 7 8 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 6 def adapter @adapter end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
6 7 8 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 6 def object @object end |
Instance Method Details
#attributes ⇒ Hash
Generate a Hash resulting from the mapping of Fedora LDP graphs to Valkyrie Resource attributes For example:
{
:internal_resource => "CustomResource",
:created_at => 2018-08-08 15:45:03 UTC,
[...]
id => #<Valkyrie::ID:0x00007ff821e9cb38 @id="9e5aef75-f4cc-42f4-b050-0eadeeab908d",
new_record => false
}
32 33 34 35 36 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 32 def attributes GraphToAttributes.new(graph: graph, adapter: adapter) .convert .merge(id: id, new_record: false) end |
#convert ⇒ Valkyrie::Resource
Convert a Fedora LDP container to a Valkyrie Resource
18 19 20 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 18 def convert populate_native_lock(Valkyrie::Types::Anything[attributes]) end |
#id ⇒ Valkyrie::ID
Generate the Valkyrie ID from the existing Fedora LDP resource property Should no such property exist, the URI for the LDP resource is used to mint a new one
52 53 54 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 52 def id id_property.present? ? Valkyrie::ID.new(id_property) : adapter.uri_to_id(object.subject_uri) end |
#id_property ⇒ String
Retrieve the RDF property for the Valkyrie ID
59 60 61 62 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 59 def id_property return unless object.subject_uri.to_s.include?("#") object.graph.query([RDF::URI(""), PermissiveSchema.id, nil]).to_a.first.try(:object).to_s end |
#populate_native_lock(resource) ⇒ Object
Get Fedora’s lastModified value from the LDP response
39 40 41 42 43 44 45 46 47 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 39 def populate_native_lock(resource) return resource unless resource.respond_to?(Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK) lastmod = object.response_graph.first_object([nil, RDF::URI("http://fedora.info/definitions/v4/repository#lastModified"), nil]) return resource unless lastmod token = Valkyrie::Persistence::OptimisticLockToken.new(adapter_id: "native-#{adapter.id}", token: DateTime.parse(lastmod.to_s).httpdate) resource.send(Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK) << token resource end |