Class: Triannon::LdpLoader

Inherits:
Object
  • Object
show all
Defined in:
app/services/triannon/ldp_loader.rb

Overview

Loads an existing Annotation from the LDP server

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = nil) ⇒ LdpLoader

Returns a new instance of LdpLoader.

Parameters:

  • id (String) (defaults to: nil)

    the unique id of the annotation. Can include base_uri prefix or omit it.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/triannon/ldp_loader.rb', line 28

def initialize id = nil
  @id = id
  base_url = Triannon.config[:ldp]['url']
  base_url.chop! if base_url.end_with?('/')
  container_path = Triannon.config[:ldp]['uber_container']
  if container_path
    container_path.strip!
    container_path = container_path[1..-1] if container_path.start_with?('/')
    container_path.chop! if container_path.end_with?('/')
  end
  @base_uri = "#{base_url}/#{container_path}"
  @ldp_annotation = Triannon::AnnotationLdp.new

end

Instance Attribute Details

#ldp_annotationObject

Returns the value of attribute ldp_annotation.



25
26
27
# File 'app/services/triannon/ldp_loader.rb', line 25

def ldp_annotation
  @ldp_annotation
end

Class Method Details

.find_allObject

Deprecated.

was needed by old annotations#index action, which now redirects to search (2015-04)



20
21
22
23
# File 'app/services/triannon/ldp_loader.rb', line 20

def self.find_all
  l = Triannon::LdpLoader.new
  l.find_all
end

.load(id) ⇒ Object

Parameters:

  • id (String)

    the unique id of the annotation. Can include base_uri prefix or omit it.



9
10
11
12
13
14
15
16
17
# File 'app/services/triannon/ldp_loader.rb', line 9

def self.load id
  l = Triannon::LdpLoader.new id
  l.load_anno_container
  l.load_bodies
  l.load_targets

  oa_graph = Triannon::LdpToOaMapper.ldp_to_oa l.ldp_annotation
  oa_graph
end

Instance Method Details

#find_allArray<Triannon::Annotation>

Deprecated.

was needed by old annotations#index action, which now redirects to search (2015-04).

Returns an array of Triannon::Annotation objects with just the id set. Enough info to build the index page.

Returns:

  • (Array<Triannon::Annotation>)

    an array of Triannon::Annotation objects with just the id set. Enough info to build the index page



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/services/triannon/ldp_loader.rb', line 66

def find_all
  root_ttl = get_ttl
  objs = []

  g = RDF::Graph.new
  g.from_ttl root_ttl
  root_uri = RDF::URI.new @base_uri
  results = g.query [root_uri, RDF::Vocab::LDP.contains, nil]
  results.each do |stmt|
    # FIXME:  can't be last with pair trees in fedora urls - leave broke as this method is deprecated
    id = stmt.object.to_s.split('/').last
    objs << Triannon::Annotation.new(:id => id)
  end

  objs
end

#load_anno_containerObject

load annotation container object into @ldp_annotation’s (our Triannon::AnnotationLdp object) graph



44
45
46
# File 'app/services/triannon/ldp_loader.rb', line 44

def load_anno_container
  load_object_into_annotation_graph(@id)
end

#load_bodiesObject

load body objects into @ldp_annotation’s (our Triannon::AnnotationLdp object) graph



49
50
51
52
53
54
# File 'app/services/triannon/ldp_loader.rb', line 49

def load_bodies
  @ldp_annotation.body_uris.each { |body_uri|
    body_obj_path = body_uri.to_s.split(@base_uri + '/').last
    load_object_into_annotation_graph(body_obj_path)
  }
end

#load_targetsObject

load target objects into @ldp_annotation’s (our Triannon::AnnotationLdp object) graph



57
58
59
60
61
62
# File 'app/services/triannon/ldp_loader.rb', line 57

def load_targets
  @ldp_annotation.target_uris.each { |target_uri|
    target_obj_path = target_uri.to_s.split(@base_uri + '/').last
    load_object_into_annotation_graph(target_obj_path)
  }
end