Skip to content

Commit

Permalink
Fixes Wings migration of based_near attribute in to_resource (#6922)
Browse files Browse the repository at this point in the history
* 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.

#6926

---------

Co-authored-by: Rob Kaufman <rob@notch8.com>
  • Loading branch information
laritakr and orangewolf authored Oct 16, 2024
1 parent 0f522be commit ce352d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/wings/transformer_value_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions spec/wings/attribute_transformer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ce352d3

Please sign in to comment.