Class: Triannon::LdpWriter
- Inherits:
-
Object
- Object
- Triannon::LdpWriter
- Defined in:
- app/services/triannon/ldp_writer.rb
Overview
writes data/objects to the LDP server; also does deletes
Class Method Summary collapse
-
.create_anno(anno) ⇒ Object
use LDP protocol to create the OpenAnnotation.Annotation in an RDF store.
-
.delete_container(id) ⇒ Object
(also: delete_anno)
deletes the indicated container and all its child containers from the LDP store.
Instance Method Summary collapse
-
#create_base ⇒ String
creates a stored LDP container for this object’s Annotation, without its targets or bodies (as those are put in descendant containers) SIDE EFFECT: assigns the uuid of the container created to @id.
-
#create_body_container ⇒ Object
creates the LDP container for any and all bodies for this annotation.
-
#create_body_resources ⇒ Object
create the body resources inside the (already created) body container.
-
#create_target_container ⇒ Object
creates the LDP container for any and all targets for this annotation.
-
#create_target_resources ⇒ Object
create the target resources inside the (already created) target container.
-
#delete_containers(ldp_container_uris) ⇒ Object
True if a resource was deleted; false otherwise.
-
#initialize(anno, id = nil) ⇒ LdpWriter
constructor
A new instance of LdpWriter.
Constructor Details
Class Method Details
.create_anno(anno) ⇒ Object
use LDP protocol to create the OpenAnnotation.Annotation in an RDF store
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/services/triannon/ldp_writer.rb', line 8 def self.create_anno(anno) if anno && anno.graph # TODO: special case if the Annotation object already has an id -- # see https://github.com/sul-dlss/triannon/issues/84 ldp_writer = Triannon::LdpWriter.new anno id = ldp_writer.create_base bodies_solns = anno.graph.query([nil, RDF::OpenAnnotation.hasBody, nil]) if bodies_solns.size > 0 ldp_writer.create_body_container ldp_writer.create_body_resources end targets_solns = anno.graph.query([nil, RDF::OpenAnnotation.hasTarget, nil]) # NOTE: Annotation is invalid if there are no target statements if targets_solns.size > 0 ldp_writer.create_target_container ldp_writer.create_target_resources end id end end |
.delete_container(id) ⇒ Object Also known as: delete_anno
deletes the indicated container and all its child containers from the LDP store
36 37 38 39 40 41 |
# File 'app/services/triannon/ldp_writer.rb', line 36 def self.delete_container id if id && id.size > 0 ldpw = Triannon::LdpWriter.new nil ldpw.delete_containers id end end |
Instance Method Details
#create_base ⇒ String
creates a stored LDP container for this object’s Annotation, without its targets or bodies (as those are put in descendant containers)
SIDE EFFECT: assigns the uuid of the container created to @id
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/services/triannon/ldp_writer.rb', line 58 def create_base if @anno.graph.query([nil, RDF::Triannon.externalReference, nil]).count > 0 raise Triannon::ExternalReferenceError, "Incoming annotations may not have http://triannon.stanford.edu/ns/externalReference as a predicate." end if @anno.graph.id_as_url && @anno.graph.id_as_url.size > 0 raise Triannon::ExternalReferenceError, "Incoming new annotations may not have an existing id (yet)." end # TODO: special case if the Annotation object already has an id -- # see https://github.com/sul-dlss/triannon/issues/84 # we need to work with a copy of the graph so we don't change @anno.graph g = RDF::Graph.new @anno.graph.each { |s| g << s } g = Triannon::Graph.new(g) g.remove_non_base_statements g.make_null_relative_uri_out_of_blank_node @id = create_resource g.to_ttl end |
#create_body_container ⇒ Object
creates the LDP container for any and all bodies for this annotation
83 84 85 |
# File 'app/services/triannon/ldp_writer.rb', line 83 def create_body_container create_direct_container RDF::OpenAnnotation.hasBody end |
#create_body_resources ⇒ Object
create the body resources inside the (already created) body container
93 94 95 |
# File 'app/services/triannon/ldp_writer.rb', line 93 def create_body_resources create_resources_in_container RDF::OpenAnnotation.hasBody end |
#create_target_container ⇒ Object
creates the LDP container for any and all targets for this annotation
88 89 90 |
# File 'app/services/triannon/ldp_writer.rb', line 88 def create_target_container create_direct_container RDF::OpenAnnotation.hasTarget end |
#create_target_resources ⇒ Object
create the target resources inside the (already created) target container
98 99 100 |
# File 'app/services/triannon/ldp_writer.rb', line 98 def create_target_resources create_resources_in_container RDF::OpenAnnotation.hasTarget end |
#delete_containers(ldp_container_uris) ⇒ Object
Returns true if a resource was deleted; false otherwise.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/services/triannon/ldp_writer.rb', line 105 def delete_containers ldp_container_uris return false if !ldp_container_uris || ldp_container_uris.empty? if ldp_container_uris.kind_of? String ldp_container_uris = [ldp_container_uris] end something_deleted = false ldp_container_uris.each { |uri| ldp_id = uri.to_s.split(@base_uri + '/').last resp = conn.delete { |req| req.url ldp_id } if resp.status != 204 raise Triannon::LDPStorageError.new("Unable to delete LDP container #{ldp_id}", resp.status, resp.body) end something_deleted = true } something_deleted end |