Class: Valkyrie::Persistence::Fedora::MetadataAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/persistence/fedora/metadata_adapter.rb

Overview

Metadata Adapter for Fedora adapter.

Examples:

Instantiate with connection to Fedora.

Valkyrie::Persistence::Fedora::MetadataAdapter.new(
  connection: ::Ldp::Client.new("http://localhost:8988/rest"),
  base_path: "test_fed",
  schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new(title: RDF::URI("http://bad.com/title"))
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:, base_path: "/", schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new, fedora_version: 4) ⇒ MetadataAdapter

Returns a new instance of MetadataAdapter.

Parameters:



18
19
20
21
22
23
24
25
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 18

def initialize(connection:, base_path: "/", schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new, fedora_version: 4)
  @connection = connection
  @base_path = base_path
  @schema = schema
  @fedora_version = fedora_version

  warn "[DEPRECATION] `fedora_version` will default to 5 in the next major release." unless fedora_version
end

Instance Attribute Details

#base_pathObject (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

#connectionObject (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_versionObject (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

#schemaObject (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_prefixString

Generate the prefix used in HTTP requests to the Fedora RESTful endpoint

Returns:

  • (String)


78
79
80
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 78

def connection_prefix
  "#{connection.http.url_prefix}/#{base_path}"
end

#idValkyrie::ID

Generate the Valkyrie ID for this unique metadata adapter This uses the URL of the Fedora endpoint to ensure that this is unique

Returns:



42
43
44
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 42

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

Parameters:

Returns:



62
63
64
65
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 62

def id_to_uri(id)
  prefix = fedora_version == 5 ? "" : "#{pair_path(id)}/"
  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



72
73
74
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 72

def pair_path(id)
  id.to_s.split(/[-\/]/).first.split("").each_slice(2).map(&:join).join("/")
end

#persisterValkyrie::Persistence::Fedora::Persister

Construct the persister object using this adapter



35
36
37
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 35

def persister
  Valkyrie::Persistence::Fedora::Persister.new(adapter: self)
end

#query_serviceValkyrie::Persistence::Fedora::QueryService

Construct the query service object using this adapter



29
30
31
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 29

def query_service
  @query_service ||= Valkyrie::Persistence::Fedora::QueryService.new(adapter: self)
end

#resource_factoryValkyrie::Persistence::Fedora::Persister::ResourceFactory

Construct the factory object used to construct Valkyrie::Resource objects using this adapter



48
49
50
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 48

def resource_factory
  Valkyrie::Persistence::Fedora::Persister::ResourceFactory.new(adapter: self)
end

#standardize_query_result?Boolean

Returns:

  • (Boolean)


82
83
84
85
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 82

def standardize_query_result?
  Valkyrie.warn_about_standard_queries! if Valkyrie.config.standardize_query_result != true
  Valkyrie.config.standardize_query_result == true
end

#uri_to_id(uri) ⇒ Valkyrie::ID

Generate a Valkyrie ID for a given URI

Parameters:

  • uri (RDF::URI)

    the URI for a Fedora resource

Returns:



55
56
57
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 55

def uri_to_id(uri)
  Valkyrie::ID.new(CGI.unescape(uri.to_s.gsub(/^.*\//, '')))
end