Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I897 Bulkrax readiness for Hyku 6 and Hyrax 4 & 5 #898

Merged
merged 15 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions app/models/concerns/bulkrax/has_mapping_ext.rb

This file was deleted.

23 changes: 17 additions & 6 deletions app/models/concerns/bulkrax/has_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def add_metadata(node_name, node_content, index = nil)
end
end

def get_object_name(field)
mapping&.[](field)&.[]('object')
end

def set_parsed_data(name, value)
return parsed_metadata[name] = value unless multiple?(name)

Expand Down Expand Up @@ -125,9 +129,14 @@ def field_supported?(field)

return false if excluded?(field)
return true if supported_bulkrax_fields.include?(field)

property_defined = factory_class.singleton_methods.include?(:properties) && factory_class.properties[field].present?

factory_class.method_defined?(field) && (Bulkrax::ValkyrieObjectFactory.schema_properties(factory_class).include?(field) || property_defined)
if factory_class == Bulkrax::ValkyrieObjectFactory
factory_class.method_defined?(field) && (Bulkrax::ValkyrieObjectFactory.schema_properties(factory_class).include?(field) || property_defined)
else
factory_class.method_defined?(field) && factory_class.properties[field].present?
end
end

def supported_bulkrax_fields
Expand All @@ -144,6 +153,8 @@ def supported_bulkrax_fields
]
end

##
# Determine a multiple properties field
def multiple?(field)
@multiple_bulkrax_fields ||=
%W[
Expand All @@ -157,13 +168,17 @@ def multiple?(field)
return true if @multiple_bulkrax_fields.include?(field)
return false if field == 'model'

if factory.class.respond_to?(:schema)
if factory_class == Bulkrax::ValkyrieObjectFactory
field_supported?(field) && valkyrie_multiple?(field)
else
field_supported?(field) && ar_multiple?(field)
end
end

def schema_form_definitions
@schema_form_definitions ||= ::SchemaLoader.new.form_definitions_for(factory_class.name.underscore.to_sym)
end

def ar_multiple?(field)
factory_class.singleton_methods.include?(:properties) && factory_class&.properties&.[](field)&.[]("multiple")
end
Expand All @@ -174,10 +189,6 @@ def valkyrie_multiple?(field)
factory_class.schema.key(sym_field).respond_to?(:of) if factory_class.fields.include?(sym_field)
end

def get_object_name(field)
mapping&.[](field)&.[]('object')
end

# Hyrax field to use for the given import field
# @param field [String] the importer field name
# @return [Array] hyrax fields
Expand Down
50 changes: 36 additions & 14 deletions spec/bulkrax/entry_spec_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,44 @@
}
end

let(:data) { { model: "Work", source_identifier: identifier, title: "If You Want to Go Far" } }

it { is_expected.to be_a(Bulkrax::CsvEntry) }

it "parses metadata" do
entry.build_metadata

expect(entry.factory_class).to eq(Work)
{
"title" => ["If You Want to Go Far"],
"admin_set_id" => "admin_set/default",
"source" => [identifier]
}.each do |key, value|
expect(entry.parsed_metadata.fetch(key)).to eq(value)
context 'when ActiveFedora object' do
let(:data) { { model: "Work", source_identifier: identifier, title: "If You Want to Go Far" } }

it { is_expected.to be_a(Bulkrax::CsvEntry) }

it "parses metadata" do
entry.build_metadata

expect(entry.factory_class).to eq(Work)
{
"title" => ["If You Want to Go Far"],
"admin_set_id" => "admin_set/default",
"source" => [identifier]
}.each do |key, value|
expect(entry.parsed_metadata.fetch(key)).to eq(value)
end
end
end

# TODO: Add specs for when Bulkrax::ValkyrieObjectFactory is used
# context 'when Valkyrie object' do
# let(:data) { { model: "Work", source_identifier: identifier, title: "If You Want to Go Far" } }

# it { is_expected.to be_a(Bulkrax::CsvEntry) }

# it "parses metadata" do
# entry.build_metadata

# expect(entry.factory_class).to eq(Work)
# {
# "title" => ["If You Want to Go Far"],
# "admin_set_id" => "admin_set/default",
# "source" => [identifier]
# }.each do |key, value|
# expect(entry.parsed_metadata.fetch(key)).to eq(value)
# end
# end
# end
end

context 'for parser_class_name: "Bulkrax::OaiDcParser"' do
Expand Down
Loading