Class: Wings::Valkyrie::Storage
- Inherits:
-
Valkyrie::Storage::Fedora
- Object
- Valkyrie::Storage::Fedora
- Wings::Valkyrie::Storage
- Defined in:
- lib/wings/valkyrie/storage.rb
Overview
This is a Wings storage adapter designed for compatibility with Hydra::Pcdm/Hydra::Works.
Where the built-in ‘Valkyrie::Storage::Fedora` adapter uploads files without LDP containment relationships (via HTTP PUT), this adapter supports adding files to a `/files` container when a `FileSet` is passed as the `resource:` argument.
If a non ‘#file_set?` resource is passed, the logic is very similar to the built-in storage adapter.
For use with Hyrax, this adapter defaults to Fedora 4.
Defined Under Namespace
Classes: Version
Constant Summary collapse
- DEFAULT_CTYPE =
'application/octet-stream'
- LINK_HEADER =
"<http://www.w3.org/ns/ldp#NonRDFSource>; rel=\"type\""
- FILES_PATH =
'files'
- VERSIONS_SLUG =
'/fcr:versions'
Instance Attribute Summary collapse
-
#sha1 ⇒ Object
readonly
Returns the value of attribute sha1.
Class Method Summary collapse
Instance Method Summary collapse
-
#find_versions(id:) ⇒ Enumerable<Version> ordered list of versions
Enumerable<Version> ordered list of versions.
-
#initialize(connection: Ldp::Client.new(ActiveFedora.fedora.host), base_path: ActiveFedora.fedora.base_path, fedora_version: 4) ⇒ Storage
constructor
A new instance of Storage.
-
#supports?(key) ⇒ Boolean
Whether.
-
#upload(file:, original_filename:, resource:, content_type: DEFAULT_CTYPE, resource_uri_transformer: default_resource_uri_transformer, use: Hydra::PCDM::Vocab::PCDMTerms.File, id_hint: 'original', **extra_arguments) ⇒ Object
rubocop:disable Metrics/ParameterLists.
Constructor Details
#initialize(connection: Ldp::Client.new(ActiveFedora.fedora.host), base_path: ActiveFedora.fedora.base_path, fedora_version: 4) ⇒ Storage
Returns a new instance of Storage.
28 29 30 31 |
# File 'lib/wings/valkyrie/storage.rb', line 28 def initialize(connection: Ldp::Client.new(ActiveFedora.fedora.host), base_path: ActiveFedora.fedora.base_path, fedora_version: 4) @sha1 = fedora_version == 5 ? "sha" : "sha1" super end |
Instance Attribute Details
#sha1 ⇒ Object (readonly)
Returns the value of attribute sha1.
26 27 28 |
# File 'lib/wings/valkyrie/storage.rb', line 26 def sha1 @sha1 end |
Class Method Details
.cast_to_valkyrie_id(id) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 |
# File 'lib/wings/valkyrie/storage.rb', line 35 def self.cast_to_valkyrie_id(id) ::Valkyrie::ID.new(id.to_s.sub(/^.+\/\//, PROTOCOL)) end |
Instance Method Details
#find_versions(id:) ⇒ Enumerable<Version> ordered list of versions
Returns Enumerable<Version> ordered list of versions.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/wings/valkyrie/storage.rb', line 66 def find_versions(id:) response = connection.http.get(fedora_identifier(id: id) + VERSIONS_SLUG) return [] if response.status == 404 reader = RDF::Reader.for(content_type: response.headers['content-type']) version_graph = RDF::Graph.new << reader.new(response.body) query = { predicate: RDF::Vocab::Fcrepo4.hasVersion } version_graph.query(query).objects.map do |uri| = version_graph.query([uri, RDF::Vocab::Fcrepo4.created, :created]) .first_object .object Version.new(id: cast_to_valkyrie_id(uri.to_s), created: , adapter: self) end.sort end |
#supports?(key) ⇒ Boolean
Returns whether.
43 44 45 |
# File 'lib/wings/valkyrie/storage.rb', line 43 def supports?(key) key == :versions end |
#upload(file:, original_filename:, resource:, content_type: DEFAULT_CTYPE, resource_uri_transformer: default_resource_uri_transformer, use: Hydra::PCDM::Vocab::PCDMTerms.File, id_hint: 'original', **extra_arguments) ⇒ Object
rubocop:disable Metrics/ParameterLists
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/wings/valkyrie/storage.rb', line 47 def upload(file:, original_filename:, resource:, content_type: DEFAULT_CTYPE, # rubocop:disable Metrics/ParameterLists resource_uri_transformer: default_resource_uri_transformer, use: Hydra::PCDM::Vocab::PCDMTerms.File, id_hint: 'original', **extra_arguments) id = if resource.try(:file_set?) upload_with_works(resource: resource, file: file, use: use) else put_file(file: file, original_filename: original_filename, resource: resource, content_type: content_type, resource_uri_transformer: resource_uri_transformer, id_hint: id_hint, **extra_arguments) end find_by(id: cast_to_valkyrie_id(id)) end |