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(root_container, 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.

  • root_container (String)

    the LDP parent container for the annotation



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/services/triannon/ldp_loader.rb', line 23

def initialize(root_container, id = nil)
  @id = id
  @root_container = root_container
  if @root_container.blank?
    fail Triannon::LDPContainerError, "Annotations must be in a root container."
  end
  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.



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

def ldp_annotation
  @ldp_annotation
end

Class Method Details

.load(root_container, id) ⇒ Object

Parameters:

  • root_container (String)

    the LDP parent container for the annotation

  • 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(root_container, id)
  l = Triannon::LdpLoader.new(root_container, id)
  l.load_anno_container
  l.load_bodies
  l.load_targets

  oa_graph = Triannon::LdpToOaMapper.ldp_to_oa(l.ldp_annotation, root_container)
  oa_graph
end

Instance Method Details

#load_anno_containerObject

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



42
43
44
# File 'app/services/triannon/ldp_loader.rb', line 42

def load_anno_container
  load_object_into_annotation_graph("#{@root_container}/#{@id}")
end

#load_bodiesObject

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



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

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



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

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