Class: Valkyrie::Persistence::Fedora::Persister::ModelConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/persistence/fedora/persister/model_converter.rb

Overview

Responsible for converting Resource to LDP::Container::Basic

Defined Under Namespace

Classes: BooleanValue, CompositeProperty, DateTimeValue, EnumerableValue, FedoraValue, FloatValue, GraphProperty, IdentifiableValue, IntegerValue, InternalValkyrieID, MappedFedoraValue, NestedInternalValkyrieID, NestedProperty, OrderedMembers, OrderedProperties, Property, SymbolValue, TimeValue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:, adapter:, subject_uri: RDF::URI("")) ⇒ ModelConverter

Returns a new instance of ModelConverter.

Parameters:



12
13
14
15
16
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 12

def initialize(resource:, adapter:, subject_uri: RDF::URI(""))
  @resource = resource
  @adapter = adapter
  @subject_uri = subject_uri
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



6
7
8
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 6

def adapter
  @adapter
end

#resourceObject (readonly)

Returns the value of attribute resource.



6
7
8
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 6

def resource
  @resource
end

#subject_uriObject (readonly)

Returns the value of attribute subject_uri.



6
7
8
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 6

def subject_uri
  @subject_uri
end

Instance Method Details

#convertLdp::Container::Basic

Convert a Valkyrie Resource into a RDF LDP basic container

Returns:

  • (Ldp::Container::Basic)


20
21
22
23
24
25
26
27
28
29
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 20

def convert
  graph_resource.graph.delete([nil, nil, nil])
  properties.each do |property|
    values = resource_attributes[property]

    output = property_converter.for(Property.new(subject_uri, property, values, adapter, resource)).result
    graph_resource.graph << output.to_graph
  end
  graph_resource
end

#graph_resourceLdp::Container::Basic

Construct the LDP Basic Container modeling the Valkyrie Resource in Fedora

Returns:

  • (Ldp::Container::Basic)

See Also:



44
45
46
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 44

def graph_resource
  @graph_resource ||= ::Ldp::Container::Basic.new(connection, subject, nil, base_path)
end

#propertiesArray<Symbol>

Access the Valkyrie attribute names to be used for the Fedora resource properties Filters resource properties to remove properties that should not be persisted to Fedora.

  • new_record is a virtual property for marking unsaved objects

Returns:

  • (Array<Symbol>)


35
36
37
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 35

def properties
  resource_attributes.keys - [:new_record]
end

#property_converterClass

Provide the Class used for values This should be derived from Valkyrie::ValueMapper as a base class

Returns:

  • (Class)


57
58
59
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 57

def property_converter
  FedoraValue
end

#subjectRDF::URI

Generate a URI from the Valkyrie Resource ID to be used as the RDF subject for Fedora LDP resources

Returns:



50
51
52
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 50

def subject
  adapter.id_to_uri(resource.id) if resource.try(:id)
end