Class: Triannon::LdpLoader
- Inherits:
-
Object
- Object
- Triannon::LdpLoader
- Defined in:
- app/services/triannon/ldp_loader.rb
Overview
Loads an existing Annotation from the LDP server
Instance Attribute Summary collapse
-
#ldp_annotation ⇒ Object
Returns the value of attribute ldp_annotation.
Class Method Summary collapse
-
.find_all ⇒ Object
deprecated
Deprecated.
was needed by old annotations#index action, which now redirects to search (2015-04)
- .load(id) ⇒ Object
Instance Method Summary collapse
-
#find_all ⇒ Array<Triannon::Annotation>
deprecated
Deprecated.
was needed by old annotations#index action, which now redirects to search (2015-04).
-
#initialize(id = nil) ⇒ LdpLoader
constructor
A new instance of LdpLoader.
-
#load_anno_container ⇒ Object
load annotation container object into @ldp_annotation’s (our Triannon::AnnotationLdp object) graph.
-
#load_bodies ⇒ Object
load body objects into @ldp_annotation’s (our Triannon::AnnotationLdp object) graph.
-
#load_targets ⇒ Object
load target objects into @ldp_annotation’s (our Triannon::AnnotationLdp object) graph.
Constructor Details
#initialize(id = nil) ⇒ LdpLoader
Returns a new instance of LdpLoader.
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_annotation ⇒ Object
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
Instance Method Details
#find_all ⇒ Array<Triannon::Annotation>
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.
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_container ⇒ Object
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_bodies ⇒ Object
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_targets ⇒ Object
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 |