Class: Valkyrie::Persistence::Fedora::MetadataAdapter
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Fedora::MetadataAdapter
- Defined in:
- lib/valkyrie/persistence/fedora/metadata_adapter.rb
Overview
Metadata Adapter for Fedora adapter.
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#fedora_version ⇒ Object
readonly
Returns the value of attribute fedora_version.
-
#pairtree_count ⇒ Object
readonly
Returns the value of attribute pairtree_count.
-
#pairtree_length ⇒ Object
readonly
Returns the value of attribute pairtree_length.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#connection_prefix ⇒ String
Generate the prefix used in HTTP requests to the Fedora RESTful endpoint.
-
#id ⇒ Valkyrie::ID
Generate the Valkyrie ID for this unique metadata adapter This uses the URL of the Fedora endpoint to ensure that this is unique.
-
#id_to_uri(id) ⇒ RDF::URI
Generate a URI for a given Valkyrie ID.
-
#initialize(connection:, base_path: "/", schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new, fedora_version: Valkyrie::Persistence::Fedora::DEFAULT_FEDORA_VERSION, fedora_pairtree_count: 0, fedora_pairtree_length: 0) ⇒ MetadataAdapter
constructor
A new instance of MetadataAdapter.
-
#pair_path(id) ⇒ Array<String>
Generate the pairtree path for a given Valkyrie ID.
-
#persister ⇒ Valkyrie::Persistence::Fedora::Persister
Construct the persister object using this adapter.
-
#query_service ⇒ Valkyrie::Persistence::Fedora::QueryService
Construct the query service object using this adapter.
-
#resource_factory ⇒ Valkyrie::Persistence::Fedora::Persister::ResourceFactory
Construct the factory object used to construct Valkyrie::Resource objects using this adapter.
-
#uri_to_id(uri) ⇒ Valkyrie::ID
Generate a Valkyrie ID for a given URI.
- #url_prefix ⇒ Object
Constructor Details
#initialize(connection:, base_path: "/", schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new, fedora_version: Valkyrie::Persistence::Fedora::DEFAULT_FEDORA_VERSION, fedora_pairtree_count: 0, fedora_pairtree_length: 0) ⇒ MetadataAdapter
Returns a new instance of MetadataAdapter.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 20 def initialize(connection:, base_path: "/", schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new, # rubocop:disable Metrics/ParameterLists fedora_version: Valkyrie::Persistence::Fedora::DEFAULT_FEDORA_VERSION, fedora_pairtree_count: 0, fedora_pairtree_length: 0) @connection = connection @base_path = base_path @schema = schema @fedora_version = fedora_version @pairtree_count = fedora_pairtree_count @pairtree_length = fedora_pairtree_length end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
12 13 14 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 12 def base_path @base_path end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
12 13 14 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 12 def connection @connection end |
#fedora_version ⇒ Object (readonly)
Returns the value of attribute fedora_version.
12 13 14 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 12 def fedora_version @fedora_version end |
#pairtree_count ⇒ Object (readonly)
Returns the value of attribute pairtree_count.
12 13 14 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 12 def pairtree_count @pairtree_count end |
#pairtree_length ⇒ Object (readonly)
Returns the value of attribute pairtree_length.
12 13 14 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 12 def pairtree_length @pairtree_length end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
12 13 14 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 12 def schema @schema end |
Instance Method Details
#connection_prefix ⇒ String
Generate the prefix used in HTTP requests to the Fedora RESTful endpoint
96 97 98 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 96 def connection_prefix "#{connection.http.url_prefix}/#{base_path}" end |
#id ⇒ Valkyrie::ID
Generate the Valkyrie ID for this unique metadata adapter This uses the URL of the Fedora endpoint to ensure that this is unique
46 47 48 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 46 def id @id ||= Valkyrie::ID.new(Digest::MD5.hexdigest(connection_prefix)) end |
#id_to_uri(id) ⇒ RDF::URI
Generate a URI for a given Valkyrie ID
66 67 68 69 70 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 66 def id_to_uri(id) prefix = "" prefix = "#{pair_path(id)}/" if fedora_version == 4 || (fedora_version >= 6.5 && (pairtree_count * pairtree_length).positive?) RDF::URI("#{connection_prefix}/#{prefix}#{CGI.escape(id.to_s)}") end |
#pair_path(id) ⇒ Array<String>
Generate the pairtree path for a given Valkyrie ID
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 77 def pair_path(id) if fedora_version >= 6.5 # When configurable, pair the part up to count * length, but only up to a slash pair_part = id.to_s[0, pairtree_count * pairtree_length].split(/[\/]/).first slice_length = pairtree_length else # When not configurable, pair the full string, but only up to a dash or slash pair_part = id.to_s.split(/[-\/]/).first slice_length = 2 end pair_part.split("").each_slice(slice_length).map(&:join).join("/") end |
#persister ⇒ Valkyrie::Persistence::Fedora::Persister
Construct the persister object using this adapter
39 40 41 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 39 def persister Valkyrie::Persistence::Fedora::Persister.new(adapter: self) end |
#query_service ⇒ Valkyrie::Persistence::Fedora::QueryService
Construct the query service object using this adapter
33 34 35 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 33 def query_service @query_service ||= Valkyrie::Persistence::Fedora::QueryService.new(adapter: self) end |
#resource_factory ⇒ Valkyrie::Persistence::Fedora::Persister::ResourceFactory
Construct the factory object used to construct Valkyrie::Resource objects using this adapter
52 53 54 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 52 def resource_factory Valkyrie::Persistence::Fedora::Persister::ResourceFactory.new(adapter: self) end |
#uri_to_id(uri) ⇒ Valkyrie::ID
Generate a Valkyrie ID for a given URI
59 60 61 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 59 def uri_to_id(uri) Valkyrie::ID.new(CGI.unescape(uri.to_s.gsub(/^.*\//, ''))) end |
#url_prefix ⇒ Object
90 91 92 |
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 90 def url_prefix connection.http.url_prefix end |