From ce352d3d10390f0032fa131010ab9d76759faddd Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Wed, 16 Oct 2024 15:49:22 -0400 Subject: [PATCH] Fixes Wings migration of based_near attribute in to_resource (#6922) * Add failing specs to fix * Maps location for wings migrations - Native Valkyrie objects contain a URI string, not an RDF::URI - Fedora contains Hyrax::ControlledVocabularies::Location objects Modifies the behavior of the `based_near` attribute in the `to_resource` and `from_resource` methods. When using wings to convert between resources & fedora works, we were previously storing the RDF::URI in Valkyrie. This PR updates the behavior to consistently return values consistent with what would be seen in native objects. * Pacify the cops * Undo Active Fedora conversion of based_near This may still be needed, but this doesn't work correctly. A ticket has been created for this bug if this is something that is ever needed. https://github.com/samvera/hyrax/issues/6926 --------- Co-authored-by: Rob Kaufman --- lib/wings/transformer_value_mapper.rb | 6 +++++- spec/wings/attribute_transformer_spec.rb | 15 +++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/wings/transformer_value_mapper.rb b/lib/wings/transformer_value_mapper.rb index d67a72ebcc..0c2b29d55a 100644 --- a/lib/wings/transformer_value_mapper.rb +++ b/lib/wings/transformer_value_mapper.rb @@ -49,8 +49,12 @@ def self.handles?(value) end ## - # @return [RDF::Term] + # Valkyrie objects contain a URI string for location objects so we need + # to return just the string for mapping from Fedora + # + # @return [RDF::Term || String] def result + return value.id if value.is_a?(Hyrax::ControlledVocabularies::Location) value.to_term end end diff --git a/spec/wings/attribute_transformer_spec.rb b/spec/wings/attribute_transformer_spec.rb index 310014cb1f..4130e14524 100644 --- a/spec/wings/attribute_transformer_spec.rb +++ b/spec/wings/attribute_transformer_spec.rb @@ -5,21 +5,28 @@ require 'wings/attribute_transformer' RSpec.describe Wings::AttributeTransformer, :active_fedora do - let(:id) { 'moomin123' } + let(:id) { 'moomin123' } + let(:based_near) { Hyrax::ControlledVocabularies::Location.new("https://sws.geonames.org/4920808/") } let(:work) { GenericWork.new(id: id, **attributes) } let(:attributes) do { title: ['fake title', 'fake title 2'], contributor: ['user1'], - description: ['a description'] + description: ['a description'], + based_near: [based_near] } end - it "transform the attributes" do - expect(described_class.run(work)) + it "transforms the attributes" do + converted_work = described_class.run(work) + expect(converted_work) .to include title: work.title, contributor: work.contributor.first, description: work.description.first + # ensure that based_near is converted from RDF::URI to URI string during valkyrization + converted_based_near = Array.wrap(converted_work[:based_near]).first + expect(converted_based_near).to be_a(String) + expect(converted_based_near).to eq(work.based_near.first.id) end end