Skip to content

Commit

Permalink
Mapping nested URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Aug 29, 2017
1 parent 44f4935 commit 42ac53c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion valkyrie/lib/valkyrie/persistence/solr/resource_factory.rb
Expand Up @@ -170,12 +170,28 @@ def self.handles?(value)
end

def result
NestedResourceConverter.for(JSON.parse(json, symbolize_names: true)).result
NestedResourceConverter.for(convert_uris(JSON.parse(json, symbolize_names: true))).result
end

def json
value.gsub(/^serialized-/, '')
end

def convert_uris(h)
h.map { |k, v| [k, convert_uri_values(v)] }.to_h
end

def convert_uri_values(v)
return RDF::URI.new(v[:@id]) if uri?(v)
return v unless v.is_a?(Array)
v.map do |inner|
uri?(inner) ? ::RDF::URI.new(inner[:@id]) : inner
end
end

def uri?(obj)
obj.is_a?(Hash) && obj[:@id] && obj.length == 1
end
end

class NestedResourceConverter < ::Valkyrie::ValueMapper
Expand Down

0 comments on commit 42ac53c

Please sign in to comment.