Class: Valkyrie::Persistence::Fedora::ListNode

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

Overview

Represents a node in an ORE List. Used for persisting ordered members into an Resource Description Framework (RDF) Graph for Fedora, to keep order maintained.

RDF graph nodes are used to implement a linked list An RDF hash URI is referenced for the list itself <www.iana.org/assignments/relation/first> is the predicate which links to the first element in the list <www.iana.org/assignments/relation/last> is the predicate which links to the last element Each element is also referenced using a hash URI <www.iana.org/assignments/relation/next> is the predicate which links one element to the next element in the list (This permits unidirectional traversal) <www.openarchives.org/ore/terms/proxyFor> is the predicate which links any given element to its value (These can be IRIs or XML literals supported by a graph store)

Defined Under Namespace

Classes: Builder, Resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_cache, rdf_subject, adapter, graph = RDF::Repository.new) ⇒ ListNode

Returns a new instance of ListNode.

Parameters:

  • node_cache (Hash)

    structure used to cache the nodes of the graph

  • rdf_subject (RDF::URI)

    the URI for the linked list in the graph store (usually a hash URI)

  • adapter
  • graph (RDF::Repository) (defaults to: RDF::Repository.new)

    the RDF graph storing the structure of the RDF statements



29
30
31
32
33
34
35
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 29

def initialize(node_cache, rdf_subject, adapter, graph = RDF::Repository.new)
  @rdf_subject = rdf_subject
  @graph = graph
  @node_cache = node_cache
  @adapter = adapter
  Builder.new(rdf_subject, graph).populate(self)
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



23
24
25
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 23

def adapter
  @adapter
end

#graphObject (readonly)

Returns the value of attribute graph.



19
20
21
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 19

def graph
  @graph
end

#nextRDF::URI

Returns the next proxy or a tail sentinel.

Returns:



39
40
41
42
43
44
45
46
47
48
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 39

def next
  @next ||=
    if next_uri
      node_cache.fetch(next_uri) do
        node = self.class.new(node_cache, next_uri, adapter, graph)
        node.prev = self
        node
      end
    end
end

#next_uri=(value) ⇒ Object

Sets the attribute next_uri

Parameters:

  • value

    the value to set the attribute next_uri to.



21
22
23
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 21

def next_uri=(value)
  @next_uri = value
end

#prevRDF::URI

Returns the previous proxy or a head sentinel.

Returns:



52
53
54
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 52

def prev
  @prev ||= node_cache.fetch(prev_uri) if prev_uri
end

#prev_uri=(value) ⇒ Object

Sets the attribute prev_uri

Parameters:

  • value

    the value to set the attribute prev_uri to.



21
22
23
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 21

def prev_uri=(value)
  @prev_uri = value
end

#proxy_forObject

Returns the value of attribute proxy_for.



22
23
24
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 22

def proxy_for
  @proxy_for
end

#proxy_inObject

Returns the value of attribute proxy_in.



22
23
24
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 22

def proxy_in
  @proxy_in
end

#rdf_subjectObject (readonly)

Returns the value of attribute rdf_subject.



19
20
21
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 19

def rdf_subject
  @rdf_subject
end

Instance Method Details

#targetRDF::URI

Returns or [String].

Returns:



69
70
71
72
73
74
75
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 69

def target
  if target_id.is_a?(Valkyrie::ID)
    adapter.id_to_uri(target_id.to_s)
  else
    target_id
  end
end

#target_idString

Returns:

  • (String)


78
79
80
81
82
83
84
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 78

def target_id
  if proxy_for.to_s.include?("/") && proxy_for.to_s.start_with?(adapter.connection_prefix)
    adapter.uri_to_id(proxy_for)
  else
    proxy_for
  end
end

#to_graphValkyrie::Persistence::Fedora::ListNode::Resource

Graph representation of node.



58
59
60
61
62
63
64
65
66
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 58

def to_graph
  return RDF::Graph.new if target_id.blank?
  g = Resource.new(rdf_subject)
  g.proxy_for = target
  g.proxy_in = proxy_in.try(:uri)
  g.next = self.next.try(:rdf_subject)
  g.prev = prev.try(:rdf_subject)
  g.graph
end