Class: Wings::Valkyrie::Storage

Inherits:
Valkyrie::Storage::Fedora
  • Object
show all
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'
"<http://www.w3.org/ns/ldp#NonRDFSource>; rel=\"type\""
FILES_PATH =
'files'
VERSIONS_SLUG =
'/fcr:versions'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.


26
27
28
29
# File 'lib/wings/valkyrie/storage.rb', line 26

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

#sha1Object (readonly)

Returns the value of attribute sha1.


24
25
26
# File 'lib/wings/valkyrie/storage.rb', line 24

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.


33
34
35
# File 'lib/wings/valkyrie/storage.rb', line 33

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.

Returns:

  • (Enumerable<Version> ordered list of versions)

    Enumerable<Version> ordered list of versions


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/wings/valkyrie/storage.rb', line 64

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)

  version_graph.query(predicate: RDF::Vocab::Fcrepo4.hasVersion).objects.map do |uri|
    timestamp =
      version_graph.query([uri, RDF::Vocab::Fcrepo4.created, :created])
                   .first_object
                   .object
    Version.new(cast_to_valkyrie_id(uri.to_s), timestamp, self)
  end.sort
end

#supports?(key) ⇒ Boolean

Returns whether.

Parameters:

  • key (Symbol)

    the key for plugin behavior to check support for

Returns:

  • (Boolean)

    whether


41
42
43
# File 'lib/wings/valkyrie/storage.rb', line 41

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


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/wings/valkyrie/storage.rb', line 45

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