Skip to content

Commit

Permalink
Wings persister saves a native valkyrie resource
Browse files Browse the repository at this point in the history
Adds all current shared specs from valkyrie, marks pending those that do
not pass. Removed ones that were pending upstream (i.e. not supported in
valkyrie adapters). Removed deep nesting and mixed nesting.

Sketches out the beginning of a "Default" active fedora object for use
with an unrecognized Valkyrie Resource

Co-authored-by: LaRita Robinson <[email protected]>
Co-authored-by: jeremyf <[email protected]>
  • Loading branch information
3 people committed Mar 18, 2019
1 parent bc59aea commit 25957fb
Show file tree
Hide file tree
Showing 5 changed files with 560 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .rubocop_fixme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ RSpec/ExampleLength:
- 'spec/services/hyrax/workflow/state_machine_generator_spec.rb'
- 'spec/services/hyrax/workflow/workflow_importer_spec.rb'
- 'spec/views/**/*'

- 'spec/wings/valkyrie/persister_spec.rb'
RSpec/VerifiedDoubles:
Enabled: false

Expand Down
1 change: 0 additions & 1 deletion lib/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
require 'hyrax/version'
require 'hyrax/inflections'
require 'kaminari_route_prefix'
require 'wings'

module Hyrax
extend ActiveSupport::Autoload
Expand Down
1 change: 1 addition & 0 deletions lib/hyrax/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Engine < ::Rails::Engine
require 'dry/struct'
require 'dry/equalizer'
require 'dry/validation'
require 'wings'
begin
require 'valkyrie'
rescue LoadError
Expand Down
39 changes: 37 additions & 2 deletions lib/wings/active_fedora_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ def initialize(resource:)
##
# @return [ActiveFedora::Base]
def convert
resource.internal_resource.constantize.new(attributes).tap do |obj|
active_fedora_class.new(attributes).tap do |obj|
obj.id = id unless id.empty?
resource.member_ids.each { |valkyrie_id| obj.members << ActiveFedora::Base.find(valkyrie_id.id) } if resource.respond_to? :member_ids
resource.member_ids.each { |valkyrie_id| obj.members << ActiveFedora::Base.find(valkyrie_id.id) } if resource.respond_to?(:member_ids) && resource.member_ids
end
end

def active_fedora_class
klass = resource.internal_resource.constantize
return klass if klass <= ActiveFedora::Base
DefaultWork
end

##
# @return [Hash<Symbol, Object>]
def attributes
Expand All @@ -55,7 +61,36 @@ def attributes
##
# @return [String]
def id
return "" unless resource.respond_to?(:alternate_ids)
resource.alternate_ids.first.to_s
end

# A dummy work class for valkyrie resources that don't have corresponding
# hyrax ActiveFedora::Base models.
#
# A possible improvement would be to dynamically generate properties based
# on what's found in the resource.
class DefaultWork < ActiveFedora::Base
include Hyrax::WorkBehavior
property :ordered_authors, predicate: ::RDF::Vocab::DC.creator
property :ordered_nested, predicate: ::RDF::URI("http://example.com/ordered_nested")
property :nested_resource, predicate: ::RDF::URI("http://example.com/nested_resource"), class_name: "Wings::ActiveFedoraConverter::NestedResource"
accepts_nested_attributes_for :nested_resource

# self.indexer = <%= class_name %>Indexer
include ::Hyrax::BasicMetadata
end

class NestedResource < ActiveTriples::Resource
def initialize(uri = RDF::Node.new, _parent = ActiveTriples::Resource.new)
uri = if uri.try(:node?)
RDF::URI("#nested_resource_#{uri.to_s.gsub('_:', '')}")
elsif uri.to_s.include?('#')
RDF::URI(uri)
end
super
end
include ::Hyrax::BasicMetadata
end
end
end
Loading

0 comments on commit 25957fb

Please sign in to comment.